diff options
Diffstat (limited to 'jill/src')
-rw-r--r-- | jill/src/com/android/jill/Jill.java | 44 | ||||
-rw-r--r-- | jill/src/com/android/jill/Main.java | 2 | ||||
-rw-r--r-- | jill/src/com/android/jill/Version.java | 122 | ||||
-rw-r--r-- | jill/src/com/android/jill/api/impl/JillProviderImpl.java | 118 | ||||
-rw-r--r-- | jill/src/com/android/jill/api/v01/impl/Api01ConfigImpl.java | 93 |
5 files changed, 348 insertions, 31 deletions
diff --git a/jill/src/com/android/jill/Jill.java b/jill/src/com/android/jill/Jill.java index 35c5c18..0017175 100644 --- a/jill/src/com/android/jill/Jill.java +++ b/jill/src/com/android/jill/Jill.java @@ -24,9 +24,9 @@ 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.CheckForNull; import javax.annotation.Nonnull; /** @@ -36,11 +36,12 @@ public class Jill { @Nonnull private static final String PROPERTIES_FILE = "jill.properties"; - + @CheckForNull + private static Version version = null; public static void process(@Nonnull Options options) { File binaryFile = options.getBinaryFile(); - JavaTransformer jt = new JavaTransformer(getVersion(), options); + JavaTransformer jt = new JavaTransformer(getVersion().getVersion(), options); if (binaryFile.isFile()) { if (FileUtils.isJavaBinaryFile(binaryFile)) { List<File> javaBinaryFiles = new ArrayList<File>(); @@ -63,36 +64,19 @@ public class Jill { } @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 + public static Version getVersion() { + if (version == null) { + InputStream is = Jill.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE); + if (is != null) { + version = new Version(is); + } else { + System.err.println("Failed to open Jack properties file " + PROPERTIES_FILE); + throw new AssertionError(); } } + assert version != null; return version; } + } diff --git a/jill/src/com/android/jill/Main.java b/jill/src/com/android/jill/Main.java index 0c5c91b..dce329a 100644 --- a/jill/src/com/android/jill/Main.java +++ b/jill/src/com/android/jill/Main.java @@ -46,7 +46,7 @@ public class Main { if (options.askForVersion()) { System.out.println("Jill"); - System.out.println("Version: " + Jill.getVersion() + '.'); + System.out.println("Version: " + Jill.getVersion().getVersion() + '.'); System.exit(ExitStatus.SUCCESS); } diff --git a/jill/src/com/android/jill/Version.java b/jill/src/com/android/jill/Version.java new file mode 100644 index 0000000..2f7f376 --- /dev/null +++ b/jill/src/com/android/jill/Version.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jill; + +import com.android.jill.api.JillProvider.SubReleaseKind; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; + +/** + * A class describing version, release, build & code. + */ +public class Version { + + @Nonnull + private String version; + @Nonnull + private String releaseName; + @Nonnegative + private int releaseCode; + @Nonnull + private SubReleaseKind subReleaseKind; + @Nonnegative + private int subReleaseCode; + @CheckForNull + private String buildId; + @CheckForNull + private String codeBase; + + public Version(@Nonnull InputStream is) { + Properties prop = new Properties(); + try { + prop.load(is); + + version = prop.getProperty("jill.version"); + assert version != null; + + releaseName = prop.getProperty("jill.version.release.name"); + assert releaseName != null; + + releaseCode = Integer.parseInt(prop.getProperty("jill.version.release.code")); + assert releaseCode >= 1; + + subReleaseCode = Integer.parseInt(prop.getProperty("jill.version.sub-release.code")); + assert subReleaseCode >= 1; + + subReleaseKind = + SubReleaseKind.valueOf(SubReleaseKind.class, + prop.getProperty("jill.version.sub-release.kind")); + buildId = prop.getProperty("jill.version.buildid"); + codeBase = prop.getProperty("jill.version.sha"); + + if (codeBase == null || buildId == null) { + subReleaseKind = SubReleaseKind.ENGINEERING; + } + } catch (IOException e) { + System.err.println("Failed to read Jill properties"); + throw new AssertionError(e); + } + } + + @Nonnull + public String getVersion() { + return version; + } + + @Nonnull + public String getReleaseName() { + return releaseName; + } + + @Nonnegative + public int getReleaseCode() { + return releaseCode; + } + + @Nonnull + public SubReleaseKind getSubReleaseKind() { + return subReleaseKind; + } + + @Nonnegative + public int getSubReleaseCode() { + return subReleaseCode; + } + + @CheckForNull + public String getBuildId() { + return buildId; + } + + @CheckForNull + public String getCodeBase() { + return codeBase; + } + + @Nonnull + public String getVerboseVersion() { + return version + " '" + releaseName + "' (" + + (buildId != null ? buildId : "engineering") + + (codeBase != null ? (' ' + codeBase) : "") + ")"; + } +}
\ No newline at end of file diff --git a/jill/src/com/android/jill/api/impl/JillProviderImpl.java b/jill/src/com/android/jill/api/impl/JillProviderImpl.java new file mode 100644 index 0000000..98a0978 --- /dev/null +++ b/jill/src/com/android/jill/api/impl/JillProviderImpl.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jill.api.impl; + +import com.android.jill.Jill; +import com.android.jill.api.ConfigNotSupportedException; +import com.android.jill.api.JillConfig; +import com.android.jill.api.JillProvider; +import com.android.jill.api.v01.Api01Config; +import com.android.jill.api.v01.impl.Api01ConfigImpl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** + * This class provides an implementation to build the requested {@link JillConfig} + */ +public class JillProviderImpl implements JillProvider { + + @Override + @Nonnull + @SuppressWarnings("unchecked") + public <T extends JillConfig> T createConfig(@Nonnull Class<T> cls) + throws ConfigNotSupportedException { + if (cls == Api01Config.class) { + return (T) new Api01ConfigImpl(); + } + + throw new ConfigNotSupportedException(cls.getName() + " are not supported"); + } + + @Override + @Nonnull + public <T extends JillConfig> boolean isConfigSupported(@Nonnull Class<T> cls) { + return cls == Api01Config.class; + } + + @Override + @Nonnull + public Collection<Class<? extends JillConfig>> getSupportedConfigs() { + List<Class<? extends JillConfig>> result = new ArrayList<Class<? extends JillConfig>>(1); + result.add(Api01Config.class); + return result; + } + + @Override + @Nonnull + public String getTranslatorVersion() { + return Jill.getVersion().getVersion(); + } + + @Override + @Nonnull + public String getTranslatorReleaseName() { + return Jill.getVersion().getReleaseName(); + } + + @Override + public int getTranslatorReleaseCode() { + return Jill.getVersion().getReleaseCode(); + } + + @Override + public int getTranslatorSubReleaseCode() { + return Jill.getVersion().getSubReleaseCode(); + } + + @Override + @Nonnull + public SubReleaseKind getTranslatorSubReleaseKind() { + switch (Jill.getVersion().getSubReleaseKind()) { + case ENGINEERING: + return SubReleaseKind.ENGINEERING; + case PRE_ALPHA: + return SubReleaseKind.PRE_ALPHA; + case ALPHA: + return SubReleaseKind.ALPHA; + case BETA: + return SubReleaseKind.BETA; + case CANDIDATE: + return SubReleaseKind.CANDIDATE; + case RELEASE: + return SubReleaseKind.RELEASE; + default: + throw new AssertionError(Jill.getVersion().getSubReleaseKind().name()); + } + } + + @Override + @CheckForNull + public String getTranslatorBuildId() { + return Jill.getVersion().getBuildId(); + } + + @Override + @CheckForNull + public String getTranslatorSourceCodeBase() { + return Jill.getVersion().getCodeBase(); + } +}
\ No newline at end of file diff --git a/jill/src/com/android/jill/api/v01/impl/Api01ConfigImpl.java b/jill/src/com/android/jill/api/v01/impl/Api01ConfigImpl.java new file mode 100644 index 0000000..6aba8a0 --- /dev/null +++ b/jill/src/com/android/jill/api/v01/impl/Api01ConfigImpl.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jill.api.v01.impl; + +import com.android.jill.Jill; +import com.android.jill.Options; +import com.android.jill.api.v01.Api01Config; +import com.android.jill.api.v01.Api01TranslationTask; +import com.android.jill.api.v01.ConfigurationException; +import com.android.jill.utils.FileUtils; + +import java.io.File; + +import javax.annotation.Nonnull; + +/** + * This class provides the version 01 implementation of Jill API. + */ +public class Api01ConfigImpl implements Api01Config { + + @Nonnull + private final Options options; + + public Api01ConfigImpl() { + options = new Options(); + } + + @Override + @Nonnull + public Api01TranslationTask getTask() { + return new Api01TranslationTaskImpl(options); + } + + private static class Api01TranslationTaskImpl implements Api01TranslationTask { + + @Nonnull + private final Options options; + + public Api01TranslationTaskImpl(@Nonnull Options options) { + this.options = options; + } + + @Override + public void run() { + Jill.process(options); + } + + } + + @Override + public void setVerbose(boolean isVerbose) { + options.setVerbose(isVerbose); + } + + @Override + public void setInputJavaBinaryFile(@Nonnull File input) throws ConfigurationException { + if (!input.exists()) { + throw new ConfigurationException("Input file does not exist: " + input.getPath()); + } + if (!input.getAbsoluteFile().isFile()) { + throw new ConfigurationException("Input is not a file: " + input.getPath()); + } + if (!FileUtils.isJarFile(input)) { + throw new ConfigurationException("Unsupported file type: " + input.getName()); + } + options.setBinaryFile(input); + } + + @Override + public void setOutputJackFile(@Nonnull File outputJackFile) { + options.setOutput(outputJackFile); + } + + @Override + public void setDebugInfo(boolean debugInfo) { + options.setEmitDebugInfo(debugInfo); + } + +} |