Index: plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java =================================================================== --- plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java (revision 41682) +++ plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java (working copy) @@ -132,7 +132,7 @@ MojoExecution mojoExecution = getCompilerMojoExecution(mavenProjectFacade, session, monitor); //Parse for -Djava.endorsed.dirs - String compilerArgument = maven.getMojoParameterValue(session, mojoExecution, "compilerArgument", String.class); + String compilerArgument = maven.getMojoParameterValue(session, mojoExecution, "compilerArgument", String.class);// File[] javaEndorsedDirs = parseJavaEndorsedDirs(mavenProjectFacade.getProject(), compilerArgument); //Check for @@ -148,12 +148,29 @@ if (compilerArgument == null) { return null; } - Matcher matcher = jAVA_ENDORSED_DIRS_PATTERN.matcher(compilerArgument); - if (matcher.matches()) { - String endorsedDirs = matcher.group(1); - return parseEndorsedDirs(project, endorsedDirs); + + //We can expect patterns like -Djava.endorsed.dirs=/path/white space/dir" "-Dfoo=bar + //as a workaround for maven-compiler-plugin not handling multiple values correctly + //So instead of using rexeps to parse the path, we manually look for the presence of quotes and spaces + String key = "-Djava.endorsed.dirs="; + int start = compilerArgument.indexOf(key); + if (start < 0) { + return null; } - return null; + File[] dirs = null; + int end = compilerArgument.indexOf("\"", start); + if (end < 0) { + end = compilerArgument.indexOf(" ", start); + if (end < 0) { + end = compilerArgument.length(); + } + } + if (end > 0) { + String argument = compilerArgument.substring(start+key.length(), end); + dirs = parseEndorsedDirs(project, argument); + + } + return dirs; } private File[] parseEndorsedDirs(IProject project, String endorsedDirs) { Index: tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml =================================================================== --- tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml (revision 0) +++ tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml (working copy) @@ -0,0 +1,84 @@ + + 4.0.0 + foo.bar + endorsing_quotehack + 0.0.1-SNAPSHOT + + + + + maven-compiler-plugin + 2.4 + + -Djava.endorsed.dirs=${basedir}/target/end orsed" "-Dfoo=bar + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.1 + + + copy + validate + + copy + + + ${basedir}/target/end orsed + + + + junit + junit + 3.8.1 + jar + false + optional-new-name.jar + + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-dependency-plugin + + + [2.1,) + + + copy + + + + + + + + + + + + + + \ No newline at end of file Index: tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java =================================================================== --- tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java (revision 0) +++ tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java (working copy) @@ -0,0 +1,7 @@ +package foo; + +import junit.framework.Assert; + +public class Bar extends Assert { + +} Index: tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java =================================================================== --- tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java (revision 41682) +++ tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java (working copy) @@ -70,7 +70,52 @@ ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath())); } + @Test + public void testJBIDE11738_quote_hack_support() throws Exception { + String projectLocation = "projects/endorsed_lib/endorsing_quotehack"; + IProject endorsing = importProject(projectLocation+"/pom.xml"); + endorsing.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); + waitForJobsToComplete(); + + //When the project is imported, the endorsed dir doesn't exist, so we should see + //compilation errors and a marker about that missing Endorsed dir + List errors = findErrorMarkers(endorsing); + assertEquals(toString(errors), 3, errors.size()); + IMarker marker = errors.get(2); + String error = getMessage(marker); + assertTrue("Unexpected error message :"+error, error.startsWith("Endorsed dir")); + + //Since the endorsed dir is missing, no Endorsed Libraries classpath library + //is added to the project's classpath + IJavaProject javaProject = JavaCore.create(endorsing); + IClasspathEntry[] classpath = javaProject.getRawClasspath(); + assertFalse("Endorsed Lib should not have been added", + ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath())); + + //Now let's fix the project + + //Check quick fix is available + MissingEndorsedLibMarkerResolutionGenerator generator = new MissingEndorsedLibMarkerResolutionGenerator(); + assertTrue("project should be fixable", generator.hasResolutions(marker)); + IMarkerResolution[] resolutions = generator.getResolutions(marker); + assertEquals(1, resolutions.length); + //Execute quick fix + resolutions[0].run(marker); + waitForJobsToComplete(); + endorsing.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); + waitForJobsToComplete(); + + //Check it compiles properly now + assertNoErrors(endorsing); + + //And Endorsed Libraries is added first on the classpath + classpath = javaProject.getRawClasspath(); + assertTrue("Endorsed Lib should have been added first", + ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath())); + } + + @Test public void testJBIDE11738_non_fixable_endorsed_libraries() throws Exception { String projectLocation = "projects/endorsed_lib/broken_endorsing"; IProject endorsing = importProject(projectLocation+"/pom.xml");