diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4ceced5a..38fddea7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -49,4 +49,4 @@ jobs: java-version: ${{ matrix.java }} - name: Build with Maven - run: mvn install -e -B -V -Pno-tests-if-not-on-osx + run: mvn install javadoc:javadoc -e -B -V -Pno-tests-if-not-on-osx diff --git a/plexus-compiler-manager/pom.xml b/plexus-compiler-manager/pom.xml index 0391ffd0..22c4a204 100644 --- a/plexus-compiler-manager/pom.xml +++ b/plexus-compiler-manager/pom.xml @@ -17,5 +17,9 @@ org.codehaus.plexus plexus-compiler-api + + org.codehaus.plexus + plexus-component-annotations + 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 0ed57506..741111bb 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 @@ -25,21 +25,21 @@ */ import org.codehaus.plexus.compiler.Compiler; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.util.Map; /** * @author Trygve Laugstøl - * @plexus.component */ +@Component( role = CompilerManager.class ) public class DefaultCompilerManager extends AbstractLogEnabled implements CompilerManager { - /** - * @plexus.requirement role="org.codehaus.plexus.compiler.Compiler" - */ + @Requirement private Map compilers; // ---------------------------------------------------------------------- diff --git a/plexus-compilers/plexus-compiler-aspectj/pom.xml b/plexus-compilers/plexus-compiler-aspectj/pom.xml index f8b9e7a8..c4b7eda3 100644 --- a/plexus-compilers/plexus-compiler-aspectj/pom.xml +++ b/plexus-compilers/plexus-compiler-aspectj/pom.xml @@ -18,6 +18,10 @@ + + org.codehaus.plexus + plexus-component-annotations + org.aspectj aspectjrt 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 29e9b2f8..286407cd 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 @@ -10,11 +10,13 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.aspectj.tools.ajc.Main; 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.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import java.io.File; import java.io.IOException; @@ -281,8 +283,8 @@ *

* * @author Jason van Zyl - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="aspectj" */ +@Component( role = Compiler.class, hint = "aspectj") public class AspectJCompiler extends AbstractCompiler { 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..aceb8762 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 ) @@ -86,7 +86,6 @@ public String getOutputJar() /** * Ignored, not supported yet - * @param ajOptions */ public void setAJOptions( Map ajOptions ) { @@ -118,4 +117,4 @@ public Map getSourcePathResources() return sourcePathResources; } -} \ No newline at end of file +} diff --git a/plexus-compilers/plexus-compiler-csharp/pom.xml b/plexus-compilers/plexus-compiler-csharp/pom.xml index bccc5680..100ff2cb 100644 --- a/plexus-compilers/plexus-compiler-csharp/pom.xml +++ b/plexus-compilers/plexus-compiler-csharp/pom.xml @@ -14,6 +14,10 @@ C# Compiler support for Plexus Compiler component. + + org.codehaus.plexus + plexus-component-annotations + org.codehaus.plexus plexus-utils 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..6b360930 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 @@ -22,6 +22,7 @@ import org.codehaus.plexus.compiler.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.Os; @@ -54,9 +55,8 @@ * @author Trygve Laugstøl * @author Matthew Pocock * @author Chris Stevenson - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" - * role-hint="csharp" */ +@Component( role = Compiler.class, hint = "csharp" ) public class CSharpCompiler extends AbstractCompiler { @@ -242,7 +242,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 +358,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 ); } @@ -439,7 +439,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 ) { @@ -548,7 +548,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(); @@ -582,7 +582,7 @@ private String getType( Map compilerArguments ) private String getTypeExtension( CompilerConfiguration configuration ) throws CompilerException { - String type = getType( configuration.getCustomCompilerArguments() ); + String type = getType( configuration.getCustomCompilerArgumentsAsMap() ); if ( "exe".equals( type ) || "winexe".equals( type ) ) { @@ -600,7 +600,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 +637,7 @@ protected static String[] getSourceFiles( CompilerConfiguration config ) } else { - result = (String[]) sources.toArray( new String[sources.size()] ); + result = sources.toArray( new String[sources.size()] ); } return result; @@ -685,7 +685,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-eclipse/pom.xml b/plexus-compilers/plexus-compiler-eclipse/pom.xml index 810ea226..7fb5f4f1 100644 --- a/plexus-compilers/plexus-compiler-eclipse/pom.xml +++ b/plexus-compilers/plexus-compiler-eclipse/pom.xml @@ -23,6 +23,10 @@ ecj 3.22.0 + + org.codehaus.plexus + plexus-component-annotations + diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java index 5c4f62d2..7fda6f47 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java @@ -4,11 +4,14 @@ * @author Frits Jalvingh * Created on 22-4-18. */ -public class EcjFailureException extends RuntimeException { +public class EcjFailureException + extends RuntimeException +{ private final String ecjOutput; - public EcjFailureException(String ecjOutput) { - super("Failed to run the ecj compiler: " + ecjOutput); + public EcjFailureException( String ecjOutput ) + { + super( "Failed to run the ecj compiler: " + ecjOutput ); this.ecjOutput = ecjOutput; } 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..651de08d 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 @@ -19,139 +19,201 @@ * @author Frits Jalvingh * Created on 31-3-18. */ -public class EcjResponseParser { - /*--------------------------------------------------------------*/ - /* CODING: Decode ECJ -log format results. */ - /*--------------------------------------------------------------*/ - /** - * Scan the specified response file for compilation messages. - */ - public List parse(File xmltf, boolean errorsAsWarnings) throws Exception { - //if(xmltf.length() < 80) - // return; - - List list = new ArrayList<>(); - XMLInputFactory xmlif = getStreamFactory(); - try(Reader src = new BufferedReader(new InputStreamReader(new FileInputStream(xmltf), "utf-8"))) { - XMLStreamReader xsr = xmlif.createXMLStreamReader(src); - - // scan for "source" elements, skip all else. - while(xsr.hasNext()) { - int type = xsr.next(); - if(type == XMLStreamConstants.START_ELEMENT && "source".equals(xsr.getLocalName())) { - decodeSourceElement(list, xsr, errorsAsWarnings); +public class EcjResponseParser +{ + /*--------------------------------------------------------------*/ + /* CODING: Decode ECJ -log format results. */ + /*--------------------------------------------------------------*/ + + private static final XMLInputFactory FACTORY = getStreamFactory(); + + static private XMLInputFactory getStreamFactory() + { + XMLInputFactory xmlif = XMLInputFactory.newInstance(); + xmlif.setProperty( XMLInputFactory.IS_VALIDATING, Boolean.FALSE ); + xmlif.setProperty( XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE ); + xmlif.setProperty( XMLInputFactory.SUPPORT_DTD, Boolean.FALSE ); + return xmlif; + } + + /** + * @param xmltf the xml file + * @param errorsAsWarnings should we treat errors as warnings + * Scan the specified response file for compilation messages. + */ + public List parse( File xmltf, boolean errorsAsWarnings ) + throws Exception + { + //if(xmltf.length() < 80) + // return; + + List list = new ArrayList<>(); + + try (Reader src = new BufferedReader( new InputStreamReader( new FileInputStream( xmltf ), "utf-8" ) )) + { + XMLStreamReader xsr = FACTORY.createXMLStreamReader( src ); + + // scan for "source" elements, skip all else. + while ( xsr.hasNext() ) + { + int type = xsr.next(); + if ( type == XMLStreamConstants.START_ELEMENT && "source".equals( xsr.getLocalName() ) ) + { + decodeSourceElement( list, xsr, errorsAsWarnings ); + } + } + } + return list; + } + + private void decodeSourceElement( List list, XMLStreamReader xsr, boolean errorsAsWarnings ) + throws Exception + { + String filename = xsr.getAttributeValue( null, "path" ); + + //-- Got a file- call handler + File path = new File( filename ).getCanonicalFile(); + while ( xsr.hasNext() ) + { + int type = xsr.nextTag(); + if ( type == XMLStreamConstants.START_ELEMENT ) + { + if ( "problems".equals( xsr.getLocalName() ) ) + { + decodeProblems( list, path.toString(), xsr, errorsAsWarnings ); } - } - } - return list; - } - - private void decodeSourceElement(List list, XMLStreamReader xsr, boolean errorsAsWarnings) throws Exception { - String filename = xsr.getAttributeValue(null, "path"); - - //-- Got a file- call handler - File path = new File(filename).getCanonicalFile(); - while(xsr.hasNext()) { - int type = xsr.nextTag(); - if(type == XMLStreamConstants.START_ELEMENT) { - if("problems".equals(xsr.getLocalName())) { - decodeProblems(list, path.toString(), xsr, errorsAsWarnings); - } else - ignoreTillEnd(xsr); - - } else if(type == XMLStreamConstants.END_ELEMENT) { - return; - } - } - } - - /** - * Locate "problem" nodes. - */ - private void decodeProblems(List list, String sourcePath, XMLStreamReader xsr, boolean errorsAsWarnings) throws Exception { - while(xsr.hasNext()) { - int type = xsr.nextTag(); - if(type == XMLStreamConstants.START_ELEMENT) { - if("problem".equals(xsr.getLocalName())) { - decodeProblem(list, sourcePath, xsr, errorsAsWarnings); - } else - ignoreTillEnd(xsr); - - } else if(type == XMLStreamConstants.END_ELEMENT) { - return; - } - } - } - - - private void decodeProblem(List list, String sourcePath, XMLStreamReader xsr, boolean errorsAsWarnings) throws Exception { - String id = xsr.getAttributeValue(null, "optionKey"); // Key for the problem - int startline = getInt(xsr, "line"); - int column = getInt(xsr, "charStart"); - int endCol = getInt(xsr, "charEnd"); - String sev = xsr.getAttributeValue(null, "severity"); - String message = "Unknown message?"; - - //-- Go watch for "message" - while(xsr.hasNext()) { - int type = xsr.nextTag(); - if(type == XMLStreamConstants.START_ELEMENT) { - if("message".equals(xsr.getLocalName())) { - message = xsr.getAttributeValue(null, "value"); + else + { + ignoreTillEnd( xsr ); + } + } + else if ( type == XMLStreamConstants.END_ELEMENT ) + { + return; + } + } + } + + /** + * Locate "problem" nodes. + */ + private void decodeProblems( List list, String sourcePath, XMLStreamReader xsr, + boolean errorsAsWarnings ) + throws Exception + { + while ( xsr.hasNext() ) + { + int type = xsr.nextTag(); + if ( type == XMLStreamConstants.START_ELEMENT ) + { + if ( "problem".equals( xsr.getLocalName() ) ) + { + decodeProblem( list, sourcePath, xsr, errorsAsWarnings ); + } + else + { + ignoreTillEnd( xsr ); } - ignoreTillEnd(xsr); - - } else if(type == XMLStreamConstants.END_ELEMENT) { - break; - } - } - Kind msgtype; - if("warning".equalsIgnoreCase(sev)) + } + else if ( type == XMLStreamConstants.END_ELEMENT ) + { + return; + } + } + } + + + private void decodeProblem( List list, String sourcePath, XMLStreamReader xsr, + boolean errorsAsWarnings ) + throws Exception + { + String id = xsr.getAttributeValue( null, "optionKey" ); // Key for the problem + int startline = getInt( xsr, "line" ); + int column = getInt( xsr, "charStart" ); + int endCol = getInt( xsr, "charEnd" ); + String sev = xsr.getAttributeValue( null, "severity" ); + String message = "Unknown message?"; + + //-- Go watch for "message" + while ( xsr.hasNext() ) + { + int type = xsr.nextTag(); + if ( type == XMLStreamConstants.START_ELEMENT ) + { + if ( "message".equals( xsr.getLocalName() ) ) + { + message = xsr.getAttributeValue( null, "value" ); + } + ignoreTillEnd( xsr ); + + } + else if ( type == XMLStreamConstants.END_ELEMENT ) + { + break; + } + } + + Kind msgtype; + if ( "warning".equalsIgnoreCase( sev ) ) + { msgtype = Kind.WARNING; - else if("error".equalsIgnoreCase(sev)) + } + else if ( "error".equalsIgnoreCase( sev ) ) + { msgtype = errorsAsWarnings ? Kind.WARNING : Kind.ERROR; - else if("info".equalsIgnoreCase(sev)) + } + else if ( "info".equalsIgnoreCase( sev ) ) + { msgtype = Kind.NOTE; - else { + } + else + { msgtype = Kind.OTHER; } - CompilerMessage cm = new CompilerMessage(sourcePath, msgtype, startline, column, startline, endCol, message); - list.add(cm); - } - - private static void ignoreTillEnd(XMLStreamReader xsr) throws Exception { - int depth = 1; - while(xsr.hasNext()) { - int type = xsr.next(); - if(type == XMLStreamConstants.START_ELEMENT) { - depth++; - } else if(type == XMLStreamConstants.END_ELEMENT) { - depth--; - if(depth == 0) + CompilerMessage cm = new CompilerMessage( sourcePath, msgtype, startline, column, startline, endCol, message ); + list.add( cm ); + } + + private static void ignoreTillEnd( XMLStreamReader xsr ) + throws Exception + { + int depth = 1; + while ( xsr.hasNext() ) + { + int type = xsr.next(); + if ( type == XMLStreamConstants.START_ELEMENT ) + { + depth++; + } + else if ( type == XMLStreamConstants.END_ELEMENT ) + { + depth--; + if ( depth == 0 ) + { return; - } - } - } - - private static int getInt(XMLStreamReader xsr, String name) throws IOException { - String v = xsr.getAttributeValue(null, name); - if(null == v) + } + } + } + } + + private static int getInt( XMLStreamReader xsr, String name ) + throws IOException + { + String v = xsr.getAttributeValue( null, name ); + if ( null == v ) + { return -1; - try { - return Integer.parseInt(v.trim()); - } catch(Exception x) { - throw new IOException("Illegal integer value '" + v + "' in attribute " + name); } - } - - static private XMLInputFactory getStreamFactory() { - XMLInputFactory xmlif = XMLInputFactory.newInstance(); - xmlif.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); - xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); - xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); - return xmlif; - } + try + { + return Integer.parseInt( v.trim() ); + } + catch ( Exception x ) + { + throw new IOException( "Illegal integer value '" + v + "' in attribute " + name ); + } + } } 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 29c119fc..63666348 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 @@ -2,19 +2,19 @@ /** * 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 @@ -25,16 +25,23 @@ */ 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.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.StringUtils; import org.eclipse.jdt.core.compiler.CompilationProgress; import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticListener; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; @@ -50,15 +57,10 @@ import java.util.ServiceLoader; import java.util.Set; -import javax.tools.Diagnostic; -import javax.tools.DiagnosticListener; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.StandardJavaFileManager; - /** - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="eclipse" + * */ +@Component( role = Compiler.class, hint = "eclipse" ) public class EclipseJavaCompiler extends AbstractCompiler { @@ -73,27 +75,29 @@ public EclipseJavaCompiler() boolean errorsAsWarnings = false; @Override - public CompilerResult performCompile(CompilerConfiguration config ) + public CompilerResult performCompile( CompilerConfiguration config ) throws CompilerException { List args = new ArrayList<>(); - args.add("-noExit"); // Make sure ecj does not System.exit on us 8-/ + args.add( "-noExit" ); // Make sure ecj does not System.exit on us 8-/ // Build settings from configuration if ( config.isDebug() ) { - args.add("-preserveAllLocals"); - args.add("-g:lines,vars,source"); - } else { - args.add("-g:lines,source"); + args.add( "-preserveAllLocals" ); + args.add( "-g:lines,vars,source" ); + } + else + { + args.add( "-g:lines,source" ); } String releaseVersion = decodeVersion( config.getReleaseVersion() ); // EcjFailureException: Failed to run the ecj compiler: option -source is not supported when --release is used if ( releaseVersion != null ) { - args.add("--release"); - args.add(releaseVersion); + args.add( "--release" ); + args.add( releaseVersion ); } else { @@ -101,74 +105,78 @@ public CompilerResult performCompile(CompilerConfiguration config ) if ( sourceVersion != null ) { - args.add("-source"); - args.add(sourceVersion); + args.add( "-source" ); + args.add( sourceVersion ); } String targetVersion = decodeVersion( config.getTargetVersion() ); if ( targetVersion != null ) { - args.add("-target"); - args.add(targetVersion); + args.add( "-target" ); + args.add( targetVersion ); } } if ( StringUtils.isNotEmpty( config.getSourceEncoding() ) ) { - args.add("-encoding"); - args.add(config.getSourceEncoding()); + args.add( "-encoding" ); + args.add( config.getSourceEncoding() ); } if ( !config.isShowWarnings() ) { - args.add("-warn:none"); + args.add( "-warn:none" ); } else { StringBuilder warns = new StringBuilder(); - if(config.isShowDeprecation()) + if ( config.isShowDeprecation() ) { - append(warns, "+deprecation"); + append( warns, "+deprecation" ); } else { - append(warns, "-deprecation"); + append( warns, "-deprecation" ); } //-- Make room for more warnings to be enabled/disabled - args.add("-warn:" + warns); + args.add( "-warn:" + warns ); } - if(config.isParameters()) + if ( config.isParameters() ) { - args.add("-parameters"); + args.add( "-parameters" ); } // Set Eclipse-specific options // compiler-specific extra options override anything else in the config object... Map extras = config.getCustomCompilerArgumentsAsMap(); - if( extras.containsKey( "errorsAsWarnings" ) ) + if ( extras.containsKey( "errorsAsWarnings" ) ) { extras.remove( "errorsAsWarnings" ); this.errorsAsWarnings = true; } - else if(extras.containsKey("-errorsAsWarnings")) + else if ( extras.containsKey( "-errorsAsWarnings" ) ) { extras.remove( "-errorsAsWarnings" ); this.errorsAsWarnings = true; } //-- check for existence of the properties file manually - String props = extras.get("-properties"); - if(null != props) { - File propFile = new File(props); - if(! propFile.exists() || ! propFile.isFile()) - throw new IllegalArgumentException("Properties file specified by -properties " + propFile + " does not exist"); + String props = extras.get( "-properties" ); + if ( null != props ) + { + File propFile = new File( props ); + if ( !propFile.exists() || !propFile.isFile() ) + { + throw new IllegalArgumentException( + "Properties file specified by -properties " + propFile + " does not exist" ); + } } - for(Entry entry : extras.entrySet()) + for ( Entry entry : extras.entrySet() ) { /* * The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH @@ -199,107 +207,131 @@ else if(extras.containsKey("-errorsAsWarnings")) */ String opt = entry.getKey(); String optionValue = entry.getValue(); - if(null == optionValue) { + if ( null == optionValue ) + { //-- We have an option from compilerArgs: use the key as-is as a single option value - args.add(opt); - } else { - if(!opt.startsWith("-")) + args.add( opt ); + } + else + { + if ( !opt.startsWith( "-" ) ) + { opt = "-" + opt; - args.add(opt); - args.add(optionValue); + } + args.add( opt ); + args.add( optionValue ); } } // Output path - args.add("-d"); - args.add(config.getOutputLocation()); + args.add( "-d" ); + args.add( config.getOutputLocation() ); // Annotation processors defined? List extraSourceDirs = new ArrayList<>(); - if(!isPreJava1_6(config)) { + if ( !isPreJava1_6( config ) ) + { //now add jdk 1.6 annotation processing related parameters String[] annotationProcessors = config.getAnnotationProcessors(); List processorPathEntries = config.getProcessorPathEntries(); - if((annotationProcessors != null && annotationProcessors.length > 0) || (processorPathEntries != null && processorPathEntries.size() > 0)) { - if(annotationProcessors != null && annotationProcessors.length > 0) { - args.add("-processor"); + if ( ( annotationProcessors != null && annotationProcessors.length > 0 ) || ( processorPathEntries != null + && processorPathEntries.size() > 0 ) ) + { + if ( annotationProcessors != null && annotationProcessors.length > 0 ) + { + args.add( "-processor" ); StringBuilder sb = new StringBuilder(); - for(String ap : annotationProcessors) { - if(sb.length() > 0) - sb.append(','); - sb.append(ap); + for ( String ap : annotationProcessors ) + { + if ( sb.length() > 0 ) + { + sb.append( ',' ); + } + sb.append( ap ); } - args.add(sb.toString()); + args.add( sb.toString() ); } - if(processorPathEntries != null && processorPathEntries.size() > 0) { - args.add("-processorpath"); - args.add(getPathString(processorPathEntries)); + if ( processorPathEntries != null && processorPathEntries.size() > 0 ) + { + args.add( "-processorpath" ); + args.add( getPathString( processorPathEntries ) ); } File generatedSourcesDir = config.getGeneratedSourcesDirectory(); - if(generatedSourcesDir != null) { + if ( generatedSourcesDir != null ) + { generatedSourcesDir.mkdirs(); - extraSourceDirs.add(generatedSourcesDir.getAbsolutePath()); + extraSourceDirs.add( generatedSourcesDir.getAbsolutePath() ); //-- option to specify where annotation processor is to generate its output - args.add("-s"); - args.add(generatedSourcesDir.getAbsolutePath()); + args.add( "-s" ); + args.add( generatedSourcesDir.getAbsolutePath() ); } - if(config.getProc() != null) { - args.add("-proc:" + config.getProc()); + if ( config.getProc() != null ) + { + args.add( "-proc:" + config.getProc() ); } } } //-- Write .class files even when error occur, but make sure methods with compile errors do abort when called - if(extras.containsKey("-proceedOnError")) - args.add("-proceedOnError:Fatal"); // Generate a class file even with errors, but make methods with errors fail when called + if ( extras.containsKey( "-proceedOnError" ) ) + { + // Generate a class file even with errors, but make methods with errors fail when called + args.add( "-proceedOnError:Fatal" ); + } //-- classpath - List classpathEntries = new ArrayList<>(config.getClasspathEntries()); - classpathEntries.add(config.getOutputLocation()); - args.add("-classpath"); - args.add(getPathString(classpathEntries)); + List classpathEntries = new ArrayList<>( config.getClasspathEntries() ); + classpathEntries.add( config.getOutputLocation() ); + args.add( "-classpath" ); + args.add( getPathString( classpathEntries ) ); // Collect sources List allSources = new ArrayList<>(); - for (String source : config.getSourceLocations()) + for ( String source : config.getSourceLocations() ) { - File srcFile = new File(source); - if (srcFile.exists()) + File srcFile = new File( source ); + if ( srcFile.exists() ) { - Set ss = getSourceFilesForSourceRoot(config, source); - allSources.addAll(ss); + Set ss = getSourceFilesForSourceRoot( config, source ); + allSources.addAll( ss ); } } - for (String extraSrcDir : extraSourceDirs) { - File extraDir = new File(extraSrcDir); - if (extraDir.isDirectory()) { - addExtraSources(extraDir, allSources); + for ( String extraSrcDir : extraSourceDirs ) + { + File extraDir = new File( extraSrcDir ); + if ( extraDir.isDirectory() ) + { + addExtraSources( extraDir, allSources ); } } List messageList = new ArrayList<>(); - if (allSources.isEmpty()) { + if ( allSources.isEmpty() ) + { // -- Nothing to do -> bail out - return new CompilerResult(true, messageList); + return new CompilerResult( true, messageList ); } // Compile - try { + try + { StringWriter sw = new StringWriter(); - PrintWriter devNull = new PrintWriter(sw); + PrintWriter devNull = new PrintWriter( sw ); JavaCompiler compiler = getEcj(); boolean success = false; - if (compiler != null) { - getLogger().debug("Using JSR-199 EclipseCompiler"); + if ( compiler != null ) + { + getLogger().debug( "Using JSR-199 EclipseCompiler" ); // ECJ JSR-199 compiles against the latest Java version it supports if no source // version is given explicitly. BatchCompiler uses 1.3 as default. So check // whether a source version is specified, and if not supply 1.3 explicitly. - if (!haveSourceOrReleaseArgument(args)) { - getLogger().debug("ecj: no source level nor release specified, defaulting to Java 1.3"); - args.add("-source"); - args.add("1.3"); + if ( !haveSourceOrReleaseArgument( args ) ) + { + getLogger().debug( "ecj: no source level nor release specified, defaulting to Java 1.3" ); + args.add( "-source" ); + args.add( "1.3" ); } // Also check for the encoding. Could have been set via the CompilerConfig @@ -307,250 +339,319 @@ else if(extras.containsKey("-errorsAsWarnings")) // StandardJavaFileManager below. String encoding = null; Iterator allArgs = args.iterator(); - while (encoding == null && allArgs.hasNext()) { + while ( encoding == null && allArgs.hasNext() ) + { String option = allArgs.next(); - if ("-encoding".equals(option) && allArgs.hasNext()) { + if ( "-encoding".equals( option ) && allArgs.hasNext() ) + { encoding = allArgs.next(); } } final Locale defaultLocale = Locale.getDefault(); final List messages = messageList; - DiagnosticListener messageCollector = new DiagnosticListener() { + DiagnosticListener messageCollector = new DiagnosticListener() + { @Override - public void report(Diagnostic diagnostic) { + public void report( Diagnostic diagnostic ) + { // Convert to Plexus' CompilerMessage and append to messageList String fileName = "Unknown source"; - try { + try + { JavaFileObject file = diagnostic.getSource(); - if (file != null) { + if ( file != null ) + { fileName = file.getName(); } - } catch (NullPointerException e) { + } + catch ( NullPointerException e ) + { // ECJ bug: diagnostic.getSource() may throw an NPE if there is no source } long startColumn = diagnostic.getColumnNumber(); // endColumn may be wrong if the endPosition is not on the same line. - long endColumn = startColumn + (diagnostic.getEndPosition() - diagnostic.getStartPosition()); - CompilerMessage message = new CompilerMessage(fileName, - convert(diagnostic.getKind()), (int) diagnostic.getLineNumber(), (int) startColumn, - (int) diagnostic.getLineNumber(), (int) endColumn, - diagnostic.getMessage(defaultLocale)); - messages.add(message); + long endColumn = startColumn + ( diagnostic.getEndPosition() - diagnostic.getStartPosition() ); + CompilerMessage message = new CompilerMessage( fileName, convert( diagnostic.getKind() ), + (int) diagnostic.getLineNumber(), + (int) startColumn, + (int) diagnostic.getLineNumber(), + (int) endColumn, + diagnostic.getMessage( defaultLocale ) ); + messages.add( message ); } }; Charset charset = null; - if (encoding != null) { + if ( encoding != null ) + { encoding = encoding.trim(); - try { - charset = Charset.forName(encoding); - } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - getLogger().warn("ecj: invalid or unsupported character set '" + encoding + "', using default"); + try + { + charset = Charset.forName( encoding ); + } + catch ( IllegalCharsetNameException | UnsupportedCharsetException e ) + { + getLogger().warn( + "ecj: invalid or unsupported character set '" + encoding + "', using default" ); // charset remains null } } - if (charset == null) { + if ( charset == null ) + { charset = Charset.defaultCharset(); } - StandardJavaFileManager manager = compiler.getStandardFileManager(messageCollector, defaultLocale, - charset); - - if (getLogger().isDebugEnabled()) { - getLogger().debug("ecj: using character set " + charset.displayName()); - getLogger().debug("ecj command line: " + args); - getLogger().debug("ecj input source files: " + allSources); + StandardJavaFileManager manager = + compiler.getStandardFileManager( messageCollector, defaultLocale, charset ); + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "ecj: using character set " + charset.displayName() ); + getLogger().debug( "ecj command line: " + args ); + getLogger().debug( "ecj input source files: " + allSources ); } - Iterable units = manager.getJavaFileObjectsFromStrings(allSources); - try { - success = Boolean.TRUE - .equals(compiler.getTask(devNull, manager, messageCollector, args, null, units).call()); - } catch (RuntimeException e) { - throw new EcjFailureException(e.getLocalizedMessage()); + Iterable units = manager.getJavaFileObjectsFromStrings( allSources ); + try + { + success = Boolean.TRUE.equals( + compiler.getTask( devNull, manager, messageCollector, args, null, units ).call() ); } - getLogger().debug(sw.toString()); - } else { + catch ( RuntimeException e ) + { + throw new EcjFailureException( e.getLocalizedMessage() ); + } + getLogger().debug( sw.toString() ); + } + else + { // Use the BatchCompiler and send all errors to xml temp file. File errorF = null; - try { - errorF = File.createTempFile("ecjerr-", ".xml"); - getLogger().debug("Using legacy BatchCompiler; error file " + errorF); - - args.add("-log"); - args.add(errorF.toString()); - args.addAll(allSources); - - getLogger().debug("ecj command line: " + args); - - success = BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, - new CompilationProgress() { - @Override - public void begin(int i) { - } - - @Override - public void done() { - } - - @Override - public boolean isCanceled() { - return false; - } - - @Override - public void setTaskName(String s) { - } - - @Override - public void worked(int i, int i1) { - } - }); - getLogger().debug(sw.toString()); - - if (errorF.length() < 80) { - throw new EcjFailureException(sw.toString()); + try + { + errorF = File.createTempFile( "ecjerr-", ".xml" ); + getLogger().debug( "Using legacy BatchCompiler; error file " + errorF ); + + args.add( "-log" ); + args.add( errorF.toString() ); + args.addAll( allSources ); + + getLogger().debug( "ecj command line: " + args ); + + success = BatchCompiler.compile( args.toArray( new String[args.size()] ), devNull, devNull, + new CompilationProgress() + { + @Override + public void begin( int i ) + { + } + + @Override + public void done() + { + } + + @Override + public boolean isCanceled() + { + return false; + } + + @Override + public void setTaskName( String s ) + { + } + + @Override + public void worked( int i, int i1 ) + { + } + } ); + getLogger().debug( sw.toString() ); + + if ( errorF.length() < 80 ) + { + throw new EcjFailureException( sw.toString() ); } - messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings); - } finally { - if (null != errorF) { - try { + messageList = new EcjResponseParser().parse( errorF, errorsAsWarnings ); + } + finally + { + if ( null != errorF ) + { + try + { errorF.delete(); - } catch (Exception x) { + } + catch ( Exception x ) + { } } } } boolean hasError = false; - for (CompilerMessage compilerMessage : messageList) { - if (compilerMessage.isError()) { + for ( CompilerMessage compilerMessage : messageList ) + { + if ( compilerMessage.isError() ) + { hasError = true; break; } } - if (!hasError && !success && !errorsAsWarnings) { - CompilerMessage.Kind kind = errorsAsWarnings ? CompilerMessage.Kind.WARNING - : CompilerMessage.Kind.ERROR; + 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); - messageList.add(cm); + CompilerMessage cm = + new CompilerMessage( "[ecj] The compiler reported an error but has not written it to its logging", + kind ); + messageList.add( cm ); hasError = true; // -- Try to find the actual message by reporting the last 5 lines as a message - 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); - messageList.add(cm); + 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 ); + messageList.add( cm ); } } - return new CompilerResult(!hasError || errorsAsWarnings, messageList); - } catch(EcjFailureException x) { + return new CompilerResult( !hasError || errorsAsWarnings, messageList ); + } + catch ( EcjFailureException x ) + { throw x; - } catch(Exception x) { - throw new RuntimeException(x); // sigh + } + catch ( Exception x ) + { + throw new RuntimeException( x ); // sigh } } - private static boolean haveSourceOrReleaseArgument(List args) { + private static boolean haveSourceOrReleaseArgument( List args ) + { Iterator allArgs = args.iterator(); - while (allArgs.hasNext()) { + while ( allArgs.hasNext() ) + { String option = allArgs.next(); - if (("-source".equals(option) || "--release".equals(option)) && allArgs.hasNext()) { + if ( ( "-source".equals( option ) || "--release".equals( option ) ) && allArgs.hasNext() ) + { return true; } } return false; } - private JavaCompiler getEcj() { - ServiceLoader javaCompilerLoader = ServiceLoader.load(JavaCompiler.class, - BatchCompiler.class.getClassLoader()); + private JavaCompiler getEcj() + { + ServiceLoader javaCompilerLoader = + ServiceLoader.load( JavaCompiler.class, BatchCompiler.class.getClassLoader() ); Class c = null; - try { - c = Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompiler", false, - BatchCompiler.class.getClassLoader()); - } catch (ClassNotFoundException e) { + try + { + c = Class.forName( "org.eclipse.jdt.internal.compiler.tool.EclipseCompiler", false, + BatchCompiler.class.getClassLoader() ); + } + catch ( ClassNotFoundException e ) + { // Ignore } - if (c != null) { - for (JavaCompiler javaCompiler : javaCompilerLoader) { - if (c.isInstance(javaCompiler)) { + if ( c != null ) + { + for ( JavaCompiler javaCompiler : javaCompilerLoader ) + { + if ( c.isInstance( javaCompiler ) ) + { return javaCompiler; } } } - getLogger().debug("Cannot find org.eclipse.jdt.internal.compiler.tool.EclipseCompiler"); + getLogger().debug( "Cannot find org.eclipse.jdt.internal.compiler.tool.EclipseCompiler" ); return null; } - private void addExtraSources(File dir, List allSources) { + private void addExtraSources( File dir, List allSources ) + { DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(dir.getAbsolutePath()); - scanner.setIncludes(new String[] { "**/*.java" }); + scanner.setBasedir( dir.getAbsolutePath() ); + scanner.setIncludes( new String[]{ "**/*.java" } ); scanner.scan(); - for (String file : scanner.getIncludedFiles()) { - allSources.add(new File(dir, file).getAbsolutePath()); + for ( String file : scanner.getIncludedFiles() ) + { + allSources.add( new File( dir, file ).getAbsolutePath() ); } } - private CompilerMessage.Kind convert(Diagnostic.Kind kind) { - if (kind == null) { + private CompilerMessage.Kind convert( Diagnostic.Kind kind ) + { + if ( kind == null ) + { return CompilerMessage.Kind.OTHER; } - switch (kind) { - case ERROR: - return errorsAsWarnings ? CompilerMessage.Kind.WARNING : CompilerMessage.Kind.ERROR; - case WARNING: - return CompilerMessage.Kind.WARNING; - case MANDATORY_WARNING: - return CompilerMessage.Kind.MANDATORY_WARNING; - case NOTE: - return CompilerMessage.Kind.NOTE; - case OTHER: - default: - return CompilerMessage.Kind.OTHER; + switch ( kind ) + { + case ERROR: + return errorsAsWarnings ? CompilerMessage.Kind.WARNING : CompilerMessage.Kind.ERROR; + case WARNING: + return CompilerMessage.Kind.WARNING; + case MANDATORY_WARNING: + return CompilerMessage.Kind.MANDATORY_WARNING; + case NOTE: + return CompilerMessage.Kind.NOTE; + case OTHER: + default: + return CompilerMessage.Kind.OTHER; } } - private String getLastLines(String text, int lines) + private String getLastLines( String text, int lines ) { List lineList = new ArrayList<>(); - text = text.replace("\r\n", "\n"); - text = text.replace("\r", "\n"); // make sure eoln is \n + text = text.replace( "\r\n", "\n" ); + text = text.replace( "\r", "\n" ); // make sure eoln is \n int index = text.length(); - while(index > 0) { - int before = text.lastIndexOf('\n', index - 1); + while ( index > 0 ) + { + int before = text.lastIndexOf( '\n', index - 1 ); - if(before + 1 < index) { // Non empty line? - lineList.add(text.substring(before + 1, index)); + if ( before + 1 < index ) + { // Non empty line? + lineList.add( text.substring( before + 1, index ) ); lines--; - if(lines <= 0) + if ( lines <= 0 ) + { break; + } } index = before; } StringBuilder sb = new StringBuilder(); - for(int i = lineList.size() - 1; i >= 0; i--) + for ( int i = lineList.size() - 1; i >= 0; i-- ) { - String s = lineList.get(i); - sb.append(s); - sb.append(System.getProperty("line.separator")); // 8-/ + String s = lineList.get( i ); + sb.append( s ); + sb.append( System.getProperty( "line.separator" ) ); // 8-/ } return sb.toString(); } - static private void append(StringBuilder warns, String s) { - if(warns.length() > 0) - warns.append(','); - warns.append(s); + static private void append( StringBuilder warns, String s ) + { + if ( warns.length() > 0 ) + { + warns.append( ',' ); + } + warns.append( s ); } - private boolean isPreJava1_6(CompilerConfiguration config) { + private boolean isPreJava1_6( CompilerConfiguration config ) + { String s = config.getSourceVersion(); if ( s == null ) { @@ -581,8 +682,9 @@ private String decodeVersion( String versionSpec ) return null; } - if(versionSpec.equals("1.9")) { - getLogger().warn("Version 9 should be specified as 9, not 1.9"); + if ( versionSpec.equals( "1.9" ) ) + { + getLogger().warn( "Version 9 should be specified as 9, not 1.9" ); return "9"; } return versionSpec; 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..76de9dcf 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 @@ -2,19 +2,19 @@ /** * 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 @@ -24,10 +24,10 @@ * SOFTWARE. */ +import java.io.File; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.HashMap; -import java.io.File; /** * @author Trygve Laugstøl @@ -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-j2objc/pom.xml b/plexus-compilers/plexus-compiler-j2objc/pom.xml index 3ebf6ae2..cd1123d1 100644 --- a/plexus-compilers/plexus-compiler-j2objc/pom.xml +++ b/plexus-compilers/plexus-compiler-j2objc/pom.xml @@ -18,6 +18,10 @@ org.codehaus.plexus plexus-utils + + org.codehaus.plexus + plexus-component-annotations + 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 ae5d867e..d4098e00 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 @@ -17,12 +17,14 @@ */ 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.CompilerMessage; import org.codehaus.plexus.compiler.CompilerMessage.Kind; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; @@ -47,8 +49,9 @@ * * @author Ludovic * Maître - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="j2objc" + * */ +@Component( role = Compiler.class, hint = "j2objc ") public class J2ObjCCompiler extends AbstractCompiler { diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml b/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml index ec6c1767..ce9308a8 100644 --- a/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml +++ b/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml @@ -31,6 +31,10 @@ error_prone_core 2.4.0 + + org.codehaus.plexus + plexus-component-annotations + 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 f9a05951..33766bb7 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 @@ -18,6 +18,7 @@ import com.google.errorprone.ErrorProneJavaCompiler; +import org.codehaus.plexus.compiler.Compiler; import org.codehaus.plexus.compiler.CompilerConfiguration; import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.compiler.CompilerMessage; @@ -25,6 +26,7 @@ import org.codehaus.plexus.compiler.javac.InProcessCompiler; import org.codehaus.plexus.compiler.javac.JavacCompiler; import org.codehaus.plexus.compiler.javac.JavaxToolsCompiler; +import org.codehaus.plexus.component.annotations.Component; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; @@ -38,8 +40,8 @@ * entry point into Javac. * * @author Alex Eagle - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="javac-with-errorprone" */ +@Component( role = Compiler.class, hint = "javac-with-errorprone") public class JavacCompilerWithErrorProne extends JavacCompiler { @@ -125,4 +127,4 @@ protected JavaCompiler newJavaCompiler() return new ErrorProneJavaCompiler(); } } -} \ No newline at end of file +} diff --git a/plexus-compilers/plexus-compiler-javac/pom.xml b/plexus-compilers/plexus-compiler-javac/pom.xml index 0d6bddad..cccc7621 100644 --- a/plexus-compilers/plexus-compiler-javac/pom.xml +++ b/plexus-compilers/plexus-compiler-javac/pom.xml @@ -18,6 +18,10 @@ org.codehaus.plexus plexus-utils + + org.codehaus.plexus + plexus-component-annotations + 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 35713fa1..e03580cf 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 @@ -63,11 +63,13 @@ import java.util.concurrent.CopyOnWriteArrayList; 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.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; @@ -80,9 +82,9 @@ * @author Matthew Pocock * @author Jörg Waßmer * @author Others - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" - * role-hint="javac" + * */ +@Component( role = Compiler.class, hint = "javac ") public class JavacCompiler extends AbstractCompiler { 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 7eaa3ab0..44ec1732 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 @@ -18,10 +18,12 @@ * under the License. */ +import org.codehaus.plexus.compiler.Compiler; import org.codehaus.plexus.compiler.CompilerConfiguration; import org.codehaus.plexus.compiler.CompilerMessage; import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; import javax.tools.Diagnostic; import javax.tools.DiagnosticCollector; @@ -41,6 +43,7 @@ * @author David M. Lloyd * @since 2.0 */ +@Component( role = Compiler.class ) public class JavaxToolsCompiler implements InProcessCompiler { /** diff --git a/plexus-compilers/plexus-compiler-jikes/pom.xml b/plexus-compilers/plexus-compiler-jikes/pom.xml index d8d2e076..7adaaa52 100644 --- a/plexus-compilers/plexus-compiler-jikes/pom.xml +++ b/plexus-compilers/plexus-compiler-jikes/pom.xml @@ -18,6 +18,10 @@ org.codehaus.plexus plexus-utils + + org.codehaus.plexus + plexus-component-annotations + 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..fa5121c9 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 @@ -74,13 +74,14 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- */ 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.CompilerMessage; import org.codehaus.plexus.compiler.CompilerOutputStyle; import org.codehaus.plexus.compiler.CompilerResult; import org.codehaus.plexus.compiler.util.StreamPumper; -import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; @@ -98,9 +99,7 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- import java.util.List; import java.util.Map; -/** - * @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="jikes" - */ +@Component( role = Compiler.class, hint = "jikes" ) public class JikesCompiler extends AbstractCompiler { @@ -158,7 +157,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 +168,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 +177,7 @@ public CompilerResult performCompile( CompilerConfiguration config ) public String[] createCommandLine( CompilerConfiguration config ) throws CompilerException { - List args = new ArrayList(); + List args = new ArrayList<>(); args.add( "jikes" ); @@ -204,15 +199,13 @@ public String[] createCommandLine( CompilerConfiguration config ) args.add( "+E" ); - if ( config.getCustomCompilerArguments().size() > 0 ) + for ( Map.Entry arg : config.getCustomCompilerArgumentsAsMap().entrySet() ) { - for ( Map.Entry arg : config.getCustomCompilerArgumentsAsMap().entrySet() ) - { - args.add( arg.getKey() ); - args.add( arg.getValue() ); - } + args.add( arg.getKey() ); + args.add( arg.getValue() ); } + args.add( "-target" ); if ( StringUtils.isNotEmpty( config.getTargetVersion() ) ) { @@ -275,32 +268,28 @@ public String[] createCommandLine( CompilerConfiguration config ) if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) { String tempFileName = null; - BufferedWriter fw = null; - try { File tempFile = File.createTempFile( "compList", ".cmp" ); tempFileName = tempFile.getAbsolutePath(); - getLogger().debug( "create TempFile" + tempFileName ); - - tempFile.getParentFile().mkdirs(); - fw = new BufferedWriter( new FileWriter( tempFile ) ); - for ( int i = 0; i < sourceFiles.length; i++ ) + try (BufferedWriter fw = new BufferedWriter( new FileWriter( tempFile ) )) { - fw.write( sourceFiles[i] ); - fw.newLine(); + + getLogger().debug( "create TempFile" + tempFileName ); + + tempFile.getParentFile().mkdirs(); + for ( int i = 0; i < sourceFiles.length; i++ ) + { + fw.write( sourceFiles[i] ); + fw.newLine(); + } + tempFile.deleteOnExit(); } - fw.flush(); - tempFile.deleteOnExit(); } catch ( IOException e ) { throw new CompilerException( "Could not create temporary file " + tempFileName, e ); } - finally - { - IOUtil.close( fw ); - } args.add( "@" + tempFileName ); } @@ -313,7 +302,7 @@ public String[] createCommandLine( CompilerConfiguration config ) } - return (String[]) args.toArray( new String[args.size()] ); + return args.toArray( new String[args.size()] ); } // ----------------------------------------------------------------------- @@ -334,7 +323,7 @@ private File getDestinationDir( CompilerConfiguration config ) private List getBootClassPath() { - List bootClassPath = new ArrayList(); + List bootClassPath = new ArrayList<>(); FileFilter filter = new FileFilter() { @@ -371,7 +360,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() ); diff --git a/pom.xml b/pom.xml index 7b78234d..b913e9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,11 @@ plexus-compiler-test ${project.version} + + org.codehaus.plexus + plexus-component-annotations + 1.7.1 + junit junit @@ -104,13 +109,6 @@ maven-javadoc-plugin -Xdoclint:none - - - org.codehaus.plexus - plexus-javadoc - 1.0 - - @@ -139,7 +137,6 @@ org.codehaus.mojo animal-sniffer-maven-plugin 1.19 - test