diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index 93394d8b..ea172abd 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1667,7 +1667,7 @@ private List resolveProcessorPathEntries() resolutionErrorHandler.throwErrors( request, resolutionResult ); - List elements = new ArrayList( resolutionResult.getArtifacts().size() ); + List elements = new ArrayList<>( resolutionResult.getArtifacts().size() ); for ( Object resolved : resolutionResult.getArtifacts() ) { diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java index 8bc437b3..78d39088 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java @@ -230,7 +230,7 @@ protected void preparePaths( Set sourceFiles ) .setMainModuleDescriptor( moduleDescriptorPath ); Toolchain toolchain = getToolchain(); - if ( toolchain != null && toolchain instanceof DefaultJavaToolChain ) + if ( toolchain instanceof DefaultJavaToolChain ) { request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) ); } @@ -256,27 +256,22 @@ protected void preparePaths( Set sourceFiles ) { pathElements.put( entry.getKey().getPath(), entry.getValue() ); } - + + if ( compilerArgs == null ) + { + compilerArgs = new ArrayList<>(); + } + for ( File file : resolvePathsResult.getClasspathElements() ) { classpathElements.add( file.getPath() ); if ( multiReleaseOutput ) { - if ( compilerArgs == null ) - { - compilerArgs = new ArrayList<>(); - } - if ( getOutputDirectory().toPath().startsWith( file.getPath() ) ) { compilerArgs.add( "--patch-module" ); - - StringBuilder patchModuleValue = new StringBuilder( moduleDescriptor.name() ) - .append( '=' ) - .append( file.getPath() ); - - compilerArgs.add( patchModuleValue.toString() ); + compilerArgs.add( String.format( "%s=%s", moduleDescriptor.name(), file.getPath() ) ); } } } @@ -286,10 +281,6 @@ protected void preparePaths( Set sourceFiles ) modulepathElements.add( file.getPath() ); } - if ( compilerArgs == null ) - { - compilerArgs = new ArrayList<>(); - } compilerArgs.add( "--module-version" ); compilerArgs.add( getProject().getVersion() ); diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java index f8b9ba18..5b0518b1 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java @@ -241,7 +241,7 @@ protected void preparePaths( Set sourceFiles ) .setMainModuleDescriptor( mainModuleDescriptorClassFile.getAbsolutePath() ); Toolchain toolchain = getToolchain(); - if ( toolchain != null && toolchain instanceof DefaultJavaToolChain ) + if ( toolchain instanceof DefaultJavaToolChain ) { request.setJdkHome( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ); } @@ -285,7 +285,7 @@ protected void preparePaths( Set sourceFiles ) .setMainModuleDescriptor( testModuleDescriptorJavaFile.getAbsolutePath() ); Toolchain toolchain = getToolchain(); - if ( toolchain != null && toolchain instanceof DefaultJavaToolChain ) + if ( toolchain instanceof DefaultJavaToolChain ) { request.setJdkHome( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ); } @@ -336,7 +336,7 @@ else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) ) { if ( compilerArgs == null ) { - compilerArgs = new ArrayList(); + compilerArgs = new ArrayList<>(); } compilerArgs.add( "--patch-module" ); @@ -380,7 +380,7 @@ else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) ) { if ( compilerArgs == null ) { - compilerArgs = new ArrayList(); + compilerArgs = new ArrayList<>(); } compilerArgs.add( "--patch-module" ); diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java index 37a60ca5..348cfb04 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java @@ -161,11 +161,11 @@ public void testCompilerIncludesExcludes() CompilerMojo compileMojo = getCompilerMojo( "target/test-classes/unit/compiler-includes-excludes-test/plugin-config.xml" ); - Set includes = new HashSet(); + Set includes = new HashSet<>(); includes.add( "**/TestCompile4*.java" ); setVariableValueToObject( compileMojo, "includes", includes ); - Set excludes = new HashSet(); + Set excludes = new HashSet<>(); excludes.add( "**/TestCompile2*.java" ); excludes.add( "**/TestCompile3*.java" ); setVariableValueToObject( compileMojo, "excludes", excludes ); @@ -275,11 +275,11 @@ public void testOneOutputFileForAllInput2() setVariableValueToObject( compileMojo, "compilerManager", new CompilerManagerStub() ); - Set includes = new HashSet(); + Set includes = new HashSet<>(); includes.add( "**/TestCompile4*.java" ); setVariableValueToObject( compileMojo, "includes", includes ); - Set excludes = new HashSet(); + Set excludes = new HashSet<>(); excludes.add( "**/TestCompile2*.java" ); excludes.add( "**/TestCompile3*.java" ); setVariableValueToObject( compileMojo, "excludes", excludes ); @@ -414,7 +414,7 @@ private TestCompilerMojo getTestCompilerMojo( CompilerMojo compilerMojo, String File testClassesDir = new File( buildDir, "test-classes" ); setVariableValueToObject( mojo, "outputDirectory", testClassesDir ); - List testClasspathList = new ArrayList(); + List testClasspathList = new ArrayList<>(); Artifact junitArtifact = mock( Artifact.class ); ArtifactHandler handler = mock( ArtifactHandler.class ); diff --git a/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerManagerStub.java b/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerManagerStub.java index efa5ee9f..eff1ce34 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerManagerStub.java +++ b/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerManagerStub.java @@ -20,7 +20,6 @@ */ import org.codehaus.plexus.compiler.manager.CompilerManager; -import org.codehaus.plexus.compiler.manager.NoSuchCompilerException; /** * @author Edwin Punzalan @@ -41,7 +40,6 @@ public CompilerManagerStub( boolean shouldFail ) } public org.codehaus.plexus.compiler.Compiler getCompiler( String compilerId ) - throws NoSuchCompilerException { return new CompilerStub( shouldFail ); } diff --git a/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerStub.java b/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerStub.java index 94710c6c..fd94cc24 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerStub.java +++ b/src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerStub.java @@ -55,25 +55,21 @@ public CompilerOutputStyle getCompilerOutputStyle() } public String getInputFileEnding( CompilerConfiguration compilerConfiguration ) - throws CompilerException { return "java"; } public String getOutputFileEnding( CompilerConfiguration compilerConfiguration ) - throws CompilerException { return "class"; } public String getOutputFile( CompilerConfiguration compilerConfiguration ) - throws CompilerException { return "output-file"; } public boolean canUpdateTarget( CompilerConfiguration compilerConfiguration ) - throws CompilerException { return false; } @@ -126,7 +122,6 @@ public CompilerResult performCompile( CompilerConfiguration compilerConfiguratio } public String[] createCommandLine( CompilerConfiguration compilerConfiguration ) - throws CompilerException { return new String[0]; }