Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Fix processor option format with maven-compiler compilerArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
WonderCsabo authored and fbricon committed Sep 9, 2014
1 parent bf10404 commit 21495dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@
*/
public class ProjectUtils {

private static final Pattern OPTION_PATTERN = Pattern.compile("-A([^ \\t\"']+)");

/**
* Parse a string to extract Annotation Processor options
*/
public static Map<String, String> parseProcessorOptions(String compilerArgument) {
Pattern fullOptionPattern = Pattern.compile("-A([^ \\t\"']+)");
return parseProcessorOptions(compilerArgument, fullOptionPattern);
}

private static Map<String, String> parseProcessorOptions(String compilerArgument, Pattern pattern) {

if (compilerArgument == null || compilerArgument.trim().isEmpty()) {
return Collections.emptyMap();
}
Map<String, String> ret = new HashMap<String, String>();

Matcher matcher = pattern.matcher(compilerArgument);
Matcher matcher = OPTION_PATTERN.matcher(compilerArgument);

int start = 0;
while(matcher.find(start)) {
Expand Down Expand Up @@ -90,11 +87,9 @@ public static Map<String, String> parseProcessorOptions(List<String> compilerArg
}
Map<String, String> options = new HashMap<String, String>();

Pattern pattern = Pattern.compile("A([^ \\t\"']+)");

for (String arg : compilerArgs) {
if (arg.startsWith("A")) {
options.putAll(parseProcessorOptions(arg, pattern));
if (arg.startsWith("-A")) {
options.putAll(parseProcessorOptions(arg));
}
}
return options;
Expand Down
4 changes: 2 additions & 2 deletions org.jboss.tools.maven.apt.tests/projects/compilerArgs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<AaddGenerationDate>true</AaddGenerationDate>
</compilerArguments>
<compilerArgs>
<arg>AaddGeneratedAnnotation=true</arg>
<arg>AcompilerArg</arg>
<arg>-AaddGeneratedAnnotation=true</arg>
<arg>-AcompilerArg</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ProjectUtilsTest {

@Test
public void testParseCompilerArgs() {
List<String> compilerArgs = Arrays.asList("Afoo=bar","Abracadabra", "Xman");
List<String> compilerArgs = Arrays.asList("-Afoo=bar","-Abracadabra", "Xman");

Map<String, String> result = ProjectUtils.parseProcessorOptions(compilerArgs);
assertNotNull(result);
Expand Down

0 comments on commit 21495dd

Please sign in to comment.