Skip to content

Commit 37bb82e

Browse files
committed
Introduce provider methods to allow replacement by subclassing
1 parent d34d50f commit 37bb82e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public CompilerResult performCompile( CompilerConfiguration config )
173173
{
174174
// use fqcn to prevent loading of the class on 1.5 environment !
175175
result =
176-
new org.codehaus.plexus.compiler.javac.JavaxToolsCompiler().compileInProcess( args, config, sourceFiles );
176+
javaxToolsCompiler().compileInProcess( args, config, sourceFiles );
177177
}
178178
else
179179
{
@@ -184,6 +184,11 @@ public CompilerResult performCompile( CompilerConfiguration config )
184184
return result;
185185
}
186186

187+
protected JavaxToolsCompiler javaxToolsCompiler()
188+
{
189+
return new org.codehaus.plexus.compiler.javac.JavaxToolsCompiler();
190+
}
191+
187192
protected static boolean isJava16()
188193
{
189194
try

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public class JavaxToolsCompiler
4747
* is that thread safe ???
4848
*/
4949
@SuppressWarnings( "restriction" )
50-
private final JavaCompiler COMPILER = ToolProvider.getSystemJavaCompiler();
50+
private final JavaCompiler COMPILER = newJavaCompiler();
51+
52+
protected JavaCompiler newJavaCompiler()
53+
{
54+
return ToolProvider.getSystemJavaCompiler();
55+
}
5156

5257
private List<JavaCompiler> JAVA_COMPILERS = new CopyOnWriteArrayList<>();
5358

@@ -56,7 +61,7 @@ private JavaCompiler getJavaCompiler( CompilerConfiguration compilerConfiguratio
5661
switch ( compilerConfiguration.getCompilerReuseStrategy() )
5762
{
5863
case AlwaysNew:
59-
return ToolProvider.getSystemJavaCompiler();
64+
return newJavaCompiler();
6065
case ReuseCreated:
6166
JavaCompiler javaCompiler;
6267
synchronized ( JAVA_COMPILERS )
@@ -68,7 +73,7 @@ private JavaCompiler getJavaCompiler( CompilerConfiguration compilerConfiguratio
6873
return javaCompiler;
6974
}
7075
}
71-
javaCompiler = ToolProvider.getSystemJavaCompiler();
76+
javaCompiler = newJavaCompiler();
7277
return javaCompiler;
7378
case ReuseSame:
7479
default:

0 commit comments

Comments
 (0)