diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2015-03-04 11:49:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-04 11:49:05 +0000 |
commit | 5a9426417497ef939d6123c5b4343229123a72c6 (patch) | |
tree | e85597e9b4b52ccc4600bc99753fba63e15fb9ea | |
parent | a8fa1311f2e251b484d6fdbbdf20c8f6447d171c (diff) | |
parent | ddcfc4106e8fd9c84a28a4c625d2c32909886519 (diff) | |
download | toolchain_jill-5a9426417497ef939d6123c5b4343229123a72c6.zip toolchain_jill-5a9426417497ef939d6123c5b4343229123a72c6.tar.gz toolchain_jill-5a9426417497ef939d6123c5b4343229123a72c6.tar.bz2 |
Merge "Simplify usage of Jill by API" into ub-jack
-rw-r--r-- | jill/src/com/android/jill/Jill.java | 78 | ||||
-rw-r--r-- | jill/src/com/android/jill/Main.java | 47 | ||||
-rw-r--r-- | jill/tests/com/android/jill/Core.java | 4 |
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); } } |