Merge "AIDEGen: Create an empty workspace in Eclipse for AIDEGen project."
diff --git a/aidegen/aidegen_main.py b/aidegen/aidegen_main.py
index 264533d..e3ac917 100644
--- a/aidegen/aidegen_main.py
+++ b/aidegen/aidegen_main.py
@@ -71,6 +71,12 @@
 _CONGRATULATION = common_util.COLORED_PASS('CONGRATULATION:')
 _LAUNCH_SUCCESS_MSG = (
     'IDE launched successfully. Please check your IDE window.')
+_LAUNCH_ECLIPSE_SUCCESS_MSG = (
+    'The project files .classpath and .project are generated under '
+    '{PROJECT_PATH} and AIDEGen doesn\'t import the project automatically, '
+    'please import the project manually by steps: File -> Import -> select \''
+    'General\' -> \'Existing Projects into Workspace\' -> click \'Next\' -> '
+    'Choose the root directory -> click \'Finish\'.')
 _IDE_CACHE_REMINDER_MSG = (
     'To prevent the existed IDE cache from impacting your IDE dependency '
     'analysis, please consider to clear IDE caches if necessary. To do that, in'
@@ -208,7 +214,13 @@
     """
     ide_util_obj.config_ide(project_absolute_path)
     ide_util_obj.launch_ide()
-    print('\n{} {}\n'.format(_CONGRATULATION, _LAUNCH_SUCCESS_MSG))
+    if ide_util_obj.ide_name() == constant.IDE_ECLIPSE:
+        launch_msg = ' '.join([_LAUNCH_SUCCESS_MSG,
+                               _LAUNCH_ECLIPSE_SUCCESS_MSG.format(
+                                   PROJECT_PATH=project_absolute_path)])
+    else:
+        launch_msg = _LAUNCH_SUCCESS_MSG
+    print('\n{} {}\n'.format(_CONGRATULATION, launch_msg))
 
 
 def _check_native_projects(targets, ide):
diff --git a/aidegen/lib/ide_util.py b/aidegen/lib/ide_util.py
index a1c6687..2a45022 100644
--- a/aidegen/lib/ide_util.py
+++ b/aidegen/lib/ide_util.py
@@ -47,6 +47,13 @@
 _IML_EXTENSION = '.iml'
 _JDK_PATH_TOKEN = '@JDKpath'
 _COMPONENT_END_TAG = '  </component>'
+_ECLIPSE_WS = '~/Documents/AIDEGen_Eclipse_workspace'
+_ALERT_CREATE_WS = ('AIDEGen will create a workspace at %s for Eclipse, '
+                    'Enter `y` to allow AIDEgen to automatically create the '
+                    'workspace for you. Otherwise, you need to select the '
+                    'workspace after Eclipse is launched.\nWould you like '
+                    'AIDEgen to automatically create the workspace for you?'
+                    '(y/n)' % _ECLIPSE_WS)
 
 
 class IdeUtil:
@@ -551,6 +558,9 @@
 class IdeEclipse(IdeBase):
     """Class offers a set of Eclipse launching utilities.
 
+    Attributes:
+        cmd: A list of the build command.
+
     For example:
         1. Check if Eclipse is installed.
         2. Launch an Eclipse.
@@ -560,6 +570,7 @@
         super().__init__(installed_path, config_reset)
         self._ide_name = constant.IDE_ECLIPSE
         self._bin_file_name = 'eclipse'
+        self.cmd = []
 
     def _get_script_from_system(self):
         """Get correct IDE installed path from internal path.
@@ -590,6 +601,23 @@
         logging.error('No %s installed.', self._ide_name)
         return None
 
+    def _get_ide_cmd(self):
+        """Compose launch IDE command to run a new process and redirect output.
+
+        AIDEGen will create a default workspace
+        ~/Documents/AIDEGen_Eclipse_workspace for users if they agree to do
+        that. Also, we could not import the default project through the command
+        line so remove the project path argument.
+
+        Returns:
+            A string of launch IDE command.
+        """
+        if (os.path.exists(os.path.expanduser(_ECLIPSE_WS))
+                or str(input(_ALERT_CREATE_WS)).lower() == 'y'):
+            self.cmd.extend(['-data', _ECLIPSE_WS])
+        self.cmd.extend([_IGNORE_STD_OUT_ERR_CMD, '&'])
+        return ' '.join(self.cmd)
+
 
 class IdeLinuxEclipse(IdeEclipse):
     """Class offers a set of Eclipse launching utilities for OS Linux.
@@ -604,6 +632,7 @@
         self._bin_folders = ['/opt/eclipse*', '/usr/bin/']
         self._bin_paths = self._get_possible_bin_paths()
         self._init_installed_path(installed_path)
+        self.cmd = [_NOHUP, self._installed_path.replace(' ', r'\ ')]
 
 
 class IdeMacEclipse(IdeEclipse):
@@ -620,17 +649,7 @@
         self._bin_folders = [os.path.expanduser('~/eclipse/**')]
         self._bin_paths = self._get_possible_bin_paths()
         self._init_installed_path(installed_path)
-
-    def _get_ide_cmd(self):
-        """Compose launch IDE command to run a new process and redirect output.
-
-        Returns:
-            A string of launch IDE command.
-        """
-        return ' '.join([
-            self._installed_path.replace(' ', r'\ '),
-            os.path.dirname(self.project_abspath), _IGNORE_STD_OUT_ERR_CMD, '&'
-        ])
+        self.cmd = [self._installed_path.replace(' ', r'\ ')]
 
 
 class IdeCLion(IdeBase):
@@ -800,8 +819,11 @@
         ide_name: the IDE name is to be launched.
     """
     assert project_path, 'Empty content path is not allowed.'
-    logging.info('Launch %s for project content path: %s.', ide_name,
-                 project_path)
+    if ide_name == constant.IDE_ECLIPSE:
+        logging.info('Launch %s with workspace: %s.', ide_name, _ECLIPSE_WS)
+    else:
+        logging.info('Launch %s for project content path: %s.', ide_name,
+                     project_path)
     _run_ide_sh(run_ide_cmd, project_path)