From 90407c3697672648b4dcabd38577d7de7fb482ca Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lesot Date: Wed, 11 Mar 2015 08:26:57 -0700 Subject: Rework Jack API, add better control over versioning Change-Id: I1afa95dae0177c19891c3669a672bd5481191dba --- .../com/android/jack/api/JackConfigProvider.java | 74 ----------- .../src/com/android/jack/api/JackProvider.java | 140 +++++++++++++++++++++ .../jack/api/example/SampleWithClassLoader.java | 102 --------------- .../jack/api/example/SampleWithServiceLoader.java | 94 -------------- .../jack/api/example/WithServiceLoader.java | 112 +++++++++++++++++ .../com/android/jack/api/v01/AbortException.java | 43 ------- .../android/jack/api/v01/Api01CompilationTask.java | 4 +- .../android/jack/api/v01/CompilationException.java | 43 +++++++ 8 files changed, 297 insertions(+), 315 deletions(-) delete mode 100644 jack-api/src/com/android/jack/api/JackConfigProvider.java create mode 100644 jack-api/src/com/android/jack/api/JackProvider.java delete mode 100644 jack-api/src/com/android/jack/api/example/SampleWithClassLoader.java delete mode 100644 jack-api/src/com/android/jack/api/example/SampleWithServiceLoader.java create mode 100644 jack-api/src/com/android/jack/api/example/WithServiceLoader.java delete mode 100644 jack-api/src/com/android/jack/api/v01/AbortException.java create mode 100644 jack-api/src/com/android/jack/api/v01/CompilationException.java (limited to 'jack-api') diff --git a/jack-api/src/com/android/jack/api/JackConfigProvider.java b/jack-api/src/com/android/jack/api/JackConfigProvider.java deleted file mode 100644 index 018b6d2..0000000 --- a/jack-api/src/com/android/jack/api/JackConfigProvider.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.jack.api; - -import java.util.Collection; - -import javax.annotation.Nonnull; - -/** - * Provides instances of {@link JackConfig}. - */ -public interface JackConfigProvider { - @Nonnull - static final String CLASS_NAME = "com.android.jack.api.impl.JackConfigProviderImpl"; - - /** - * Creates a {@link JackConfig} instance for an interface representing a {@link JackConfig} API - * version. - * @param cls the {@link JackConfig} API interface - * @return the {@link JackConfig} instance - * @throws ConfigNotSupportedException If no implementation is found for the given interface. - */ - @Nonnull - T getConfig(@Nonnull Class cls) throws ConfigNotSupportedException; - - /** - * Gives a {@link Collection} containing supported {@link JackConfig} API versions. - * @return the supported {@link JackConfig} API versions - */ - @Nonnull - Collection> getSupportedConfigs(); - - /** - * The code name of this Jack compiler. - * @return the code name - */ - @Nonnull - String getCompilerCodeName(); - - /** - * The version of this Jack compiler. - * @return the version - */ - @Nonnull - String getCompilerVersion(); - - /** - * The build ID of this Jack compiler. - * @return the build ID - */ - @Nonnull - String getCompilerBuildId(); - - /** - * The code base of this Jack compiler. - * @return the code base - */ - @Nonnull - String getCompilerCodeBase(); -} diff --git a/jack-api/src/com/android/jack/api/JackProvider.java b/jack-api/src/com/android/jack/api/JackProvider.java new file mode 100644 index 0000000..50cbfc1 --- /dev/null +++ b/jack-api/src/com/android/jack/api/JackProvider.java @@ -0,0 +1,140 @@ +/* + * 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.jack.api; + +import java.util.Collection; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; + +/** + * Provides instances of {@link JackConfig}. + */ +public interface JackProvider { + /** + * Creates a {@link JackConfig} instance for an interface representing a {@link JackConfig} API + * version. + * @param cls the {@link JackConfig} API interface + * @return the {@link JackConfig} instance + * @throws ConfigNotSupportedException If no implementation is found for the given interface. + */ + @Nonnull + T createConfig(@Nonnull Class cls) throws ConfigNotSupportedException; + + /** + * Gives if an interface representing a {@link JackConfig} API version is supported. + * + * @param cls the {@link JackConfig} API interface + * @return if the config is supported + */ + @Nonnull + boolean isConfigSupported(@Nonnull Class cls); + + /** + * Gives a {@link Collection} containing supported {@link JackConfig} API versions. + * @return the supported {@link JackConfig} API versions + */ + @Nonnull + Collection> getSupportedConfigs(); + + /** + * Gives the version of this Jack compiler, summarized in one string (e.g. "1.1-rc1", "2.0-a2", + * ...). + * + * @return the version + */ + @Nonnull + String getCompilerVersion(); + + /** + * Gives the release name of this Jack compiler (e.g. Arzon, Brest, ...). + * + * @return the release name + */ + @Nonnull + String getCompilerReleaseName(); + + /** + * Gives an integer value that represents the release of Jack compiler, relative to other release. + * + * @return the release code + */ + @Nonnegative + int getCompilerReleaseCode(); + + /** + * Gives an integer value that represents the sub-release of Jack compiler, relative to other + * sub-release of the same release. + * + * @return the sub-release code + */ + @Nonnegative + int getCompilerSubReleaseCode(); + + /** + * Gives the kind of the sub-release of Jack compiler. + * + * @return the sub-release kind + */ + @Nonnull + SubReleaseKind getCompilerSubReleaseKind(); + + /** + * The kind of a sub-release. + */ + public enum SubReleaseKind { + /** + * A sub-release from an engineering development, not tested, not in the code base repository. + */ + ENGINEERING, + /** + * A sub-release not functionally completed, not tested. + */ + PRE_ALPHA, + /** + * A sub-release not functionally completed, tested. + */ + ALPHA, + /** + * A sub-release functionally completed, tested, but likely contains known or unknown bugs. + */ + BETA, + /** + * A pre-production sub-release, tested. + */ + CANDIDATE, + /** + * A production and stable sub-release. + */ + RELEASE; + } + + /** + * The build ID of this Jack compiler. + * @return the build ID, or null if not available + */ + @CheckForNull + String getCompilerBuildId(); + + /** + * Identify the source code base of this Jack compiler. + * @return the source code base, or null if not available + */ + @CheckForNull + String getCompilerSourceCodeBase(); +} diff --git a/jack-api/src/com/android/jack/api/example/SampleWithClassLoader.java b/jack-api/src/com/android/jack/api/example/SampleWithClassLoader.java deleted file mode 100644 index f2b3040..0000000 --- a/jack-api/src/com/android/jack/api/example/SampleWithClassLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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.jack.api.example; - -import com.android.jack.api.ConfigNotSupportedException; -import com.android.jack.api.JackConfig; -import com.android.jack.api.JackConfigProvider; -import com.android.jack.api.v01.AbortException; -import com.android.jack.api.v01.Api01CompilationTask; -import com.android.jack.api.v01.Api01Config; -import com.android.jack.api.v01.ConfigurationException; -import com.android.jack.api.v01.UnrecoverableException; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; - -/** - * STOPSHIP - */ -public class SampleWithClassLoader { - - public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, - SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, - IllegalAccessException, InvocationTargetException { - ClassLoader loader = - URLClassLoader.newInstance(new URL[] {new File( - "").toURI().toURL()}, - SampleWithClassLoader.class.getClassLoader()); - - Class confProviderClass = - Class.forName(JackConfigProvider.CLASS_NAME, true, loader).asSubclass( - JackConfigProvider.class); - - JackConfigProvider confProvider = confProviderClass.getConstructor().newInstance(); - - System.out.println("Jack version: " + confProvider.getCompilerVersion() + " '" - + confProvider.getCompilerCodeName() + "' (" + confProvider.getCompilerBuildId() + " " - + confProvider.getCompilerCodeBase() + ")"); - - System.out.println("Supported configs: "); - for (Class cls : confProvider.getSupportedConfigs()) { - System.out.print(cls.getSimpleName() + " "); - } - System.out.println(); - - Api01CompilationTask compilationTask; - Api01Config config; - - // Get configuration object - try { - config = confProvider.getConfig(Api01Config.class); - } catch (ConfigNotSupportedException e1) { - System.err.println("Brest config not supported)"); - return; - } - - // Configure the compiler - try { - // Set standard options - config.setOutputDexDir(new File("out/")); - config.setJarJarConfigFile(new File("rules.jarjar")); - // Set provisional properties - config.setProperty("jack.internal.test", "true"); - // Check and build compiler - compilationTask = config.getTask(); - } catch (ConfigurationException e) { - System.err.println(e.getMessage()); - return; - } - - // Run the compilation - try { - compilationTask.run(); - } catch (AbortException e) { - System.out.println("User error, see reporter"); - return; - } catch (UnrecoverableException e) { - System.out.println("Something out of Jack control has happen: " + e.getMessage()); - return; - } catch (ConfigurationException e) { - System.err.println(e.getMessage()); - return; - } - } -} diff --git a/jack-api/src/com/android/jack/api/example/SampleWithServiceLoader.java b/jack-api/src/com/android/jack/api/example/SampleWithServiceLoader.java deleted file mode 100644 index 3754946..0000000 --- a/jack-api/src/com/android/jack/api/example/SampleWithServiceLoader.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.jack.api.example; - -import com.android.jack.api.ConfigNotSupportedException; -import com.android.jack.api.JackConfigProvider; -import com.android.jack.api.v01.AbortException; -import com.android.jack.api.v01.Api01CompilationTask; -import com.android.jack.api.v01.Api01Config; -import com.android.jack.api.v01.ConfigurationException; -import com.android.jack.api.v01.UnrecoverableException; - -import java.io.File; -import java.util.Arrays; -import java.util.NoSuchElementException; -import java.util.ServiceLoader; - -/** - * Sample of Jack api usage based on a service provider. - * This sample requires jack.jar on classpath. - */ -public class SampleWithServiceLoader { - - public static void main(String[] args) throws SecurityException, IllegalArgumentException { - if (args.length != 3) { - System.out.println( - "Usage: "); - return; - } - - ServiceLoader serviceLoader = ServiceLoader.load(JackConfigProvider.class); - JackConfigProvider confProvider; - try { - confProvider = serviceLoader.iterator().next(); - } catch (NoSuchElementException e) { - System.out.println("Check that jack.jar is on classpath"); - return; - } - - Api01CompilationTask compilationTask; - Api01Config config; - - // Get configuration object - try { - config = confProvider.getConfig(Api01Config.class); - } catch (ConfigNotSupportedException e1) { - System.err.println("Brest config not supported)"); - return; - } - - // Configure the compiler - try { - config.setClasspath(Arrays.asList(new File(args[0]))); - - config.setSourceEntries(Arrays.asList(new File(args[1]))); - - config.setOutputDexDir(new File(args[2])); - - // Check and build compiler - compilationTask = config.getTask(); - } catch (ConfigurationException e) { - System.err.println(e.getMessage()); - return; - } - - // Run the compilation - try { - compilationTask.run(); - } catch (AbortException e) { - System.out.println("User error, see reporter"); - return; - } catch (UnrecoverableException e) { - System.out.println("Something out of Jack control has happen: " + e.getMessage()); - return; - } catch (ConfigurationException e) { - System.err.println(e.getMessage()); - return; - } - } -} diff --git a/jack-api/src/com/android/jack/api/example/WithServiceLoader.java b/jack-api/src/com/android/jack/api/example/WithServiceLoader.java new file mode 100644 index 0000000..3e2a82a --- /dev/null +++ b/jack-api/src/com/android/jack/api/example/WithServiceLoader.java @@ -0,0 +1,112 @@ +/* + * 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.jack.api.example; + +import com.android.jack.api.ConfigNotSupportedException; +import com.android.jack.api.JackConfig; +import com.android.jack.api.JackProvider; +import com.android.jack.api.v01.Api01CompilationTask; +import com.android.jack.api.v01.Api01Config; +import com.android.jack.api.v01.CompilationException; +import com.android.jack.api.v01.ConfigurationException; +import com.android.jack.api.v01.UnrecoverableException; + +import java.io.File; +import java.util.Arrays; +import java.util.NoSuchElementException; +import java.util.ServiceLoader; + +/** + * Sample of Jack api usage based on a service provider. + * This sample requires jack.jar on classpath. + */ +public class WithServiceLoader { + public static void main(String[] args) throws SecurityException, IllegalArgumentException { + if (args.length != 3) { + System.out.println( + "Usage: "); + return; + } + + ServiceLoader serviceLoader = ServiceLoader.load(JackProvider.class); + JackProvider provider; + try { + provider = serviceLoader.iterator().next(); + } catch (NoSuchElementException e) { + System.out.println("Check that jack.jar is on classpath"); + return; + } + + System.out.println("Compiler version: " + provider.getCompilerVersion()); + System.out.println("Compiler release name: " + provider.getCompilerReleaseName()); + System.out.println("Compiler release code: " + provider.getCompilerReleaseCode()); + System.out.println("Compiler sub-release kind: " + provider.getCompilerSubReleaseKind()); + System.out.println("Compiler sub-release code: " + provider.getCompilerSubReleaseCode()); + String str; + str = provider.getCompilerBuildId(); + System.out.println("Compiler build id: " + ((str != null) ? str : "Unknown")); + str = provider.getCompilerSourceCodeBase(); + System.out.println("Compiler souce code base: " + ((str != null) ? str : "Unknown")); + System.out.print("Supported configurations: "); + + for (Class config : provider.getSupportedConfigs()) { + System.out.print(config.getSimpleName()); + assert provider.isConfigSupported(config); + } + System.out.println(); + + Api01CompilationTask compilationTask; + Api01Config config; + + // Get configuration object + try { + config = provider.createConfig(Api01Config.class); + } catch (ConfigNotSupportedException e1) { + System.err.println("Brest config not supported)"); + return; + } + + // Configure the compiler + try { + config.setClasspath(Arrays.asList(new File(args[0]))); + + config.setSourceEntries(Arrays.asList(new File(args[1]))); + + config.setOutputDexDir(new File(args[2])); + + // Check and build compiler + compilationTask = config.getTask(); + } catch (ConfigurationException e) { + System.err.println(e.getMessage()); + return; + } + + // Run the compilation + try { + compilationTask.run(); + } catch (CompilationException e) { + System.out.println("User error, see reporter"); + return; + } catch (UnrecoverableException e) { + System.out.println("Something out of Jack control has happen: " + e.getMessage()); + return; + } catch (ConfigurationException e) { + System.err.println(e.getMessage()); + return; + } + } +} diff --git a/jack-api/src/com/android/jack/api/v01/AbortException.java b/jack-api/src/com/android/jack/api/v01/AbortException.java deleted file mode 100644 index 294efd1..0000000 --- a/jack-api/src/com/android/jack/api/v01/AbortException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.jack.api.v01; - -import javax.annotation.Nonnull; - -/** - * A fatal problem that caused Jack to abort. The problem should already have reported, so it is - * safe to ignore its message. - */ -public class AbortException extends Exception { - private static final long serialVersionUID = 1L; - - public AbortException() { - super(); - } - - public AbortException(@Nonnull String message) { - super(message); - } - - public AbortException(@Nonnull String message, @Nonnull Throwable cause) { - super(message, cause); - } - - public AbortException(@Nonnull Throwable cause) { - super(cause); - } -} diff --git a/jack-api/src/com/android/jack/api/v01/Api01CompilationTask.java b/jack-api/src/com/android/jack/api/v01/Api01CompilationTask.java index 479abc8..cf6141f 100644 --- a/jack-api/src/com/android/jack/api/v01/Api01CompilationTask.java +++ b/jack-api/src/com/android/jack/api/v01/Api01CompilationTask.java @@ -24,11 +24,11 @@ public interface Api01CompilationTask { /** * Runs the Jack compiler. May be called only once. - * @throws AbortException If a fatal error occurred during the compilation + * @throws CompilationException If a fatal error occurred during the compilation * @throws UnrecoverableException If an error out of Jack's control occurred * @throws ConfigurationException If there is an error in the configuration * @throws IllegalStateException If Jack is run more than once */ - void run() throws AbortException, UnrecoverableException, ConfigurationException, + void run() throws CompilationException, UnrecoverableException, ConfigurationException, IllegalStateException; } diff --git a/jack-api/src/com/android/jack/api/v01/CompilationException.java b/jack-api/src/com/android/jack/api/v01/CompilationException.java new file mode 100644 index 0000000..99423a8 --- /dev/null +++ b/jack-api/src/com/android/jack/api/v01/CompilationException.java @@ -0,0 +1,43 @@ +/* + * 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.jack.api.v01; + +import javax.annotation.Nonnull; + +/** + * A fatal problem that caused Jack to abort the compilation. The problem should already have + * reported, so it is safe to ignore its message. + */ +public class CompilationException extends Exception { + private static final long serialVersionUID = 1L; + + public CompilationException() { + super(); + } + + public CompilationException(@Nonnull String message) { + super(message); + } + + public CompilationException(@Nonnull String message, @Nonnull Throwable cause) { + super(message, cause); + } + + public CompilationException(@Nonnull Throwable cause) { + super(cause); + } +} -- cgit v1.1