From 82cdf807aab1a7d1ede943118fb9a94eeae9adf4 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 30 Jun 2017 02:27:20 -0400 Subject: [PATCH] Move CompilerBridgeProvider.constant into ZincCompilerUtil On both my local machine and on Drone box, `ZincComponentCompilerSpec` fails to compile 2.10 compiler bridge with the following error: ``` /T/sbt_1234/xsbti/compile/CompilerBridgeProvider.java:33: error: `;' expected but `{' found. static CompilerBridgeProvider constant(File file, ScalaInstance scalaInstance) { ^ ``` I suspected that this is due to Java `interface` defining a static method, a change introduced in only in Java 8. After making this change, the spec passed the test. --- .../xsbti/compile/CompilerBridgeProvider.java | 40 ------------------- .../scala/sbt/internal/inc/IncHandler.scala | 2 +- .../java/xsbti/compile/ZincCompilerUtil.java | 40 +++++++++++++++++++ .../scala/sbt/internal/inc/ZincUtil.scala | 6 ++- .../test/scala/sbt/inc/BaseCompilerSpec.scala | 2 +- .../sbt/inc/MultiProjectIncrementalSpec.scala | 2 +- 6 files changed, 48 insertions(+), 44 deletions(-) diff --git a/internal/compiler-interface/src/main/java/xsbti/compile/CompilerBridgeProvider.java b/internal/compiler-interface/src/main/java/xsbti/compile/CompilerBridgeProvider.java index 6d8f513eeb..c2fc08cf2e 100644 --- a/internal/compiler-interface/src/main/java/xsbti/compile/CompilerBridgeProvider.java +++ b/internal/compiler-interface/src/main/java/xsbti/compile/CompilerBridgeProvider.java @@ -7,9 +7,7 @@ package xsbti.compile; -import xsbti.F0; import xsbti.Logger; - import java.io.File; /** @@ -20,44 +18,6 @@ * compile them and then define the sbt component, which is reused across different sbt projects. */ public interface CompilerBridgeProvider { - - /** - * Defines a constant {@link CompilerBridgeProvider} that returns an already compiled bridge. - *

- * This method is useful for external build tools that want full control over the retrieval - * and compilation of the compiler bridge, as well as the Scala instance to be used. - * - * @param file The jar or directory of the compiled Scala bridge. - * @return A provider that always returns the same compiled bridge. - */ - static CompilerBridgeProvider constant(File file, ScalaInstance scalaInstance) { - return new CompilerBridgeProvider() { - @Override - public File fetchCompiledBridge(ScalaInstance scalaInstance, Logger logger) { - logger.debug(new F0() { - @Override - public String apply() { - String bridgeName = file.getAbsolutePath(); - return "Returning already retrieved and compiled bridge: " + bridgeName + "."; - } - }); - return file; - } - - @Override - public ScalaInstance fetchScalaInstance(String scalaVersion, Logger logger) { - logger.debug(new F0() { - @Override - public String apply() { - String instance = scalaInstance.toString(); - return "Returning default scala instance:\n\t" + instance; - } - }); - return scalaInstance; - } - }; - } - /** * Get the location of the compiled Scala compiler bridge for a concrete Scala version. * diff --git a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala index 2888177ae2..f47ce2bc59 100644 --- a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala +++ b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala @@ -113,7 +113,7 @@ final class IncHandler(directory: File, cacheDir: File, scriptedLog: ManagedLogg private final val unit = (_: Seq[String]) => () def scalaCompiler(instance: xsbti.compile.ScalaInstance, bridgeJar: File): AnalyzingCompiler = { - val bridgeProvider = CompilerBridgeProvider.constant(bridgeJar, instance) + val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar) val classpath = ClasspathOptionsUtil.boot new AnalyzingCompiler(instance, bridgeProvider, classpath, unit, IncHandler.classLoaderCache) } diff --git a/zinc/src/main/java/xsbti/compile/ZincCompilerUtil.java b/zinc/src/main/java/xsbti/compile/ZincCompilerUtil.java index 4f46965690..21ba7f4867 100644 --- a/zinc/src/main/java/xsbti/compile/ZincCompilerUtil.java +++ b/zinc/src/main/java/xsbti/compile/ZincCompilerUtil.java @@ -8,6 +8,8 @@ package xsbti.compile; import java.io.File; +import xsbti.F0; +import xsbti.Logger; /** * Defines a util interface to get Scala compilers and the default implementation @@ -51,4 +53,42 @@ public static ScalaCompiler scalaCompiler(ScalaInstance scalaInstance, File compilerBridgeJar) { return sbt.internal.inc.ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar); } + + /** + * Defines a constant {@link CompilerBridgeProvider} that returns an already compiled bridge. + *

+ * This method is useful for external build tools that want full control over the retrieval + * and compilation of the compiler bridge, as well as the Scala instance to be used. + * + * @param file The jar or directory of the compiled Scala bridge. + * @return A provider that always returns the same compiled bridge. + */ + public static CompilerBridgeProvider constantBridgeProvider(ScalaInstance scalaInstance, + File compilerBridgeJar) { + return new CompilerBridgeProvider() { + @Override + public File fetchCompiledBridge(ScalaInstance scalaInstance, Logger logger) { + logger.debug(new F0() { + @Override + public String apply() { + String bridgeName = compilerBridgeJar.getAbsolutePath(); + return "Returning already retrieved and compiled bridge: " + bridgeName + "."; + } + }); + return compilerBridgeJar; + } + + @Override + public ScalaInstance fetchScalaInstance(String scalaVersion, Logger logger) { + logger.debug(new F0() { + @Override + public String apply() { + String instance = scalaInstance.toString(); + return "Returning default scala instance:\n\t" + instance; + } + }); + return scalaInstance; + } + }; + } } diff --git a/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala b/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala index 412f53df26..9b54d773c5 100644 --- a/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala +++ b/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala @@ -46,7 +46,7 @@ object ZincUtil { compilerBridgeJar: File, classpathOptions: ClasspathOptions ): AnalyzingCompiler = { - val bridgeProvider = CompilerBridgeProvider.constant(compilerBridgeJar, scalaInstance) + val bridgeProvider = constantBridgeProvider(scalaInstance, compilerBridgeJar) val emptyHandler = (_: Seq[String]) => () val loader = Some(new ClassLoaderCache(new URLClassLoader(Array()))) new AnalyzingCompiler( @@ -126,4 +126,8 @@ object ZincUtil { def compilers(javaTools: XJavaTools, scalac: ScalaCompiler): Compilers = { new Compilers(scalac, javaTools) } + + def constantBridgeProvider(scalaInstance: xsbti.compile.ScalaInstance, + compilerBridgeJar: File): xsbti.compile.CompilerBridgeProvider = + ZincCompilerUtil.constantBridgeProvider(scalaInstance, compilerBridgeJar) } diff --git a/zinc/src/test/scala/sbt/inc/BaseCompilerSpec.scala b/zinc/src/test/scala/sbt/inc/BaseCompilerSpec.scala index 340df16143..c1c725edc8 100644 --- a/zinc/src/test/scala/sbt/inc/BaseCompilerSpec.scala +++ b/zinc/src/test/scala/sbt/inc/BaseCompilerSpec.scala @@ -88,7 +88,7 @@ class BaseCompilerSpec extends BridgeProviderSpecification { } def scalaCompiler(instance: xsbti.compile.ScalaInstance, bridgeJar: File): AnalyzingCompiler = { - val bridgeProvider = CompilerBridgeProvider.constant(bridgeJar, instance) + val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar) val classpath = ClasspathOptionsUtil.boot val cache = Some(new ClassLoaderCache(new URLClassLoader(Array()))) new AnalyzingCompiler(instance, bridgeProvider, classpath, _ => (), cache) diff --git a/zinc/src/test/scala/sbt/inc/MultiProjectIncrementalSpec.scala b/zinc/src/test/scala/sbt/inc/MultiProjectIncrementalSpec.scala index e20ced046a..180ea48a62 100644 --- a/zinc/src/test/scala/sbt/inc/MultiProjectIncrementalSpec.scala +++ b/zinc/src/test/scala/sbt/inc/MultiProjectIncrementalSpec.scala @@ -207,7 +207,7 @@ class MultiProjectIncrementalSpec extends BridgeProviderSpecification { } def scalaCompiler(instance: ScalaInstance, bridgeJar: File): AnalyzingCompiler = { - val bridgeProvider = CompilerBridgeProvider.constant(bridgeJar, instance) + val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar) val classpath = ClasspathOptionsUtil.boot val cache = Some(new ClassLoaderCache(new URLClassLoader(Array()))) new AnalyzingCompiler(instance, bridgeProvider, classpath, _ => (), cache)