aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2010-10-26 11:42:22 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2010-10-26 11:42:22 -0700
commit89bdaa02a786c3b7de1aa21654bc16c4951980e1 (patch)
tree9cf096cece74b362bb8fc477fce6637a03374cf7
parent7ddef5e5752da9e13cb6c2b30a316fdb79bf0bc7 (diff)
parent705714c7ba1dfda24adcd3d8aee9dec99b6f317d (diff)
downloadsdk-89bdaa02a786c3b7de1aa21654bc16c4951980e1.zip
sdk-89bdaa02a786c3b7de1aa21654bc16c4951980e1.tar.gz
sdk-89bdaa02a786c3b7de1aa21654bc16c4951980e1.tar.bz2
merge from open-source master
Change-Id: I51c83c375936259d6ebe3efabd77eb1f46805236
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java66
-rwxr-xr-xfiles/proguard/bin/proguard.bat17
-rwxr-xr-xfiles/proguard/bin/proguardgui.bat17
-rwxr-xr-xfiles/proguard/bin/retrace.bat17
4 files changed, 112 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
index 2fde101..5047e11 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
@@ -57,6 +57,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
@@ -64,6 +65,8 @@ import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
/**
* Helper with methods for the last 3 steps of the generation of an APK.
@@ -88,7 +91,8 @@ import java.util.List;
*/
public class BuildHelper {
- private static final String CONSOLE_PREFIX_DX = "Dx"; //$NON-NLS-1$
+ private static final String CONSOLE_PREFIX_DX = "Dx"; //$NON-NLS-1$
+ private final static String TEMP_PREFIX = "android_"; //$NON-NLS-1$
private final IProject mProject;
private final AndroidPrintStream mOutStream;
@@ -399,8 +403,8 @@ public class BuildHelper {
}
public void runProguard(File proguardConfig, File inputJar, String[] jarFiles,
- File obfuscatedJar, File logOutput) throws ProguardResultException,
- ProguardExecException {
+ File obfuscatedJar, File logOutput)
+ throws ProguardResultException, ProguardExecException, IOException {
IAndroidTarget target = Sdk.getCurrent().getTarget(mProject);
// prepare the command line for proguard
@@ -449,13 +453,65 @@ public class BuildHelper {
command.add(new File(logOutput, "mapping.txt").getAbsolutePath()); //$NON-NLS-1$
}
- String commandArray[] = command.toArray(new String[command.size()]);
+ String commandArray[];
+
+ if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS) {
+ // On Windows, proguard.bat can only pass %1...%9 to the java -jar proguard.jar
+ // call, but we have at least 15 arguments here so some get dropped silently
+ // and quoting is a big issue. So instead we'll work around that by writing
+ // all the arguments to a temporary config file.
+
+ commandArray = new String[3];
+
+ // Arg 0 is the proguard.bat path and arg 1 is the user config file
+ commandArray[0] = command.get(0);
+ commandArray[1] = command.get(1);
+
+ // Write all the other arguments to a config file
+ File argsFile = File.createTempFile(TEMP_PREFIX, ".pro"); //$NON-NLS-1$
+ // TODO FIXME this may leave a lot of temp files around on a long session.
+ // Should have a better way to clean up e.g. before each build.
+ argsFile.deleteOnExit();
+
+ FileWriter fw = new FileWriter(argsFile);
+
+ for (int i = 2; i < command.size(); i++) {
+ String s = command.get(i);
+ fw.write(s);
+ fw.write(s.startsWith("-") ? ' ' : '\n'); //$NON-NLS-1$
+ }
+
+ fw.close();
+
+ commandArray[2] = "@" + argsFile.getAbsolutePath(); //$NON-NLS-1$
+ } else {
+ // For Mac & Linux, use a regular command string array.
+
+ commandArray = command.toArray(new String[command.size()]);
+ }
+
+ // Define PROGUARD_HOME to point to $SDK/tools/proguard if it's not yet defined.
+ // The Mac/Linux proguard.sh can infer it correctly but not the proguard.bat one.
+ String[] envp = null;
+ Map<String, String> envMap = new TreeMap<String, String>(System.getenv());
+ if (!envMap.containsKey("PROGUARD_HOME")) { //$NON-NLS-1$
+ envMap.put("PROGUARD_HOME", Sdk.getCurrent().getSdkLocation() + //$NON-NLS-1$
+ SdkConstants.FD_TOOLS + File.separator +
+ SdkConstants.FD_PROGUARD);
+ envp = new String[envMap.size()];
+ int i = 0;
+ for (Map.Entry<String, String> entry : envMap.entrySet()) {
+ envp[i++] = String.format("%1$s=%2$s", //$NON-NLS-1$
+ entry.getKey(),
+ entry.getValue());
+ }
+ }
// launch
int execError = 1;
try {
// launch the command line process
- Process process = Runtime.getRuntime().exec(commandArray);
+ Process process = Runtime.getRuntime().exec(commandArray, envp);
// list to store each line of stderr
ArrayList<String> results = new ArrayList<String>();
diff --git a/files/proguard/bin/proguard.bat b/files/proguard/bin/proguard.bat
new file mode 100755
index 0000000..1e767b8
--- /dev/null
+++ b/files/proguard/bin/proguard.bat
@@ -0,0 +1,17 @@
+@ECHO OFF
+
+REM Start-up script for ProGuard -- free class file shrinker, optimizer,
+REM obfuscator, and preverifier for Java bytecode.
+
+rem Change current directory and drive to where the script is, to avoid
+rem issues with directories containing whitespaces.
+cd /d %~dp0
+
+IF EXIST "%PROGUARD_HOME%" GOTO home
+SET PROGUARD_HOME=..
+:home
+
+set java_exe=
+call %PROGUARD_HOME%\..\lib\find_java.bat
+
+call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
diff --git a/files/proguard/bin/proguardgui.bat b/files/proguard/bin/proguardgui.bat
new file mode 100755
index 0000000..4e41570
--- /dev/null
+++ b/files/proguard/bin/proguardgui.bat
@@ -0,0 +1,17 @@
+@ECHO OFF
+
+REM Start-up script for the GUI of ProGuard -- free class file shrinker,
+REM optimizer, obfuscator, and preverifier for Java bytecode.
+
+rem Change current directory and drive to where the script is, to avoid
+rem issues with directories containing whitespaces.
+cd /d %~dp0
+
+IF EXIST "%PROGUARD_HOME%" GOTO home
+SET PROGUARD_HOME=..
+:home
+
+set java_exe=
+call %PROGUARD_HOME%\..\lib\find_java.bat
+
+call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguardgui.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
diff --git a/files/proguard/bin/retrace.bat b/files/proguard/bin/retrace.bat
new file mode 100755
index 0000000..94ec615
--- /dev/null
+++ b/files/proguard/bin/retrace.bat
@@ -0,0 +1,17 @@
+@ECHO OFF
+
+REM Start-up script for Retrace -- companion tool for ProGuard, free class file
+REM shrinker, optimizer, obfuscator, and preverifier for Java bytecode.
+
+rem Change current directory and drive to where the script is, to avoid
+rem issues with directories containing whitespaces.
+cd /d %~dp0
+
+IF EXIST "%PROGUARD_HOME%" GOTO home
+SET PROGUARD_HOME=..
+:home
+
+set java_exe=
+call %PROGUARD_HOME%\..\lib\find_java.bat
+
+call %java_exe% -jar "%PROGUARD_HOME%"\lib\retrace.jar %1 %2 %3 %4 %5 %6 %7 %8 %9