Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[MCOMPILER-178] add List parameter compilerArgs #4

Closed
wants to merge 1 commit into from

2 participants

@jsievers

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

  1. 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.

@jsievers jsievers [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.
d7d8b02
@olamy

patch applied.
Thanks !
Can you close this pr ?

@jsievers

thanks!

@jsievers jsievers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2013
  1. @jsievers

    [MCOMPILER-178] add List parameter compilerArgs

    jsievers authored
    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.
This page is out of date. Refresh to see the latest.
View
27 maven-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  maven-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>
Something went wrong with that request. Please try again.