ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1201254 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/plugins/resolver/JarResolver.java test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java
Date Sat, 12 Nov 2011 12:29:50 GMT
Author: hibou
Date: Sat Nov 12 12:29:50 2011
New Revision: 1201254

URL: http://svn.apache.org/viewvc?rev=1201254&view=rev
Log:
- fix the JarResolver when used with an URL
- fix the unit tests: the settings are the last set on the resolver

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java?rev=1201254&r1=1201253&r2=1201254&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/JarResolver.java Sat Nov 12
12:29:50 2011
@@ -28,10 +28,13 @@ import org.apache.ivy.core.event.EventMa
 import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.plugins.repository.jar.JarRepository;
+import org.apache.ivy.plugins.repository.url.URLRepository;
 import org.apache.ivy.plugins.repository.url.URLResource;
 
 public class JarResolver extends RepositoryResolver {
 
+    private URL url;
+
     public JarResolver() {
         setRepository(new JarRepository());
     }
@@ -45,30 +48,12 @@ public class JarResolver extends Reposit
     }
 
     public void setUrl(String jarUrl) {
-        URL url;
         try {
             url = new URL(jarUrl);
         } catch (MalformedURLException e) {
             throw new RuntimeException("the jar repository " + getName()
                     + " has an malformed url : " + jarUrl + " (" + e.getMessage() + ")");
         }
-
-        ArtifactDownloadReport report;
-        EventManager eventManager = getEventManager();
-        try {
-            if (eventManager != null) {
-                getRepository().addTransferListener(eventManager);
-            }
-            Resource jarResource = new URLResource(url);
-            CacheResourceOptions options = new CacheResourceOptions();
-            report = getRepositoryCacheManager().downloadRepositoryResource(jarResource,
-                "jarrepository", "jar", "jar", options, getRepository());
-        } finally {
-            if (eventManager != null) {
-                getRepository().removeTransferListener(eventManager);
-            }
-        }
-        setJarFile(report.getLocalFile());
     }
 
     public JarRepository getJarRepository() {
@@ -86,4 +71,26 @@ public class JarResolver extends Reposit
         getJarRepository().setJarFile(jar);
     }
 
+    public void setSettings(ResolverSettings settings) {
+        super.setSettings(settings);
+        // let's resolve the url
+        if (url != null) {
+            ArtifactDownloadReport report;
+            EventManager eventManager = getEventManager();
+            try {
+                if (eventManager != null) {
+                    getRepository().addTransferListener(eventManager);
+                }
+                Resource jarResource = new URLResource(url);
+                CacheResourceOptions options = new CacheResourceOptions();
+                report = getRepositoryCacheManager().downloadRepositoryResource(jarResource,
+                    "jarrepository", "jar", "jar", options, new URLRepository());
+            } finally {
+                if (eventManager != null) {
+                    getRepository().removeTransferListener(eventManager);
+                }
+            }
+            setJarFile(report.getLocalFile());
+        }
+    }
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java?rev=1201254&r1=1201253&r2=1201254&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/JarResolverTest.java Sat
Nov 12 12:29:50 2011
@@ -62,30 +62,43 @@ public class JarResolverTest extends Tes
     public void testSimpleFile() throws Exception {
         JarResolver resolver = new JarResolver();
         resolver.setName("jarresolver1");
-        resolver.setSettings(settings);
         resolver.setFile(new File("test/jar-repos/jarrepo1.jar").getAbsolutePath());
         resolver.addIvyPattern("[organisation]/[module]/ivys/ivy-[revision].xml");
         resolver.addArtifactPattern("[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
+        resolver.setSettings(settings);
 
         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
         ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
                 false), data);
         assertNotNull(rmr);
-
     }
 
     public void testSubdirInFile() throws Exception {
         JarResolver resolver = new JarResolver();
         resolver.setName("jarresolver1_subdir");
-        resolver.setSettings(settings);
         resolver.setFile(new File("test/jar-repos/jarrepo1_subdir.jar").getAbsolutePath());
         resolver.addIvyPattern("1/[organisation]/[module]/ivys/ivy-[revision].xml");
         resolver.addArtifactPattern("1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
+        resolver.setSettings(settings);
 
         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
         ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
                 false), data);
         assertNotNull(rmr);
+    }
 
+    public void testUrl() throws Exception {
+        JarResolver resolver = new JarResolver();
+        resolver.setName("jarresolver1");
+        resolver.setUrl(new File("test/jar-repos/jarrepo1.jar").toURI().toURL().toExternalForm());
+        resolver.addIvyPattern("[organisation]/[module]/ivys/ivy-[revision].xml");
+        resolver.addArtifactPattern("[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
+        resolver.setSettings(settings);
+
+        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
+        ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
+                false), data);
+        assertNotNull(rmr);
     }
+
 }



Mime
View raw message