You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2008/03/14 03:10:43 UTC

svn commit: r636955 - in /maven/plugins/trunk/maven-eclipse-plugin: ./ src/main/java/org/apache/maven/plugin/eclipse/writers/ src/test/java/org/apache/maven/plugin/eclipse/writers/ src/test/resources/projects/project-10/expected/

Author: aheritier
Date: Thu Mar 13 19:10:42 2008
New Revision: 636955

URL: http://svn.apache.org/viewvc?rev=636955&view=rev
Log:
MECLIPSE-399: URL for javadoc attachments on Unix is invalid 
Thanks for the patch from Benjamin.
I had o change a little bit the test case to pass it on MacOS and I had to fix the project testcase #10

Modified:
    maven/plugins/trunk/maven-eclipse-plugin/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-10/expected/.classpath

Modified: maven/plugins/trunk/maven-eclipse-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/pom.xml?rev=636955&r1=636954&r2=636955&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/pom.xml Thu Mar 13 19:10:42 2008
@@ -169,7 +169,7 @@
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
-      <version>1.0-beta-1</version>
+      <version>1.1</version>
       <scope>test</scope>
     </dependency>
     <dependency>

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=636955&r1=636954&r2=636955&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java Thu Mar 13 19:10:42 2008
@@ -494,7 +494,7 @@
             }
 
             writer.startElement( "attribute" ); //$NON-NLS-1$
-            writer.addAttribute( "value", "jar:file:/" + javadocpath + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            writer.addAttribute( "value", "jar:" + new File( javadocpath ).toURI() + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
             writer.addAttribute( "name", "javadoc_location" ); //$NON-NLS-1$ //$NON-NLS-2$
             writer.endElement();
 

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java?rev=636955&r1=636954&r2=636955&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriterUnitTest.java Thu Mar 13 19:10:42 2008
@@ -20,14 +20,20 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.Iterator;
 
 import junit.framework.TestCase;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 import org.apache.maven.plugin.eclipse.writers.testutils.TestEclipseWriterConfig;
+import org.apache.maven.plugin.ide.IdeDependency;
 import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
 import org.apache.maven.shared.tools.easymock.TestFileManager;
+import org.jdom.Attribute;
 import org.jdom.Document;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
@@ -99,6 +105,61 @@
 
         assertTrue( "standard output classpath entry not found.", stdOutputPath.selectSingleNode( doc ) != null );
 
+    }
+
+    public void testWrite_ShouldGenerateValidJavadocURLs()
+        throws MojoExecutionException, JDOMException, IOException
+    {
+        TestEclipseWriterConfig config = new TestEclipseWriterConfig();
+
+        File basedir = fileManager.createTempDir();
+
+        File repoDir = new File( basedir, "repo" );
+        config.setLocalRepository( new StubArtifactRepository( repoDir.getPath() ) );
+
+        config.setProjectBaseDir( basedir );
+        config.setEclipseProjectDirectory( basedir );
+
+        String baseOutputDir = "target/classes";
+        String maskedOutputDir = "target/classes/main-resources";
+
+        File buildOutputDir = new File( basedir, baseOutputDir );
+        buildOutputDir.mkdirs();
+
+        config.setBuildOutputDirectory( buildOutputDir );
+
+        new File( basedir, maskedOutputDir ).mkdirs();
+
+        config.setEclipseProjectName( "test-project" );
+
+        IdeDependency dependency = new IdeDependency();
+        dependency.setFile( new File( repoDir, "g/a/v/a-v.jar" ) );
+        dependency.setGroupId( "g" );
+        dependency.setArtifactId( "a" );
+        dependency.setVersion( "v" );
+        dependency.setAddedToClasspath( true );
+        dependency.setJavadocAttachment( new File( System.getProperty( "user.home" ) + ".m2/some.jar" ) );
+
+        config.setDeps( new IdeDependency[] { dependency } );
+
+        TestLog log = new TestLog();
+
+        EclipseClasspathWriter classpathWriter = new EclipseClasspathWriter();
+        classpathWriter.init( log, config );
+        classpathWriter.write();
+
+        SAXBuilder builder = new SAXBuilder( false );
+
+        Document doc = builder.build( new File( basedir, ".classpath" ) );
+
+        XPath javadocUrls = XPath.newInstance( "//attribute/@value" );
+        for ( Iterator it = javadocUrls.selectNodes( doc ).iterator(); it.hasNext(); )
+        {
+            Attribute attribute = (Attribute) it.next();
+            URL jarUrl = new URL( attribute.getValue() );
+            URL fileUrl = ( (JarURLConnection) jarUrl.openConnection() ).getJarFileURL();
+            assertTrue( "".equals( fileUrl.getHost() ) || "localhost".equals( fileUrl.getHost() ) );
+        }
     }
 
     private static final class TestLog

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-10/expected/.classpath
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-10/expected/.classpath?rev=636955&r1=636954&r2=636955&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-10/expected/.classpath (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-10/expected/.classpath Thu Mar 13 19:10:42 2008
@@ -4,7 +4,7 @@
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/3.0/junit-3.0.jar">
     <attributes>
-      <attribute value="jar:file:/${M2_REPO}/junit/junit/3.0/junit-3.0-javadoc.jar!/" name="javadoc_location"/>
+      <attribute value="jar:file:${M2_REPO}/junit/junit/3.0/junit-3.0-javadoc.jar!/" name="javadoc_location"/>
     </attributes>
   </classpathentry>
-</classpath>
\ No newline at end of file
+</classpath>