Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

400307 introduce compilerArgs mojo parameter

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

Change-Id: Ia1ac9be45047626abf811f6cb9ac1db4395c3d7f
  • Loading branch information...
commit 3db2338afb46317116605742615850f9dbe26acd 1 parent ecfec91
@jsievers jsievers authored
View
16 tycho-compiler-plugin/src/main/java/copied/org/apache/maven/plugin/AbstractCompilerMojo.java
@@ -222,11 +222,20 @@
* compiler version.
* </p>
*
+ * @deprecated use {@link #compilerArgs} instead.
* @parameter
*/
private Map compilerArguments;
/**
+ * Arguments to be passed to the compiler.
+ *
+ * @parameter
+ * @since 0.17.0
+ */
+ private List<String> compilerArgs;
+
+ /**
* <p>
* Unformatted argument string to be passed to the compiler if fork is set to true.
* </p>
@@ -467,7 +476,7 @@ protected CompilerConfiguration getCompilerConfiguration(List<String> compileSou
compilerConfiguration.setSourceEncoding(getEncoding());
- if ((compilerArguments != null) || (compilerArgument != null)) {
+ if ((compilerArguments != null) || (compilerArgument != null) || compilerArgs != null) {
LinkedHashMap cplrArgsCopy = new LinkedHashMap();
if (compilerArguments != null) {
for (Iterator i = compilerArguments.entrySet().iterator(); i.hasNext();) {
@@ -487,6 +496,11 @@ protected CompilerConfiguration getCompilerConfiguration(List<String> compileSou
if (!StringUtils.isEmpty(compilerArgument)) {
cplrArgsCopy.put(compilerArgument, null);
}
+ if (compilerArgs != null) {
+ for (String arg : compilerArgs) {
+ cplrArgsCopy.put(arg, null);
+ }
+ }
compilerConfiguration.setCustomCompilerArguments(cplrArgsCopy);
}
View
27 ...o-compiler-plugin/src/test/java/org/eclipse/tycho/osgicompiler/test/OsgiCompilerTest.java
@@ -350,6 +350,33 @@ public void warn(CharSequence content) {
}
}
+ public void testCompilerArgs() throws Exception {
+ File basedir = getBasedir("projects/compiler-args");
+ List<MavenProject> projects = getSortedProjects(basedir, null);
+ MavenProject project = projects.get(0);
+ AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
+ final List<CharSequence> warnings = new ArrayList<CharSequence>();
+ mojo.setLog(new SystemStreamLog() {
+
+ @Override
+ public void warn(CharSequence content) {
+ warnings.add(content);
+ }
+
+ });
+ try {
+ mojo.execute();
+ fail("compilation failure expected");
+ } catch (CompilationFailureException e) {
+ String message = e.getLongMessage();
+ assertThat(message, containsString("2 problems (1 error, 1 warning)"));
+ // 1 error
+ assertThat(message, containsString("unused"));
+ }
+ // 1 warning
+ assertThat((String) warnings.iterator().next(), containsString("is boxed"));
+ }
+
public void test367431_frameworkExtensionCompileAccessRules() throws Exception {
File basedir = getBasedir("projects/367431_frameworkExtensionCompileAccessRules/bundle");
List<MavenProject> projects = getSortedProjects(basedir, new File(
View
5 tycho-compiler-plugin/src/test/resources/projects/compiler-args/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: CompilerArgs
+Bundle-SymbolicName: compilerArgs
+Bundle-Version: 1.0.0
View
4 tycho-compiler-plugin/src/test/resources/projects/compiler-args/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
View
25 tycho-compiler-plugin/src/test/resources/projects/compiler-args/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.tycho.test</groupId>
+ <artifactId>compilerArgs</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <version>1.0.0</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-compiler-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <compilerId>jdt</compilerId>
+ <compilerArgs>
+ <arg>-warn:+boxing</arg>
+ <arg>-err:+unusedPrivate</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
22 tycho-compiler-plugin/src/test/resources/projects/compiler-args/src/Test.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2013 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+
+public class Test {
+
+ // autoboxing => warning
+ private Integer autoBoxed = 1;
+ // unused private => error
+ private String unused;
+
+ void foo() {
+ System.out.println(autoBoxed);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.