Permalink
Browse files

fixes broken run/debug actions when having no file selected (see FUSE…

…TOOLS-1165)
  • Loading branch information...
1 parent ee27f05 commit 63399ee3c469a5c8d8a18fc61b99d1ba681f32b7 @lhein lhein committed Jul 22, 2014
@@ -20,7 +20,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IPath;
@@ -104,7 +103,7 @@ public void launch(IEditorPart editor, String mode) {
if (editor != null) {
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
- launch(((IFileEditorInput) editorInput).getFile().getParent(), mode);
+ launchCamelContext(((IFileEditorInput) editorInput).getFile(), mode);
}
}
}
@@ -126,54 +125,33 @@ public void launch(ISelection selection, String mode) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object object = structuredSelection.getFirstElement();
- IContainer basedir = null;
- if (object instanceof IProject || object instanceof IFolder) {
- basedir = (IContainer) object;
- } else if (object instanceof IFile) {
- basedir = ((IFile) object).getParent();
- } else if (object instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) object;
- Object adapter = adaptable.getAdapter(IProject.class);
- if (adapter != null) {
- basedir = (IContainer) adapter;
- } else {
- adapter = adaptable.getAdapter(IFolder.class);
- if (adapter != null) {
- basedir = (IContainer) adapter;
- } else {
- adapter = adaptable.getAdapter(IFile.class);
- if (adapter != null) {
- basedir = ((IFile) object).getParent();
- }
- }
- }
+ if (object instanceof IFile) {
+ launchCamelContext((IFile)object, mode);
}
-
- launch(basedir, mode);
}
}
-
- @SuppressWarnings("deprecation")
- private void launch(IContainer basecon, String mode) {
- if (basecon == null) {
- return;
- }
-
- IContainer basedir = findPomXmlBasedir(basecon);
-
- ILaunchConfiguration launchConfiguration;
- try {
- launchConfiguration = getLaunchConfiguration(basedir, mode);
- if (launchConfiguration == null) {
- launchConfiguration = createLaunchConfiguration(basedir,
- defaultMavenGoals);
- if (launchConfiguration == null) {
- return;
- }
- }
- } catch (InvalidConfigurationException e) {
- return;
- }
+
+ @SuppressWarnings("deprecation")
+ private void launchCamelContext(IFile file, String mode) {
+ if (file == null) {
+ return;
+ }
+
+ IContainer basedir = findPomXmlBasedir(file.getParent());
+
+ ILaunchConfiguration launchConfiguration;
+ try {
+ launchConfiguration = getLaunchConfiguration(basedir, mode);
+ if (launchConfiguration == null) {
+ launchConfiguration = createLaunchConfiguration(basedir,
+ defaultMavenGoals);
+ if (launchConfiguration == null) {
+ return;
+ }
+ }
+ } catch (InvalidConfigurationException e) {
+ return;
+ }
boolean isWARPackaging = false;
try {
@@ -189,11 +167,11 @@ private void launch(IContainer basecon, String mode) {
Activator.getLogger().error(ex);
MessageDialog.openError(getShell(), "Unable to launch...", "An error occured when trying to launch the project. Message: " + ex.getMessage());
return;
- }
- boolean openDialog = showDialog;
- if (!openDialog) {
- try {
- // if no goals specified
+ }
+ boolean openDialog = showDialog;
+ if (!openDialog) {
+ try {
+ // if no goals specified
String goals = lc.getAttribute(MavenLaunchConstants.ATTR_GOALS, (String) null);
if (Strings.isBlank(goals)) {
goals = isWARPackaging ? CamelContextLaunchConfigConstants.DEFAULT_MAVEN_GOALS_WAR : CamelContextLaunchConfigConstants.DEFAULT_MAVEN_GOALS_JAR;
@@ -205,14 +183,18 @@ private void launch(IContainer basecon, String mode) {
// add
goals = isWARPackaging ? CamelContextLaunchConfigConstants.DEFAULT_MAVEN_GOALS_WAR : CamelContextLaunchConfigConstants.DEFAULT_MAVEN_GOALS_JAR;
}
- }
- openDialog = Strings.isBlank(goals);
+ }
+ // no rider file selection
+ if (Strings.isBlank(lc.getAttribute(CamelContextLaunchConfigConstants.ATTR_FILE, ""))) {
+ lc.setAttribute(CamelContextLaunchConfigConstants.ATTR_FILE, file.getLocation().toOSString());
+ }
+ openDialog = Strings.isBlank(goals) || Strings.isBlank(lc.getAttribute(CamelContextLaunchConfigConstants.ATTR_FILE, ""));
lc.setAttribute(MavenLaunchConstants.ATTR_GOALS, goals);
- } catch (CoreException ex) {
- Activator.getLogger().error("Error getting the maven goals from the configuration.", ex);
- }
- }
-
+ } catch (CoreException ex) {
+ Activator.getLogger().error("Error getting the maven goals from the configuration.", ex);
+ }
+ }
+
if (openDialog) {
String category = "org.fusesource.ide.launcher.ui.runCamelLaunchGroup";
if (mode == ILaunchManager.DEBUG_MODE) {
@@ -223,48 +205,48 @@ private void launch(IContainer basecon, String mode) {
}
}
- try {
- final ILaunch launch = lc.launch(mode, new NullProgressMonitor());
- if (postProcessor != null) {
-
- // TODO would be nice to avoid the thread here but I guess there's no other way?
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- while (!launch.isTerminated()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- }
-
- IProcess[] processes = launch.getProcesses();
- boolean failed = false;
- for (IProcess process : processes) {
- try {
- if (process.getExitValue() != 0) {
- failed = true;
- break;
- }
- } catch (DebugException e) {
- Activator.getLogger().error("Failed to get exit code of build process", e);
- }
- }
- // only invoke post processor on sucess
- if (!failed) {
- postProcessor.executeOnSuccess();
- } else {
- postProcessor.executeOnFailure();
- }
- }
- });
- t.setDaemon(false);
- t.start();
- }
- } catch (CoreException ex) {
- DebugUITools.launch(lc, mode);
- }
- }
+ try {
+ final ILaunch launch = lc.launch(mode, new NullProgressMonitor());
+ if (postProcessor != null) {
+
+ // TODO would be nice to avoid the thread here but I guess there's no other way?
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!launch.isTerminated()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ IProcess[] processes = launch.getProcesses();
+ boolean failed = false;
+ for (IProcess process : processes) {
+ try {
+ if (process.getExitValue() != 0) {
+ failed = true;
+ break;
+ }
+ } catch (DebugException e) {
+ Activator.getLogger().error("Failed to get exit code of build process", e);
+ }
+ }
+ // only invoke post processor on sucess
+ if (!failed) {
+ postProcessor.executeOnSuccess();
+ } else {
+ postProcessor.executeOnFailure();
+ }
+ }
+ });
+ t.setDaemon(false);
+ t.start();
+ }
+ } catch (CoreException ex) {
+ DebugUITools.launch(lc, mode);
+ }
+ }
private Shell getShell() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

0 comments on commit 63399ee

Please sign in to comment.