org.codehaus.plexus
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 286407cd..0f70efca 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
@@ -17,6 +17,7 @@
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 java.io.File;
import java.io.IOException;
@@ -25,9 +26,11 @@
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
*
@@ -295,7 +298,9 @@ public class AspectJCompiler
public AspectJCompiler()
{
- super( CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE, ".java", ".class", null );
+ // Input file ending "" means: Give me all files, I am going to filter them myself later. We are doing this,
+ // because in method 'getSourceFiles' we need to search for both ".java" and ".aj" files.
+ super( CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE, "", ".class", null );
}
public CompilerResult performCompile( CompilerConfiguration config )
@@ -344,15 +349,17 @@ private AjBuildConfig buildCompilerConfig( CompilerConfiguration config )
buildConfig.setFiles( buildFileList( Arrays.asList( files ) ) );
}
- setSourceVersion( buildConfig, config.getSourceVersion() );
+ String releaseVersion = config.getReleaseVersion();
+ setSourceVersion( buildConfig, releaseVersion == null ? config.getSourceVersion() : releaseVersion );
+ setTargetVersion( buildConfig, releaseVersion == null ? config.getTargetVersion() : releaseVersion );
if ( config.isDebug() )
{
buildConfig.getOptions().produceDebugAttributes =
- ClassFileConstants.ATTR_SOURCE + ClassFileConstants.ATTR_LINES + ClassFileConstants.ATTR_VARS;
+ ClassFileConstants.ATTR_SOURCE + ClassFileConstants.ATTR_LINES + ClassFileConstants.ATTR_VARS;
}
- Map javaOpts = config.getCustomCompilerArguments();
+ Map javaOpts = config.getCustomCompilerArgumentsAsMap();
if ( javaOpts != null && !javaOpts.isEmpty() )
{
// TODO support customCompilerArguments
@@ -557,7 +564,7 @@ private List buildFileList( List locations )
}
/**
- * Set the source version in ajc compiler
+ * Set the source version in AspectJ compiler
*
* @param buildConfig
* @param sourceVersion
@@ -565,75 +572,149 @@ private List buildFileList( List locations )
private void setSourceVersion( AjBuildConfig buildConfig, String sourceVersion )
throws CompilerException
{
- if ( "11".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK11;
- }
- else if ( "10".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK10;
- }
- else if ( "9".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK9;
- }
- else if ( "1.9".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK9;
- }
- else if ( "1.8".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_8;
- }
- else if ( "1.7".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_7;
- }
- else if ( "1.6".equals( sourceVersion ) )
- {
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_6;
- }
- else if ( "1.5".equals( sourceVersion ) )
+ buildConfig.getOptions().sourceLevel = versionStringToMajorMinor( sourceVersion );
+ }
+
+ /**
+ * Set the target version in AspectJ compiler
+ *
+ * @param buildConfig
+ * @param targetVersion
+ */
+ private void setTargetVersion( AjBuildConfig buildConfig, String targetVersion )
+ throws CompilerException
+ {
+ buildConfig.getOptions().targetJDK = versionStringToMajorMinor( targetVersion );
+ }
+
+ private static long versionStringToMajorMinor(String version) throws CompilerException
+ {
+ if ( version == null )
+ {
+ version = "";
+ }
+ // Note: We avoid using org.codehaus.plexus:plexus-java here on purpose, because Maven Compiler might depend on
+ // a different (older) versionm, e.g. not having the 'asMajor' method yet. This can cause problems for users
+ // trying to compile their AspectJ code using Plexus.
+
+ version = version.trim()
+ // Cut off leading "1.", focusing on the Java major
+ .replaceFirst( "^1[.]", "" )
+ // Accept, but cut off trailing ".0", as ECJ/ACJ explicitly support versions like 5.0, 8.0, 11.0
+ .replaceFirst("[.]0$", "");
+
+ switch ( version )
+ {
+ // Java 1.6 as a default source/target seems to make sense. Maven Compiler should set its own default
+ // anyway, so this probably never needs to be used. But not having a default feels bad, too.
+ case "" : return ClassFileConstants.JDK1_6;
+ case "1" : return ClassFileConstants.JDK1_1;
+ case "2" : return ClassFileConstants.JDK1_2;
+ case "3" : return ClassFileConstants.JDK1_3;
+ case "4" : return ClassFileConstants.JDK1_4;
+ case "5" : return ClassFileConstants.JDK1_5;
+ case "6" : return ClassFileConstants.JDK1_6;
+ case "7" : return ClassFileConstants.JDK1_7;
+ case "8" : return ClassFileConstants.JDK1_8;
+ case "9" : return ClassFileConstants.JDK9;
+ case "10" : return ClassFileConstants.JDK10;
+ case "11" : return ClassFileConstants.JDK11;
+ case "12" : return ClassFileConstants.JDK12;
+ case "13" : return ClassFileConstants.JDK13;
+ case "14" : return ClassFileConstants.JDK14;
+ case "15" : return ClassFileConstants.JDK15;
+ case "16" : return ClassFileConstants.JDK16;
+ }
+ throw new CompilerException( "Unknown Java source/target version number: " + version );
+ }
+
+ /**
+ * @return null
+ */
+ public String[] createCommandLine( CompilerConfiguration config )
+ throws CompilerException
+ {
+ return null;
+ }
+
+ protected static String[] getSourceFiles( CompilerConfiguration config )
+ {
+ Set sources = new HashSet<>();
+
+ Set sourceFiles = config.getSourceFiles();
+
+ if ( sourceFiles != null && !sourceFiles.isEmpty() )
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_5;
+ for ( File sourceFile : sourceFiles )
+ {
+ if ( sourceFile.getName().endsWith( ".java" ) || sourceFile.getName().endsWith( ".aj" ) )
+ {
+ sources.add( sourceFile.getAbsolutePath() );
+ }
+ }
}
- else if ( "5.0".equals( sourceVersion ) )
+ else
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_5;
+ for ( String sourceLocation : config.getSourceLocations() )
+ {
+ sources.addAll( getSourceFilesForSourceRoot( config, sourceLocation ) );
+ }
}
- else if ( "1.4".equals( sourceVersion ) )
+
+ String[] result;
+
+ if ( sources.isEmpty() )
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_4;
+ result = new String[0];
}
- else if ( "1.3".equals( sourceVersion ) )
+ else
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_3;
+ result = sources.toArray( new String[sources.size()] );
}
- else if ( "1.2".equals( sourceVersion ) )
+
+ return result;
+ }
+
+ protected static Set getSourceFilesForSourceRoot( CompilerConfiguration config, String sourceLocation )
+ {
+ DirectoryScanner scanner = new DirectoryScanner();
+
+ scanner.setBasedir( sourceLocation );
+
+ Set includes = config.getIncludes();
+
+ if ( includes != null && !includes.isEmpty() )
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_2;
+ String[] inclStrs = includes.toArray( new String[includes.size()] );
+ scanner.setIncludes( inclStrs );
}
- else if ( "1.1".equals( sourceVersion ) )
+ else
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_1;
+ scanner.setIncludes( new String[] {"**/*.java", "**/*.aj"} );
}
- else if ( sourceVersion == null || sourceVersion.length() <= 0 )
+
+ Set excludes = config.getExcludes();
+
+ if ( excludes != null && !excludes.isEmpty() )
{
- buildConfig.getOptions().sourceLevel = ClassFileConstants.JDK1_3;
+ String[] exclStrs = excludes.toArray( new String[excludes.size()] );
+ scanner.setExcludes( exclStrs );
}
- else
+
+ scanner.scan();
+
+ String[] sourceDirectorySources = scanner.getIncludedFiles();
+
+ Set sources = new HashSet<>();
+
+ for ( String sourceDirectorySource : sourceDirectorySources )
{
- throw new CompilerException( "The source version was not recognized: " + sourceVersion );
+ File f = new File( sourceLocation, sourceDirectorySource );
+
+ sources.add( f.getPath() );
}
- }
- /**
- * @return null
- */
- public String[] createCommandLine( CompilerConfiguration config )
- throws CompilerException
- {
- return null;
+ return sources;
}
}
diff --git a/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java b/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java
index e3c9835b..fceb9277 100644
--- a/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java
+++ b/plexus-compilers/plexus-compiler-aspectj/src/test/java/org/codehaus/plexus/compiler/ajc/AspectJCompilerTest.java
@@ -3,7 +3,6 @@
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import org.codehaus.plexus.compiler.AbstractCompilerTest;
@@ -24,40 +23,19 @@ protected String getRoleHint()
return "aspectj";
}
- protected int expectedErrors()
- {
- // olamy well I agree it's hackhish but I don't want to waste too much time with aspectj which is probably
- // not used a lot anymore...
- String javaVersion = getJavaVersion();
- if (javaVersion.equals( "11" ))
- {
- return 11;
- }
- return 1;
- }
-
protected Collection expectedOutputFiles()
{
- String javaVersion = System.getProperty( "java.version" );
- // olamy well I agree it's hackhish but I don't want to waste too much time with aspectj which is probably
- // not used a lot anymore...
-// if (javaVersion.startsWith( "9" ) || javaVersion.startsWith( "10" ))
-// {
-// return Collections.emptyList();
-// }
- return Arrays.asList( new String[]{ "org/codehaus/foo/ExternalDeps.class", "org/codehaus/foo/Person.class" } );
+ return Arrays.asList( "org/codehaus/foo/ExternalDeps.class", "org/codehaus/foo/Person.class" );
}
protected List getClasspath()
throws Exception
{
- List cp = super.getClasspath();
-
- File localArtifactPath =
- getLocalArtifactPath( "org.aspectj", "aspectjrt", System.getProperty( "aspectj.version" ), "jar" );
- cp.add( localArtifactPath.getAbsolutePath() );
-
- return cp;
+ List classpath = super.getClasspath();
+ String aspectjVersion = System.getProperty( "aspectj.version" );
+ File aspectjRuntime = getLocalArtifactPath( "org.aspectj", "aspectjrt", aspectjVersion, "jar" );
+ classpath.add( aspectjRuntime.getAbsolutePath() );
+ return classpath;
}
}
diff --git a/pom.xml b/pom.xml
index 3605183c..c35d8a2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,8 @@
7
true
2020-08-24T00:30:49Z
+ 4.13.2
+ 1.9.7.M3
2.6.0
@@ -80,7 +82,7 @@
junit
junit
test
- 4.13.2
+ ${junit.version}