[jbosstools-commits] JBoss Tools SVN: r41688 - in trunk/maven: tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib and 7 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Jun 4 11:53:42 EDT 2012


Author: fbricon
Date: 2012-06-04 11:53:42 -0400 (Mon, 04 Jun 2012)
New Revision: 41688

Added:
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/resources/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/test/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/test/java/
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/test/resources/
Modified:
   trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java
   trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java
Log:
JBIDE-12092 : Fix Endorsed Libraries configurator doesn't support quotes in <compilerArgument>

Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java	2012-06-04 15:43:42 UTC (rev 41687)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java	2012-06-04 15:53:42 UTC (rev 41688)
@@ -132,7 +132,7 @@
 		MojoExecution mojoExecution = getCompilerMojoExecution(mavenProjectFacade, session, monitor);
 		
 		//Parse <compilerArgument> 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 <compilerArguments> for <endorseddirs>
@@ -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  <compilerArgument> 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) {

Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml	                        (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/pom.xml	2012-06-04 15:53:42 UTC (rev 41688)
@@ -0,0 +1,84 @@
+<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/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>foo.bar</groupId>
+	<artifactId>endorsing_quotehack</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<compilerArgument>-Djava.endorsed.dirs=${basedir}/target/end orsed" "-Dfoo=bar</compilerArgument>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.1</version>
+				<executions>
+					<execution>
+						<id>copy</id>
+						<phase>validate</phase>
+						<goals>
+							<goal>copy</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${basedir}/target/end orsed</outputDirectory>
+
+							<artifactItems>
+								<artifactItem>
+									<groupId>junit</groupId>
+									<artifactId>junit</artifactId>
+									<version>3.8.1</version>
+									<type>jar</type>
+									<overWrite>false</overWrite>
+									<destFileName>optional-new-name.jar</destFileName>
+								</artifactItem>
+							</artifactItems>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+		<pluginManagement>
+			<plugins>
+				<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+				<plugin>
+					<groupId>org.eclipse.m2e</groupId>
+					<artifactId>lifecycle-mapping</artifactId>
+					<version>1.0.0</version>
+					<configuration>
+						<lifecycleMappingMetadata>
+							<pluginExecutions>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>
+											org.apache.maven.plugins
+										</groupId>
+										<artifactId>
+											maven-dependency-plugin
+										</artifactId>
+										<versionRange>
+											[2.1,)
+										</versionRange>
+										<goals>
+											<goal>copy</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<ignore></ignore>
+									</action>
+								</pluginExecution>
+							</pluginExecutions>
+						</lifecycleMappingMetadata>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
+</project>
\ No newline at end of file

Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java	                        (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing_quotehack/src/main/java/foo/Bar.java	2012-06-04 15:53:42 UTC (rev 41688)
@@ -0,0 +1,7 @@
+package foo;
+
+import junit.framework.Assert;
+
+public class Bar extends Assert {
+
+}

Modified: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java	2012-06-04 15:43:42 UTC (rev 41687)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java	2012-06-04 15:53:42 UTC (rev 41688)
@@ -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<IMarker> 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");



More information about the jbosstools-commits mailing list