You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2012/08/21 16:58:53 UTC
svn commit: r1375593 - in /ant/ivy/core/trunk:
src/java/org/apache/ivy/ant/IvyCachePath.java
test/java/org/apache/ivy/ant/IvyCachePathTest.java
Author: hibou
Date: Tue Aug 21 14:58:53 2012
New Revision: 1375593
URL: http://svn.apache.org/viewvc?rev=1375593&view=rev
Log:
Make IvyCachePath understand OSGi classpaths with their Bundle-Classpath header
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCachePath.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCachePathTest.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCachePath.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCachePath.java?rev=1375593&r1=1375592&r2=1375593&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCachePath.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCachePath.java Tue Aug 21 14:58:53 2012
@@ -19,8 +19,11 @@ package org.apache.ivy.ant;
import java.io.File;
import java.util.Iterator;
+import java.util.List;
import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.osgi.core.BundleInfo;
+import org.apache.ivy.osgi.core.ManifestParser;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
@@ -29,10 +32,13 @@ import org.apache.tools.ant.types.Path;
* Creates an ant path consisting in all artifacts found during a resolve.
*/
public class IvyCachePath extends IvyCacheTask {
+
private String pathid;
private String id;
+ private boolean osgi = false;
+
public String getPathid() {
return pathid;
}
@@ -41,6 +47,10 @@ public class IvyCachePath extends IvyCac
pathid = id;
}
+ public void setOsgi(boolean osgi) {
+ this.osgi = osgi;
+ }
+
/**
* @deprecated use setPathid instead
* @param id
@@ -68,7 +78,7 @@ public class IvyCachePath extends IvyCac
if (isUncompressed() && a.getUncompressedLocalDir() != null) {
f = a.getUncompressedLocalDir();
}
- path.createPathElement().setLocation(f);
+ addToPath(path, f);
}
} catch (Exception ex) {
throw new BuildException("impossible to build ivy path: " + ex, ex);
@@ -76,4 +86,30 @@ public class IvyCachePath extends IvyCac
}
+ protected void addToPath(Path path, File f) throws Exception {
+ if (!osgi || !f.isDirectory()) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ File manifest = new File(f, "META-INF/MANIFEST.MF");
+ if (!manifest.exists()) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
+ List/* <String> */cp = bundleInfo.getClasspath();
+ if (cp == null) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ for (int i = 0; i < cp.size(); i++) {
+ String p = (String) cp.get(i);
+ if (p.equals(".")) {
+ path.createPathElement().setLocation(f);
+ } else {
+ path.createPathElement().setLocation(new File(f, p));
+ }
+ }
+ }
+
}
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCachePathTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCachePathTest.java?rev=1375593&r1=1375592&r2=1375593&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCachePathTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCachePathTest.java Tue Aug 21 14:58:53 2012
@@ -240,7 +240,8 @@ public class IvyCachePathTest extends Te
}
public void testUncompress() throws Exception {
- project.setProperty("ivy.dep.file", "test/repositories/1/compression/module1/ivys/ivy-1.0.xml");
+ project.setProperty("ivy.dep.file",
+ "test/repositories/1/compression/module1/ivys/ivy-1.0.xml");
path.setPathid("testUncompress");
path.setUncompressed(true);
path.execute();
@@ -252,9 +253,46 @@ public class IvyCachePathTest extends Te
assertTrue(new File(p.list()[0]).isDirectory());
}
+ public void testOSGi() throws Exception {
+ project.setProperty("ivy.dep.file",
+ "test/repositories/1/compression/module5/ivys/ivy-1.0.xml");
+ path.setPathid("testOSGi");
+ path.setUncompressed(true);
+ path.setOsgi(true);
+ path.execute();
+ Object ref = project.getReference("testOSGi");
+ assertNotNull(ref);
+ assertTrue(ref instanceof Path);
+ Path p = (Path) ref;
+ assertEquals(4, p.size());
+ File cacheDir = path.getSettings().getDefaultRepositoryCacheBasedir();
+ File uncompressed = new File(cacheDir, "compression/module3/jar_uncompresseds/module3-1.0");
+ assertEquals(new File(uncompressed, "lib/ant-antlr.jar"), new File(p.list()[0]));
+ assertEquals(new File(uncompressed, "lib/ant-apache-bcel.jar"), new File(p.list()[1]));
+ assertEquals(new File(uncompressed, "lib/ant-apache-bsf.jar"), new File(p.list()[2]));
+ assertEquals(new File(uncompressed, "lib/ant-apache-log4j.jar"), new File(p.list()[3]));
+ }
+
+ public void testOSGi2() throws Exception {
+ project.setProperty("ivy.dep.file",
+ "test/repositories/1/compression/module6/ivys/ivy-1.0.xml");
+ path.setPathid("testOSGi");
+ path.setUncompressed(true);
+ path.setOsgi(true);
+ path.execute();
+ Object ref = project.getReference("testOSGi");
+ assertNotNull(ref);
+ assertTrue(ref instanceof Path);
+ Path p = (Path) ref;
+ assertEquals(1, p.size());
+ File cacheDir = path.getSettings().getDefaultRepositoryCacheBasedir();
+ File uncompressed = new File(cacheDir, "compression/module4/jar_uncompresseds/module4-1.0");
+ assertEquals(uncompressed, new File(p.list()[0]));
+ }
+
private File getArchiveFileInCache(String organisation, String module, String revision,
String artifact, String type, String ext) {
- return TestHelper.getArchiveFileInCache(path.getIvyInstance(), organisation,
- module, revision, artifact, type, ext);
+ return TestHelper.getArchiveFileInCache(path.getIvyInstance(), organisation, module,
+ revision, artifact, type, ext);
}
}