AIDEGen: Only generating .idea folder for main project.

Bug: 137517578
Test: 1. Patch CL: aosp/1014358
      2. Remove the iml files and .idea folder under Settings and
         SettingsLib.
      3. m aidegen;aidegen-dev Settings SettingsLib
      4. Check the folder .idea only exists in packages/apps/Settings,
         not in frameworks/base/packages/SettingsLib.

Change-Id: I5241d2fc7efd2efa7e00736578db5e3ca959169b
diff --git a/aidegen/lib/project_file_gen.py b/aidegen/lib/project_file_gen.py
index 50caf2c..4ee270b 100644
--- a/aidegen/lib/project_file_gen.py
+++ b/aidegen/lib/project_file_gen.py
@@ -192,9 +192,10 @@
         source_dict.update(
             self._generate_source_section('test_folder_path', True))
         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()
+        self.project_info.git_path = self._get_project_git_path()
+        if self.project_info.is_main_project:
+            self._generate_modules_xml(iml_path_list)
+            self._copy_constant_project_files()
 
     @classmethod
     def generate_ide_project_files(cls, projects):
@@ -519,13 +520,8 @@
         target_path = os.path.join(module_path, _IDEA_FOLDER, _MODULES_XML)
         common_util.file_generate(target_path, content)
 
-    def _generate_vcs_xml(self):
-        """Generate vcs.xml file.
-
-        IntelliJ use vcs.xml to record version control software's information.
-        Since we are using a single project file, it will only contain the
-        module itself. If there is no git folder inside, it would find it in
-        parent's folder.
+    def _get_project_git_path(self):
+        """Get the project's git path.
 
         Return:
             String: A module's git path.
@@ -543,7 +539,6 @@
             if git_path == os.sep:
                 logging.warning('%s can\'t find its .git folder', module_path)
                 return None
-        _write_vcs_xml(module_path, [git_path])
         return git_path
 
 
diff --git a/aidegen/lib/project_file_gen_unittest.py b/aidegen/lib/project_file_gen_unittest.py
index dac5c0c..ace6ec6 100644
--- a/aidegen/lib/project_file_gen_unittest.py
+++ b/aidegen/lib/project_file_gen_unittest.py
@@ -176,28 +176,30 @@
             self._MAIN_MODULE_XML_SAMPLE)
         self.assertEqual(test_module, sample_module)
 
+    @mock.patch('os.path.isdir')
     @mock.patch('aidegen.lib.project_info.ProjectInfo')
-    def test_generate_vcs_xml(self, mock_project):
-        """Test _generate_vcs_xml."""
-        mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
-        try:
-            git_path = os.path.join(self._ANDROID_PROJECT_PATH,
-                                    project_file_gen._GIT_FOLDER_NAME)
-            if not os.path.exists(git_path):
-                os.mkdir(git_path)
-            pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
-            pfile_gen._generate_vcs_xml()
-            test_vcs = common_util.read_file_content(self._VCS_PATH)
-        finally:
-            shutil.rmtree(git_path)
+    def test_get_project_git_path(self, mock_project, mock_isdir):
+        """Test _get_project_git_path."""
+        mock_project.project_absolute_path = '/a/b'
+        mock_isdir.return_value = True
+        expected_git_path = '/a/b'
+        pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
+        test_git_path = pfile_gen._get_project_git_path()
+        self.assertEqual(test_git_path, expected_git_path)
+
+    @mock.patch('aidegen.lib.project_info.ProjectInfo')
+    def test_merge_project_vcs_xmls(self, mock_project):
+        """Test _merge_project_vcs_xmls."""
+        mock_project.project_absolute_path = (
+            unittest_constants.ANDROID_PROJECT_PATH)
+        mock_project.git_path = unittest_constants.ANDROID_PROJECT_PATH
+        project_file_gen._merge_project_vcs_xmls([mock_project])
+        test_vcs = common_util.read_file_content(self._VCS_PATH)
         sample_vcs = common_util.read_file_content(self._VCS_XML_SAMPLE)
         # The sample must base on the real path.
         sample_vcs = sample_vcs.replace(self._LOCAL_PATH_TOKEN,
                                         self._ANDROID_PROJECT_PATH)
         self.assertEqual(test_vcs, sample_vcs)
-        mock_project.project_absolute_path = common_util.get_android_root_dir()
-        pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
-        self.assertIsNone(pfile_gen._generate_vcs_xml())
 
     def test_get_uniq_iml_name(self):
         """Test the unique name cache mechanism.