Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[MCOMPILER-178] add List parameter compilerArgs

Add List parameter compilerArgs which only uses
values of configuration XML elements.
Deprecate Map parameter compilerArguments because
1. it adds "-" in front of the key and "=" between key and value
   which is an implicit assumption on argument syntax that
   is generally is not desired

2. ultimately since the XML element name is used as key,
   certain characters not allowed in XML element can't be used
   and there is no way to escape these characters in XML

The new parameter allows to escape unallowed XML
characters
e.g. using <![CDATA[my special weird non-XML valid
argument]]>
since only the text body of the XML element is used as
argument to pass to the compiler.
  • Loading branch information...
commit d7d8b02f52d8c069c584948f9b6404755f64f92a 1 parent 6f37845
@jsievers authored
View
27 ...-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -233,12 +233,30 @@
* </pre>
*
* @since 2.0.1
+ * @deprecated use {@link #compilerArgs} instead.
*/
@Parameter
+ @Deprecated
protected Map<String, String> compilerArguments;
/**
* <p>
+ * Sets the arguments to be passed to the compiler if {@link #fork} is set to <code>true</code>.
+ * Example:
+ * <pre>
+ * &lt;compilerArgs&gt;
+ * &lt;arg&gt;-Xmaxerrs=1000&lt;/arg&gt;
+ * &lt;arg&gt;-Xlint&lt;/arg&gt;
+ * &lt;/compilerArgs&gt;
+ * </pre>
+ *
+ * @since 3.1
+ */
+ @Parameter
+ protected List<String> compilerArgs;
+
+ /**
+ * <p>
* Sets the unformatted single argument string to be passed to the compiler if {@link #fork} is set to <code>true</code>.
* To pass multiple arguments such as <code>-Xmaxerrs 1000</code> (which are actually two arguments) you have to use {@link #compilerArguments}.
* </p>
@@ -489,7 +507,7 @@ public void execute()
String effectiveCompilerArgument = getCompilerArgument();
- if ( ( effectiveCompilerArguments != null ) || ( effectiveCompilerArgument != null ) )
+ if ( ( effectiveCompilerArguments != null ) || ( effectiveCompilerArgument != null ) || ( compilerArgs != null ) )
{
LinkedHashMap<String, String> cplrArgsCopy = new LinkedHashMap<String, String>();
if ( effectiveCompilerArguments != null )
@@ -517,6 +535,13 @@ public void execute()
{
cplrArgsCopy.put( effectiveCompilerArgument, null );
}
+ if ( compilerArgs != null )
+ {
+ for ( String arg : compilerArgs )
+ {
+ cplrArgsCopy.put( arg, null );
+ }
+ }
compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
}
View
2  ...-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
@@ -32,6 +32,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -205,6 +206,7 @@ public void testCompilerArgs()
File testClass = new File( compileMojo.getOutputDirectory(), "compiled.class" );
assertTrue( testClass.exists() );
+ assertEquals( Arrays.asList( "key1=value1","-Xlint","-my&special:param-with+chars/not>allowed_in_XML_element_names" ), compileMojo.compilerArgs );
}
public void testOneOutputFileForAllInput2()
View
5 maven-compiler-plugin/src/test/resources/unit/compiler-args-test/plugin-config.xml
@@ -36,6 +36,11 @@
<param2>value2</param2>
</compilerArgument>
</compilerArguments>
+ <compilerArgs>
+ <arg>key1=value1</arg>
+ <arg>-Xlint</arg>
+ <arg><![CDATA[-my&special:param-with+chars/not>allowed_in_XML_element_names]]></arg>
+ </compilerArgs>
<compilerArgument>param value</compilerArgument>
</configuration>
</plugin>
Please sign in to comment.
Something went wrong with that request. Please try again.