AIDEGen: Check the target is the main project by the target sequence
am: a9d18347a8

Change-Id: Ia9e9691664b9471adc927edae54b87a2f7377fa6
diff --git a/aidegen/lib/project_file_gen.py b/aidegen/lib/project_file_gen.py
index 06edfa7..50caf2c 100644
--- a/aidegen/lib/project_file_gen.py
+++ b/aidegen/lib/project_file_gen.py
@@ -188,12 +188,10 @@
             iml_path_list: An optional list of submodule's iml paths, the
                            default value is None.
         """
-        is_main_module = iml_path_list is not None
         source_dict = self._generate_source_section('source_folder_path', False)
         source_dict.update(
             self._generate_source_section('test_folder_path', True))
-        self.project_info.iml_path, _ = self._generate_iml(source_dict,
-                                                           is_main_module)
+        self.project_info.iml_path, _ = self._generate_iml(source_dict)
         self._generate_modules_xml(iml_path_list)
         self.project_info.git_path = self._generate_vcs_xml()
         self._copy_constant_project_files()
@@ -423,7 +421,7 @@
         return content.replace(_SRCJAR_TOKEN + '\n', '')
 
     # pylint: disable=too-many-locals
-    def _generate_iml(self, source_dict, is_main_module=False):
+    def _generate_iml(self, source_dict):
         """Generate iml file.
 
         Args:
@@ -431,8 +429,6 @@
                          the path is test or source folder in IntelliJ.
                          e.g.
                          {'path_a': True, 'path_b': False}
-            is_main_module: A boolean with default False, True if the current
-                            project is the main module.
 
         Returns:
             String: The absolute paths of module iml and dependencies iml.
@@ -464,7 +460,7 @@
 
         # Only generate the dependencies.iml in the main module's folder.
         dependencies_iml_path = None
-        if is_main_module:
+        if self.project_info.is_main_project:
             dependencies_content = constant.FILE_IML.replace(_FACET_TOKEN, '')
             dependencies_content = self._handle_source_folder(
                 dependencies_content, source_dict, False)
diff --git a/aidegen/lib/project_file_gen_unittest.py b/aidegen/lib/project_file_gen_unittest.py
index 4533c8a..dac5c0c 100644
--- a/aidegen/lib/project_file_gen_unittest.py
+++ b/aidegen/lib/project_file_gen_unittest.py
@@ -131,8 +131,7 @@
         # Test for main project.
         try:
             iml_path, dependencies_iml_path = pfile_gen._generate_iml(
-                copy.deepcopy(unittest_constants.ANDROID_SOURCE_DICT),
-                is_main_module=True)
+                copy.deepcopy(unittest_constants.ANDROID_SOURCE_DICT))
             test_iml = common_util.read_file_content(iml_path)
             sample_iml = common_util.read_file_content(self._IML_SAMPLE)
         finally:
diff --git a/aidegen/lib/project_info.py b/aidegen/lib/project_info.py
index 4dd6591..aa9b9f2 100644
--- a/aidegen/lib/project_info.py
+++ b/aidegen/lib/project_info.py
@@ -77,22 +77,26 @@
                                   e.g. out/.../aapt2.srcjar!/
                                   The "!/" is a content descriptor for
                                   compressed files in IntelliJ.
+        is_main_project: A boolean to verify the project is main project.
     """
 
     modules_info = None
     config = None
 
-    def __init__(self, target=None):
+    def __init__(self, target=None, is_main_project=False):
         """ProjectInfo initialize.
 
         Args:
             target: Includes target module or project path from user input, when
                     locating the target, project with matching module name of
                     the given target has a higher priority than project path.
+            is_main_project: A boolean, default is False. True if the target is
+                             the main project, otherwise False.
         """
         rel_path, abs_path = common_util.get_related_paths(self.modules_info,
                                                            target)
         self.module_name = self._get_target_name(target, abs_path)
+        self.is_main_project = is_main_project
         self.project_module_names = set(
             self.modules_info.get_module_names(rel_path))
         self.project_relative_path = rel_path
@@ -261,7 +265,7 @@
         Returns:
             List: A list of ProjectInfo instances.
         """
-        return [ProjectInfo(target) for target in targets]
+        return [ProjectInfo(target, i == 0) for i, target in enumerate(targets)]
 
     @staticmethod
     def _get_target_name(target, abs_path):
diff --git a/aidegen/lib/project_info_unittest.py b/aidegen/lib/project_info_unittest.py
index 96ea627..b3c9e7a 100644
--- a/aidegen/lib/project_info_unittest.py
+++ b/aidegen/lib/project_info_unittest.py
@@ -63,7 +63,7 @@
         mock_module_info.get_paths.return_value = ['m1']
         mock_module_info.get_module_names.return_value = ['m1']
         project_info.ProjectInfo.modules_info = mock_module_info
-        proj_info = project_info.ProjectInfo(self.args.module_name)
+        proj_info = project_info.ProjectInfo(self.args.module_name, False)
         self.assertEqual(proj_info.dep_modules, _EXPECT_DEPENDENT_MODULES)
 
     def test_is_a_target_module(self):