diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e74ccc33..8ed8ccb4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,19 +1,24 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. +# MIT License +# +# Copyright 2021 Mojohaus +# +# 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 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. name: GitHub CI diff --git a/LICENSE.txt b/LICENSE.txt index 7320d25d..49131c09 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,13 +1,14 @@ -The MIT License +MIT License -Copyright 2005-2006 The Codehaus. +Copyright 2005-2015 Mojo@Codehaus +Copyright 2015-2021 Mojohaus -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: +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. @@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index cfadb0d8..d3b32a79 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Mojohaus AspectJ-Maven-Plugin +# Mojohaus AspectJ Maven Plugin This is the [aspectj-maven-plugin](https://www.mojohaus.org/aspectj-maven-plugin/). @@ -8,7 +8,7 @@ This is the [aspectj-maven-plugin](https://www.mojohaus.org/aspectj-maven-plugin ## Overview -This plugin weaves AspectJ aspects into your classes using the AspectJ compiler ("ajc"). +This plugin weaves AspectJ aspects into your classes using the AspectJ compiler `ajc`. Typically, aspects are used in one of two ways within your Maven reactors: * As part of a Single Project, implying aspects and code are defined within the same Maven project. @@ -18,7 +18,7 @@ Typically, aspects are used in one of two ways within your Maven reactors: * As part of a Multi-module Maven Reactor where one/some project(s) contains aspects and other projects within the Maven reactor contain code using the aspects ("woven by the aspects"). This is a more complex and powerful approach, best suited when several Maven projects should be woven - by a common set of aspects. The "Examples: Multi-module AspectJ use" contains a basic walkthrough + by a common set of aspects. The "Examples: Multi-module AspectJ use" contains a basic walk-through of this approach. ## Contributing diff --git a/src/it/LineNumbersInAjcWarnings/pom.xml b/src/it/LineNumbersInAjcWarnings/pom.xml index d0d091d3..7185c658 100644 --- a/src/it/LineNumbersInAjcWarnings/pom.xml +++ b/src/it/LineNumbersInAjcWarnings/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it WarningMessagesWithLineNumbers 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/NoParameters/pom.xml b/src/it/NoParameters/pom.xml index 087ad5b6..7b38998e 100644 --- a/src/it/NoParameters/pom.xml +++ b/src/it/NoParameters/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it parameters 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/Parameters/pom.xml b/src/it/Parameters/pom.xml index 9f87a75a..aa34d1aa 100644 --- a/src/it/Parameters/pom.xml +++ b/src/it/Parameters/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it parameters 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/TOFIX_MASPECTJ-4/pom.xml b/src/it/TOFIX_MASPECTJ-4/pom.xml index b9d591cd..9f2b759b 100644 --- a/src/it/TOFIX_MASPECTJ-4/pom.xml +++ b/src/it/TOFIX_MASPECTJ-4/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it maspectj-4 0.0.1-SNAPSHOT @@ -67,4 +67,4 @@ - \ No newline at end of file + diff --git a/src/it/Xajruntimetarget/pom.xml b/src/it/Xajruntimetarget/pom.xml index 4f06c96a..00c3ae52 100644 --- a/src/it/Xajruntimetarget/pom.xml +++ b/src/it/Xajruntimetarget/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it xajruntimetarget 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/XhasMember/pom.xml b/src/it/XhasMember/pom.xml index f531bdf6..1b35a442 100644 --- a/src/it/XhasMember/pom.xml +++ b/src/it/XhasMember/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it xhasmember 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/Xlint/pom.xml b/src/it/Xlint/pom.xml index a4f77cea..4191f358 100644 --- a/src/it/Xlint/pom.xml +++ b/src/it/Xlint/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it xlint 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/it/Xlintfile/pom.xml b/src/it/Xlintfile/pom.xml index 7daa6fb9..f33782f3 100644 --- a/src/it/Xlintfile/pom.xml +++ b/src/it/Xlintfile/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.codehaus.mjo.aspectj.it + org.codehaus.mojo.aspectj.it xlintfile 0.0.1-SNAPSHOT @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java b/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java index 3221581c..232a7d02 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java @@ -1,8 +1,5 @@ package org.codehaus.mojo.aspectj; - -import org.apache.commons.collections.CollectionUtils; - /** * The MIT License * @@ -27,6 +24,7 @@ * SOFTWARE. */ +import org.apache.commons.collections.CollectionUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.plugin.MojoExecutionException; @@ -48,8 +46,9 @@ import java.util.Set; /** - *
Base class for the two aspectJ compiletime weaving mojos.
- *
For all available options see ajc-ref
+ * Base class for the two aspectJ compile-time weaving mojos. + *

