nikgoodley-ibboost / maven-external-dependency-plugin

Automatically exported from code.google.com/p/maven-external-dependency-plugin
0 stars 0 forks source link

plugin won't use a proxy configured in maven's settings.xml #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get yourself behind a proxy
2. Disable all other internet connections
3. try to download something with maven-external-dependency-plugin

What is the expected output? What do you see instead?
Expected: Download works, because my (http) proxy is configured in the 
settings.xml for maven.
Instead, i get a "Connection timed out" message.

What version of the product are you using? On what operating system?
Windows 7 x64, Plugin version 0.5-SONATYPE-r116

Please provide any additional information below.

Original issue reported on code.google.com by julak...@gmail.com on 8 Sep 2011 at 4:07

GoogleCodeExporter commented 9 years ago
If I fix this, would be possible to get a new release out?

Original comment by velo...@gmail.com on 7 Aug 2012 at 7:46

GoogleCodeExporter commented 9 years ago
Hi Velo,

Sure thing.  You are already a commiter, just just ping me when commits are 
complte  and I can push the release out to Sonatype OSS. 

Thanks, Robert

Original comment by rob...@savage7.com on 8 Aug 2012 at 12:58

GoogleCodeExporter commented 9 years ago
Index: pom.xml
===================================================================
--- pom.xml (revision 128)
+++ pom.xml (working copy)
@@ -47,6 +47,14 @@
           <role>Add support to extra compressed artifacts like bzip2, dir, gzip, tar, tgz, tar.gz, tbz2, tar.bz2</role>
         </roles>
       </contributor>
+      <contributor> 
+            <name>Valera Kharseko</name>
+            <email>vharseko@openam.org.ru</email>
+            <roles>
+                <role>vagon extension provider</role>
+            </roles>
+            <url>http://openam.org.ru</url>
+        </contributor>
     </contributors>
     <issueManagement>
         <system>Google Code - Issue Tracking</system>
@@ -193,7 +201,17 @@
           <groupId>org.codehaus.plexus</groupId>
           <artifactId>plexus-archiver</artifactId>
           <version>1.1</version>
-        </dependency> 
+        </dependency>
+        <dependency>
+           <groupId>org.apache.maven</groupId>
+           <artifactId>maven-settings</artifactId>
+           <version>2.2.1</version>
+        </dependency>
+        <dependency>
+           <groupId>org.apache.maven.wagon</groupId>
+           <artifactId>wagon-provider-api</artifactId>
+           <version>2.2</version>
+        </dependency>
     </dependencies>

     <!--  SOURCE CONTROL -->
Index: 
src/main/java/com/savage7/maven/plugin/dependency/ResolveExternalDependencyMojo.
java
===================================================================
--- 
src/main/java/com/savage7/maven/plugin/dependency/ResolveExternalDependencyMojo.
java    (revision 128)
+++ 
src/main/java/com/savage7/maven/plugin/dependency/ResolveExternalDependencyMojo.
java    (working copy)
@@ -20,12 +20,20 @@
 import java.util.Map;

 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+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.observers.Debug;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
@@ -75,6 +83,20 @@
      */
     protected ArchiverManager archiverManager;

+    /** 
+     * @component 
+     * @required 
+     * @readonly 
+     */ 
+    private WagonManager wagonManager; 
+
+    /** 
+     * @component 
+     * @required 
+     * @readonly 
+     */ 
+    private MavenSettingsBuilder mavenSettingsBuilder; 
+    
     public void execute() throws MojoExecutionException, MojoFailureException
     {
         try
@@ -152,8 +174,40 @@
                                     + tempDownloadFile.getCanonicalPath());

                             // download file from URL
-                            FileUtils.copyURLToFile(downloadUrl, 
tempDownloadFile);
+                            //FileUtils.copyURLToFile(downloadUrl, 
tempDownloadFile);

+                            //vharseko@openam.org.ru
+                            String endPointUrl = downloadUrl.getProtocol() + 
"://"+ downloadUrl.getAuthority();
+                            Repository repository = new 
Repository("additonal-configs", endPointUrl);
+                            Wagon wagon = 
wagonManager.getWagon(downloadUrl.getProtocol());
+                            if (getLog().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(downloadUrl.getPath(), tempDownloadFile);
+
                             getLog().debug(
                                 "caching temporary file for later");
                             cachedDownloads.put(downloadUrl, tempDownloadFile);

Original comment by vharseko@openam.org.ru on 22 Sep 2012 at 11:32

GoogleCodeExporter commented 9 years ago
0.6-SNAPSHOT deployed with this patch applied.

https://oss.sonatype.org/content/groups/public/com/savage7/maven/plugins/maven-e
xternal-dependency-plugin/0.6-SNAPSHOT/

Original comment by rob...@savage7.com on 27 Sep 2012 at 5:34

GoogleCodeExporter commented 9 years ago

Original comment by savage7....@gmail.com on 27 Sep 2012 at 5:40