From e27bbc4d1cf9c9d6b23344b977331bed0a3357a5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 21 Feb 2012 23:19:33 -0800 Subject: ADT: Suggest solution to ADT version check error. This amends the ADT version check to help the user either: - open the SDK Manager - open the P2 Updater - open the Android Preference On Windows the launch the *external* SDK Manager since eventually we know that ADT will lock something that would prevent the update from working in the first place. Change-Id: Ib20e4e1411b36e3cd794cccbc02518db0a40ced9 --- .../android/sdklib/internal/avd/AvdManager.java | 3 +- .../sdklib/internal/build/KeystoreHelper.java | 3 +- .../internal/repository/ArchiveInstaller.java | 3 +- .../sdklib/internal/repository/ToolPackage.java | 3 +- .../com/android/sdklib/util/GrabProcessOutput.java | 39 ++++++++++++++++++++-- 5 files changed, 44 insertions(+), 7 deletions(-) (limited to 'sdkmanager/libs') diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java index 436f2e8..db3cc33 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java @@ -28,6 +28,7 @@ import com.android.sdklib.internal.avd.AvdInfo.AvdStatus; import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.util.GrabProcessOutput; import com.android.sdklib.util.GrabProcessOutput.IProcessOutput; +import com.android.sdklib.util.GrabProcessOutput.Wait; import com.android.util.Pair; import java.io.File; @@ -1398,7 +1399,7 @@ public class AvdManager { int status = GrabProcessOutput.grabProcessOutput( process, - true /*waitForReaders*/, + Wait.WAIT_FOR_READERS, new IProcessOutput() { @Override public void out(String line) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java index 06f5351..af5b401 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java @@ -20,6 +20,7 @@ import com.android.sdklib.internal.build.DebugKeyProvider.IKeyGenOutput; import com.android.sdklib.internal.build.DebugKeyProvider.KeytoolException; import com.android.sdklib.util.GrabProcessOutput; import com.android.sdklib.util.GrabProcessOutput.IProcessOutput; +import com.android.sdklib.util.GrabProcessOutput.Wait; import java.io.File; import java.io.IOException; @@ -107,7 +108,7 @@ public final class KeystoreHelper { Process process = Runtime.getRuntime().exec(commandArray); result = GrabProcessOutput.grabProcessOutput( process, - true /*waitForReaders*/, + Wait.WAIT_FOR_READERS, new IProcessOutput() { @Override public void out(String line) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java index 9e50430..2e2396f 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java @@ -25,6 +25,7 @@ import com.android.sdklib.io.IFileOp; import com.android.sdklib.repository.RepoConstants; import com.android.sdklib.util.GrabProcessOutput; import com.android.sdklib.util.GrabProcessOutput.IProcessOutput; +import com.android.sdklib.util.GrabProcessOutput.Wait; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; @@ -598,7 +599,7 @@ public class ArchiveInstaller { Process process = Runtime.getRuntime().exec(command); int retCode = GrabProcessOutput.grabProcessOutput( process, - true /*waitForReaders*/, + Wait.WAIT_FOR_READERS, new IProcessOutput() { @Override public void out(String line) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java index ffd561f..3ddacb4 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java @@ -25,6 +25,7 @@ import com.android.sdklib.internal.repository.Archive.Os; import com.android.sdklib.repository.SdkRepoConstants; import com.android.sdklib.util.GrabProcessOutput; import com.android.sdklib.util.GrabProcessOutput.IProcessOutput; +import com.android.sdklib.util.GrabProcessOutput.Wait; import org.w3c.dom.Node; @@ -276,7 +277,7 @@ public class ToolPackage extends Package implements IMinPlatformToolsDependency final String tag = scriptName; status = GrabProcessOutput.grabProcessOutput( proc, - false /*waitForReaders*/, + Wait.WAIT_FOR_PROCESS, new IProcessOutput() { @Override public void out(String line) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/util/GrabProcessOutput.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/util/GrabProcessOutput.java index b470153..2935493 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/util/GrabProcessOutput.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/util/GrabProcessOutput.java @@ -25,6 +25,35 @@ import java.io.InputStreamReader; public class GrabProcessOutput { + public enum Wait { + /** + * Doesn't wait for the exec to complete. + * This still monitors the output but does not wait for the process to finish. + * In this mode the process return code is unknown and always 0. + */ + ASYNC, + /** + * This waits for the process to finish. + * In this mode, {@link GrabProcessOutput#grabProcessOutput} returns the + * error code from the process. + * In some rare cases and depending on the OS, the process might not have + * finished dumping data into stdout/stderr. + *

+ * Use this when you don't particularly care for the output but instead + * care for the return code of the executed process. + */ + WAIT_FOR_PROCESS, + /** + * This waits for the process to finish and for the stdout/stderr + * threads to complete. + * In this mode, {@link GrabProcessOutput#grabProcessOutput} returns the + * error code from the process. + *

+ * Use this one when capturing all the output from the process is important. + */ + WAIT_FOR_READERS, + } + public interface IProcessOutput { /** * Processes an stdout message line. @@ -46,13 +75,13 @@ public class GrabProcessOutput { * @param output Optional object to capture stdout/stderr. * Note that on Windows capturing the output is not optional. If output is null * the stdout/stderr will be captured and discarded. - * @param waitForReaders True to wait for the reader threads to finish. + * @param waitMode Whether to wait for the process and/or the readers to finish. * @return the process return code. * @throws InterruptedException if {@link Process#waitFor()} was interrupted. */ public static int grabProcessOutput( @NonNull final Process process, - boolean waitForReaders, + Wait waitMode, @Nullable final IProcessOutput output) throws InterruptedException { // read the lines as they come. if null is returned, it's // because the process finished @@ -104,10 +133,14 @@ public class GrabProcessOutput { threadErr.start(); threadOut.start(); + if (waitMode == Wait.ASYNC) { + return 0; + } + // it looks like on windows process#waitFor() can return // before the thread have filled the arrays, so we wait for both threads and the // process itself. - if (waitForReaders) { + if (waitMode == Wait.WAIT_FOR_READERS) { try { threadErr.join(); } catch (InterruptedException e) { -- cgit v1.1