diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index adc4e58fb191..2b6b378e1ef4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -530,7 +530,7 @@ public class BuildManager implements ApplicationComponent{ } myBuildsInProgress.put(projectPath, future); final Process process = launchBuildProcess(project, myListenPort, sessionId); - final OSProcessHandler processHandler = new OSProcessHandler(process, null) { + final OSProcessHandler processHandler = new OSProcessHandler(process) { @Override protected boolean shouldDestroyProcessRecursively() { return true; diff --git a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java index eea9d00d4d53..8ba6c29612f6 100644 --- a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java +++ b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java @@ -254,6 +254,7 @@ public class ExecutionHelper { } } + /** @deprecated use lookup by user data (to remove in IDEA 13) */ public static Collection findRunningConsoleByCmdLine(final Project project, @NotNull final NotNullFunction cmdLineMatcher) { return findRunningConsole(project, new NotNullFunction() { diff --git a/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java index 843210d58ed5..e79694719284 100644 --- a/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,14 +27,23 @@ import java.util.concurrent.Future; public class OSProcessHandler extends BaseOSProcessHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.execution.process.OSProcessHandler"); + private boolean myDestroyRecursively = false; - public OSProcessHandler(@NotNull final Process process, @Nullable final String commandLine, final Charset defaultCharset) { - super(process, commandLine, defaultCharset); + public OSProcessHandler(@NotNull final Process process) { + this(process, null); } public OSProcessHandler(@NotNull final Process process, @Nullable final String commandLine) { - super(process, commandLine, EncodingManager.getInstance().getDefaultCharset()); + this(process, commandLine, EncodingManager.getInstance().getDefaultCharset()); + } + + public OSProcessHandler(@NotNull final Process process, @Nullable final String commandLine, @Nullable final Charset charset) { + super(process, commandLine, charset); + } + + protected OSProcessHandler(@NotNull final OSProcessHandler base) { + this(base.myProcess, base.myCommandLine); } @Override @@ -48,7 +57,7 @@ public class OSProcessHandler extends BaseOSProcessHandler { return super.executeOnPooledThread(task); } - protected boolean shouldDestroyProcessRecursively(){ + protected boolean shouldDestroyProcessRecursively() { // Override this method if you want to kill process recursively (whole process try) by default // such behaviour is better than default java one, which doesn't kill children processes return myDestroyRecursively; @@ -71,7 +80,8 @@ public class OSProcessHandler extends BaseOSProcessHandler { } /** - * Kill whole process tree. + * Kill the whole process tree. + * * @param process Process * @return True if process tree has been successfully killed. */ diff --git a/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java b/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java index 7730f44f46f3..b73d5e732be5 100644 --- a/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java +++ b/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,11 @@ import java.util.concurrent.*; public class BaseOSProcessHandler extends ProcessHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.execution.process.OSProcessHandlerBase"); - @NotNull - protected final Process myProcess; - @Nullable - protected final String myCommandLine; + + @NotNull protected final Process myProcess; + @Nullable protected final String myCommandLine; protected final ProcessWaitFor myWaitFor; - @Nullable - private final Charset myCharset; + @Nullable private final Charset myCharset; public BaseOSProcessHandler(@NotNull final Process process, @Nullable final String commandLine, @Nullable Charset charset) { myProcess = process; @@ -169,7 +167,7 @@ public class BaseOSProcessHandler extends ProcessHandler { return myProcess.getOutputStream(); } - // todo: to remove + /** @deprecated internal use only (to remove in IDEA 13) */ @Nullable public String getCommandLine() { return myCommandLine; @@ -185,9 +183,10 @@ public class BaseOSProcessHandler extends ProcessHandler { private static ThreadPoolExecutor createServiceImpl() { return new ThreadPoolExecutor(10, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactory() { + @NotNull @Override @SuppressWarnings({"HardCodedStringLiteral"}) - public Thread newThread(Runnable r) { + public Thread newThread(@NotNull Runnable r) { return new Thread(r, "OSProcessHandler pooled thread"); } }); @@ -256,5 +255,4 @@ public class BaseOSProcessHandler extends ProcessHandler { notifyTextAvailable(text, myProcessOutputType); } } - } diff --git a/platform/util/src/com/intellij/util/io/BaseOutputReader.java b/platform/util/src/com/intellij/util/io/BaseOutputReader.java index 06ee16776db2..0fd4d3d02e0d 100644 --- a/platform/util/src/com/intellij/util/io/BaseOutputReader.java +++ b/platform/util/src/com/intellij/util/io/BaseOutputReader.java @@ -16,6 +16,7 @@ package com.intellij.util.io; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.TimeoutUtil; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -63,11 +64,9 @@ public abstract class BaseOutputReader { break; } - Thread.sleep(read ? 1 : 5); // give other threads a chance + TimeoutUtil.sleep(read ? 1 : 5); // give other threads a chance } } - catch (InterruptedException ignore) { - } catch (IOException e) { LOG.info(e); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java index e3c7279899d2..0630a385522b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyShellAction.java @@ -172,7 +172,7 @@ public class GroovyShellAction extends DumbAwareAction { @Override protected OSProcessHandler createProcessHandler(Process process) { - return new OSProcessHandler(process, null); + return new OSProcessHandler(process); } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java index 4cb8876e7048..d58d3b22464a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java @@ -263,7 +263,7 @@ public class MvcConsole implements Disposable { final OSProcessHandler handler; try { Process process = commandLine.createProcess(); - handler = new OSProcessHandler(process, ""); + handler = new OSProcessHandler(process); @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") OutputStreamWriter writer = new OutputStreamWriter(process.getOutputStream());