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 --- .../jack/test/toolchain/JackApiToolchainBase.java | 101 +++++++++++---------- .../jack/test/toolchain/JackApiV01Toolchain.java | 4 +- 2 files changed, 56 insertions(+), 49 deletions(-) (limited to 'jack-tests/src') diff --git a/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchainBase.java b/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchainBase.java index af2dd65..8e1db1f 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchainBase.java +++ b/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchainBase.java @@ -18,18 +18,21 @@ package com.android.jack.test.toolchain; import com.android.jack.api.ConfigNotSupportedException; import com.android.jack.api.JackConfig; -import com.android.jack.api.JackConfigProvider; +import com.android.jack.api.JackProvider; +import com.android.jack.api.JackProvider.SubReleaseKind; import com.android.jack.api.v01.VerbosityLevel; import com.android.jack.shrob.spec.Flags; import com.android.jack.test.TestConfigurationException; import java.io.File; -import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.NoSuchElementException; +import java.util.ServiceLoader; import javax.annotation.CheckForNull; +import javax.annotation.Nonnegative; import javax.annotation.Nonnull; /** @@ -40,78 +43,82 @@ public abstract class JackApiToolchainBase extends JackBasedToolchain { @Nonnull protected JackConfig config; - @Nonnull - private String compilerCodeName; - @Nonnull - private String compilerVersion; - @Nonnull - private String compilerBuildId; - @Nonnull - private String compilerCodeBase; - @CheckForNull protected File incrementalFolder; @Nonnull protected VerbosityLevel verbosityLevel = VerbosityLevel.WARNING; @CheckForNull - private static JackConfigProvider configProvider; + private static JackProvider configProvider; - public String getCompilerCodeName() { - return compilerCodeName; + @Nonnull + private static String releaseName; + @Nonnegative + private static int releaseCode; + @Nonnull + private static SubReleaseKind subReleaseKind; + @Nonnegative + private static int subSubReleaseCode; + @Nonnull + private static String compilerVersion; + + + @Nonnull + public static String getReleaseName() { + return releaseName; } - public String getCompilerVersion() { - return compilerVersion; + @Nonnegative + public static int getReleaseCode() { + return releaseCode; } - public String getCompilerBuildId() { - return compilerBuildId; + @Nonnull + public static SubReleaseKind getSubReleaseKind() { + return subReleaseKind; } - public String getCompilerCodeBase() { - return compilerCodeBase; + @Nonnegative + public static int getSubSubReleaseCode() { + return subSubReleaseCode; + } + + @Nonnull + public static String getCompilerVersion() { + return compilerVersion; } protected JackApiToolchainBase(@Nonnull File jackPrebuilt, @Nonnull Class jackConfig) { - try { - if (configProvider == null) { + if (configProvider == null) { + try { ClassLoader classLoader = URLClassLoader.newInstance( new URL[] {jackPrebuilt.toURI().toURL()}, JackApiToolchainBase.class.getClassLoader()); - Class confProviderClass = Class.forName( - JackConfigProvider.CLASS_NAME, true, classLoader).asSubclass(JackConfigProvider.class); - configProvider = confProviderClass.getConstructor().newInstance(); + ServiceLoader serviceLoader = + ServiceLoader.load(JackProvider.class, classLoader); + configProvider = serviceLoader.iterator().next(); + } catch (MalformedURLException e1) { + throw new TestConfigurationException(e1); + } catch (NoSuchElementException e) { + throw new TestConfigurationException(e); } + } - assert configProvider != null; + assert configProvider != null; - compilerCodeName = configProvider.getCompilerCodeName(); - compilerVersion = configProvider.getCompilerVersion(); - compilerBuildId = configProvider.getCompilerBuildId(); - compilerCodeBase = configProvider.getCompilerCodeBase(); + releaseName = configProvider.getCompilerReleaseName(); + releaseCode = configProvider.getCompilerReleaseCode(); + subReleaseKind = configProvider.getCompilerSubReleaseKind(); + subSubReleaseCode = configProvider.getCompilerSubReleaseCode(); + compilerVersion = configProvider.getCompilerVersion(); + + try { - config = configProvider.getConfig(jackConfig); + config = configProvider.createConfig(jackConfig); } catch (ConfigNotSupportedException e) { throw new TestConfigurationException("Jack API v01 not supported", e); - } catch (MalformedURLException e) { - throw new TestConfigurationException(e); - } catch (ClassNotFoundException e) { - throw new TestConfigurationException(e); - } catch (InstantiationException e) { - throw new TestConfigurationException(e); - } catch (IllegalAccessException e) { - throw new TestConfigurationException(e); - } catch (IllegalArgumentException e) { - throw new TestConfigurationException(e); - } catch (InvocationTargetException e) { - throw new TestConfigurationException(e); - } catch (NoSuchMethodException e) { - throw new TestConfigurationException(e); - } catch (SecurityException e) { - throw new TestConfigurationException(e); } } diff --git a/jack-tests/src/com/android/jack/test/toolchain/JackApiV01Toolchain.java b/jack-tests/src/com/android/jack/test/toolchain/JackApiV01Toolchain.java index 52e4b3f..0927650 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/JackApiV01Toolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/JackApiV01Toolchain.java @@ -20,8 +20,8 @@ import com.google.common.base.Splitter; import com.google.common.collect.Lists; import com.android.jack.Options; -import com.android.jack.api.v01.AbortException; 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.DebugInfoLevel; import com.android.jack.api.v01.ReporterKind; @@ -173,7 +173,7 @@ public class JackApiV01Toolchain extends JackApiToolchainBase { } else { throw new AssertionError(); } - } catch (AbortException e1) { + } catch (CompilationException e1) { Throwable t1 = e1.getCause(); if (t1 instanceof Exception) { throw (Exception) t1; -- cgit v1.1