Skip to content

Commit de5e97a

Browse files
authored
Merge pull request #17 from rhowe/tidyups
Miscellaneous code cleanups
2 parents 62438bb + 3aab7d7 commit de5e97a

File tree

6 files changed

+18
-34
lines changed

6 files changed

+18
-34
lines changed

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ private List<String> resolveProcessorPathEntries()
16671667

16681668
resolutionErrorHandler.throwErrors( request, resolutionResult );
16691669

1670-
List<String> elements = new ArrayList<String>( resolutionResult.getArtifacts().size() );
1670+
List<String> elements = new ArrayList<>( resolutionResult.getArtifacts().size() );
16711671

16721672
for ( Object resolved : resolutionResult.getArtifacts() )
16731673
{

src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java

+8-17
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected void preparePaths( Set<File> sourceFiles )
230230
.setMainModuleDescriptor( moduleDescriptorPath );
231231

232232
Toolchain toolchain = getToolchain();
233-
if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
233+
if ( toolchain instanceof DefaultJavaToolChain )
234234
{
235235
request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
236236
}
@@ -256,27 +256,22 @@ protected void preparePaths( Set<File> sourceFiles )
256256
{
257257
pathElements.put( entry.getKey().getPath(), entry.getValue() );
258258
}
259-
259+
260+
if ( compilerArgs == null )
261+
{
262+
compilerArgs = new ArrayList<>();
263+
}
264+
260265
for ( File file : resolvePathsResult.getClasspathElements() )
261266
{
262267
classpathElements.add( file.getPath() );
263268

264269
if ( multiReleaseOutput )
265270
{
266-
if ( compilerArgs == null )
267-
{
268-
compilerArgs = new ArrayList<>();
269-
}
270-
271271
if ( getOutputDirectory().toPath().startsWith( file.getPath() ) )
272272
{
273273
compilerArgs.add( "--patch-module" );
274-
275-
StringBuilder patchModuleValue = new StringBuilder( moduleDescriptor.name() )
276-
.append( '=' )
277-
.append( file.getPath() );
278-
279-
compilerArgs.add( patchModuleValue.toString() );
274+
compilerArgs.add( String.format( "%s=%s", moduleDescriptor.name(), file.getPath() ) );
280275
}
281276
}
282277
}
@@ -286,10 +281,6 @@ protected void preparePaths( Set<File> sourceFiles )
286281
modulepathElements.add( file.getPath() );
287282
}
288283

289-
if ( compilerArgs == null )
290-
{
291-
compilerArgs = new ArrayList<>();
292-
}
293284
compilerArgs.add( "--module-version" );
294285
compilerArgs.add( getProject().getVersion() );
295286

src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected void preparePaths( Set<File> sourceFiles )
241241
.setMainModuleDescriptor( mainModuleDescriptorClassFile.getAbsolutePath() );
242242

243243
Toolchain toolchain = getToolchain();
244-
if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
244+
if ( toolchain instanceof DefaultJavaToolChain )
245245
{
246246
request.setJdkHome( ( (DefaultJavaToolChain) toolchain ).getJavaHome() );
247247
}
@@ -285,7 +285,7 @@ protected void preparePaths( Set<File> sourceFiles )
285285
.setMainModuleDescriptor( testModuleDescriptorJavaFile.getAbsolutePath() );
286286

