[Git][java-team/plexus-compiler][upstream] New upstream version 2.8.4
Emmanuel Bourg
gitlab at salsa.debian.org
Fri Jun 15 23:15:01 BST 2018
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / plexus-compiler
Commits:
4dd474ca by Emmanuel Bourg at 2018-06-15T23:07:08+02:00
New upstream version 2.8.4
- - - - -
16 changed files:
- plexus-compiler-api/pom.xml
- plexus-compiler-manager/pom.xml
- plexus-compiler-test/pom.xml
- plexus-compilers/plexus-compiler-aspectj/pom.xml
- plexus-compilers/plexus-compiler-csharp/pom.xml
- plexus-compilers/plexus-compiler-eclipse/pom.xml
- + plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java
- plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
- plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java
- plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java
- plexus-compilers/plexus-compiler-j2objc/pom.xml
- plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
- plexus-compilers/plexus-compiler-javac/pom.xml
- plexus-compilers/plexus-compiler-jikes/pom.xml
- plexus-compilers/pom.xml
- pom.xml
Changes:
=====================================
plexus-compiler-api/pom.xml
=====================================
--- a/plexus-compiler-api/pom.xml
+++ b/plexus-compiler-api/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-api</artifactId>
=====================================
plexus-compiler-manager/pom.xml
=====================================
--- a/plexus-compiler-manager/pom.xml
+++ b/plexus-compiler-manager/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-manager</artifactId>
=====================================
plexus-compiler-test/pom.xml
=====================================
--- a/plexus-compiler-test/pom.xml
+++ b/plexus-compiler-test/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-test</artifactId>
=====================================
plexus-compilers/plexus-compiler-aspectj/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-aspectj/pom.xml
+++ b/plexus-compilers/plexus-compiler-aspectj/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-aspectj</artifactId>
=====================================
plexus-compilers/plexus-compiler-csharp/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-csharp/pom.xml
+++ b/plexus-compilers/plexus-compiler-csharp/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-csharp</artifactId>
=====================================
plexus-compilers/plexus-compiler-eclipse/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-eclipse/pom.xml
+++ b/plexus-compilers/plexus-compiler-eclipse/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-eclipse</artifactId>
=====================================
plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java
=====================================
--- /dev/null
+++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjResponseParser.java
@@ -0,0 +1,157 @@
+package org.codehaus.plexus.compiler.eclipse;
+
+import org.codehaus.plexus.compiler.CompilerMessage;
+import org.codehaus.plexus.compiler.CompilerMessage.Kind;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:jal at etc.to">Frits Jalvingh</a>
+ * Created on 31-3-18.
+ */
+public class EcjResponseParser {
+ /*--------------------------------------------------------------*/
+ /* CODING: Decode ECJ -log format results. */
+ /*--------------------------------------------------------------*/
+ /**
+ * Scan the specified response file for compilation messages.
+ */
+ public List<CompilerMessage> parse(File xmltf, boolean errorsAsWarnings) throws Exception {
+ //if(xmltf.length() < 80)
+ // return;
+
+ List<CompilerMessage> 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);
+ }
+ }
+ }
+ return list;
+ }
+
+ private void decodeSourceElement(List<CompilerMessage> 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<CompilerMessage> 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<CompilerMessage> 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))
+ msgtype = errorsAsWarnings ? Kind.WARNING : Kind.ERROR;
+ else if("info".equalsIgnoreCase(sev))
+ msgtype = Kind.NOTE;
+ 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)
+ return;
+ }
+ }
+ }
+
+ 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;
+ }
+
+}
=====================================
plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
=====================================
--- 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
@@ -30,46 +30,20 @@ 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.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.internal.compiler.ClassFile;
-import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.Compiler;
-import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
-import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
-import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
-import org.eclipse.jdt.internal.compiler.IProblemFactory;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
-import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
-import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
-
-import java.io.BufferedInputStream;
+import org.eclipse.jdt.core.compiler.CompilationProgress;
+import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
+
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Collections;
import java.util.List;
-import java.util.Locale;
-import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Properties;
+import java.util.Map.Entry;
import java.util.Set;
-import java.util.StringTokenizer;
/**
* @plexus.component role="org.codehaus.plexus.compiler.Compiler" role-hint="eclipse"
@@ -87,669 +61,264 @@ public class EclipseJavaCompiler
// ----------------------------------------------------------------------
boolean errorsAsWarnings = false;
- public CompilerResult performCompile( CompilerConfiguration config )
+ public CompilerResult performCompile(CompilerConfiguration config )
throws CompilerException
{
- List<CompilerMessage> errors = new LinkedList<CompilerMessage>();
-
- List<String> classpathEntries = config.getClasspathEntries();
-
- URL[] urls = new URL[1 + classpathEntries.size()];
-
- int i = 0;
-
- try
- {
- urls[i++] = new File( config.getOutputLocation() ).toURL();
-
- for ( String entry : classpathEntries )
- {
- urls[i++] = new File( entry ).toURL();
- }
- }
- catch ( MalformedURLException e )
- {
- throw new CompilerException( "Error while converting the classpath entries to URLs.", e );
- }
-
- ClassLoader classLoader = new URLClassLoader( urls );
-
- SourceCodeLocator sourceCodeLocator = new SourceCodeLocator( config.getSourceLocations() );
-
- INameEnvironment env = new EclipseCompilerINameEnvironment( sourceCodeLocator, classLoader, errors );
-
- IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
-
- // ----------------------------------------------------------------------
// Build settings from configuration
- // ----------------------------------------------------------------------
-
- Map<String, String> settings = new HashMap<String, String>();
-
+ List<String> args = new ArrayList<>();
if ( config.isDebug() )
{
- settings.put( CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE );
- settings.put( CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE );
- settings.put( CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE );
- }
-
- if ( !config.isShowWarnings() )
- {
- Map opts = new CompilerOptions().getMap();
- for (Object optKey : opts.keySet()) {
- if (opts.get(optKey).equals(CompilerOptions.WARNING)) {
- settings.put((String) optKey, CompilerOptions.IGNORE);
- }
- }
+ args.add("-preserveAllLocals");
+ args.add("-g:lines,vars,source");
+ } else {
+ args.add("-g:lines,source");
}
String sourceVersion = decodeVersion( config.getSourceVersion() );
if ( sourceVersion != null )
{
- settings.put( CompilerOptions.OPTION_Source, sourceVersion );
+ args.add("-source");
+ args.add(sourceVersion);
}
String targetVersion = decodeVersion( config.getTargetVersion() );
if ( targetVersion != null )
{
- settings.put( CompilerOptions.OPTION_TargetPlatform, targetVersion );
- settings.put( CompilerOptions.OPTION_Compliance, targetVersion );
+ args.add("-target");
+ args.add(targetVersion);
}
if ( StringUtils.isNotEmpty( config.getSourceEncoding() ) )
{
- settings.put( CompilerOptions.OPTION_Encoding, config.getSourceEncoding() );
+ args.add("-encoding");
+ args.add(config.getSourceEncoding());
}
- if ( config.isShowDeprecation() )
+ if ( !config.isShowWarnings() )
{
- settings.put( CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING );
+ args.add("-warn:none");
}
else
{
- settings.put( CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE );
- }
-
- if ( config.isParameters() )
- {
- settings.put( CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE );
- }
-
- // ----------------------------------------------------------------------
- // Set Eclipse-specific options
- // ----------------------------------------------------------------------
-
- settings.put( CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE );
- settings.put( CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE );
-
- // compiler-specific extra options override anything else in the config object...
- Map<String, String> extras = cleanKeyNames( config.getCustomCompilerArgumentsAsMap() );
- if( extras.containsKey( "errorsAsWarnings" ) )
- {
- extras.remove( "errorsAsWarnings" );
- this.errorsAsWarnings = true;
- }
-
- settings.putAll( extras );
-
- if ( settings.containsKey( "properties" ) )
- {
- initializeWarnings( settings.get( "properties" ), settings );
- settings.remove( "properties" );
- }
-
- IProblemFactory problemFactory = new DefaultProblemFactory( Locale.getDefault() );
-
- ICompilerRequestor requestor = new EclipseCompilerICompilerRequestor( config.getOutputLocation(), errors );
+ StringBuilder warns = new StringBuilder();
- List<CompilationUnit> compilationUnits = new ArrayList<CompilationUnit>();
-
- for ( String sourceRoot : config.getSourceLocations() )
- {
- // annotations directory does not always exist and the below scanner fails on non existing directories
- File potentialSourceDirectory = new File( sourceRoot );
- if ( potentialSourceDirectory.exists() )
+ if(config.isShowDeprecation())
{
- Set<String> sources = getSourceFilesForSourceRoot( config, sourceRoot );
-
- for ( String source : sources )
- {
- CompilationUnit unit = new CompilationUnit( source, makeClassName( source, sourceRoot ), errors,
- config.getSourceEncoding() );
-
- compilationUnits.add( unit );
- }
+ append(warns, "+deprecation");
}
- }
-
- // ----------------------------------------------------------------------
- // Compile!
- // ----------------------------------------------------------------------
-
- CompilerOptions options = new CompilerOptions( settings );
- Compiler compiler = new Compiler( env, policy, options, requestor, problemFactory );
-
- ICompilationUnit[] units = compilationUnits.toArray( new ICompilationUnit[compilationUnits.size()] );
-
- compiler.compile( units );
-
- CompilerResult compilerResult = new CompilerResult().compilerMessages( errors );
-
- for ( CompilerMessage compilerMessage : errors )
- {
- if ( compilerMessage.isError() )
- {
- compilerResult.setSuccess( false );
- continue;
- }
- }
-
- return compilerResult;
- }
-
- // The compiler mojo adds a dash to all keys which does not make sense for the eclipse compiler
- Map<String, String> cleanKeyNames( Map<String, String> customCompilerArgumentsAsMap )
- {
- LinkedHashMap<String, String> cleanedMap = new LinkedHashMap<String, String>();
-
- for ( Map.Entry<String, String> entry : customCompilerArgumentsAsMap.entrySet() )
- {
- String key = entry.getKey();
- if ( key.startsWith( "-" ) )
+ else
{
- key = key.substring( 1 );
+ append(warns, "-deprecation");
}
- cleanedMap.put( key, entry.getValue() );
- }
-
- return cleanedMap;
- }
- public String[] createCommandLine( CompilerConfiguration config )
- throws CompilerException
- {
- return null;
- }
-
- private CompilerMessage handleError( String className, int line, int column, Object errorMessage )
- {
- if ( className.endsWith( ".java" ) )
- {
- className = className.substring( 0, className.lastIndexOf( '.' ) );
- }
- String fileName = className.replace( '.', File.separatorChar ) + ".java";
-
- if ( column < 0 )
- {
- column = 0;
- }
-
- String message;
-
- if ( errorMessage != null )
- {
- message = errorMessage.toString();
- }
- else
- {
- message = "No message";
- }
-
- return new CompilerMessage( fileName, CompilerMessage.Kind.ERROR, line, column, line, column, message );
-
- }
-
- private CompilerMessage handleWarning( String fileName, IProblem warning )
- {
- return new CompilerMessage( fileName, CompilerMessage.Kind.WARNING,
- warning.getSourceLineNumber(), warning.getSourceStart(),
- warning.getSourceLineNumber(), warning.getSourceEnd(), warning.getMessage() );
- }
-
- private String decodeVersion( String versionSpec )
- {
- if ( StringUtils.isEmpty( versionSpec ) )
- {
- return null;
- }
- else if ( "1.1".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_1;
- }
- else if ( "1.2".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_2;
+ //-- Make room for more warnings to be enabled/disabled
+ args.add("-warn:" + warns);
}
- else if ( "1.3".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_3;
- }
- else if ( "1.4".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_4;
- }
- else if ( "1.5".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_5;
- }
- else if ( "1.6".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_6;
- }
- else if ( "1.7".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_7;
- }
- else if ( "1.8".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_1_8;
- }
- else if ( "9".equals( versionSpec ) )
- {
- return CompilerOptions.VERSION_9;
- }
- else
- {
- getLogger().warn(
- "Unknown version '" + versionSpec + "', no version setting will be given to the compiler." );
- return null;
- }
- }
-
- // ----------------------------------------------------------------------
- // Classes
- // ----------------------------------------------------------------------
-
- private class CompilationUnit
- implements ICompilationUnit
- {
- private final String className;
-
- private final String sourceFile;
-
- private final String sourceEncoding;
-
- private final List<CompilerMessage> errors;
-
- CompilationUnit( String sourceFile, String className, List<CompilerMessage> errors )
+ if(config.isParameters())
{
- this( sourceFile, className, errors, null );
+ args.add("-parameters");
}
- CompilationUnit( String sourceFile, String className, List<CompilerMessage> errors, String sourceEncoding )
+ // Set Eclipse-specific options
+ // compiler-specific extra options override anything else in the config object...
+ Map<String, String> extras = config.getCustomCompilerArgumentsAsMap();
+ if( extras.containsKey( "errorsAsWarnings" ) )
{
- this.className = className;
- this.sourceFile = sourceFile;
- this.errors = errors;
- this.sourceEncoding = sourceEncoding;
+ extras.remove( "errorsAsWarnings" );
+ this.errorsAsWarnings = true;
}
-
- public char[] getFileName()
+ else if(extras.containsKey("-errorsAsWarnings"))
{
- String fileName = sourceFile;
-
- int lastSeparator = fileName.lastIndexOf( File.separatorChar );
-
- if ( lastSeparator > 0 )
- {
- fileName = fileName.substring( lastSeparator + 1 );
- }
-
- return fileName.toCharArray();
+ extras.remove( "-errorsAsWarnings" );
+ this.errorsAsWarnings = true;
}
- String getAbsolutePath()
- {
- return sourceFile;
+ //-- 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");
}
- public char[] getContents()
+ for(Entry<String, String> entry : extras.entrySet())
{
- try
- {
- return FileUtils.fileRead( sourceFile, sourceEncoding ).toCharArray();
- }
- catch ( FileNotFoundException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
-
- return null;
- }
- catch ( IOException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
-
- return null;
- }
+ String opt = entry.getKey();
+ if(! opt.startsWith("-"))
+ opt = "-" + opt; // compiler mojo apparently messes with this; make sure we are safe
+ args.add(opt);
+ String value = entry.getValue();
+ if(null != value && ! value.isEmpty())
+ args.add(value);
}
- public char[] getMainTypeName()
- {
- int dot = className.lastIndexOf( '.' );
+ // Output path
+ args.add("-d");
+ args.add(config.getOutputLocation());
- if ( dot > 0 )
- {
- return className.substring( dot + 1 ).toCharArray();
- }
-
- return className.toCharArray();
- }
-
- public char[][] getPackageName()
- {
- StringTokenizer izer = new StringTokenizer( className, "." );
+ // Annotation processors defined?
+ List<String> extraSourceDirs = new ArrayList<>();
+ if(!isPreJava16(config)) {
+ //now add jdk 1.6 annotation processing related parameters
+ String[] annotationProcessors = config.getAnnotationProcessors();
+ List<String> processorPathEntries = config.getProcessorPathEntries();
+ 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);
+ }
+ args.add(sb.toString());
+ }
- char[][] result = new char[izer.countTokens() - 1][];
+ if(processorPathEntries != null && processorPathEntries.size() > 0) {
+ args.add("-processorpath");
+ args.add(getPathString(processorPathEntries));
+ }
- for ( int i = 0; i < result.length; i++ )
- {
- String tok = izer.nextToken();
+ File generatedSourcesDir = config.getGeneratedSourcesDirectory();
+ if(generatedSourcesDir != null) {
+ generatedSourcesDir.mkdirs();
+ extraSourceDirs.add(generatedSourcesDir.getAbsolutePath());
- result[i] = tok.toCharArray();
+ //-- option to specify where annotation processor is to generate its output
+ args.add("-s");
+ args.add(generatedSourcesDir.getAbsolutePath());
+ }
+ if(config.getProc() != null) {
+ args.add("-proc:" + config.getProc());
+ }
}
-
- return result;
}
- public boolean ignoreOptionalProblems()
- {
- return false;
- }
- }
-
- private class EclipseCompilerINameEnvironment
- implements INameEnvironment
- {
- private SourceCodeLocator sourceCodeLocator;
-
- private ClassLoader classLoader;
+ //-- 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
- private List<CompilerMessage> errors;
+ //-- classpath
+ List<String> classpathEntries = new ArrayList<>(config.getClasspathEntries());
+ classpathEntries.add(config.getOutputLocation());
+ args.add("-classpath");
+ args.add(getPathString(classpathEntries));
- public EclipseCompilerINameEnvironment( SourceCodeLocator sourceCodeLocator, ClassLoader classLoader,
- List<CompilerMessage> errors )
- {
- this.sourceCodeLocator = sourceCodeLocator;
- this.classLoader = classLoader;
- this.errors = errors;
- }
-
- public NameEnvironmentAnswer findType( char[][] compoundTypeName )
- {
- String result = "";
+ // Compile! Send all errors to xml temp file.
+ File errorF = null;
+ try {
+ errorF = File.createTempFile("ecjerr-", ".xml");
- String sep = "";
+ args.add("-log");
+ args.add(errorF.toString());
- for ( int i = 0; i < compoundTypeName.length; i++ )
- {
- result += sep;
- result += new String( compoundTypeName[i] );
- sep = ".";
+ // Add all sources.
+ int argCount = args.size();
+ for(String source : config.getSourceLocations()) {
+ File srcFile = new File(source);
+ if(srcFile.exists()) {
+ Set<String> ss = getSourceFilesForSourceRoot( config, source );
+ args.addAll(ss);
+ }
}
-
- return findType( result );
- }
-
- public NameEnvironmentAnswer findType( char[] typeName, char[][] packageName )
- {
- String result = "";
-
- String sep = "";
-
- for ( int i = 0; i < packageName.length; i++ )
- {
- result += sep;
- result += new String( packageName[i] );
- sep = ".";
+ args.addAll(extraSourceDirs);
+ if(args.size() == argCount) {
+ //-- Nothing to do -> bail out
+ return new CompilerResult(true, Collections.EMPTY_LIST);
}
- result += sep;
- result += new String( typeName );
- return findType( result );
- }
-
- private NameEnvironmentAnswer findType( String className )
- {
- try
- {
- File f = sourceCodeLocator.findSourceCodeForClass( className );
-
- if ( f != null )
- {
- ICompilationUnit compilationUnit = new CompilationUnit( f.getAbsolutePath(), className, errors );
+ StringWriter sw = new StringWriter();
+ PrintWriter devNull = new PrintWriter(sw);
- return new NameEnvironmentAnswer( compilationUnit, null );
+ //BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() {
+ BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
+ @Override public void begin(int i) {
}
- String resourceName = className.replace( '.', '/' ) + ".class";
-
- InputStream is = classLoader.getResourceAsStream( resourceName );
-
- if ( is == null )
- {
- return null;
+ @Override public void done() {
}
- byte[] classBytes = IOUtil.toByteArray( is );
-
- char[] fileName = className.toCharArray();
-
- ClassFileReader classFileReader = new ClassFileReader( classBytes, fileName, true );
-
- return new NameEnvironmentAnswer( classFileReader, null );
- }
- catch ( IOException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
+ @Override public boolean isCanceled() {
+ return false;
+ }
- return null;
- }
- catch ( ClassFormatException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
+ @Override public void setTaskName(String s) {
+ }
- return null;
- }
- }
+ @Override public void worked(int i, int i1) {
+ }
+ });
+ getLogger().debug(sw.toString());
- private boolean isPackage( String result )
- {
- if ( sourceCodeLocator.findSourceCodeForClass( result ) != null )
- {
- return false;
+ List<CompilerMessage> messageList;
+ boolean hasError = false;
+ if(errorF.length() < 80) {
+ throw new IOException("Failed to run the ECJ compiler:\n" + sw.toString());
}
+ messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings);
- String resourceName = "/" + result.replace( '.', '/' ) + ".class";
-
- InputStream is = classLoader.getResourceAsStream( resourceName );
-
- return is == null;
- }
-
- public boolean isPackage( char[][] parentPackageName, char[] packageName )
- {
- String result = "";
-
- String sep = "";
-
- if ( parentPackageName != null )
- {
- for ( int i = 0; i < parentPackageName.length; i++ )
- {
- result += sep;
- result += new String( parentPackageName[i] );
- sep = ".";
+ for(CompilerMessage compilerMessage : messageList) {
+ if(compilerMessage.isError()) {
+ hasError = true;
+ break;
}
}
-
- if ( Character.isUpperCase( packageName[0] ) )
- {
- return false;
+ return new CompilerResult(! hasError, messageList);
+
+ } catch(Exception x) {
+ throw new RuntimeException(x); // sigh
+ } finally {
+ if(null != errorF) {
+ try {
+ errorF.delete();
+ } catch(Exception x) {}
}
-
- String str = new String( packageName );
-
- result += sep;
-
- result += str;
-
- return isPackage( result );
- }
-
- public void cleanup()
- {
- // nothing to do
}
}
- private class EclipseCompilerICompilerRequestor
- implements ICompilerRequestor
- {
- private String destinationDirectory;
-
- private List<CompilerMessage> errors;
-
- public EclipseCompilerICompilerRequestor( String destinationDirectory, List<CompilerMessage> errors )
- {
- this.destinationDirectory = destinationDirectory;
- this.errors = errors;
- }
+ static private void append(StringBuilder warns, String s) {
+ if(warns.length() > 0)
+ warns.append(',');
+ warns.append(s);
+ }
- public void acceptResult( CompilationResult result )
+ private boolean isPreJava16(CompilerConfiguration config) {
+ String s = config.getSourceVersion();
+ if ( s == null )
{
- boolean hasErrors = false;
-
- if ( result.hasProblems() )
- {
- IProblem[] problems = result.getProblems();
-
- for ( IProblem problem : problems )
- {
- String name = getFileName( result.getCompilationUnit(), problem.getOriginatingFileName() );
-
- if ( problem.isWarning() )
- {
- errors.add( handleWarning( name, problem ) );
- }
- else
- {
- if( errorsAsWarnings )
- {
- errors.add( handleWarning( name, problem ) );
- }
- else
- {
- hasErrors = true;
- errors.add( handleError( name, problem.getSourceLineNumber(), -1, problem.getMessage() ) );
- }
- }
- }
- }
-
- if ( !hasErrors )
- {
- ClassFile[] classFiles = result.getClassFiles();
-
- for ( ClassFile classFile : classFiles )
- {
- char[][] compoundName = classFile.getCompoundName();
- String className = "";
- String sep = "";
-
- for ( int j = 0; j < compoundName.length; j++ )
- {
- className += sep;
- className += new String( compoundName[j] );
- sep = ".";
- }
-
- byte[] bytes = classFile.getBytes();
-
- File outFile = new File( destinationDirectory, className.replace( '.', '/' ) + ".class" );
-
- if ( !outFile.getParentFile().exists() )
- {
- outFile.getParentFile().mkdirs();
- }
-
- FileOutputStream fout = null;
-
- try
- {
- fout = new FileOutputStream( outFile );
-
- fout.write( bytes );
- }
- catch ( FileNotFoundException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
- }
- catch ( IOException e )
- {
- errors.add( handleError( className, -1, -1, e.getMessage() ) );
- }
- finally
- {
- IOUtil.close( fout );
- }
- }
- }
+ //now return true, as the 1.6 version is not the default - 1.4 is.
+ return true;
}
+ return s.startsWith( "1.5" ) || s.startsWith( "1.4" ) || s.startsWith( "1.3" ) || s.startsWith( "1.2" )
+ || s.startsWith( "1.1" ) || s.startsWith( "1.0" );
+ }
- private String getFileName( ICompilationUnit compilationUnit, char[] originalFileName )
- {
- if ( compilationUnit instanceof CompilationUnit )
- {
- return ( (CompilationUnit) compilationUnit ).getAbsolutePath();
- }
- else
- {
- return String.valueOf( originalFileName );
- }
- }
+ public String[] createCommandLine( CompilerConfiguration config )
+ throws CompilerException
+ {
+ return null;
}
- private void initializeWarnings( String propertiesFile, Map<String, String> setting )
+
+ /**
+ * Change any Maven Java version number to ECJ's version number. Do not check the validity
+ * of the version: the compiler does that nicely, and this allows compiler updates without
+ * changing the compiler plugin. This is important with the half year release cycle for Java.
+ */
+ private String decodeVersion( String versionSpec )
{
- File file = new File( propertiesFile );
- if ( !file.exists() )
- {
- throw new IllegalArgumentException( "Properties file not exist" );
- }
- BufferedInputStream stream = null;
- Properties properties = null;
- try
- {
- stream = new BufferedInputStream( new FileInputStream( propertiesFile ) );
- properties = new Properties();
- properties.load( stream );
- }
- catch ( IOException e )
- {
- throw new IllegalArgumentException( "Properties file load error" );
- }
- finally
+ if ( StringUtils.isEmpty( versionSpec ) )
{
- if ( stream != null )
- {
- try
- {
- stream.close();
- }
- catch ( IOException e )
- {
- // ignore
- }
- }
+ return null;
}
- for ( Iterator iterator = properties.entrySet().iterator(); iterator.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) iterator.next();
- final String key = (String) entry.getKey();
- setting.put( key, entry.getValue().toString() );
+
+ if(versionSpec.equals("1.9")) {
+ getLogger().warn("Version 9 should be specified as 9, not 1.9");
+ return "9";
}
+ return versionSpec;
}
}
=====================================
plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerErrorsAsWarningsTest.java
=====================================
--- 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
@@ -1,11 +1,11 @@
package org.codehaus.plexus.compiler.eclipse;
-import java.util.Arrays;
-import java.util.Collection;
-
import org.codehaus.plexus.compiler.AbstractCompilerTest;
import org.codehaus.plexus.compiler.CompilerConfiguration;
+import java.util.Arrays;
+import java.util.Collection;
+
public class EclipseCompilerErrorsAsWarningsTest extends AbstractCompilerTest
{
@@ -39,9 +39,14 @@ public class EclipseCompilerErrorsAsWarningsTest extends AbstractCompilerTest
protected Collection<String> 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",
- "org/codehaus/foo/UnknownSymbol.class", "org/codehaus/foo/RightClassname.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",
+ //"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"
+ });
}
}
=====================================
plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerTest.java
=====================================
--- 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
@@ -24,14 +24,13 @@ package org.codehaus.plexus.compiler.eclipse;
* SOFTWARE.
*/
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-
import org.codehaus.plexus.compiler.AbstractCompilerTest;
import org.codehaus.plexus.compiler.Compiler;
import org.codehaus.plexus.compiler.CompilerConfiguration;
+import java.util.Arrays;
+import java.util.Collection;
+
/**
* @author <a href="mailto:jason at plexus.org">Jason van Zyl</a>
*/
@@ -82,25 +81,6 @@ public class EclipseCompilerTest
compiler.performCompile( compilerConfig );
}
- public void testCustomArgumentCleanup()
- {
- EclipseJavaCompiler compiler = new EclipseJavaCompiler();
-
- CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
-
- compilerConfig.addCompilerCustomArgument( "-key", "value" );
- compilerConfig.addCompilerCustomArgument( "cleanKey", "value" );
-
- Map<String, String> cleaned = compiler.cleanKeyNames( compilerConfig.getCustomCompilerArgumentsAsMap() );
-
- assertTrue( "Key should have been cleaned", cleaned.containsKey( "key" ) );
-
- assertFalse( "Key should have been cleaned", cleaned.containsKey( "-key" ) );
-
- assertTrue( "This key should not have been cleaned does not start with dash", cleaned.containsKey( "cleanKey" ) );
-
- }
-
public void testInitializeWarningsForPropertiesArgument()
throws Exception
{
@@ -117,7 +97,7 @@ public class EclipseCompilerTest
}
catch ( IllegalArgumentException e )
{
- assertEquals( "Properties file not exist", e.getMessage() );
+ assertTrue("Message must start with 'Properties file'", e.getMessage().startsWith("Properties file"));
}
}
=====================================
plexus-compilers/plexus-compiler-j2objc/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-j2objc/pom.xml
+++ b/plexus-compilers/plexus-compiler-j2objc/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-j2objc</artifactId>
=====================================
plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
+++ b/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
=====================================
plexus-compilers/plexus-compiler-javac/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-javac/pom.xml
+++ b/plexus-compilers/plexus-compiler-javac/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-javac</artifactId>
=====================================
plexus-compilers/plexus-compiler-jikes/pom.xml
=====================================
--- a/plexus-compilers/plexus-compiler-jikes/pom.xml
+++ b/plexus-compilers/plexus-compiler-jikes/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compiler-jikes</artifactId>
=====================================
plexus-compilers/pom.xml
=====================================
--- a/plexus-compilers/pom.xml
+++ b/plexus-compilers/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
</parent>
<artifactId>plexus-compilers</artifactId>
=====================================
pom.xml
=====================================
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
</parent>
<artifactId>plexus-compiler</artifactId>
- <version>2.8.3</version>
+ <version>2.8.4</version>
<packaging>pom</packaging>
<name>Plexus Compiler</name>
@@ -27,7 +27,7 @@
<connection>${scm.url}</connection>
<developerConnection>${scm.url}</developerConnection>
<url>http://github.com/codehaus-plexus/plexus-compiler/tree/${project.scm.tag}/</url>
- <tag>plexus-compiler-2.8.3</tag>
+ <tag>plexus-compiler-2.8.4</tag>
</scm>
<issueManagement>
<system>github</system>
View it on GitLab: https://salsa.debian.org/java-team/plexus-compiler/commit/4dd474cabd90e57bb356e0f6235d86ad7a63fb4a
--
View it on GitLab: https://salsa.debian.org/java-team/plexus-compiler/commit/4dd474cabd90e57bb356e0f6235d86ad7a63fb4a
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20180615/8e16ba63/attachment.html>
More information about the pkg-java-commits
mailing list