use of org.eclipse.debug.core.ILaunchListener 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;
}
Aggregations