diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java index 5957950f9..08d42df85 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java @@ -42,7 +42,10 @@ public abstract class AbstractCompiler implements Compiler { private final Logger log = LoggerFactory.getLogger(getClass()); - private final org.codehaus.plexus.logging.Logger plexusLogger; + // created on first use, through a factory method so that verifying this class does not load the Plexus + // logging classes: the Plexus logging classes are optional, a compiler created without a container + // (see DefaultCompilerManager.fromServiceLoader) must not need them + private volatile org.codehaus.plexus.logging.Logger plexusLogger; protected static final String EOL = System.lineSeparator(); @@ -72,8 +75,6 @@ protected AbstractCompiler( this.outputFileEnding = outputFileEnding; this.outputFile = outputFile; - - this.plexusLogger = new PlexusLoggerWrapper(log); } /** @@ -90,7 +91,11 @@ protected Logger getLog() { */ @Deprecated protected org.codehaus.plexus.logging.Logger getLogger() { - return plexusLogger; + org.codehaus.plexus.logging.Logger result = plexusLogger; + if (result == null) { + plexusLogger = result = PlexusLoggerWrapper.wrap(log); + } + return result; } // ---------------------------------------------------------------------- diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/PlexusLoggerWrapper.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/PlexusLoggerWrapper.java index 0aa8413be..a8d254f51 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/PlexusLoggerWrapper.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/PlexusLoggerWrapper.java @@ -6,6 +6,10 @@ class PlexusLoggerWrapper implements org.codehaus.plexus.logging.Logger { private final Logger log; + static org.codehaus.plexus.logging.Logger wrap(Logger log) { + return new PlexusLoggerWrapper(log); + } + PlexusLoggerWrapper(Logger log) { this.log = log; } diff --git a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java index b8024a221..8989e6dcd 100644 --- a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java +++ b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java @@ -26,9 +26,16 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; +import javax.inject.Singleton; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Objects; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; +import org.codehaus.plexus.compiler.AbstractCompiler; import org.codehaus.plexus.compiler.Compiler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,11 +52,115 @@ public class DefaultCompilerManager implements CompilerManager { + "might indicate, that the compiler needs a more recent Java runtime. " + "IllegalArgumentException in ClassReader. might mean, that you need to upgrade Maven."; + private static final int MAX_LOOKUP_FAILURES = 100; + @Inject private Map> compilers; private final Logger log = LoggerFactory.getLogger(getClass()); + /** + * Creates a manager populated through {@link ServiceLoader} instead of a dependency injection container. + * Intended for callers that cannot use Sisu/Plexus, for example Maven 4 API plugins that bind the result + * with a plugin-local {@code @Provides} method. + *

+ * Every {@link Compiler} registered in {@code META-INF/services/org.codehaus.plexus.compiler.Compiler} of the + * given class loader is registered under its {@code @Named} value, the key Sisu uses (equal to + * {@link AbstractCompiler#getCompilerId()}), or under the compiler id if it has no {@code @Named}. Instance + * scope follows the Sisu-based manager: a compiler class annotated {@code @Singleton} (javac, eclipse) is + * shared, any other one gets a new instance on every {@link #getCompiler(String)} call, so it needs a public + * no-argument constructor. + * If two providers share an id, the first one found wins. + *

+ * A provider that cannot be loaded or instantiated, for example because an optional dependency such as + * ecj, AspectJ or Error Prone is missing from the class loader, is skipped with a warning and the other + * providers are still registered. Asking for the skipped id throws {@link NoSuchCompilerException}. + * + * @param classLoader the class loader to look providers up in + * @return a new manager holding every compiler that could be loaded + * @since 2.18.0 + */ + public static DefaultCompilerManager fromServiceLoader(ClassLoader classLoader) { + Objects.requireNonNull(classLoader, "classLoader"); + DefaultCompilerManager manager = new DefaultCompilerManager(); + Map> providers = new HashMap<>(); + Iterator iterator = + ServiceLoader.load(Compiler.class, classLoader).iterator(); + int failures = 0; + while (failures < MAX_LOOKUP_FAILURES) { + Compiler compiler; + try { + if (!iterator.hasNext()) { + break; + } + compiler = iterator.next(); + } catch (ServiceConfigurationError e) { + // the iterator has already moved past the offending entry, so carry on with the next one; + // the cap only guards against an iterator that would fail forever + failures++; + manager.log.warn("Skipping a compiler that cannot be loaded: {}", e.getMessage(), e); + continue; + } + String id = idOf(compiler); + if (id == null) { + manager.log.warn("Skipping compiler {}: it has neither @Named nor a compiler id", compiler.getClass()); + continue; + } + Class type = compiler.getClass(); + providers.putIfAbsent( + id, + type.isAnnotationPresent(Singleton.class) + ? new SingletonProvider(compiler) + : new NewInstanceProvider(type)); + } + manager.compilers = providers; + return manager; + } + + /** + * The key Sisu registers the compiler under: its {@code @Named} value, which equals + * {@link AbstractCompiler#getCompilerId()} for every compiler in this project. + */ + private static String idOf(Compiler compiler) { + Named named = compiler.getClass().getAnnotation(Named.class); + if (named != null && !named.value().isEmpty()) { + return named.value(); + } + return compiler instanceof AbstractCompiler ? ((AbstractCompiler) compiler).getCompilerId() : null; + } + + /** Hands out the one instance, like a Sisu binding of a {@code @Singleton} class. */ + private static final class SingletonProvider implements Provider { + private final Compiler instance; + + SingletonProvider(Compiler instance) { + this.instance = instance; + } + + @Override + public Compiler get() { + return instance; + } + } + + /** Creates a fresh compiler per call, like an unscoped Sisu binding. */ + private static final class NewInstanceProvider implements Provider { + private final Class type; + + NewInstanceProvider(Class type) { + this.type = type; + } + + @Override + public Compiler get() { + try { + return type.getConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Cannot instantiate " + type.getName(), e); + } + } + } + // ---------------------------------------------------------------------- // CompilerManager Implementation // ---------------------------------------------------------------------- diff --git a/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilerManagerTest.java b/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilerManagerTest.java new file mode 100644 index 000000000..55a2a0b7a --- /dev/null +++ b/plexus-compiler-manager/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilerManagerTest.java @@ -0,0 +1,120 @@ +package org.codehaus.plexus.compiler.manager; + +/** + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.codehaus.plexus.compiler.AbstractCompiler; +import org.codehaus.plexus.compiler.Compiler; +import org.codehaus.plexus.compiler.CompilerConfiguration; +import org.codehaus.plexus.compiler.CompilerException; +import org.codehaus.plexus.compiler.CompilerOutputStyle; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Builds a {@link DefaultCompilerManager} with no Sisu or Plexus container. + */ +class ServiceLoaderCompilerManagerTest { + + @javax.inject.Named("per-call") + public static class PerCallCompiler extends AbstractCompiler { + public PerCallCompiler() { + super(CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE, ".x", ".y", null); + } + + @Override + public String getCompilerId() { + return "per-call"; + } + + @Override + public String[] createCommandLine(CompilerConfiguration config) throws CompilerException { + return new String[0]; + } + } + + @javax.inject.Named("shared") + @javax.inject.Singleton + public static class SharedCompiler extends PerCallCompiler { + @Override + public String getCompilerId() { + return "shared"; + } + } + + private static URLClassLoader loaderWith(Path dir, String... lines) throws Exception { + Path services = dir.resolve("META-INF/services/" + Compiler.class.getName()); + Files.createDirectories(services.getParent()); + Files.write(services, String.join("\n", lines).getBytes(StandardCharsets.UTF_8)); + return new URLClassLoader( + new URL[] {dir.toUri().toURL()}, ServiceLoaderCompilerManagerTest.class.getClassLoader()); + } + + @Test + void compilersAreFoundById(@TempDir Path dir) throws Exception { + try (URLClassLoader loader = loaderWith(dir, PerCallCompiler.class.getName(), SharedCompiler.class.getName())) { + CompilerManager manager = DefaultCompilerManager.fromServiceLoader(loader); + + assertInstanceOf(PerCallCompiler.class, manager.getCompiler("per-call")); + assertInstanceOf(SharedCompiler.class, manager.getCompiler("shared")); + assertThrows(NoSuchCompilerException.class, () -> manager.getCompiler("foo")); + } + } + + @Test + void instanceScopeFollowsSisu(@TempDir Path dir) throws Exception { + try (URLClassLoader loader = loaderWith(dir, PerCallCompiler.class.getName(), SharedCompiler.class.getName())) { + CompilerManager manager = DefaultCompilerManager.fromServiceLoader(loader); + + assertNotSame(manager.getCompiler("per-call"), manager.getCompiler("per-call")); + assertSame(manager.getCompiler("shared"), manager.getCompiler("shared")); + } + } + + @Test + void providerThatCannotBeLoadedIsSkipped(@TempDir Path dir) throws Exception { + try (URLClassLoader loader = loaderWith( + dir, + "org.example.MissingCompiler", + PerCallCompiler.class.getName(), + "org.example.OtherMissingCompiler", + SharedCompiler.class.getName())) { + CompilerManager manager = DefaultCompilerManager.fromServiceLoader(loader); + + assertInstanceOf(PerCallCompiler.class, manager.getCompiler("per-call")); + assertInstanceOf(SharedCompiler.class, manager.getCompiler("shared")); + assertThrows(NoSuchCompilerException.class, () -> manager.getCompiler("missing")); + } + } +} diff --git a/plexus-compiler-service-loader-test/pom.xml b/plexus-compiler-service-loader-test/pom.xml new file mode 100644 index 000000000..ebdf38a73 --- /dev/null +++ b/plexus-compiler-service-loader-test/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + org.codehaus.plexus + plexus-compiler + 2.17.2-SNAPSHOT + + + plexus-compiler-service-loader-test + + Plexus Compiler ServiceLoader Tests + Tests that need every compiler implementation on the classpath: the ServiceLoader entries must find + them all and must not drift from the Sisu index. + + + 21 + true + + + + + org.codehaus.plexus + plexus-compiler-api + + + org.codehaus.plexus + plexus-compiler-manager + + + org.codehaus.plexus + plexus-compiler-aspectj + ${project.version} + + + org.codehaus.plexus + plexus-compiler-csharp + ${project.version} + + + org.codehaus.plexus + plexus-compiler-eclipse + ${project.version} + + + org.codehaus.plexus + plexus-compiler-javac + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + ${project.version} + + + org.junit.jupiter + junit-jupiter-api + test + + + diff --git a/plexus-compiler-service-loader-test/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilersTest.java b/plexus-compiler-service-loader-test/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilersTest.java new file mode 100644 index 000000000..5a1561b92 --- /dev/null +++ b/plexus-compiler-service-loader-test/src/test/java/org/codehaus/plexus/compiler/manager/ServiceLoaderCompilersTest.java @@ -0,0 +1,110 @@ +package org.codehaus.plexus.compiler.manager; + +/** + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.Set; +import java.util.TreeSet; + +import org.codehaus.plexus.compiler.AbstractCompiler; +import org.codehaus.plexus.compiler.Compiler; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Runs with every compiler implementation module on the classpath. + */ +class ServiceLoaderCompilersTest { + private static final String SERVICES = "META-INF/services/" + Compiler.class.getName(); + + private static final String SISU_INDEX = "META-INF/sisu/javax.inject.Named"; + + @Test + void everyCompilerIsFoundById() throws Exception { + CompilerManager manager = + DefaultCompilerManager.fromServiceLoader(getClass().getClassLoader()); + + for (String id : Arrays.asList("javac", "eclipse", "aspectj", "csharp", "javac-with-errorprone")) { + Compiler compiler = manager.getCompiler(id); + assertNotNull(compiler, id); + assertEquals(id, ((AbstractCompiler) compiler).getCompilerId()); + } + // the in-process compiler default must work without injection + assertInstanceOf(org.codehaus.plexus.compiler.javac.JavacCompiler.class, manager.getCompiler("javac")); + } + + /** + * The Sisu index is generated from {@code @Named}, the services files are written by hand: per module, + * both must name the same {@link Compiler} classes. + */ + @Test + void servicesFilesMatchTheSisuIndexPerModule() throws Exception { + Enumeration indexes = getClass().getClassLoader().getResources(SISU_INDEX); + int modules = 0; + while (indexes.hasMoreElements()) { + URL index = indexes.nextElement(); + String root = index.toString().substring(0, index.toString().length() - SISU_INDEX.length()); + Set named = new TreeSet<>(); + for (String name : lines(index)) { + Class type = Class.forName(name, false, getClass().getClassLoader()); + if (Compiler.class.isAssignableFrom(type)) { + named.add(name); + } + } + if (named.isEmpty()) { + continue; // not a compiler module (e.g. the manager itself) + } + modules++; + URL services = URI.create(root + SERVICES).toURL(); + assertEquals(named, lines(services), "services file in " + root); + } + assertEquals(5, modules, "compiler modules found with a Sisu index"); + } + + private static Set lines(URL url) throws IOException { + Set result = new TreeSet<>(); + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + int hash = line.indexOf('#'); + String name = (hash >= 0 ? line.substring(0, hash) : line).trim(); + if (!name.isEmpty()) { + result.add(name); + } + } + } + return result; + } +} diff --git a/plexus-compilers/plexus-compiler-aspectj/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler b/plexus-compilers/plexus-compiler-aspectj/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler new file mode 100644 index 000000000..e66900ce3 --- /dev/null +++ b/plexus-compilers/plexus-compiler-aspectj/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler @@ -0,0 +1,24 @@ +# +# The MIT License +# +# Copyright (c) 2005, The Codehaus +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +org.codehaus.plexus.compiler.ajc.AspectJCompiler diff --git a/plexus-compilers/plexus-compiler-csharp/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler b/plexus-compilers/plexus-compiler-csharp/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler new file mode 100644 index 000000000..68d3fa08a --- /dev/null +++ b/plexus-compilers/plexus-compiler-csharp/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler @@ -0,0 +1,24 @@ +# +# The MIT License +# +# Copyright (c) 2005, The Codehaus +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +org.codehaus.plexus.compiler.csharp.CSharpCompiler diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler b/plexus-compilers/plexus-compiler-eclipse/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler new file mode 100644 index 000000000..275daf49d --- /dev/null +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler @@ -0,0 +1,24 @@ +# +# The MIT License +# +# Copyright (c) 2005, The Codehaus +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler new file mode 100644 index 000000000..56b111b02 --- /dev/null +++ b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler @@ -0,0 +1,24 @@ +# +# The MIT License +# +# Copyright (c) 2005, The Codehaus +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java index 9dd44fdcc..bae9704c2 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java @@ -224,8 +224,9 @@ protected static class Messages { /** Cache of javac version per executable (never invalidated) */ private static final Map VERSION_PER_EXECUTABLE = new ConcurrentHashMap<>(); + // Sisu replaces this default by field injection; the default serves instances created by ServiceLoader @Inject - private InProcessCompiler inProcessCompiler; + private InProcessCompiler inProcessCompiler = new JavaxToolsCompiler(); // ---------------------------------------------------------------------- // diff --git a/plexus-compilers/plexus-compiler-javac/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler b/plexus-compilers/plexus-compiler-javac/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler new file mode 100644 index 000000000..ec7da7dc9 --- /dev/null +++ b/plexus-compilers/plexus-compiler-javac/src/main/resources/META-INF/services/org.codehaus.plexus.compiler.Compiler @@ -0,0 +1,24 @@ +# +# The MIT License +# +# Copyright (c) 2005, The Codehaus +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +org.codehaus.plexus.compiler.javac.JavacCompiler diff --git a/pom.xml b/pom.xml index d9241c184..2969105fe 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ plexus-compiler-manager plexus-compilers plexus-compiler-test + plexus-compiler-service-loader-test plexus-compiler-its