Skip to content

Commit

Permalink
Improve 'compilerArgs' Javadoc and rename to 'additionalCompilerArgs'
Browse files Browse the repository at this point in the history
Relates to #42.

TODO: write tests.
  • Loading branch information
kriegaex committed Jun 7, 2021
1 parent 3f8691c commit 64a8537
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
36 changes: 24 additions & 12 deletions src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.codehaus.mojo.aspectj;


import org.apache.commons.collections.CollectionUtils;

/**
* The MIT License
*
Expand All @@ -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;
Expand Down Expand Up @@ -405,13 +403,27 @@ public abstract class AbstractAjcCompiler extends AbstractAjcMojo {
@Parameter( defaultValue = "false" )
protected boolean forceAjcCompile;

/**
* Sets the arguments to be passed to the compiler.<br>
* Example: &lt;compilerArgs&gt; &lt;arg&gt;-Xmaxerrs=1000&lt;/arg&gt; &lt;arg&gt;-Xlint&lt;/arg&gt; &lt;arg&gt;-J-Duser.language=en_us&lt;/arg&gt;
* &lt;/compilerArgs&gt;
*/
@Parameter
protected List<String> compilerArgs = new ArrayList<>();
/**
* Sets additional compiler arguments, e.g.
* <pre>{@code
* <compilerArgs>
* <arg>-Xmaxerrs=1000</arg>
* <arg>-Xlint</arg>
* <arg>-J-Duser.language=en_us</arg>
* </compilerArgs>
* }</pre>
* This option can be used in case you want to use AJC options not (yet) supported by this plugin.
* <p>
* <b>Caveat:</b> 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<String> additionalCompilerArgs = new ArrayList<>();

/**
* Holder for ajc compiler options
Expand Down Expand Up @@ -640,8 +652,8 @@ protected void assembleArguments()
}
ajcOptions.addAll(resolvedIncludes);

if (CollectionUtils.isNotEmpty(compilerArgs)) {
ajcOptions.addAll(compilerArgs);
if (CollectionUtils.isNotEmpty(additionalCompilerArgs)) {
ajcOptions.addAll(additionalCompilerArgs);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/codehaus/mojo/aspectj/AjcHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public static boolean isValidComplianceLevel( String complianceLevel )
public static String createClassPath( MavenProject project, List<Artifact> pluginArtifacts, List<String> outDirs )
{
String cp = "";
Set<Artifact> classPathElements = Collections.synchronizedSet( new LinkedHashSet<>() );
Set<Artifact> classPathElements = Collections.synchronizedSet(
// LinkedHashSet preserves order by insertion for iteration
new LinkedHashSet<>()
);
Set<Artifact> 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 );
Expand Down

0 comments on commit 64a8537

Please sign in to comment.