Search in sources :

Example 1 with LaunchAdapter

use of com.liferay.ide.core.adapter.LaunchAdapter in project liferay-ide by liferay.

the class MavenUIProjectBuilder method runMavenGoal.

public IStatus runMavenGoal(IMavenProjectFacade projectFacade, String goal, String mode, IProgressMonitor monitor) throws CoreException {
    IStatus retval = Status.OK_STATUS;
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(MavenLaunchConstants.LAUNCH_CONFIGURATION_TYPE_ID);
    IPath basedirLocation = getProject().getLocation();
    String newName = launchManager.generateLaunchConfigurationName(basedirLocation.lastSegment());
    ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null, newName);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_POM_DIR, basedirLocation.toString());
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_GOALS, goal);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_UPDATE_SNAPSHOTS, Boolean.TRUE);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_WORKSPACE_RESOLUTION, Boolean.TRUE);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_SKIP_TESTS, Boolean.TRUE);
    if (projectFacade != null) {
        ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
        String selectedProfiles = configuration.getSelectedProfiles();
        if ((selectedProfiles != null) && (selectedProfiles.length() > 0)) {
            workingCopy.setAttribute(MavenLaunchConstants.ATTR_PROFILES, selectedProfiles);
        }
        /*
			 * <?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration
			 * type="org.eclipse.m2e.Maven2LaunchConfigurationType"> <booleanAttribute
			 * key="M2_DEBUG_OUTPUT" value="false"/> <booleanAttribute
			 * key="M2_NON_RECURSIVE" value="false"/> <booleanAttribute key="M2_OFFLINE"
			 * value="false"/> <stringAttribute key="M2_PROFILES" value="v6.2.0"/>
			 * <listAttribute key="M2_PROPERTIES"/> <stringAttribute key="M2_RUNTIME"
			 * value="EMBEDDED"/> <intAttribute key="M2_THREADS" value="1"/>
			 * <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY"
			 * value="D:/dev java/workspaces/runtime-eclipse-ide-juno-sr2/WorldDatabase/WorldDatabase-portlet"
			 * /> </launchConfiguration>
			 */
        UIJob launchJob = new UIJob("maven launch") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                DebugUITools.launch(workingCopy, mode);
                return Status.OK_STATUS;
            }
        };
        boolean[] launchTerminated = new boolean[1];
        ILaunchListener[] listener = new ILaunchListener[1];
        listener[0] = new LaunchAdapter() {

            public void launchChanged(ILaunch launch) {
                if (launch.getLaunchConfiguration().equals(workingCopy)) {
                    Thread t = new Thread() {

                        @Override
                        public void run() {
                            while ((launch.getProcesses().length > 0) && !launch.getProcesses()[0].isTerminated()) {
                                try {
                                    sleep(100);
                                } catch (InterruptedException ie) {
                                }
                            }
                            launchTerminated[0] = true;
                            ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
                            launchManager.removeLaunchListener(listener[0]);
                        }
                    };
                    t.start();
                }
            }
        };
        launchManager = DebugPlugin.getDefault().getLaunchManager();
        launchManager.addLaunchListener(listener[0]);
        launchJob.schedule();
        while ((Display.getCurrent() == null) && !launchTerminated[0]) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
            }
        }
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) UIJob(org.eclipse.ui.progress.UIJob) LaunchAdapter(com.liferay.ide.core.adapter.LaunchAdapter) ILaunchListener(org.eclipse.debug.core.ILaunchListener)

Aggregations

LaunchAdapter (com.liferay.ide.core.adapter.LaunchAdapter)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 ILaunch (org.eclipse.debug.core.ILaunch)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 ILaunchListener (org.eclipse.debug.core.ILaunchListener)1 ILaunchManager (org.eclipse.debug.core.ILaunchManager)1 ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)1 UIJob (org.eclipse.ui.progress.UIJob)1