287287
Toolchain toolchain = getToolchain();
288-
if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
288+
if ( toolchain instanceof DefaultJavaToolChain )
289289
{
290290
request.setJdkHome( ( (DefaultJavaToolChain) toolchain ).getJavaHome() );
291291
}
@@ -336,7 +336,7 @@ else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) )
336336
{
337337
if ( compilerArgs == null )
338338
{
339-
compilerArgs = new ArrayList<String>();
339+
compilerArgs = new ArrayList<>();
340340
}
341341
compilerArgs.add( "--patch-module" );
342342

@@ -380,7 +380,7 @@ else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) )
380380
{
381381
if ( compilerArgs == null )
382382
{
383-
compilerArgs = new ArrayList<String>();
383+
compilerArgs = new ArrayList<>();
384384
}
385385
compilerArgs.add( "--patch-module" );
386386

src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ public void testCompilerIncludesExcludes()
161161
CompilerMojo compileMojo =
162162
getCompilerMojo( "target/test-classes/unit/compiler-includes-excludes-test/plugin-config.xml" );
163163

164-
Set<String> includes = new HashSet<String>();
164+
Set<String> includes = new HashSet<>();
165165
includes.add( "**/TestCompile4*.java" );
166166
setVariableValueToObject( compileMojo, "includes", includes );
167167

168-
Set<String> excludes = new HashSet<String>();
168+
Set<String> excludes = new HashSet<>();
169169
excludes.add( "**/TestCompile2*.java" );
170170
excludes.add( "**/TestCompile3*.java" );
171171
setVariableValueToObject( compileMojo, "excludes", excludes );
@@ -275,11 +275,11 @@ public void testOneOutputFileForAllInput2()
275275

276276
setVariableValueToObject( compileMojo, "compilerManager", new CompilerManagerStub() );
277277

278-
Set<String> includes = new HashSet<String>();
278+
Set<String> includes = new HashSet<>();
279279
includes.add( "**/TestCompile4*.java" );
280280
setVariableValueToObject( compileMojo, "includes", includes );
281281

282-
Set<String> excludes = new HashSet<String>();
282+
Set<String> excludes = new HashSet<>();
283283
excludes.add( "**/TestCompile2*.java" );
284284
excludes.add( "**/TestCompile3*.java" );
285285
setVariableValueToObject( compileMojo, "excludes", excludes );
@@ -414,7 +414,7 @@ private TestCompilerMojo getTestCompilerMojo( CompilerMojo compilerMojo, String
414414
File testClassesDir = new File( buildDir, "test-classes" );
415415
setVariableValueToObject( mojo, "outputDirectory", testClassesDir );
416416

417-
List<String> testClasspathList = new ArrayList<String>();
417+
List<String> testClasspathList = new ArrayList<>();
418418

419419
Artifact junitArtifact = mock( Artifact.class );
420420
ArtifactHandler handler = mock( ArtifactHandler.class );

src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerManagerStub.java

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121

2222
import org.codehaus.plexus.compiler.manager.CompilerManager;
23-
import org.codehaus.plexus.compiler.manager.NoSuchCompilerException;
2423

2524
/**
2625
* @author Edwin Punzalan
@@ -41,7 +40,6 @@ public CompilerManagerStub( boolean shouldFail )
4140
}
4241

4342
public org.codehaus.plexus.compiler.Compiler getCompiler( String compilerId )
44-
throws NoSuchCompilerException
4543
{
4644
return new CompilerStub( shouldFail );
4745
}

src/test/java/org/apache/maven/plugin/compiler/stubs/CompilerStub.java

-5
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,21 @@ public CompilerOutputStyle getCompilerOutputStyle()
5555
}
5656

5757
public String getInputFileEnding( CompilerConfiguration compilerConfiguration )
58-
throws CompilerException
5958
{
6059
return "java";
6160
}
6261

6362
public String getOutputFileEnding( CompilerConfiguration compilerConfiguration )
64-
throws CompilerException
6563
{
6664
return "class";
6765
}
6866

6967
public String getOutputFile( CompilerConfiguration compilerConfiguration )
70-
throws CompilerException
7168
{
7269
return "output-file";
7370
}
7471

7572
public boolean canUpdateTarget( CompilerConfiguration compilerConfiguration )
76-
throws CompilerException
7773
{
7874
return false;
7975
}
@@ -126,7 +122,6 @@ public CompilerResult performCompile( CompilerConfiguration compilerConfiguratio
126122
}
127123

128124
public String[] createCommandLine( CompilerConfiguration compilerConfiguration )
129-
throws CompilerException
130125
{
131126
return new String[0];
132127
}

0 commit comments

Comments
 (0)