You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ba...@apache.org on 2011/12/13 07:22:44 UTC

svn commit: r1213573 - in /maven/plugins/trunk/maven-eclipse-plugin: ./ src/it/ src/main/java/org/apache/maven/plugin/eclipse/ src/main/resources/org/apache/maven/plugin/eclipse/ src/test/java/org/apache/maven/plugin/eclipse/it/ src/test/resources/proj...

Author: baerrach
Date: Tue Dec 13 06:22:43 2011
New Revision: 1213573

URL: http://svn.apache.org/viewvc?rev=1213573&view=rev
Log:
[MECLIPSE-696] Allow file contents to be obtained from url or location does not work behind a firewall
o Added wagon to handle URLs, so that firewalls are supported

Modified:
    maven/plugins/trunk/maven-eclipse-plugin/README-testing.txt
    maven/plugins/trunk/maven-eclipse-plugin/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/it/   (props changed)
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/pom.xml

Modified: maven/plugins/trunk/maven-eclipse-plugin/README-testing.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/README-testing.txt?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/README-testing.txt (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/README-testing.txt Tue Dec 13 06:22:43 2011
@@ -92,8 +92,9 @@ PluginTestTool
 Invoker
   Some tests are done via invoker. 
   
-  (TODO: Confirm this is invoker that requires this file) 
-  If you are behind a firewall then you must configure src/it/settings.xml
+  If you are behind a firewall then you must configure src/it/settings.xml.
+  Do this by copying src/it/settings-default to settings-${user.name}.xml.
+  The pom's process-resources configuration will copy this to src/it/settings.xml for you. 
   
   (TODO: Someone who understands how invoker works - can you complete this section)    
   

Modified: maven/plugins/trunk/maven-eclipse-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/pom.xml?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/pom.xml Tue Dec 13 06:22:43 2011
@@ -63,6 +63,16 @@
       <version>${mavenVersion}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-settings</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-provider-api</artifactId>
+      <version>2.1</version>
+    </dependency>   
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>1.4</version>
@@ -151,12 +161,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-settings</artifactId>
-      <version>2.0.8</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.apache.maven.plugin-testing</groupId>
       <artifactId>maven-test-tools</artifactId>
       <version>1.2</version>

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/it/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Dec 13 06:22:43 2011
@@ -1 +1,5 @@
 settings-baerrach.xml
+
+settings-pd79199.xml
+
+settings.xml

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Tue Dec 13 06:22:43 2011
@@ -23,7 +23,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.SocketException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -36,6 +36,7 @@ import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Resource;
@@ -58,6 +59,14 @@ import org.apache.maven.plugin.ide.IdeDe
 import org.apache.maven.plugin.ide.IdeUtils;
 import org.apache.maven.plugin.ide.JeeUtils;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.WagonException;
+import org.apache.maven.wagon.observers.Debug;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.resource.ResourceManager;
 import org.codehaus.plexus.resource.loader.FileResourceLoader;
 import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
@@ -65,6 +74,7 @@ import org.codehaus.plexus.util.FileUtil
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * Generates the following eclipse configuration files:
@@ -486,6 +496,24 @@ public class EclipsePlugin
     private ResourceManager locator;
 
     /**
+     * WagonManager for accessing internet resources.
+     *  
+     * @component
+     * @required
+     * @readonly
+     */
+    private WagonManager wagonManager;
+    
+    /**
+     * MavenSettingsBuilder for accessing settings.xml.
+     *  
+     * @component
+     * @required
+     * @readonly
+     */
+    private MavenSettingsBuilder mavenSettingsBuilder;
+
+    /**
      * This eclipse workspace is read and all artifacts detected there will be connected as eclipse projects and will
      * not be linked to the jars in the local repository. Requirement is that it was created with the similar wtp
      * settings as the reactor projects, but the project name template my differ. The pom's in the workspace projects
@@ -1230,25 +1258,59 @@ public class EclipsePlugin
                     projectRelativeFile.getParentFile().mkdirs();
                     if ( file.getContent() == null )
                     {
-                        InputStream inStream;
                         if ( file.getLocation() != null )
                         {
-                            inStream = locator.getResourceAsInputStream( file.getLocation() );
+                            InputStream inStream = locator.getResourceAsInputStream( file.getLocation() );
+                            OutputStream outStream = new FileOutputStream( projectRelativeFile );
+                            try
+                            {
+                                IOUtil.copy( inStream, outStream );
+                            }
+                            finally
+                            {
+                                IOUtil.close(inStream);
+                                IOUtil.close(outStream);
+                            }                            
                         }
                         else
                         {
-                            // TODO: [MECLIPSE-696] Note: This fails behind a firewall for testProject44
-                            inStream = file.getURL().openConnection().getInputStream();
-                        }
-                        OutputStream outStream = new FileOutputStream( projectRelativeFile );
-                        try
-                        {
-                            IOUtil.copy( inStream, outStream );
-                        }
-                        finally
-                        {
-                            IOUtil.close(inStream);
-                            IOUtil.close(outStream);
+                            URL url = file.getURL();
+                            String endPointUrl = url.getProtocol() + "://" + url.getAuthority();
+                            // Repository Id should be ignored by Wagon ...
+                            Repository repository = new Repository( "additonal-configs", endPointUrl );
+                            Wagon wagon = wagonManager.getWagon( repository );;
+                            if ( logger.isDebugEnabled() )
+                            {
+                                Debug debug = new Debug();
+                                wagon.addSessionListener( debug );
+                                wagon.addTransferListener( debug );
+                            }
+                            wagon.setTimeout( 1000 );
+                            Settings settings = mavenSettingsBuilder.buildSettings();
+                            ProxyInfo proxyInfo = null; 
+                            if ( settings != null && settings.getActiveProxy() != null )
+                            {
+                                Proxy settingsProxy = settings.getActiveProxy();
+
+                                proxyInfo = new ProxyInfo();
+                                proxyInfo.setHost( settingsProxy.getHost() );
+                                proxyInfo.setType( settingsProxy.getProtocol() );
+                                proxyInfo.setPort( settingsProxy.getPort() );
+                                proxyInfo.setNonProxyHosts( settingsProxy.getNonProxyHosts() );
+                                proxyInfo.setUserName( settingsProxy.getUsername() );
+                                proxyInfo.setPassword( settingsProxy.getPassword() );                                
+                            }
+                                
+                            if ( proxyInfo != null )
+                            {
+                                wagon.connect( repository, wagonManager.getAuthenticationInfo( repository.getId() ), proxyInfo );
+                            }
+                            else
+                            {
+                                wagon.connect( repository, wagonManager.getAuthenticationInfo( repository.getId() ) );
+                            }
+                            
+                            wagon.get( url.getPath(), projectRelativeFile );
                         }
                     }
                     else
@@ -1256,8 +1318,8 @@ public class EclipsePlugin
                         FileUtils.fileWrite( projectRelativeFile.getAbsolutePath(), file.getContent() );
                     }
                 }
-                catch ( SocketException e ) {
-                    throw new MojoExecutionException(Messages.getString("EclipsePlugin.socketexception", //$NON-NLS-1$
+                catch ( WagonException e ) {
+                    throw new MojoExecutionException(Messages.getString("EclipsePlugin.remoteexception", //$NON-NLS-1$
                                                                         new Object[] { file.getURL(),
                                                                             e.getMessage() }));                    
                 }
@@ -1271,7 +1333,11 @@ public class EclipsePlugin
                     throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantfindresource", //$NON-NLS-1$
                                                                           file.getLocation() ) );
                 }
-
+                catch ( XmlPullParserException e )
+                {
+                    throw new MojoExecutionException( Messages.getString( "EclipsePlugin.settingsxmlfailure", //$NON-NLS-1$
+                                                                          e.getMessage() ) );
+                }
             }
         }
     }

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties Tue Dec 13 06:22:43 2011
@@ -21,7 +21,8 @@ EclipsePlugin.workspace=Using Eclipse Wo
 EclipsePlugin.cantcanonicalize=Can't canonicalize system path: {0}
 EclipsePlugin.unchangedmanifest=Not writing Manifest file as it is unchanged: {0}
 EclipsePlugin.invalidvminworkspace=Workspace defines a VM that does not contain a valid jre/lib/rt.jar: {0}
-EclipsePlugin.socketexception=Unable to retrieve remote resource {0}: {1}
+EclipsePlugin.remoteexception=Unable to retrieve remote resource {0}: {1}
+EclipsePlugin.settingsxmlfailure=Failed to read settings.xml correctly: {0}
 
 EclipseSettingsWriter.wrotesettings=Wrote settings to {0}
 EclipseSettingsWriter.cannotcreatesettings=Cannot create settings file

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java Tue Dec 13 06:22:43 2011
@@ -589,7 +589,7 @@ public abstract class AbstractEclipsePlu
         {
             String message =
                 "Comparing '" + IdeUtils.getCanonicalPath(actualFile) + "' against '"
-                    + IdeUtils.getCanonicalPath(expectedFile);
+                    + IdeUtils.getCanonicalPath(expectedFile) + "'";
             if (CLASSPATH_FILENAME.equals(actualFile.getName())) {                
                 Diff diff = new Diff(expectedFileContents, actualFileContents);
                 XMLAssert.assertXMLIdentical( message, diff, true );

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java Tue Dec 13 06:22:43 2011
@@ -509,9 +509,7 @@ public class EclipsePluginIT
     }
 
     /**
-     * [MECLIPSE-219]
-     * Note: This fails behind a firewall, See [MECLIPSE-696]
-     * See EclipsePlugin.writeAdditionalConfig() - inStream = file.getURL().openConnection().getInputStream()
+     * [MECLIPSE-219] Allow file contents to be obtained from url or location
      * 
      * @since 2.5
      * @throws Exception

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/pom.xml?rev=1213573&r1=1213572&r2=1213573&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/pom.xml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/pom.xml Tue Dec 13 06:22:43 2011
@@ -21,10 +21,6 @@
             </file>
             <file>
               <name>.checkstyle2</name>
-              <!-- 
-                Note: This fails behind a firewall, See [MECLIPSE-696]
-                See EclipsePlugin.writeAdditionalConfig() - inStream = file.getURL().openConnection().getInputStream()
-                -->
               <url>
                 https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-44/eclipse-settings/checkstyle-config.xml
               </url>