summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2015-02-25 15:53:56 +0100
committermikaelpeltier <mikaelpeltier@google.com>2015-03-03 10:06:25 +0100
commitddcfc4106e8fd9c84a28a4c625d2c32909886519 (patch)
tree77a3f6dd2233fb6692ac102c8615ff7638bee4ac
parent15cf518caaae85c93d9eaad87699b9c88730f0b5 (diff)
downloadtoolchain_jill-ddcfc4106e8fd9c84a28a4c625d2c32909886519.zip
toolchain_jill-ddcfc4106e8fd9c84a28a4c625d2c32909886519.tar.gz
toolchain_jill-ddcfc4106e8fd9c84a28a4c625d2c32909886519.tar.bz2
Simplify usage of Jill by API
Change-Id: I3688ca5876a32eb25526d5de8e047691f95d7a4e
-rw-r--r--jill/src/com/android/jill/Jill.java78
-rw-r--r--jill/src/com/android/jill/Main.java47
-rw-r--r--jill/tests/com/android/jill/Core.java4
3 files changed, 51 insertions, 78 deletions
diff --git a/jill/src/com/android/jill/Jill.java b/jill/src/com/android/jill/Jill.java
index f32dd18..35c5c18 100644
--- a/jill/src/com/android/jill/Jill.java
+++ b/jill/src/com/android/jill/Jill.java
@@ -21,8 +21,10 @@ import com.android.jill.utils.FileUtils;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import java.util.jar.JarFile;
import javax.annotation.Nonnull;
@@ -33,50 +35,64 @@ import javax.annotation.Nonnull;
public class Jill {
@Nonnull
- private final Options options;
+ private static final String PROPERTIES_FILE = "jill.properties";
- @Nonnull
- private final String version;
-
- public Jill(@Nonnull Options options, @Nonnull String version) {
- this.options = options;
- this.version = version;
- }
- public void process(@Nonnull File binaryFile) {
+ public static void process(@Nonnull Options options) {
+ File binaryFile = options.getBinaryFile();
+ JavaTransformer jt = new JavaTransformer(getVersion(), options);
if (binaryFile.isFile()) {
if (FileUtils.isJavaBinaryFile(binaryFile)) {
- processJavaBinary(binaryFile);
+ List<File> javaBinaryFiles = new ArrayList<File>();
+ javaBinaryFiles.add(binaryFile);
+ jt.transform(javaBinaryFiles);
} else if (FileUtils.isJarFile(binaryFile)) {
- try {
- processJarFile(new JarFile(binaryFile));
- } catch (IOException e) {
- throw new JillException("Fails to create jar file " + binaryFile.getName(), e);
- }
+ try {
+ jt.transform(new JarFile(binaryFile));
+ } catch (IOException e) {
+ throw new JillException("Fails to create jar file " + binaryFile.getName(), e);
+ }
} else {
throw new JillException("Unsupported file type: " + binaryFile.getName());
}
} else {
- processFolder(binaryFile);
+ List<File> javaBinaryFiles = new ArrayList<File>();
+ FileUtils.getJavaBinaryFiles(binaryFile, javaBinaryFiles);
+ jt.transform(javaBinaryFiles);
}
}
- private void processJavaBinary(@Nonnull File javaBinaryFile) {
- assert javaBinaryFile.isFile();
- List<File> javaBinaryFiles = new ArrayList<File>();
- javaBinaryFiles.add(javaBinaryFile);
- new JavaTransformer(version, options).transform(javaBinaryFiles);
- }
+ @Nonnull
+ public static String getVersion() {
+ String version = "Unknown (problem with " + PROPERTIES_FILE + " resource file)";
- private void processJarFile(@Nonnull JarFile jarFile) {
- new JavaTransformer(version, options).transform(jarFile);
- }
+ InputStream is = Main.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE);
+ if (is != null) {
+ Properties prop = new Properties();
+ try {
+ prop.load(is);
+ String rawVersion = prop.getProperty("jill.version");
+ if (rawVersion != null) {
+ version = rawVersion;
- private void processFolder(@Nonnull File folder) {
- assert folder.isDirectory();
- List<File> javaBinaryFiles = new ArrayList<File>();
- FileUtils.getJavaBinaryFiles(folder, javaBinaryFiles);
- new JavaTransformer(version, options).transform(javaBinaryFiles);
- }
+ String codeName = prop.getProperty("jill.version.codename");
+ if (codeName != null) {
+ version += " \'" + codeName + '\'';
+ }
+ String bid = prop.getProperty("jill.version.buildid", "engineering");
+ String sha = prop.getProperty("jill.version.sha");
+ if (sha != null) {
+ version += " (" + bid + ' ' + sha + ')';
+ } else {
+ version += " (" + bid + ')';
+ }
+ }
+ } catch (IOException e) {
+ // Return default version
+ }
+ }
+
+ return version;
+ }
}
diff --git a/jill/src/com/android/jill/Main.java b/jill/src/com/android/jill/Main.java
index f514a1f..0c5c91b 100644
--- a/jill/src/com/android/jill/Main.java
+++ b/jill/src/com/android/jill/Main.java
@@ -23,10 +23,8 @@ import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
import javax.annotation.Nonnull;
@@ -48,11 +46,11 @@ public class Main {
if (options.askForVersion()) {
System.out.println("Jill");
- System.out.println("Version: " + getVersion() + '.');
+ System.out.println("Version: " + Jill.getVersion() + '.');
System.exit(ExitStatus.SUCCESS);
}
- run(options);
+ Jill.process(options);
System.exit(ExitStatus.SUCCESS);
} catch (CmdLineException e) {
@@ -112,51 +110,10 @@ public class Main {
return options;
}
- public static void run(@Nonnull Options options) {
- new Jill(options, Main.getVersion()).process(options.getBinaryFile());
- }
-
private static void printUsage(@Nonnull CmdLineParser parser) {
System.err.print("Main: ");
parser.printSingleLineUsage(System.err);
System.err.println();
parser.printUsage(System.err);
}
-
- @Nonnull
- private static final String PROPERTIES_FILE = "jill.properties";
-
- @Nonnull
- public static String getVersion() {
- String version = "Unknown (problem with " + PROPERTIES_FILE + " resource file)";
-
- InputStream is = Main.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE);
- if (is != null) {
- Properties prop = new Properties();
- try {
- prop.load(is);
- String rawVersion = prop.getProperty("jill.version");
- if (rawVersion != null) {
- version = rawVersion;
-
- String codeName = prop.getProperty("jill.version.codename");
- if (codeName != null) {
- version += " \'" + codeName + '\'';
- }
-
- String bid = prop.getProperty("jill.version.buildid", "engineering");
- String sha = prop.getProperty("jill.version.sha");
- if (sha != null) {
- version += " (" + bid + ' ' + sha + ')';
- } else {
- version += " (" + bid + ')';
- }
- }
- } catch (IOException e) {
- // Return default version
- }
- }
-
- return version;
- }
}
diff --git a/jill/tests/com/android/jill/Core.java b/jill/tests/com/android/jill/Core.java
index 2c00fec..f799084 100644
--- a/jill/tests/com/android/jill/Core.java
+++ b/jill/tests/com/android/jill/Core.java
@@ -40,7 +40,7 @@ public class Core {
+ "/out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jar"));
options.setVerbose(true);
options.output = AbstractTestTools.createTempFile("jillTest", ".zip");
- new Jill(options, "0.1").process(options.getBinaryFile());
+ Jill.process(options);
}
@Test
@@ -50,6 +50,6 @@ public class Core {
+ "/out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes/"));
options.setVerbose(true);
options.output = AbstractTestTools.createTempFile("jillTest", ".zip");
- new Jill(options, "0.1").process(options.getBinaryFile());
+ Jill.process(options);
}
}