+ * For all available options see ajc-ref * * @author Kaare Nilsen */ @@ -191,25 +190,25 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo { protected boolean XhasMember; /** - * Specify classfile target setting (1.1 to 1.8) default is 1.2 + * Specify bytecode target setting (1.3 to 1.9, 10 to 16). See 'complianceLevel' for details. * + * @see org.codehaus.mojo.aspectj.AjcHelper#ACCEPTED_COMPLIANCE_LEVEL_VALUES */ @Parameter( defaultValue = "${project.build.java.target}" ) protected String target; /** - * Toggle assertions (1.3, 1.4, 1.5, 1.6, 1.7 or 1.8 - default is 1.4). When using -source 1.3, an assert() - * statement valid under Java 1.4 will result in a compiler error. When using -source 1.4, treat assert - * as a keyword and implement assertions according to the 1.4 language spec. When using -source 1.5 or higher, Java - * 5 language features are permitted. With --source 1.7 or higher Java 7 features are supported. + * Specify source code language level (1.3 to 1.9, 10 to 16). See 'complianceLevel' for details. * + * @see org.codehaus.mojo.aspectj.AjcHelper#ACCEPTED_COMPLIANCE_LEVEL_VALUES */ @Parameter( defaultValue = "${mojo.java.target}" ) protected String source; /** - * Specify compiler compliance setting. - * Defaults to 1.4, with permitted values ("1.3", "1.4", "1.5", "1.6" and "1.7", "1.8"). + * Specify compiler compliance setting (same as setting 'source' and 'target' to the same level). + * Permitted values: 1.3, 1.4, 1.5, 5, 5.0, 1.6, 6, 6.0, 1.7, 7, 7.0, 1.8, 8, 8.0, + * 1.9, 9, 9.0, 10, 10.0, 11, 11.0, 12, 12.0, 13, 13.0, 14, 14.0, 15, 15.0, 16, 16.0. * * @see org.codehaus.mojo.aspectj.AjcHelper#ACCEPTED_COMPLIANCE_LEVEL_VALUES */ @@ -354,22 +353,22 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo { * Supported values are shown in the list below, with their respective explanations - as copied * directly from the AJC reference. *

- *
constructorName
- *
method with constructor name
- *
packageDefaultMethod
- *
attempt to override package-default method
- *
deprecation
- *
usage of deprecated type or member
- *
maskedCatchBlocks
- *
hidden catch block
- *
unusedLocals
- *
local variable never read
- *
unusedArguments
- *
method argument never read
- *
unusedImports
- *
import statement not used by code in file
- *
none
- *
suppress all compiler warnings
+ *
constructorName
+ *
method with constructor name
+ *
packageDefaultMethod
+ *
attempt to override package-default method
+ *
deprecation
+ *
usage of deprecated type or member
+ *
maskedCatchBlocks
+ *
hidden catch block
+ *
unusedLocals
+ *
local variable never read
+ *
unusedArguments
+ *
method argument never read
+ *
unusedImports
+ *
import statement not used by code in file
+ *
none
+ *
suppress all compiler warnings
*
* * @see Eclipse AJC reference @@ -378,26 +377,21 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo { protected String warn; /** - *
* The filename holding AJC build arguments. * The file will be placed in the project build output directory, and will contain all the arguments passed to * the AJC compiler in the last run, and also all the files included in the AJC build. - *
- *
+ *

* Sample content shown below to illustrate typical content within the builddef.lst file: - *

-     *     
+     * 

      * -1.6
      * -encoding
      * UTF-8
      * -classpath
-     * /Users/lj/Development/Projects/Nazgul/nazgul_tools/validation/validation-api/target/nazgul-tools-validation-api-2.0.10-SNAPSHOT.jar:/Users/lj/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar:/Users/lj/.m2/repository/org/aspectj/aspectjrt/1.7.3/aspectjrt-1.7.3.jar:/Users/lj/.m2/repository/junit/junit/4.11/junit-4.11.jar:/Users/lj/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar:/Users/lj/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar:/Users/lj/Development/Projects/Nazgul/nazgul_tools/validation/validation-aspect/target/classes
+     * /my/library/lib.jar:/somewhere/aspectjrt.jar:/my/project/target/classes
      * -d
-     * /Users/lj/Development/Projects/Nazgul/nazgul_tools/validation/validation-aspect/target/classes
-     * /Users/lj/Development/Projects/Nazgul/nazgul_tools/validation/validation-aspect/src/main/java/se/jguru/nazgul/tools/validation/aspect/ValidationAspect.java
-     *     
-     * 
- *
+ * /my/project/target/classes + * /my/project/src/main/java/org/acme/ValidationAspect.java + * */ @Parameter( defaultValue = "builddef.lst" ) protected String argumentFileName = "builddef.lst"; @@ -409,13 +403,44 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo { @Parameter( defaultValue = "false" ) protected boolean forceAjcCompile; + /** + * Sets additional compiler arguments, e.g. + *
{@code
+   * 
+   *   -Xmaxerrs=1000
+   *   -Xlint
+   *   -J-Duser.language=en_us 
+   * 
+   * }
+ * This option can be used in case you want to use AJC options not (yet) supported by this plugin. + *

+ * Caveat: Be careful when using this option and select the additional compiler arguments wisely, because + * behaviour is undefined if you add arguments which have already been added by the plugin using regular parameters + * or their default values. The resulting compiler command line will in that case contain duplicate arguments, which + * might be illegal depending on the specific argument. Do not expect to be able to manually override existing + * arguments using this option or to replace whole argument lists. + * + * @since 1.13 + */ + @Parameter + protected List additionalCompilerArgs = new ArrayList<>(); + /** - * Sets the arguments to be passed to the compiler.
- * Example: <compilerArgs> <arg>-Xmaxerrs=1000</arg> <arg>-Xlint</arg> <arg>-J-Duser.language=en_us</arg> - * </compilerArgs> + * Activates compiler preview features (e.g. sealed classes in Java 16) when used with a suitable JDK version. + *

+ * Please note: You cannot run code compiled with preview features on any other JDK than the one used for + * compilation. For example, records compiled with preview on JDK 15 cannot be used on JDK 16 without recompilation. + * This is a JVM limitation unrelated to AspectJ. Also, e.g. sealed classes are preview-1 on JDK 15 and preview-2 on + * JDK 16. You still need to recompile, no matter what. + * + * @since 1.13 */ - @Parameter - protected List compilerArgs = new ArrayList<>(); + // TODO: + // Create tickets for at least Eclipse IDE and IntelliJ IDEA to recognise this switch and import it as a compiler + // and possibly runtime setting. As for AJDT, maybe we have to implement it ourselves, but actually I found no + // references to the Maven module there, so I guess the import is implemented somewhere else. + @Parameter( defaultValue = "false" ) + protected boolean enablePreview; /** * Holder for ajc compiler options @@ -472,7 +497,7 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo { /** * Do the AspectJ compiling. * - * @throws MojoExecutionException + * @throws MojoExecutionException if arguments file cannot be written */ @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException { @@ -623,6 +648,10 @@ protected void assembleArguments() addModulesArgument("-aspectpath", ajcOptions, aspectLibraries, getAdditionalAspectPaths(), "an aspect library"); + // Add Java 9+ modules needed for compilation + addModulesArgument("--module-path", ajcOptions, javaModules, null, + "Java module"); + // Add xmlConfigured option and argument if (null != xmlConfigured) { ajcOptions.add("-xmlConfigured"); @@ -644,8 +673,8 @@ protected void assembleArguments() } ajcOptions.addAll(resolvedIncludes); - if (CollectionUtils.isNotEmpty(compilerArgs)) { - ajcOptions.addAll(compilerArgs); + if (CollectionUtils.isNotEmpty(additionalCompilerArgs)) { + ajcOptions.addAll(additionalCompilerArgs); } } @@ -731,7 +760,7 @@ private void addModulesArgument(final String argument, final List argume * Checks modifications that would make us need a build * * @return true if build is needed, otherwise false - * @throws MojoExecutionException + * @throws MojoExecutionException if an unexpected error occurs, e.g. weave directories cannot be resolved */ protected boolean isBuildNeeded() throws MojoExecutionException { @@ -882,13 +911,23 @@ public void setShowWeaveInfo(boolean showWeaveInfo) { } public void setTarget(String target) { - ajcOptions.add("-target"); - ajcOptions.add(target); + if (AjcHelper.isValidComplianceLevel(target)) { + ajcOptions.add("-target"); + ajcOptions.add(target); + } } public void setSource(String source) { - ajcOptions.add("-source"); - ajcOptions.add(source); + if (AjcHelper.isValidComplianceLevel(source)) { + ajcOptions.add("-source"); + ajcOptions.add(source); + } + } + + public void setEnablePreview(boolean enablePreview) { + if (enablePreview) { + ajcOptions.add("--enable-preview"); + } } public void setVerbose(boolean verbose) { diff --git a/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcMojo.java b/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcMojo.java index 0ada5836..f9ec48aa 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcMojo.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcMojo.java @@ -69,6 +69,15 @@ public abstract class AbstractAjcMojo extends AbstractMojo @Parameter protected String[] weaveDirectories; + /** + * Java 9+ modules to build the module path from. + * Corresponds to ajc --module-path option. + * + * @since 1.13 + */ + @Parameter + protected Module[] javaModules; + /** * Weave binary aspects from the jars. * The aspects should have been output by the same version of the compiler. diff --git a/src/main/java/org/codehaus/mojo/aspectj/AjcCompileMojo.java b/src/main/java/org/codehaus/mojo/aspectj/AjcCompileMojo.java index 73d357cb..70038152 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AjcCompileMojo.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AjcCompileMojo.java @@ -36,7 +36,9 @@ import org.codehaus.plexus.util.Scanner; /** - * Weaves all main classes.AspectJ Compiler Plugin. + * Weaves all main classes. + * + * AspectJ Compiler Plugin. * @author Kaare Nilsen */ @Mojo( name="compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true ) diff --git a/src/main/java/org/codehaus/mojo/aspectj/AjcHelper.java b/src/main/java/org/codehaus/mojo/aspectj/AjcHelper.java index 1347e8bb..8540846c 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AjcHelper.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AjcHelper.java @@ -62,8 +62,23 @@ public class AjcHelper /** * List holding all accepted values for the {@code complianceLevel} parameter. */ - public static final List ACCEPTED_COMPLIANCE_LEVEL_VALUES = - Arrays.asList("1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", "10", "11", "12", "13", "14", "15", "16"); + public static final List ACCEPTED_COMPLIANCE_LEVEL_VALUES = Arrays.asList( + // TODO: update from AJC (AspectJ Compiler) regularly, which in turn extends ECJ (Eclipse Java Compiler) + "1.3", + "1.4", + "1.5", "5", "5.0", + "1.6", "6", "6.0", + "1.7", "7", "7.0", + "1.8", "8", "8.0", + "1.9", "9", "9.0", + "10", "10.0", + "11", "11.0", + "12", "12.0", + "13", "13.0", + "14", "14.0", + "15", "15.0", + "16", "16.0" + ); /** * Checks if the given complianceLevel value is valid. @@ -90,9 +105,12 @@ public static boolean isValidComplianceLevel( String complianceLevel ) public static String createClassPath( MavenProject project, List pluginArtifacts, List outDirs ) { String cp = ""; - Set classPathElements = Collections.synchronizedSet( new LinkedHashSet<>() ); + Set classPathElements = Collections.synchronizedSet( + // LinkedHashSet preserves order by insertion for iteration + new LinkedHashSet<>() + ); Set dependencyArtifacts = project.getDependencyArtifacts(); - // Set.addAll only adds if absent, so we want to add the project artifacts first. + // Set.addAll only adds if absent, so we want to add the project artifacts first classPathElements.addAll( project.getArtifacts() ); classPathElements.addAll( dependencyArtifacts == null ? Collections.emptySet() : dependencyArtifacts ); classPathElements.addAll( pluginArtifacts == null ? Collections.emptySet() : pluginArtifacts ); @@ -128,17 +146,17 @@ public static String createClassPath( MavenProject project, List plugi /** * Based on a AJDT build properties file resolves the combination of all * include and exclude statements and returns a set of all the files to be - * compiled and weaved. + * compiled and woven. * * @param ajdtBuildDefFile the ajdtBuildDefFile * @param basedir the baseDirectory - * @return - * @throws MojoExecutionException + * @return Set of Build Files + * @throws MojoExecutionException if build properties are not found or cannot be read */ public static Set getBuildFilesForAjdtFile( String ajdtBuildDefFile, File basedir ) throws MojoExecutionException { - Set result = new LinkedHashSet(); + Set result = new LinkedHashSet<>(); Properties ajdtBuildProperties = new Properties(); try @@ -162,18 +180,18 @@ public static Set getBuildFilesForAjdtFile( String ajdtBuildDefFile, Fil /** * Based on a set of sourcedirs, apply include and exclude statements and - * returns a set of all the files to be compiled and weaved. + * returns a set of all the files to be compiled and woven. * - * @param sourceDirs - * @param includes - * @param excludes - * @return - * @throws MojoExecutionException + * @param sourceDirs source directories + * @param includes file include patterns + * @param excludes file exclude patterns + * @return Set of Build Files for Source Dirs + * @throws MojoExecutionException if sourceDirs cannot be resolved */ public static Set getBuildFilesForSourceDirs( List sourceDirs, String[] includes, String[] excludes ) throws MojoExecutionException { - Set result = new LinkedHashSet(); + Set result = new LinkedHashSet<>(); for ( String sourceDir : sourceDirs ) { @@ -200,10 +218,11 @@ public static Set getBuildFilesForSourceDirs( List sourceDirs, S } /** - * Based on a set of weavedirs returns a set of all the files to be weaved. + * Based on a set of weave directories returns a set of all the files to be woven. * - * @return - * @throws MojoExecutionException + * @param weaveDirs weave directories + * @return a set of all the files to be woven + * @throws MojoExecutionException if weave directories cannot be resolved */ public static Set getWeaveSourceFiles( String[] weaveDirs ) throws MojoExecutionException @@ -221,7 +240,7 @@ public static Set getWeaveSourceFiles( String[] weaveDirs ) } catch ( IOException e ) { - throw new MojoExecutionException( "IO Error resolving weavedirs", e ); + throw new MojoExecutionException( "IO Error resolving weave directories", e ); } } } @@ -236,7 +255,7 @@ public static Set getWeaveSourceFiles( String[] weaveDirs ) * @param arguments All arguments passed to ajc in this run * @param fileName the filename of the argfile * @param outputDir the build output area. - * @throws IOException + * @throws IOException if argfile cannot be created or written */ public static void writeBuildConfigToFile( List arguments, String fileName, File outputDir ) throws IOException @@ -260,13 +279,13 @@ public static void writeBuildConfigToFile( List arguments, String fileNa * * @param fileName the filename of the argfile * @param outputDir the build output area - * @return - * @throws IOException + * @return the List of all compiler arguments. + * @throws IOException if any file operation fails */ public static List readBuildConfigFile( String fileName, File outputDir ) throws IOException { - List arguments = new ArrayList(); + List arguments = new ArrayList<>(); File argFile = new File( outputDir, fileName ); if ( FileUtils.fileExists( argFile.getAbsolutePath() ) ) { @@ -289,8 +308,8 @@ public static List readBuildConfigFile( String fileName, File outputDir /** * Convert a string array to a comma separated list * - * @param strings - * @return + * @param strings string array to be converted + * @return A comma separated list of Strings */ protected static String getAsCsv( String[] strings ) { @@ -311,7 +330,7 @@ protected static String getAsCsv( String[] strings ) /** * Helper method to find all .java or .aj files specified by the - * includeString. The includeString is a comma separated list over files, or + * inExcludeString. The includeString is a comma separated list over files, or * directories relative to the specified basedir. Examples of correct * listings * @@ -323,22 +342,22 @@ protected static String getAsCsv( String[] strings ) * src/main/java/com/project/AnAspect.java * * - * @param input + * @param inExcludeString in-/exclude string * @param basedir the baseDirectory - * @return a list over all files inn the include string - * @throws MojoExecutionException + * @return a list over all files in the include string + * @throws MojoExecutionException if Java or AspectJ source files cannot be resolved */ - protected static Set resolveIncludeExcludeString( String input, File basedir ) + protected static Set resolveIncludeExcludeString( String inExcludeString, File basedir ) throws MojoExecutionException { Set inclExlSet = new LinkedHashSet<>(); try { - if ( null == input || input.trim().equals( "" ) ) + if ( null == inExcludeString || inExcludeString.trim().equals( "" ) ) { return inclExlSet; } - String[] elements = input.split( "," ); + String[] elements = inExcludeString.split( "," ); if ( null != elements ) { diff --git a/src/main/java/org/codehaus/mojo/aspectj/AjcReportMojo.java b/src/main/java/org/codehaus/mojo/aspectj/AjcReportMojo.java index 1203890e..40ec85db 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AjcReportMojo.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AjcReportMojo.java @@ -48,7 +48,9 @@ /** * Creates an AspectJ HTML report using the {@code ajdoc} tool and format. + * * A Maven 2.0 ajdoc report + * * @author Kaare Nilsen */ @Mojo( name="aspectj-report", requiresDependencyResolution = ResolutionScope.COMPILE ) @@ -280,7 +282,7 @@ protected void executeReport( Locale locale ) } /** - * Get the directories containg sources + * @return list of source directories */ @SuppressWarnings( "unchecked" ) protected List getSourceDirectories() @@ -300,7 +302,7 @@ protected String getOutputDirectory() } /** - * get compileroutput directory. + * @return list of classpath directories */ protected List getClasspathDirectories() { @@ -419,7 +421,9 @@ public void setVerbose( boolean verbose ) } /** - * Setters which when called sets compiler arguments + * Set source compliance level + * + * @param complianceLevel compliance level */ public void setComplianceLevel( String complianceLevel ) { diff --git a/src/main/java/org/codehaus/mojo/aspectj/AjcTestCompileMojo.java b/src/main/java/org/codehaus/mojo/aspectj/AjcTestCompileMojo.java index b7f154f0..3c455a7b 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/AjcTestCompileMojo.java +++ b/src/main/java/org/codehaus/mojo/aspectj/AjcTestCompileMojo.java @@ -37,7 +37,10 @@ import org.codehaus.plexus.util.Scanner; /** - * Weaves all test classes. AspectJ Compiler Plugin. + * Weaves all test classes. + * + * AspectJ Compiler Plugin. + * * @author Kaare Nilsen */ @Mojo( name="test-compile", threadSafe = true, defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST ) diff --git a/src/main/java/org/codehaus/mojo/aspectj/MavenMessageHandler.java b/src/main/java/org/codehaus/mojo/aspectj/MavenMessageHandler.java index 6f766de6..441df731 100644 --- a/src/main/java/org/codehaus/mojo/aspectj/MavenMessageHandler.java +++ b/src/main/java/org/codehaus/mojo/aspectj/MavenMessageHandler.java @@ -100,6 +100,7 @@ public MavenMessageHandler(final Log log) { * Copies output from the supplied message onto the active Maven Log. * If the message type (i.e. {@code message.getKind()}) is listed in the showDetailsForMessageKindList List, * the message is prefixed with location details (Class, row/line number etc.) as well. + *

* {@inheritDoc} */ public boolean handleMessage(final IMessage message) { diff --git a/src/site/apt/ajc_reference/experimental_opts.apt b/src/site/apt/ajc_reference/experimental_opts.apt index eb1f7ae6..e6493982 100644 --- a/src/site/apt/ajc_reference/experimental_opts.apt +++ b/src/site/apt/ajc_reference/experimental_opts.apt @@ -12,24 +12,23 @@ AspectJ Compiler reference: non-standard options options of its goals, as defined in the {{{../plugin-info.html}Plugin Documentation}} page. +------------------------------------------ -AspectJ Compiler 1.8.2 non-standard options: - -XnoInline dont inline advice - -XlazyTjp create thisJoinPoint objects lazily - -Xreweavable create class files that can be subsequently rewoven - by AspectJ. Deprecated, this is now on by default. - -Xreweavable:compress deprecated, reweavable is now default. - -XnotReweavable create class files that cant be subsequently rewoven - by AspectJ. - -XserializableAspects allows aspects to implement serializable - -XterminateAfterCompilation compile classes then terminate before weaving - -XaddSerialVersionUID calculates and adds the serialVersionUID to any - serializable type woven by an aspect - -Xajruntimetarget: allows code to be generated that targets - a 1.2 or a 1.5 level AspectJ runtime (default 1.5) - -XhasMember allow hasmethod() and hasfield type patterns in - declare parents and declare @type - -Xjoinpoints: supply a comma separated list of new joinpoints - that can be identified by pointcuts. Values are: - arrayconstruction, synchronization -+------------------------------------------ \ No newline at end of file +AspectJ Compiler - Eclipse Compiler a00b62fa3572b0 (17Mar2021) - Java16 + + AspectJ-specific non-standard options: + -XnoInline dont inline advice + -XnotReweavable create class files that cant be subsequently rewoven + by AspectJ. + -XserializableAspects allows aspects to implement serializable + -XterminateAfterCompilation compile classes then terminate before weaving + -XaddSerialVersionUID calculates and adds the serialVersionUID to any + serializable type woven by an aspect + -Xajruntimetarget: allows code to be generated that targets + a 1.2, 1.5, 1.9 level AspectJ runtime (default 1.5) + -XhasMember allow hasmethod() and hasfield type patterns in + declare parents and declare @type + -Xjoinpoints: supply a comma separated list of new joinpoints + that can be identified by pointcuts. Values are: + arrayconstruction, synchronization + ++------------------------------------------ diff --git a/src/site/apt/ajc_reference/standard_opts.apt b/src/site/apt/ajc_reference/standard_opts.apt index a8eb9a8d..7e1540da 100644 --- a/src/site/apt/ajc_reference/standard_opts.apt +++ b/src/site/apt/ajc_reference/standard_opts.apt @@ -14,143 +14,216 @@ AspectJ Compiler reference: standard options For a reference of non-standard AJC options, please refer to {{{./experimental_opts.html}AJC Experimental Options}}. +------------------------------------------ - AspectJ Compiler 1.8.2 - - Usage: .. - - AspectJ-specific options: - -inpath use classes in dirs and jars/zips in as source - ( uses platform-specific path delimiter) - -injars use classes in zip files as source - ( uses classpath delimiter) - deprecated - use inpath instead. - -aspectpath weave aspects in .class files from dirs and jars/zip into sources - ( uses classpath delimiter) - -outjar put output classes in zip file - -outxml generate META-INF/aop.xml - -outxmlfile specify alternate destination output of -outxml - -argfile specify line-delimited list of source files - -showWeaveInfo display information about weaving - -incremental continuously-running compiler, needs -sourceroots - (reads stdin: enter to recompile and 'q' to quit) - -sourceroots compile all .aj and .java files in - ( uses classpath delimiter) - -crossrefs generate .ajsym file into the output directory - -parameters stores formal parameter names of constructors and methods - in the generated class file so that the method - java.lang.reflect.Executable.getParameters from the Reflection API can retrieve them. - -emacssym generate .ajesym symbol files for emacs support - -Xlint same as '-Xlint:warning' - -Xlint: set default level for crosscutting messages - ( may be ignore, warning, or error) - -Xlintfile specify properties file to set per-message levels - (cf org/aspectj/weaver/XlintDefault.properties) - -X print help on non-standard options - - Standard Eclipse compiler options: - Options enabled by default are prefixed with '+' - - Classpath options: - -cp -classpath - specify location for application classes and sources - -bootclasspath - specify location for system classes - -d

destination directory (if omitted, no directory is created) - -d none generate no .class files - -encoding specify custom encoding for all sources. Each file/directory can override it - when suffixed with '['']' (e.g. X.java[utf8]) - - Compliance options: - -1.3 use 1.3 compliance level (implicit -source 1.3 -target 1.1) - -1.4 + use 1.4 compliance level - -1.5 -5 -5.0 use 1.5 compliance (-source 1.5 -target 1.5) - -1.6 -6 -6.0 use 1.6 compliance (-source 1.6 -target 1.6) - -1.7 -7 -7.0 use 1.7 compliance (-source 1.7 -target 1.7) - -1.8 -8 -8.0 use 1.8 compliance (-source 1.8 -target 1.8) - -source set source level: 1.3 to 1.8 (or 5, 5.0, etc) - -target set classfile target: 1.1 to 1.8 (or 5, 5.0, etc) - - Warning options: - -deprecation + deprecation outside deprecated code - -nowarn -warn:none disable all warnings - -warn: enable exactly the listed warnings - -warn:+ enable additional warnings - -warn:- disable specific warnings - allDeadCode dead code including trivial if(DEBUG) check - allDeprecation deprecation including inside deprecated code - allJavadoc invalid or missing javadoc - allOver-ann all missing @Override annotations - all-static-method all method can be declared as static warnings - assertIdentifier + 'assert' used as identifier - boxing autoboxing conversion - charConcat + char[] in String concat - compareIdentical + comparing identical expressions - conditionAssign possible accidental boolean assignment - constructorName + method with constructor name - deadCode + dead code excluding trivial if (DEBUG) check - dep-ann missing @Deprecated annotation - deprecation + deprecation outside deprecated code - discouraged + use of types matching a discouraged access rule - emptyBlock undocumented empty block - enumIdentifier 'enum' used as identifier - enumSwitch incomplete enum switch - fallthrough possible fall-through case - fieldHiding field hiding another variable - finalBound type parameter with final bound - finally + finally block not completing normally - forbidden + use of types matching a forbidden access rule - hashCode missing hashCode() method when overriding equals() - hiding macro for fieldHiding, localHiding, typeHiding and - maskedCatchBlock - includeAssertNull raise null warnings for variables - that got tainted in an assert expression - indirectStatic indirect reference to static member - intfAnnotation + annotation type used as super interface - intfNonInherited + interface non-inherited method compatibility - intfRedundant find redundant superinterfaces - javadoc invalid javadoc - localHiding local variable hiding another variable - maskedCatchBlock + hidden catch block - nls string literal lacking non-nls tag //$NON-NLS-$ - noEffectAssign + assignment without effect - null potential missing or redundant null check - nullDereference + missing null check - over-ann missing @Override annotation (superclass) - paramAssign assignment to a parameter - pkgDefaultMethod + attempt to override package-default method - raw + usage of raw type - semicolon unnecessary semicolon, empty statement - serial + missing serialVersionUID - specialParamHiding constructor or setter parameter hiding a field - static-method method can be declared as static - static-access macro for indirectStatic and staticReceiver - staticReceiver + non-static reference to static member - super overriding a method without making a super invocation - suppress + enable @SuppressWarnings - When used with -err:, it can also silent optional - errors and warnings - syncOverride missing synchronized in synchr. method override - syntheticAccess synthetic access for innerclass - tasks() tasks identified by tags inside comments - typeHiding + type parameter hiding another type - unavoidableGenericProblems + ignore unavoidable type safety problems - due to raw APIs - unchecked + unchecked type operation - unnecessaryElse unnecessary else clause - unqualifiedField unqualified reference to field - unused macro for unusedAllocation, unusedArgument, - unusedImport, unusedLabel, unusedLocal, - unusedPrivate, unusedThrown, and unusedTypeArgs - unusedAllocation allocating an object that is not used - unusedArgument unread method parameter - unusedImport + unused import declaration - unusedLabel + unused label - unusedLocal + unread local variable - unusedPrivate + unused private member declaration - unusedThrown unused declared thrown exception - unusedTypeArgs + unused type arguments for method and constructor - uselessTypeCheck unnecessary cast/instanceof operation - varargsCast + varargs argument need explicit cast - warningToken + unsupported or unnecessary @SuppressWarnings - -+------------------------------------------ \ No newline at end of file + +AspectJ Compiler Eclipse Compiler a00b62fa3572b0 (17Mar2021) - Java16 + + Usage: + If directories are specified, then their source contents are compiled. + Possible options are listed below. Options enabled by default are prefixed + with '+'. + +AspectJ-specific options: + -inpath use classes in dirs and jars/zips in as source + ( uses platform-specific path delimiter) + -injars use classes in zip files as source + ( uses classpath delimiter) + deprecated - use inpath instead. + -aspectpath weave aspects in .class files from dirs and jars/zip into sources + ( uses classpath delimiter) + -outjar put output classes in zip file + -outxml generate META-INF/aop.xml + -outxmlfile specify alternate destination output of -outxml + -argfile specify line-delimited list of source files + -showWeaveInfo display information about weaving + -incremental continuously-running compiler, needs -sourceroots + (reads stdin: enter to recompile and 'q' to quit) + -sourceroots compile all .aj and .java files in + ( uses classpath delimiter) + -crossrefs generate .ajsym file into the output directory + -emacssym generate .ajesym symbol files for emacs support + -Xlint same as '-Xlint:warning' + -Xlint: set default level for crosscutting messages + ( may be ignore, warning, or error) + -Xlintfile specify properties file to set per-message levels + (cf org/aspectj/weaver/XlintDefault.properties) + -X print help on non-standard options + + Standard Eclipse compiler options: + + Classpath options: + -cp -classpath + specify location for application classes and sources. + Each directory or file can specify access rules for + access to type X, [~X] to discourage access to type X, + [+p/X;-p/*] to forbid access to all types in package p + but allow access to p/X) + -bootclasspath + specify location for system classes. Each directory or + file can specify access rules for types between '[' + and ']' + -sourcepath + specify location for application sources. Each directory + or file can specify access rules for types between '[' + and ']'. Each directory can further specify a specific + destination directory using a '-d' option between '[' + and ']'; this overrides the general '-d' option. + .class files created from source files contained in a + jar file are put in the user.dir folder in case no + general '-d' option is specified. ZIP archives cannot + override the general '-d' option + -extdirs + specify location for extension ZIP archives + -endorseddirs + specify location for endorsed ZIP archives + -d destination directory (if omitted, no directory is + created); this option can be overridden per source + directory + -d none generate no .class files + -encoding specify default encoding for all source files. Each + file/directory can override it when suffixed with + '['']' (e.g. X.java[utf8]). + If multiple default encodings are specified, the last + one will be used. + + Module compilation options: + These options are meaningful only in Java 9 environment or later. + --module-source-path + specify where to find source files for multiple modules + -p --module-path + specify where to find application modules + --processor-module-path + specify module path where annotation processors + can be found + --system Override location of system modules + --add-exports /=(,)* + specify additional package exports clauses to the + given modules + --add-reads =(,)* + specify additional modules to be considered as required + by given modules + --add-modules (,)* + specify the additional module names that should be + resolved to be root modules + --limit-modules (,)* + specify the observable module names + --release compile for a specific VM version + + Compliance options: + -1.3 use 1.3 compliance (-source 1.3 -target 1.1) + -1.4 + use 1.4 compliance (-source 1.3 -target 1.2) + -1.5 -5 -5.0 use 1.5 compliance (-source 1.5 -target 1.5) + -1.6 -6 -6.0 use 1.6 compliance (-source 1.6 -target 1.6) + -1.7 -7 -7.0 use 1.7 compliance (-source 1.7 -target 1.7) + -1.8 -8 -8.0 use 1.8 compliance (-source 1.8 -target 1.8) + -1.9 -9 -9.0 use 1.9 compliance (-source 1.9 -target 1.9) + -10 -10.0 use 10 compliance (-source 10 -target 10) + -11 -11.0 use 11 compliance (-source 11 -target 11) + -12 -12.0 use 12 compliance (-source 12 -target 12) + -13 -13.0 use 13 compliance (-source 13 -target 13) + -14 -14.0 use 14 compliance (-source 14 -target 14) + -15 -15.0 use 15 compliance (-source 15 -target 15) + -16 -16.0 use 16 compliance (-source 16 -target 16) + -source set source level: 1.3 to 1.9, 10 to 16 + (or 6, 6.0, etc) + -target set classfile target: 1.3 to 1.9, 10 to 16 + (or 6, 6.0, etc) + cldc1.1 can also be used to generate the StackMap + attribute + --enable-preview enable support for preview features of the + latest Java release + + Warning options: + -deprecation + deprecation outside deprecated code (equivalent to + -warn:+deprecation) + -nowarn -warn:none disable all warnings + -nowarn:[] + specify directories from which optional problems should + be ignored + -?:warn -help:warn display advanced warning options + + Error options: + -err: convert exactly the listed warnings + to be reported as errors + -err:+ enable additional warnings to be + reported as errors + -err:- disable specific warnings to be + reported as errors + + Info options: + -info: convert exactly the listed warnings + to be reported as infos + -info:+ enable additional warnings to be + reported as infos + -info:- disable specific warnings to be + reported as infos + + Setting warning, error or info options using properties file: + -properties set warnings/errors/info option based on the properties + file contents. This option can be used with -nowarn, + -err:.., -info: or -warn:.. options, but the last one + on the command line sets the options to be used. + + Debug options: + -g[:lines,vars,source] custom debug info + -g:lines,source + both lines table and source debug info + -g all debug info + -g:none no debug info + -preserveAllLocals preserve unused local vars for debug purpose + + Annotation processing options: + These options are meaningful only in a 1.6 environment. + -Akey[=value] options that are passed to annotation processors + -processorpath + specify locations where to find annotation processors. + If this option is not used, the classpath will be + searched for processors + -processor + qualified names of the annotation processors to run. + This bypasses the default annotation discovery process + -proc:only run annotation processors, but do not compile + -proc:none perform compilation but do not run annotation + processors + -s destination directory for generated source files + a processor is asked to process + -classNames + qualified names of binary classes to process + + Advanced options: + @ read command line arguments from file + -maxProblems max number of problems per compilation unit (100 by + default) + -log log to a file. If the file extension is '.xml', then + the log will be a xml file. + -proceedOnError[:Fatal] + do not stop at first error, dumping class files with + problem methods + With ":Fatal", all optional errors are treated as fatal + -failOnWarning fail compilation if there are warnings + -verbose enable verbose output + -referenceInfo compute reference info + -progress show progress (only in -log mode) + -time display speed information + -noExit do not call System.exit(n) at end of compilation (n==0 + if no error) + -repeat repeat compilation process times for perf analysis + -inlineJSR inline JSR bytecode (implicit if target >= 1.5) + -enableJavadoc consider references in javadoc + -parameters generate method parameters attribute (for target >= 1.8) + -genericsignature generate generic signature for lambda expressions + It does not affect the xml log output + -missingNullDefault report missing default nullness annotation + -annotationpath + specify locations where to find external annotations + to support annotation-based null analysis. + The special name CLASSPATH will cause lookup of + external annotations from the classpath and sourcepath. + + -? -help print this help message + -v -version print compiler version + -showversion print compiler version and continue + + Ignored options: + -J