diff --git a/org.eclim.core/java/org/eclim/plugin/core/command/project/EclimLaunchManager.java b/org.eclim.core/java/org/eclim/plugin/core/command/project/EclimLaunchManager.java index 545080cf4..51b8e3ab3 100644 --- a/org.eclim.core/java/org/eclim/plugin/core/command/project/EclimLaunchManager.java +++ b/org.eclim.core/java/org/eclim/plugin/core/command/project/EclimLaunchManager.java @@ -31,44 +31,14 @@ */ public class EclimLaunchManager implements Runnable { - - public interface OutputHandler - { - /** - * NB: If your OutputHandler's prepare might take - * a non-trivial amount of time, you MUST - * queue up any outputs that come along before - * you started. Future work could abstract that - * out as necessary - */ - public void prepare(final String launchId) - throws Exception; - public void sendErr(String line); - public void sendOut(String line); - public void sendTerminated(); - } - - static class LaunchSet - { - final String id; - final ILaunch launch; - final OutputHandler output; - - LaunchSet(String id, ILaunch launch, OutputHandler output) - { - this.id = id; - this.launch = launch; - this.output = output; - } - } - - static HashMap sLaunches = new HashMap(); - static Thread thread; + private static HashMap sLaunches = + new HashMap(); + private static Thread thread; @Override public void run() { - for (;;) { + while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { @@ -81,7 +51,7 @@ public void run() } } - static synchronized void cleanLaunches() + private static synchronized void cleanLaunches() { Iterator iter = sLaunches.values().iterator(); while (iter.hasNext()) { @@ -114,7 +84,7 @@ public static synchronized boolean terminate(final String launchId) return true; } - static void terminate(final LaunchSet set) + private static void terminate(final LaunchSet set) throws DebugException { if (set.launch.isTerminated()) { @@ -146,7 +116,8 @@ public static synchronized void terminateAll() * to perform it. The original exception can be retreived * from #getCause() */ - public static synchronized void manage(final ILaunch launch, + public static synchronized void manage( + final ILaunch launch, final OutputHandler output) throws IllegalArgumentException { @@ -182,8 +153,12 @@ public void streamAppended(String text, IStreamMonitor monitor) // dump buffered content, if any final String pendingOut = stdout.getContents(); final String pendingErr = stderr.getContents(); - if (pendingOut.length() > 0) output.sendOut(pendingOut); - if (pendingErr.length() > 0) output.sendErr(pendingErr); + if (pendingOut.length() > 0){ + output.sendOut(pendingOut); + } + if (pendingErr.length() > 0){ + output.sendErr(pendingErr); + } // attach listeners stdout.addListener(outListener); @@ -205,11 +180,10 @@ public void streamAppended(String text, IStreamMonitor monitor) // re-raise throw new IllegalArgumentException( - "OutputHandler does not support async output", - e); + "OutputHandler does not support async output", e); } - sLaunches.put(id, new LaunchSet(id, launch, output)); + sLaunches.put(id, new LaunchSet(launch, output)); if (thread == null) { thread = new Thread(new EclimLaunchManager()); @@ -218,7 +192,7 @@ public void streamAppended(String text, IStreamMonitor monitor) } } - static synchronized String allocateId(ILaunch launch) + private static synchronized String allocateId(ILaunch launch) { final String name = launch.getLaunchConfiguration().getName(); if (!sLaunches.containsKey(name)) { @@ -237,8 +211,36 @@ static synchronized String allocateId(ILaunch launch) return id; } - static synchronized void remove(String id) + private static synchronized void remove(String id) { sLaunches.remove(id); } + + public interface OutputHandler + { + /** + * NB: If your OutputHandler's prepare might take + * a non-trivial amount of time, you MUST + * queue up any outputs that come along before + * you started. Future work could abstract that + * out as necessary + */ + public void prepare(final String launchId) + throws Exception; + public void sendErr(String line); + public void sendOut(String line); + public void sendTerminated(); + } + + private static class LaunchSet + { + final ILaunch launch; + final OutputHandler output; + + LaunchSet(ILaunch launch, OutputHandler output) + { + this.launch = launch; + this.output = output; + } + } } diff --git a/org.eclim.core/java/org/eclim/plugin/core/command/project/ProjectRunCommand.java b/org.eclim.core/java/org/eclim/plugin/core/command/project/ProjectRunCommand.java index 589e45223..9f583ce43 100644 --- a/org.eclim.core/java/org/eclim/plugin/core/command/project/ProjectRunCommand.java +++ b/org.eclim.core/java/org/eclim/plugin/core/command/project/ProjectRunCommand.java @@ -100,7 +100,7 @@ public Object execute(CommandLine commandLine) // find the actual mode for that group final String mode = getGroupMode(group); if (mode == null) { - throw new IllegalStateException("Invalid group mode. Should never happen"); + throw new IllegalStateException("Invalid group mode. Should never happen"); } // get the requested project @@ -210,7 +210,7 @@ public Object execute(CommandLine commandLine) } } - ILaunchConfiguration findConfiguration( + private ILaunchConfiguration findConfiguration( final Iterable configs, final String name) { @@ -223,7 +223,7 @@ ILaunchConfiguration findConfiguration( return null; } - String getGroupMode(final String groupId) + private String getGroupMode(final String groupId) { final ILaunchGroup[] groups = DebugUITools.getLaunchGroups(); for (final ILaunchGroup group : groups) { @@ -235,7 +235,7 @@ String getGroupMode(final String groupId) return null; } - IProject getProject(ILaunchConfiguration config) + private IProject getProject(ILaunchConfiguration config) throws Exception { @@ -251,7 +251,8 @@ IProject getProject(ILaunchConfiguration config) return resources[0].getProject(); } - abstract static class UpdatingProgressMonitor implements IProgressMonitor + private abstract static class UpdatingProgressMonitor + implements IProgressMonitor { final String completionMessage; @@ -267,9 +268,9 @@ public UpdatingProgressMonitor(final String completionMessage) @Override public void beginTask(String name, int totalWork) { - logger.info("Begin: " + name + " / " + totalWork); - baseTask = name; - currentTask = baseTask; + logger.info("Begin: " + name + " / " + totalWork); + baseTask = name; + currentTask = baseTask; } @Override @@ -287,15 +288,15 @@ public void done() @Override public void internalWorked(double work) { - logger.info("Internal..." + work); - totalProgress += work; - sendProgress(); + logger.info("Internal..." + work); + totalProgress += work; + sendProgress(); } @Override public boolean isCanceled() { - return false; + return false; } @Override @@ -350,10 +351,9 @@ public abstract void sendProgress(double percent, String label) throws Exception; } - static class NullUpdatingProgressMonitor extends UpdatingProgressMonitor + private static class NullUpdatingProgressMonitor extends UpdatingProgressMonitor { - - NullUpdatingProgressMonitor(final String completionMessage) + public NullUpdatingProgressMonitor(final String completionMessage) { super(completionMessage); } @@ -372,12 +372,12 @@ public void sendProgress(double percent, String label) } - static class VimUpdatingProgressMonitor extends UpdatingProgressMonitor + private static class VimUpdatingProgressMonitor extends UpdatingProgressMonitor { + private final VimClient client; - final VimClient client; - - public VimUpdatingProgressMonitor(final VimClient client, + public VimUpdatingProgressMonitor( + final VimClient client, final String completionMessage) { super(completionMessage); @@ -401,9 +401,10 @@ public void sendProgress(final double percent, final String label) } - static class NullOutputHandler implements OutputHandler + private static class NullOutputHandler implements OutputHandler { - @Override public void prepare(String launchId) + @Override + public void prepare(String launchId) throws Exception { // NB client-specific errors can be returned here in the future, @@ -413,29 +414,24 @@ static class NullOutputHandler implements OutputHandler "Example: vim --servername "); } - @Override public void sendErr(String line) {} - @Override public void sendOut(String line) {} - @Override public void sendTerminated() {} - } + @Override + public void sendErr(String line) {} - static class VimOutputHandler implements OutputHandler - { + @Override + public void sendOut(String line) {} - static final class PendingOutput - { - final String type, line; - PendingOutput(String type, String line) - { - this.type = type; - this.line = line; - } - } + @Override + public void sendTerminated() {} + } - final VimClient client; - final String configName; - final ArrayList pendingOutput = new ArrayList(); + private static class VimOutputHandler implements OutputHandler + { + private final VimClient client; + private final String configName; + private final ArrayList pendingOutput = + new ArrayList(); - String bufNo; + private String bufNo; public VimOutputHandler(VimClient client, String configName) { @@ -479,7 +475,7 @@ public void sendTerminated() sendLine("terminated", ""); } - void sendLine(String type, String line) + private void sendLine(String type, String line) { if (bufNo == null) { // not prepared yet; queue for later @@ -496,19 +492,35 @@ void sendLine(String type, String line) // functionExpr is safer, in case they're in input mode client.remoteFunctionExpr("eclim#project#run#onOutput", bufNo, type, clean); } catch (Exception e) { + logger.error("error", e); // no worries } } + + private static final class PendingOutput + { + private final String type; + private final String line; + + public PendingOutput(String type, String line) + { + this.type = type; + this.line = line; + } + } } - static class LaunchJob extends Job + private static class LaunchJob + extends Job { final ILaunchConfiguration config; final IProgressMonitor monitor; final OutputHandler output; - public LaunchJob(ILaunchConfiguration config, IProgressMonitor monitor, - final OutputHandler output) + public LaunchJob( + ILaunchConfiguration config, + IProgressMonitor monitor, + OutputHandler output) { super("Eclim Launch"); @@ -525,7 +537,8 @@ public IStatus run(IProgressMonitor ignore) // By default, ProcessConsoleManager will attach a ProcessConsole // that will steal any buffered output. Rude. Let's muzzle it // for a second while we launch so it won't steal our output - ProcessConsoleManager consoleMgr = DebugUIPlugin.getDefault().getProcessConsoleManager(); + ProcessConsoleManager consoleMgr = + DebugUIPlugin.getDefault().getProcessConsoleManager(); ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager(); launchMgr.removeLaunchListener(consoleMgr); @@ -540,32 +553,13 @@ public IStatus run(IProgressMonitor ignore) logger.info("Launched: " + launch); } catch (IllegalArgumentException e) { logger.error("Launch terminated; async not supported", e); - return new Status(Status.ERROR, "eclim", "Unable to capture async output", e); + return new Status( + Status.ERROR, "eclim", "Unable to capture async output", e); } catch (Exception e) { logger.error("Launch terminated; Unexpected Error", e); return new Status(Status.ERROR, "eclim", "Error while launching", e); } return Status.OK_STATUS; } - - private IStatus errorStatus(int kind, String message, - Exception e) { - final IStatus result = new Status(kind, "eclim", message, e); - if (!(monitor instanceof NullUpdatingProgressMonitor) - && (monitor instanceof UpdatingProgressMonitor)) { - // if we're in async mode, we should try to report the problem - try { - StringBuilder builder = new StringBuilder(message); - if (e != null && e.getMessage() != null && !"".equals(e.getMessage())) { - builder.append(": ") - .append(e.getMessage()); - } - ((UpdatingProgressMonitor) monitor).sendMessage(builder.toString()); - } catch (Exception ignore) { - // we did our best, but there's nothing more we can do - } - } - return result; - } } }