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 2e3da2fc..b3eb1b39 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 @@ -93,13 +93,11 @@ public CompilerOutputStyle getCompilerOutputStyle() } public String getInputFileEnding( CompilerConfiguration configuration ) - throws CompilerException { return inputFileEnding; } public String getOutputFileEnding( CompilerConfiguration configuration ) - throws CompilerException { if ( compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE ) { @@ -121,7 +119,6 @@ public String getOutputFile( CompilerConfiguration configuration ) } public boolean canUpdateTarget( CompilerConfiguration configuration ) - throws CompilerException { return true; } @@ -152,7 +149,7 @@ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration if ( includes != null && !includes.isEmpty() ) { - String[] inclStrs = includes.toArray( new String[includes.size()] ); + String[] inclStrs = includes.toArray( new String[0] ); scanner.setIncludes( inclStrs ); } else @@ -164,7 +161,7 @@ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration if ( excludes != null && !excludes.isEmpty() ) { - String[] exclStrs = excludes.toArray( new String[excludes.size()] ); + String[] exclStrs = excludes.toArray( new String[0] ); scanner.setExcludes( exclStrs ); } @@ -213,7 +210,7 @@ protected static String[] getSourceFiles( CompilerConfiguration config ) } else { - result = sources.toArray( new String[sources.size()] ); + result = sources.toArray( new String[0] ); } return result; diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/Compiler.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/Compiler.java index 1ac62d62..68d80f03 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/Compiler.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/Compiler.java @@ -39,17 +39,14 @@ public interface Compiler CompilerOutputStyle getCompilerOutputStyle(); - String getInputFileEnding( CompilerConfiguration configuration ) - throws CompilerException; + String getInputFileEnding( CompilerConfiguration configuration ); - String getOutputFileEnding( CompilerConfiguration configuration ) - throws CompilerException; + String getOutputFileEnding( CompilerConfiguration configuration ); String getOutputFile( CompilerConfiguration configuration ) throws CompilerException; - boolean canUpdateTarget( CompilerConfiguration configuration ) - throws CompilerException; + boolean canUpdateTarget( CompilerConfiguration configuration ); /** * Performs the compilation of the project. Clients must implement this diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerOutputStyle.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerOutputStyle.java index c51a734e..c6963f20 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerOutputStyle.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerOutputStyle.java @@ -57,12 +57,12 @@ public String toString() public boolean equals( Object other ) { - if ( other == null || !( other instanceof CompilerOutputStyle ) ) + if ( other instanceof CompilerOutputStyle ) { - return false; + return id.equals( ( (CompilerOutputStyle) other ).id ); } - return id.equals( ( (CompilerOutputStyle) other ).id ); + return false; } public int hashCode() diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScanner.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScanner.java index 45abc8c5..44af00a8 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScanner.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScanner.java @@ -31,7 +31,7 @@ public abstract class AbstractSourceInclusionScanner implements SourceInclusionScanner { - private final List sourceMappings = new ArrayList(); + private final List sourceMappings = new ArrayList<>(); public final void addSourceMapping( SourceMapping sourceMapping ) { @@ -56,7 +56,7 @@ protected String[] scanForSources( File sourceDir, Set sourceIncludes, S } else { - includes = sourceIncludes.toArray( new String[sourceIncludes.size()] ); + includes = sourceIncludes.toArray( new String[0] ); } ds.setIncludes( includes ); @@ -68,7 +68,7 @@ protected String[] scanForSources( File sourceDir, Set sourceIncludes, S } else { - excludes = sourceExcludes.toArray( new String[sourceExcludes.size()] ); + excludes = sourceExcludes.toArray( new String[0] ); } ds.setExcludes( excludes ); diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/InclusionScanException.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/InclusionScanException.java deleted file mode 100644 index 6b8c3a55..00000000 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/InclusionScanException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.codehaus.plexus.compiler.util.scan; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author jdcasey - */ -public class InclusionScanException - extends Exception -{ - public InclusionScanException( String message ) - { - super( message ); - } - - public InclusionScanException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScanner.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScanner.java index 967e5672..f2523cf0 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScanner.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScanner.java @@ -50,7 +50,6 @@ public SimpleSourceInclusionScanner( Set sourceIncludes, Set sou } public Set getIncludedSources( File sourceDir, File targetDir ) - throws InclusionScanException { List srcMappings = getSourceMappings(); diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SourceInclusionScanner.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SourceInclusionScanner.java index c47b4c99..a0671072 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SourceInclusionScanner.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/SourceInclusionScanner.java @@ -30,8 +30,6 @@ public interface SourceInclusionScanner * @param sourceDir * @param targetDir * @return Set of File objects - * @throws InclusionScanException */ - Set getIncludedSources( File sourceDir, File targetDir ) - throws InclusionScanException; + Set getIncludedSources( File sourceDir, File targetDir ); } diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScanner.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScanner.java index dc4f7d7a..50bb07ec 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScanner.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/StaleSourceScanner.java @@ -64,7 +64,6 @@ public StaleSourceScanner( long lastUpdatedWithinMsecs, Set sourceInclud // ---------------------------------------------------------------------- public Set getIncludedSources( File sourceDir, File targetDir ) - throws InclusionScanException { List srcMappings = getSourceMappings(); diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SingleTargetSourceMapping.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SingleTargetSourceMapping.java index a6273e5b..c3362a69 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SingleTargetSourceMapping.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SingleTargetSourceMapping.java @@ -24,8 +24,6 @@ * SOFTWARE. */ -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; - import java.util.Set; import java.util.Collections; import java.io.File; @@ -50,7 +48,6 @@ public SingleTargetSourceMapping( String sourceSuffix, String outputFile ) } public Set getTargetFiles( File targetDir, String source ) - throws InclusionScanException { if ( !source.endsWith( sourceSuffix ) ) { diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SourceMapping.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SourceMapping.java index 40d77ec4..e40b2073 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SourceMapping.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/util/scan/mapping/SourceMapping.java @@ -16,8 +16,6 @@ * limitations under the License. */ -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; - import java.io.File; import java.util.Set; @@ -26,6 +24,5 @@ */ public interface SourceMapping { - Set getTargetFiles( File targetDir, String source ) - throws InclusionScanException; + Set getTargetFiles( File targetDir, String source ); } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java index 3c89ed5d..fd8fa8e1 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/CompilerConfigurationTest.java @@ -12,7 +12,6 @@ public class CompilerConfigurationTest @Override protected void setUp() - throws Exception { configuration = new CompilerConfiguration(); } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java index efe343d4..10c88e3a 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/AbstractSourceInclusionScannerTest.java @@ -59,7 +59,7 @@ public void testGetIncludedSources() Set includedSources = scanner.getIncludedSources( base, base ); - assertTrue( "no sources were included", !includedSources.isEmpty() ); + assertFalse( "no sources were included", includedSources.isEmpty() ); for ( File file : includedSources ) { diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java index 27e9ca1a..32f4dad6 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/SimpleSourceInclusionScannerTest.java @@ -38,7 +38,7 @@ protected void setUp() super.setUp(); includes = Collections.singleton( "*.java" ); - excludes = new HashSet(); + excludes = new HashSet<>(); scanner = new SimpleSourceInclusionScanner( includes, excludes ); } diff --git a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java index cf980658..247dec30 100644 --- a/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java +++ b/plexus-compiler-api/src/test/java/org/codehaus/plexus/compiler/util/scan/mapping/SuffixMappingTest.java @@ -17,7 +17,6 @@ */ import junit.framework.TestCase; -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; import java.io.File; import java.util.HashSet; @@ -30,7 +29,6 @@ public class SuffixMappingTest extends TestCase { public void testShouldReturnSingleClassFileForSingleJavaFile() - throws InclusionScanException { String base = "path/to/file"; @@ -46,7 +44,6 @@ public void testShouldReturnSingleClassFileForSingleJavaFile() } public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() - throws InclusionScanException { String base = "path/to/file"; @@ -60,13 +57,12 @@ public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() } public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() - throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); - Set targets = new HashSet(); + Set targets = new HashSet<>(); targets.add( ".class" ); targets.add( ".xml" ); @@ -82,13 +78,12 @@ public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() } public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() - throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); - Set targets = new HashSet(); + Set targets = new HashSet<>(); targets.add( ".class" ); targets.add( ".xml" ); @@ -100,7 +95,6 @@ public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() } public void testSingleTargetMapper() - throws InclusionScanException { String base = "path/to/file"; diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java index d9f72f02..7487cf2c 100644 --- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java +++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTckTest.java @@ -77,9 +77,9 @@ public void testDeprecation() assertFalse( error.isError() ); - assertTrue( error.getMessage().indexOf( "Date" ) != -1 ); + assertTrue( error.getMessage().contains( "Date" ) ); - assertTrue( error.getMessage().indexOf( "deprecated" ) != -1 ); + assertTrue( error.getMessage().contains( "deprecated" ) ); } public void testWarning() @@ -111,7 +111,7 @@ public void testWarning() assertFalse( error.isError() ); - assertTrue( error.getMessage().indexOf( "finally block does not complete normally" ) != -1 ); + assertTrue( error.getMessage().contains( "finally block does not complete normally" ) ); } protected List compile( CompilerConfiguration configuration ) diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java index 50da0b4b..7a85cf2d 100644 --- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java +++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java @@ -33,7 +33,6 @@ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; -import javax.print.DocFlavor; import java.io.File; import java.util.ArrayList; import java.util.Collection; diff --git a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java index c06e391d..b60a53b5 100644 --- a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java +++ b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java @@ -297,7 +297,7 @@ private AjBuildConfig buildCompilerConfig( CompilerConfiguration config ) // buildConfig.setJavaOptions( javaOpts ); } - List cp = new LinkedList( config.getClasspathEntries() ); + List cp = new LinkedList<>( config.getClasspathEntries() ); File javaHomeDir = new File( System.getProperty( "java.home" ) ); File[] jars = new File( javaHomeDir, "lib" ).listFiles(); @@ -324,9 +324,9 @@ private AjBuildConfig buildCompilerConfig( CompilerConfiguration config ) } checkForAspectJRT( cp ); - if ( cp != null && !cp.isEmpty() ) + if ( !cp.isEmpty() ) { - List elements = new ArrayList( cp.size() ); + List elements = new ArrayList<>( cp.size() ); for ( String path : cp ) { elements.add( ( new File( path ) ).getAbsolutePath() ); @@ -404,11 +404,7 @@ private List compileInProcess( AjBuildConfig buildConfig ) { manager.batchBuild( buildConfig, messageHandler ); } - catch ( AbortException e ) - { - throw new CompilerException( "Unknown error while compiling", e ); - } - catch ( IOException e ) + catch ( AbortException | IOException e ) { throw new CompilerException( "Unknown error while compiling", e ); } @@ -424,7 +420,7 @@ private List compileInProcess( AjBuildConfig buildConfig ) boolean errors = messageHandler.hasAnyMessage( IMessage.ERROR, true ); - List messages = new ArrayList(); + List messages = new ArrayList<>(); if ( errors ) { IMessage[] errorMessages = messageHandler.getMessages( IMessage.ERROR, true ); @@ -485,7 +481,7 @@ private void checkForAspectJRT( List cp ) private List buildFileList( List locations ) { - List fileList = new LinkedList(); + List fileList = new LinkedList<>(); for ( String location : locations ) { fileList.add( new File( location ) ); @@ -569,7 +565,6 @@ else if ( sourceVersion == null || sourceVersion.length() <= 0 ) * @return null */ public String[] createCommandLine( CompilerConfiguration config ) - throws CompilerException { return null; } diff --git a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerConfiguration.java b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerConfiguration.java index 3d22aac2..69b9ce1e 100644 --- a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerConfiguration.java +++ b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerConfiguration.java @@ -17,21 +17,21 @@ public class AspectJCompilerConfiguration extends CompilerConfiguration { - private List aspectPath = new LinkedList(); + private List aspectPath = new LinkedList<>(); - private List inJars = new LinkedList(); + private List inJars = new LinkedList<>(); - private List inPath = new LinkedList(); + private List inPath = new LinkedList<>(); private String outputJar; - private Map ajOptions = new TreeMap(); + private Map ajOptions = new TreeMap<>(); private Map sourcePathResources; public void setAspectPath( List aspectPath ) { - this.aspectPath = new LinkedList( aspectPath ); + this.aspectPath = new LinkedList<>( aspectPath ); } public void addAspectPath( String aspectPath ) @@ -46,7 +46,7 @@ public List getAspectPath() public void setInJars( List inJars ) { - this.inJars = new LinkedList( inJars ); + this.inJars = new LinkedList<>( inJars ); } public void addInJar( String inJar ) @@ -61,7 +61,7 @@ public List getInJars() public void setInPath( List inPath ) { - this.inPath = new LinkedList( inPath ); + this.inPath = new LinkedList<>( inPath ); } public void addInPath( String inPath ) @@ -110,7 +110,7 @@ public Map getAJOptions() public void setSourcePathResources( Map sourcePathResources ) { - this.sourcePathResources = new TreeMap( sourcePathResources ); + this.sourcePathResources = new TreeMap<>( sourcePathResources ); } public Map getSourcePathResources() diff --git a/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java b/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java index e3c9835b..158a7635 100644 --- a/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java +++ b/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java @@ -3,7 +3,6 @@ import java.io.File; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import org.codehaus.plexus.compiler.AbstractCompilerTest; @@ -45,7 +44,7 @@ protected Collection expectedOutputFiles() // { // return Collections.emptyList(); // } - return Arrays.asList( new String[]{ "org/codehaus/foo/ExternalDeps.class", "org/codehaus/foo/Person.class" } ); + return Arrays.asList( "org/codehaus/foo/ExternalDeps.class", "org/codehaus/foo/Person.class" ); } protected List getClasspath() diff --git a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java index 7ff097de..fbf9e977 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java +++ b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java @@ -84,7 +84,6 @@ public CSharpCompiler() // ---------------------------------------------------------------------- public boolean canUpdateTarget( CompilerConfiguration configuration ) - throws CompilerException { return false; } @@ -242,7 +241,7 @@ private String findExecutable( CompilerConfiguration config ) private String[] buildCompilerArguments( CompilerConfiguration config, String[] sourceFiles ) throws CompilerException { - List args = new ArrayList(); + List args = new ArrayList<>(); if ( config.isDebug() ) { @@ -358,7 +357,7 @@ private String[] buildCompilerArguments( CompilerConfiguration config, String[] if ( !StringUtils.isEmpty( resourcefile ) ) { - String resourceTarget = (String) compilerArguments.get( "-resourcetarget" ); + String resourceTarget = compilerArguments.get( "-resourcetarget" ); args.add( "/res:" + new File( resourcefile ).getAbsolutePath() + "," + resourceTarget ); } @@ -395,12 +394,9 @@ private String[] buildCompilerArguments( CompilerConfiguration config, String[] // ---------------------------------------------------------------------- // add source files // ---------------------------------------------------------------------- - for ( String sourceFile : sourceFiles ) - { - args.add( sourceFile ); - } + args.addAll( Arrays.asList( sourceFiles ) ); - return args.toArray( new String[args.size()] ); + return args.toArray( new String[0] ); } private void addResourceArgs( CompilerConfiguration config, List args ) @@ -414,8 +410,7 @@ private void addResourceArgs( CompilerConfiguration config, List args ) scanner.addDefaultExcludes(); scanner.scan(); - List includedFiles = Arrays.asList( scanner.getIncludedFiles() ); - for ( String name : includedFiles ) + for ( String name : scanner.getIncludedFiles() ) { File filteredResource = new File( filteredResourceDir, name ); String assemblyResourceName = this.convertNameToAssemblyResourceName( name ); @@ -439,7 +434,7 @@ private File findResourceDir( CompilerConfiguration config ) Map compilerArguments = getCompilerArguments( config ); - String tempResourcesDirAsString = (String) compilerArguments.get( "-resourceDir" ); + String tempResourcesDirAsString = compilerArguments.get( "-resourceDir" ); File filteredResourceDir = null; if ( tempResourcesDirAsString != null ) { @@ -525,11 +520,7 @@ private List compileOutOfProcess( File workingDirectory, File t messages = parseCompilerOutput( new BufferedReader( new StringReader( stringWriter.toString() ) ) ); } - catch ( CommandLineException e ) - { - throw new CompilerException( "Error while executing the external compiler.", e ); - } - catch ( IOException e ) + catch ( CommandLineException | IOException e ) { throw new CompilerException( "Error while executing the external compiler.", e ); } @@ -548,7 +539,7 @@ private List compileOutOfProcess( File workingDirectory, File t public static List parseCompilerOutput( BufferedReader bufferedReader ) throws IOException { - List messages = new ArrayList(); + List messages = new ArrayList<>(); String line = bufferedReader.readLine(); @@ -600,7 +591,7 @@ private String getTypeExtension( CompilerConfiguration configuration ) // added for debug purposes.... protected static String[] getSourceFiles( CompilerConfiguration config ) { - Set sources = new HashSet(); + Set sources = new HashSet<>(); //Set sourceFiles = null; //was: @@ -637,7 +628,7 @@ protected static String[] getSourceFiles( CompilerConfiguration config ) } else { - result = (String[]) sources.toArray( new String[sources.size()] ); + result = sources.toArray( new String[0] ); } return result; @@ -665,7 +656,7 @@ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration if ( includes != null && !includes.isEmpty() ) { - String[] inclStrs = includes.toArray( new String[includes.size()] ); + String[] inclStrs = includes.toArray( new String[0] ); scanner.setIncludes( inclStrs ); } else @@ -677,7 +668,7 @@ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration if ( excludes != null && !excludes.isEmpty() ) { - String[] exclStrs = excludes.toArray( new String[excludes.size()] ); + String[] exclStrs = excludes.toArray( new String[0] ); scanner.setIncludes( exclStrs ); } @@ -685,7 +676,7 @@ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration String[] sourceDirectorySources = scanner.getIncludedFiles(); - Set sources = new HashSet(); + Set sources = new HashSet<>(); for ( String source : sourceDirectorySources ) { diff --git a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/DefaultCSharpCompilerParser.java b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/DefaultCSharpCompilerParser.java index 7fcf1fea..e2d8cf02 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/DefaultCSharpCompilerParser.java +++ b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/DefaultCSharpCompilerParser.java @@ -31,7 +31,7 @@ public class DefaultCSharpCompilerParser public static CompilerMessage parseLine( String line ) { - CompilerMessage ce = null; + CompilerMessage ce; if ( isOutputWithNoColumnNumber( line ) ) { @@ -61,7 +61,7 @@ private static boolean isOutputWithNoColumnNumber( String line ) String chunk2 = chunk1.substring( 0, j ); - return ( chunk2.indexOf( "," ) == -1 ); + return ( !chunk2.contains( "," ) ); } private static CompilerMessage parseLineWithNoColumnNumber( String line ) @@ -85,7 +85,7 @@ else if ( line.startsWith( COMPILATION_PREFIX ) ) return null; } - else if ( line.indexOf( MAGIC_LINE_MARKER ) != -1 ) + else if ( line.contains( MAGIC_LINE_MARKER ) ) { int i = line.indexOf( MAGIC_LINE_MARKER ); @@ -101,7 +101,7 @@ else if ( line.indexOf( MAGIC_LINE_MARKER ) != -1 ) message = line.substring( j + 1 + ERROR_PREFIX.length() ); - error = line.indexOf( ") error" ) != -1; + error = line.contains( ") error" ); } else { @@ -133,7 +133,7 @@ else if ( line.startsWith( COMPILATION_PREFIX ) ) { return null; } - else if ( line.indexOf( MAGIC_LINE_MARKER ) != -1 ) + else if ( line.contains( MAGIC_LINE_MARKER ) ) { int i = line.indexOf( MAGIC_LINE_MARKER ); @@ -143,10 +143,10 @@ else if ( line.indexOf( MAGIC_LINE_MARKER ) != -1 ) String linecol = line.substring( i + MAGIC_LINE_MARKER.length(), j - 2 ); - String linenum = null; - String colnum = null; + String linenum; + String colnum; - if ( linecol.indexOf( "," ) > -1 && linecol.split( "," ).length == 2 ) + if ( linecol.contains( "," ) && linecol.split( "," ).length == 2 ) { linenum = linecol.split( "," )[0]; colnum = linecol.split( "," )[1]; @@ -172,7 +172,7 @@ else if ( linecol.split( "," ).length == 1 ) message = line.substring( j + 1 + ERROR_PREFIX.length() ); - error = line.indexOf( "): error" ) != -1; + error = line.contains( "): error" ); } else { diff --git a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/JarUtil.java b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/JarUtil.java index 695b7e00..5b897378 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/JarUtil.java +++ b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/JarUtil.java @@ -21,20 +21,13 @@ public static void extract( File destDir, File jarFile ) throws IOException f.mkdir(); continue; } - InputStream is = jar.getInputStream( file ); - FileOutputStream fos = new FileOutputStream( f ); - try + try ( InputStream is = jar.getInputStream( file ); FileOutputStream fos = new FileOutputStream( f ) ) { while ( is.available() > 0 ) { fos.write( is.read() ); } } - finally - { - is.close(); - fos.close(); - } } } } diff --git a/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java b/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java index 3d353b40..d3e69456 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java +++ b/plexus-compilers/plexus-compiler-csharp/src/test/java/org/codehaus/plexus/compiler/csharp/CSharpCompilerTest.java @@ -180,9 +180,9 @@ public void testParserCscWin() assertEquals( 24, messagesWinCsc.size() ); assertTrue( "Check that the line number is not -1", - ( (CompilerMessage) messagesWinCsc.get( 0 ) ).getStartLine() != -1 ); + messagesWinCsc.get( 0 ).getStartLine() != -1 ); assertTrue( "Check that the column number is not -1", - ( (CompilerMessage) messagesWinCsc.get( 0 ) ).getStartColumn() != -1 ); + messagesWinCsc.get( 0 ).getStartColumn() != -1 ); } @@ -211,9 +211,9 @@ public void testParserMonoWin() assertEquals( 5, messagesMonoWin.size() ); assertTrue( "Check that the line number is not -1", - ( (CompilerMessage) messagesMonoWin.get( 0 ) ).getStartLine() != -1 ); + messagesMonoWin.get( 0 ).getStartLine() != -1 ); assertTrue( "Check that the column number is not -1", - ( (CompilerMessage) messagesMonoWin.get( 0 ) ).getStartColumn() != -1 ); + messagesMonoWin.get( 0 ).getStartColumn() != -1 ); } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java index 10011149..c3254901 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -32,7 +33,7 @@ public List parse(File xmltf, boolean errorsAsWarnings) throws List list = new ArrayList<>(); XMLInputFactory xmlif = getStreamFactory(); - try(Reader src = new BufferedReader(new InputStreamReader(new FileInputStream(xmltf), "utf-8"))) { + try(Reader src = new BufferedReader(new InputStreamReader(new FileInputStream(xmltf), StandardCharsets.UTF_8 ))) { XMLStreamReader xsr = xmlif.createXMLStreamReader(src); // scan for "source" elements, skip all else. diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java index 3f84de5f..44f18e14 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java @@ -26,7 +26,6 @@ import org.codehaus.plexus.compiler.AbstractCompiler; import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.compiler.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; @@ -35,7 +34,6 @@ import org.eclipse.jdt.core.compiler.batch.BatchCompiler; import java.io.File; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; @@ -62,7 +60,6 @@ public EclipseJavaCompiler() boolean errorsAsWarnings = false; public CompilerResult performCompile(CompilerConfiguration config ) - throws CompilerException { List args = new ArrayList<>(); args.add("-noExit"); // Make sure ecj does not System.exit on us 8-/ @@ -273,7 +270,7 @@ else if(extras.containsKey("-errorsAsWarnings")) PrintWriter devNull = new PrintWriter(sw); //BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() { - boolean success = BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() { + boolean success = BatchCompiler.compile(args.toArray( new String[0] ), devNull, devNull, new CompilationProgress() { @Override public void begin(int i) { @@ -320,10 +317,8 @@ public void worked(int i, int i1) } if(!hasError && !success && !errorsAsWarnings) { - CompilerMessage.Kind kind = errorsAsWarnings ? CompilerMessage.Kind.WARNING : CompilerMessage.Kind.ERROR; - //-- Compiler reported failure but we do not seem to have one -> probable exception - CompilerMessage cm = new CompilerMessage("[ecj] The compiler reported an error but has not written it to its logging", kind); + CompilerMessage cm = new CompilerMessage("[ecj] The compiler reported an error but has not written it to its logging", CompilerMessage.Kind.ERROR); messageList.add(cm); hasError = true; @@ -331,7 +326,7 @@ public void worked(int i, int i1) String stdout = getLastLines(sw.toString(), 5); if(stdout.length() > 0) { - cm = new CompilerMessage("[ecj] The following line(s) might indicate the issue:\n" + stdout, kind); + cm = new CompilerMessage("[ecj] The following line(s) might indicate the issue:\n" + stdout, CompilerMessage.Kind.ERROR); messageList.add(cm); } } @@ -397,7 +392,6 @@ private boolean isPreJava16(CompilerConfiguration config) { } public String[] createCommandLine( CompilerConfiguration config ) - throws CompilerException { return null; } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/SourceCodeLocator.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/SourceCodeLocator.java index c18b35c7..d2bf643d 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/SourceCodeLocator.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/SourceCodeLocator.java @@ -42,7 +42,7 @@ public SourceCodeLocator( List sourceRoots ) { this.sourceRoots = sourceRoots; - cache = new HashMap(); + cache = new HashMap<>(); } public File findSourceCodeForClass( String className ) diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java index 363e0cd7..2b223513 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java @@ -39,14 +39,11 @@ protected int expectedWarnings() protected Collection expectedOutputFiles() { - return Arrays.asList( new String[] { - "org/codehaus/foo/Deprecation.class", - "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", - "org/codehaus/foo/ReservedWord.class", - //"org/codehaus/foo/Bad.class", // This one has no class file generated as it's one big issue - //"org/codehaus/foo/UnknownSymbol.class", - //"org/codehaus/foo/RightClassname.class" - }); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" //, + // "org/codehaus/foo/Bad.class", // This one has no class file generated as it's one big issue + // "org/codehaus/foo/UnknownSymbol.class", + // "org/codehaus/foo/RightClassname.class" + ); } } diff --git a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java index aa5d6259..89ebe645 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java @@ -64,8 +64,8 @@ protected int expectedWarnings() protected Collection expectedOutputFiles() { - return Arrays.asList( new String[] { "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" ); } // The test is fairly meaningless as we can not validate anything diff --git a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java index 6840cbdf..df474b18 100644 --- a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java +++ b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java @@ -71,20 +71,19 @@ public class J2ObjCCompiler * Put the arguments of j2objc who takes one dash inside an array, in order * the check the command line. */ - private static final List ONE_DASH_ARGS = Arrays.asList( - new String[]{ "-pluginpath", "-pluginoptions", "-t", "-Xno-jsni-warnings", "-sourcepath", "-classpath", "-d", - "-encoding", "-g", "-q", "-v", "-Werror", "-h", "-use-arc", "-use-reference-counting", "-x" } ); + private static final List ONE_DASH_ARGS = Arrays.asList( "-pluginpath", "-pluginoptions", "-t", + "-Xno-jsni-warnings", "-sourcepath", "-classpath", "-d", "-encoding", "-g", "-q", "-v", "-Werror", "-h", + "-use-arc", "-use-reference-counting", "-x" ); /** * Put the command line arguments with 2 dashes inside an array, in order * the check the command line and build it. */ - private static final List TWO_DASH_ARGS = Arrays.asList( - new String[]{ "--build-closure", "--dead-code-report", "--doc-comments", "--no-extract-unsequenced", - "--generate-deprecated", "--mapping", "--no-class-methods", "--no-final-methods-functions", - "--no-hide-private-members", "--no-package-directories", "--prefix", "--prefixes", "--preserve-full-paths", - "--strip-gwt-incompatible", "--strip-reflection", "--segmented-headers", "--timing-info", "--quiet", - "--verbose", "--help" } ); + private static final List TWO_DASH_ARGS = Arrays.asList( "--build-closure", "--dead-code-report", + "--doc-comments", "--no-extract-unsequenced", "--generate-deprecated", "--mapping", "--no-class-methods", + "--no-final-methods-functions", "--no-hide-private-members", "--no-package-directories", "--prefix", + "--prefixes", "--preserve-full-paths", "--strip-gwt-incompatible", "--strip-reflection", + "--segmented-headers", "--timing-info", "--quiet", "--verbose", "--help" ); public J2ObjCCompiler() { @@ -96,7 +95,6 @@ public J2ObjCCompiler() // ---------------------------------------------------------------------- public boolean canUpdateTarget( CompilerConfiguration configuration ) - throws CompilerException { return false; } @@ -142,7 +140,6 @@ public CompilerResult performCompile( CompilerConfiguration config ) } public String[] createCommandLine( CompilerConfiguration config ) - throws CompilerException { return buildCompilerArguments( config, J2ObjCCompiler.getSourceFiles( config ) ); } @@ -176,15 +173,13 @@ private String findExecutable( CompilerConfiguration config ) * @param config * @param sourceFiles * @return The List to give to the command line tool - * @throws CompilerException */ private String[] buildCompilerArguments( CompilerConfiguration config, String[] sourceFiles ) - throws CompilerException { /* * j2objc --help Usage: j2objc */ - List args = new ArrayList(); + List args = new ArrayList<>(); Map compilerArguments = config.getCustomCompilerArgumentsAsMap(); // Verbose @@ -199,7 +194,7 @@ private String[] buildCompilerArguments( CompilerConfiguration config, String[] if ( !config.getClasspathEntries().isEmpty() ) { - List classpath = new ArrayList(); + List classpath = new ArrayList<>(); for ( String element : config.getClasspathEntries() ) { File f = new File( element ); @@ -256,12 +251,9 @@ else if ( ONE_DASH_ARGS.contains( k ) ) } } - for ( String sourceFile : sourceFiles ) - { - args.add( sourceFile ); - } + args.addAll( Arrays.asList( sourceFiles ) ); - return args.toArray( new String[args.size()] ); + return args.toArray( new String[0] ); } private List compileOutOfProcess( File workingDirectory, File target, String executable, @@ -293,11 +285,7 @@ private List compileOutOfProcess( File workingDirectory, File t messages = parseCompilerOutput( new BufferedReader( new StringReader( stringWriter.toString() ) ) ); } - catch ( CommandLineException e ) - { - throw new CompilerException( "Error while executing the external compiler.", e ); - } - catch ( IOException e ) + catch ( CommandLineException | IOException e ) { throw new CompilerException( "Error while executing the external compiler.", e ); } @@ -316,7 +304,7 @@ private List compileOutOfProcess( File workingDirectory, File t public static List parseCompilerOutput( BufferedReader bufferedReader ) throws IOException { - List messages = new ArrayList(); + List messages = new ArrayList<>(); String line = bufferedReader.readLine(); diff --git a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java b/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java index b3680bfb..8f39e0ff 100644 --- a/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java +++ b/plexus-compilers/plexus-compiler-j2objc/src/test/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompilerTest.java @@ -30,8 +30,8 @@ import org.codehaus.plexus.compiler.CompilerException; import java.io.File; -import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -44,15 +44,14 @@ public class J2ObjCCompilerTest { public void testJ2ObjCCompiler() - throws IOException { J2ObjCCompiler comp = new J2ObjCCompiler(); - Map customCompilerArguments = new HashMap(); + Map customCompilerArguments = new HashMap<>(); customCompilerArguments.put( "-use-arc", null ); customCompilerArguments.put( "-sourcepath", "src/test/resources" ); CompilerConfiguration cc = new CompilerConfiguration(); cc.setOutputLocation( "target/generated/objective-c" ); - cc.setSourceLocations( Arrays.asList( new String[]{ "src/test/resources" } ) ); + cc.setSourceLocations( Collections.singletonList( "src/test/resources" ) ); cc.setWorkingDirectory( new File( "." ) ); cc.setFork( true ); cc.setCustomCompilerArgumentsAsMap( customCompilerArguments ); diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java index a840b6f5..dc08edc9 100644 --- a/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java +++ b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java @@ -30,7 +30,6 @@ import javax.tools.JavaFileObject; import java.io.File; import java.lang.reflect.Method; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; @@ -53,7 +52,6 @@ public JavacCompilerWithErrorProne() } public String[] createCommandLine( CompilerConfiguration config ) - throws CompilerException { return new String[0]; } @@ -88,8 +86,7 @@ public CompilerResult performCompile( CompilerConfiguration config ) try { - CompilerResult compilerResult = (CompilerResult) getInvoker().invoke( null, new Object[]{ args } ); - return compilerResult; + return (CompilerResult) getInvoker().invoke( null, new Object[]{ args } ); } catch ( Exception e ) { @@ -103,7 +100,6 @@ private static class NonDelegatingClassLoader ClassLoader original; public NonDelegatingClassLoader( URL[] urls, ClassLoader original ) - throws MalformedURLException { super( urls, null ); this.original = original; diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/src/test/java/org/codehaus/plexus/compiler/javac/JavacErrorProneCompilerTest.java b/plexus-compilers/plexus-compiler-javac-errorprone/src/test/java/org/codehaus/plexus/compiler/javac/JavacErrorProneCompilerTest.java index 55264dba..3545659f 100644 --- a/plexus-compilers/plexus-compiler-javac-errorprone/src/test/java/org/codehaus/plexus/compiler/javac/JavacErrorProneCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac-errorprone/src/test/java/org/codehaus/plexus/compiler/javac/JavacErrorProneCompilerTest.java @@ -25,16 +25,9 @@ */ import org.codehaus.plexus.compiler.AbstractCompilerTest; -import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.util.StringUtils; -import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; /** * @author Jason van Zyl @@ -67,7 +60,7 @@ protected int expectedErrors() protected Collection expectedOutputFiles() { - return Arrays.asList( new String[]{ "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" ); } } 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 8f92a64c..4f52f94e 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 @@ -102,7 +102,7 @@ public class JavacCompiler private static volatile Class JAVAC_CLASS; - private List> javaccClasses = new CopyOnWriteArrayList>(); + private final List> javaccClasses = new CopyOnWriteArrayList<>(); // ---------------------------------------------------------------------- // @@ -198,14 +198,13 @@ protected static boolean isJava16() } public String[] createCommandLine( CompilerConfiguration config ) - throws CompilerException { return buildCompilerArguments( config, getSourceFiles( config ) ); } public static String[] buildCompilerArguments( CompilerConfiguration config, String[] sourceFiles ) { - List args = new ArrayList(); + List args = new ArrayList<>(); // ---------------------------------------------------------------------- // Set output @@ -401,7 +400,7 @@ else if ( !suppressSource( config ) ) args.add( value ); } - return args.toArray( new String[args.size()] ); + return args.toArray( new String[0] ); } /** @@ -563,11 +562,7 @@ protected CompilerResult compileOutOfProcess( CompilerConfiguration config, Stri messages = parseModernStream( returnCode, new BufferedReader( new StringReader( out.getOutput() ) ) ); } - catch ( CommandLineException e ) - { - throw new CompilerException( "Error while executing the external compiler.", e ); - } - catch ( IOException e ) + catch ( CommandLineException | IOException e ) { throw new CompilerException( "Error while executing the external compiler.", e ); } @@ -625,30 +620,18 @@ private static CompilerResult compileInProcess0( Class javacClass, String[] a try { - Method compile = javacClass.getMethod( "compile", new Class[]{ String[].class, PrintWriter.class } ); + Method compile = javacClass.getMethod( "compile", String[].class, PrintWriter.class ); ok = (Integer) compile.invoke( null, new Object[]{ args, new PrintWriter( out ) } ); - messages = parseModernStream( ok.intValue(), new BufferedReader( new StringReader( out.toString() ) ) ); - } - catch ( NoSuchMethodException e ) - { - throw new CompilerException( "Error while executing the compiler.", e ); - } - catch ( IllegalAccessException e ) - { - throw new CompilerException( "Error while executing the compiler.", e ); + messages = parseModernStream( ok, new BufferedReader( new StringReader( out.toString() ) ) ); } - catch ( InvocationTargetException e ) - { - throw new CompilerException( "Error while executing the compiler.", e ); - } - catch ( IOException e ) + catch ( NoSuchMethodException | IOException | InvocationTargetException | IllegalAccessException e ) { throw new CompilerException( "Error while executing the compiler.", e ); } - boolean success = ok.intValue() == 0; + boolean success = ok == 0; return new CompilerResult( success, messages ); } @@ -663,7 +646,7 @@ private static CompilerResult compileInProcess0( Class javacClass, String[] a static List parseModernStream( int exitCode, BufferedReader input ) throws IOException { - List errors = new ArrayList(); + List errors = new ArrayList<>(); String line; @@ -769,9 +752,9 @@ private static boolean isNote( String line ) private static boolean startsWithPrefix( String line, String[] prefixes ) { - for ( int i = 0; i < prefixes.length; i++ ) + for ( String prefix : prefixes ) { - if ( line.startsWith( prefixes[i] ) ) + if ( line.startsWith( prefix ) ) { return true; } @@ -914,10 +897,6 @@ else if ( msgLine.endsWith( "^" ) ) { return new CompilerMessage( "no more tokens - could not parse error message: " + error, isError ); } - catch ( NumberFormatException e ) - { - return new CompilerMessage( "could not parse error message: " + error, isError ); - } catch ( Exception e ) { return new CompilerMessage( "could not parse error message: " + error, isError ); @@ -926,11 +905,11 @@ else if ( msgLine.endsWith( "^" ) ) private static String getWarnPrefix( String msg ) { - for ( int i = 0; i < WARNING_PREFIXES.length; i++ ) + for ( String warningPrefix : WARNING_PREFIXES ) { - if ( msg.startsWith( WARNING_PREFIXES[i] ) ) + if ( msg.startsWith( warningPrefix ) ) { - return WARNING_PREFIXES[i]; + return warningPrefix; } } return null; @@ -963,9 +942,9 @@ private File createFileWithArguments( String[] args, String outputDirectory ) writer = new PrintWriter( new FileWriter( tempFile ) ); - for ( int i = 0; i < args.length; i++ ) + for ( String arg : args ) { - String argValue = args[i].replace( File.separatorChar, '/' ); + String argValue = arg.replace( File.separatorChar, '/' ); writer.write( "\"" + argValue + "\"" ); @@ -1061,7 +1040,7 @@ private void releaseJavaccClass( Class javaccClass, CompilerConfiguration com private Class getJavacClass( CompilerConfiguration compilerConfiguration ) throws CompilerException { - Class c = null; + Class c; switch ( compilerConfiguration.getCompilerReuseStrategy() ) { case AlwaysNew: diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java index 85b048bc..f878186a 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java @@ -49,7 +49,7 @@ public class JavaxToolsCompiler @SuppressWarnings( "restriction" ) static final JavaCompiler COMPILER = ToolProvider.getSystemJavaCompiler(); - private static List JAVA_COMPILERS = new CopyOnWriteArrayList<>(); + private static final List JAVA_COMPILERS = new CopyOnWriteArrayList<>(); protected static JavaCompiler getJavaCompiler( CompilerConfiguration compilerConfiguration ) { @@ -105,7 +105,7 @@ static CompilerResult compileInProcess( String[] args, final CompilerConfigurati } final String sourceEncoding = config.getSourceEncoding(); final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding ); - final DiagnosticCollector collector = new DiagnosticCollector(); + final DiagnosticCollector collector = new DiagnosticCollector<>(); final StandardJavaFileManager standardFileManager = compiler.getStandardFileManager( collector, null, sourceCharset ); @@ -124,7 +124,7 @@ static CompilerResult compileInProcess( String[] args, final CompilerConfigurati final JavaCompiler.CompilationTask task = compiler.getTask( null, standardFileManager, collector, arguments, null, fileObjects ); final Boolean result = task.call(); - final ArrayList compilerMsgs = new ArrayList(); + final ArrayList compilerMsgs = new ArrayList<>(); for ( Diagnostic diagnostic : collector.getDiagnostics() ) { CompilerMessage.Kind kind = convertKind(diagnostic); diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java index fdee0363..902b86ae 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java @@ -132,11 +132,11 @@ protected Collection expectedOutputFiles() { String javaVersion = getJavaVersion(); if (javaVersion.contains("9.0")||javaVersion.contains("11")){ - return Arrays.asList( new String[]{ "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class"} ); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class" ); } - return Arrays.asList( new String[]{ "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" ); } public void internalTest( CompilerConfiguration compilerConfiguration, List expectedArguments ) @@ -253,7 +253,7 @@ public void testJRuntimeArguments() expectedArguments.add( "1.3" ); // customCompilerArguments - Map customCompilerArguments = new LinkedHashMap(); + Map customCompilerArguments = new LinkedHashMap<>(); customCompilerArguments.put( "-J-Duser.language=en_us", null ); compilerConfiguration.setCustomCompilerArgumentsAsMap( customCompilerArguments ); // don't expect this argument!! @@ -261,7 +261,7 @@ public void testJRuntimeArguments() internalTest( compilerConfiguration, expectedArguments ); } - public void testModulePath() throws Exception + public void testModulePath() { List expectedArguments = new ArrayList<>(); @@ -426,7 +426,7 @@ private void populateArguments( CompilerConfiguration compilerConfiguration, Lis // classpathEntires - List classpathEntries = new ArrayList(); + List classpathEntries = new ArrayList<>(); classpathEntries.add( "/myjar1.jar" ); @@ -440,7 +440,7 @@ private void populateArguments( CompilerConfiguration compilerConfiguration, Lis // sourceRoots - List compileSourceRoots = new ArrayList(); + List compileSourceRoots = new ArrayList<>(); compileSourceRoots.add( "/src/main/one" ); @@ -512,7 +512,7 @@ private void populateArguments( CompilerConfiguration compilerConfiguration, Lis // customerCompilerArguments - Map customerCompilerArguments = new LinkedHashMap(); + Map customerCompilerArguments = new LinkedHashMap<>(); customerCompilerArguments.put( "arg1", null ); diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java index cb14c8bb..6d9c9194 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java @@ -44,7 +44,6 @@ public class ErrorMessageParserTest private static final String EOL = System.getProperty( "line.separator" ); public void testDeprecationMessage() - throws Exception { String error = "target/compiler-src/testDeprecation/Foo.java:1: warning: Date(java.lang.String) in java.util.Date has been deprecated" @@ -212,7 +211,7 @@ public void testLocalizedWarningNotTreatedAsError() JavacCompiler.parseModernStream( 0, new BufferedReader( new StringReader( errors ) ) ); assertEquals( 1, messages.size() ); - assertFalse( ( (CompilerMessage) messages.get( 0 ) ).isError() ); + assertFalse( messages.get( 0 ).isError() ); } public void testUnixFileNames() @@ -624,7 +623,7 @@ public void testCRLF_windows() List compilerMessages = JavacCompiler.parseModernStream( 0, new BufferedReader( new StringReader( errors ) ) ); assertEquals( "count", 187, compilerMessages.size() ); - List compilerErrors = new ArrayList( 3 ); + List compilerErrors = new ArrayList<>( 3 ); for ( CompilerMessage message : compilerMessages ) { if ( message.getKind() != CompilerMessage.Kind.OTHER ) { compilerErrors.add( message ); diff --git a/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java b/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java index d6d26110..feaf8c0c 100644 --- a/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java +++ b/plexus-compilers/plexus-compiler-jikes/src/main/java/org/codehaus/plexus/compiler/jikes/JikesCompiler.java @@ -95,6 +95,7 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -158,7 +159,7 @@ public CompilerResult performCompile( CompilerConfiguration config ) BufferedReader input = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( tmpErr.toByteArray() ) ) ); - List messages = new ArrayList(); + List messages = new ArrayList<>(); parseStream( input, messages ); @@ -169,11 +170,7 @@ public CompilerResult performCompile( CompilerConfiguration config ) return new CompilerResult().compilerMessages( messages ); } - catch ( IOException e ) - { - throw new CompilerException( "Error while compiling.", e ); - } - catch ( InterruptedException e ) + catch ( IOException | InterruptedException e ) { throw new CompilerException( "Error while compiling.", e ); } @@ -182,7 +179,7 @@ public CompilerResult performCompile( CompilerConfiguration config ) public String[] createCommandLine( CompilerConfiguration config ) throws CompilerException { - List args = new ArrayList(); + List args = new ArrayList<>(); args.add( "jikes" ); @@ -285,9 +282,9 @@ public String[] createCommandLine( CompilerConfiguration config ) tempFile.getParentFile().mkdirs(); fw = new BufferedWriter( new FileWriter( tempFile ) ); - for ( int i = 0; i < sourceFiles.length; i++ ) + for ( String sourceFile : sourceFiles ) { - fw.write( sourceFiles[i] ); + fw.write( sourceFile ); fw.newLine(); } fw.flush(); @@ -306,14 +303,11 @@ public String[] createCommandLine( CompilerConfiguration config ) } else { - for ( int i = 0; i < sourceFiles.length; i++ ) - { - args.add( sourceFiles[i] ); - } + Collections.addAll( args, sourceFiles ); } - return (String[]) args.toArray( new String[args.size()] ); + return args.toArray( new String[0] ); } // ----------------------------------------------------------------------- @@ -334,7 +328,7 @@ private File getDestinationDir( CompilerConfiguration config ) private List getBootClassPath() { - List bootClassPath = new ArrayList(); + List bootClassPath = new ArrayList<>(); FileFilter filter = new FileFilter() { @@ -371,7 +365,7 @@ public boolean accept( File file ) private List asList( File[] files ) { - List filenames = new ArrayList( files.length ); + List filenames = new ArrayList<>( files.length ); for ( File file : files ) { filenames.add( file.toString() ); @@ -482,7 +476,7 @@ private CompilerMessage parseError( String error ) message.append( ':' ).append( errorBits[i++] ); } - return new CompilerMessage( file, type.indexOf( "Error" ) > -1, startline, startcolumn, endline, endcolumn, + return new CompilerMessage( file, type.contains( "Error" ), startline, startcolumn, endline, endcolumn, message.toString() ); } } diff --git a/plexus-compilers/plexus-compiler-jikes/src/test/java/org/codehaus/plexus/compiler/jikes/JikesCompilerTest.java b/plexus-compilers/plexus-compiler-jikes/src/test/java/org/codehaus/plexus/compiler/jikes/JikesCompilerTest.java index dfc5a1dc..2a7362cb 100644 --- a/plexus-compilers/plexus-compiler-jikes/src/test/java/org/codehaus/plexus/compiler/jikes/JikesCompilerTest.java +++ b/plexus-compilers/plexus-compiler-jikes/src/test/java/org/codehaus/plexus/compiler/jikes/JikesCompilerTest.java @@ -61,9 +61,9 @@ protected int expectedWarnings() protected Collection expectedOutputFiles() { - return Arrays.asList( new String[]{ "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", - "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class", - "org/codehaus/foo/RightClassname.class" } ); + return Arrays.asList( "org/codehaus/foo/Deprecation.class", "org/codehaus/foo/ExternalDeps.class", + "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class", + "org/codehaus/foo/RightClassname.class" ); } }