Author: hibou
Date: Sun Jan 15 19:07:16 2012
New Revision: 1231729
URL: http://svn.apache.org/viewvc?rev=1231729&view=rev
Log:
Fix the fs iterator so it properly handle Windows paths: stick with
java.io.File rather than playing with java.lang.String
Modified:
ant/ivy/core/trunk/doc/use/buildobr.html
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/FSManifestIterable.java
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepositoryManifestIterable.java
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/repo/BundleRepoTest.java
Modified: ant/ivy/core/trunk/doc/use/buildobr.html
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/buildobr.html?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/buildobr.html (original)
+++ ant/ivy/core/trunk/doc/use/buildobr.html Sun Jan 15 19:07:16 2012
@@ -36,7 +36,6 @@
<tr><td>resolverName</td><td>the name of the resolver from which the jars
should be to gathered</td><td>No</td></tr>
<tr><td>cacheName</td><td>the name of the cache from which the jars should
be to gathered</td><td>No</td></tr>
<tr><td>baseDir</td><td>the folder into whicch the jars should be gather
recursively</td><td>No</td></tr>
- <tr><td>basePath</td><td>The base path to which the location of the jars
should be made relative to</td><td>No. Should only be used together with
<tt>baseDir</tt></td></tr>
<tr><td>encoding</td><td>The encoding of the resulting xml
file</td><td>No. Defaults to <tt>UTF-8</tt></td></tr>
<tr><td>indent</td><td>Specify if the xml result file should be
indented</td><td>No. Defaults to <tt>true</tt></td></tr>
<tr><td>quiet</td><td>Log as debug rather than warning the rejected jars
as they are illformed</td><td>No. Defaults to <tt>false</tt></td></tr>
@@ -45,7 +44,7 @@
<h1>Examples</h1>
<code type="xml">
- <ivy:buildobr baseDir="${eclipse.home}" basePath="${eclipse.home}"
out="${basedir}/target/repo-eclipse.xml" indent="true" />
+ <ivy:buildobr baseDir="${eclipse.home}"
out="${basedir}/target/repo-eclipse.xml" indent="true" />
</code>
Builds an indented OBR descriptor from an Eclipse install, with their path
relative to the Eclipse install.
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/BuildBundleRepoDescriptorTask.java
Sun Jan 15 19:07:16 2012
@@ -27,8 +27,6 @@ import java.util.Iterator;
import javax.xml.transform.TransformerConfigurationException;
import org.apache.ivy.Ivy;
-import org.apache.ivy.ant.AntMessageLogger;
-import org.apache.ivy.ant.IvyTask;
import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.cache.RepositoryCacheManager;
@@ -40,7 +38,6 @@ import org.apache.ivy.plugins.resolver.B
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -58,8 +55,6 @@ public class BuildBundleRepoDescriptorTa
private File baseDir;
- private String basePath = "";
-
private boolean quiet;
public void setResolver(String resolverName) {
@@ -86,10 +81,6 @@ public class BuildBundleRepoDescriptorTa
this.baseDir = dir;
}
- public void setBasePath(String basePath) {
- this.basePath = basePath;
- }
-
public void setQuiet(boolean quiet) {
this.quiet = quiet;
}
@@ -113,9 +104,6 @@ public class BuildBundleRepoDescriptorTa
if (cacheName != null) {
throw new BuildException("specify only one of 'resolver' or
'cache'");
}
- if (basePath != null) {
- log("'basePath' is only usefull with 'baseDir'",
Project.MSG_WARN);
- }
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
DependencyResolver resolver = settings.getResolver(resolverName);
@@ -134,7 +122,7 @@ public class BuildBundleRepoDescriptorTa
if (!baseDir.isDirectory()) {
throw new BuildException(baseDir + " is not a directory");
}
- it = new FSManifestIterable(baseDir, basePath).iterator();
+ it = new FSManifestIterable(baseDir).iterator();
} else if (cacheName != null) {
Ivy ivy = getIvyInstance();
RepositoryCacheManager cacheManager =
ivy.getSettings().getRepositoryCacheManager(
@@ -144,7 +132,7 @@ public class BuildBundleRepoDescriptorTa
+ cacheManager.getClass().getName() + "' is not
supported.");
}
File basedir = ((DefaultRepositoryCacheManager)
cacheManager).getBasedir();
- it = new FSManifestIterable(basedir, basedir.getAbsolutePath() +
File.separator).iterator();
+ it = new FSManifestIterable(basedir).iterator();
} else {
throw new BuildException(
"No resolver, cache or basedir specified: "
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractFSManifestIterable.java
Sun Jan 15 19:07:16 2012
@@ -31,20 +31,26 @@ import java.util.jar.Manifest;
import org.apache.ivy.util.Message;
-public abstract class AbstractFSManifestIterable { // implements Iterable/*
<ManifestAndLocation>
- // */{
+// T is the type of the resource "path"
+public abstract class AbstractFSManifestIterable /* <T> implements Iterable/*
<ManifestAndLocation> */{
+
+ private final Object/* T */root;
+
+ public AbstractFSManifestIterable(Object /* T */root) {
+ this.root = root;
+ }
public Iterator/* <ManifestAndLocation> */iterator() {
- return new FSManifestIterator();
+ return new FSManifestIterator(root);
}
- abstract protected List/* <String> */listBundleFiles(String dir) throws
IOException;
+ abstract protected List/* <T> */listBundleFiles(Object/* T */dir) throws
IOException;
- abstract protected List/* <String> */listDirs(String dir) throws
IOException;
+ abstract protected List/* <T> */listDirs(Object/* T */dir) throws
IOException;
- abstract protected InputStream getInputStream(String f) throws IOException;
+ abstract protected InputStream getInputStream(Object/* T */f) throws
IOException;
- abstract protected URI buildBundleURI(String location) throws IOException;
+ abstract protected URI buildBundleURI(Object/* T */location) throws
IOException;
class FSManifestIterator implements Iterator/* <ManifestAndLocation> */{
@@ -56,17 +62,17 @@ public abstract class AbstractFSManifest
* the stack is an iterator on the children on the root. The last
iterator in the stack
* points to {@link #currentDir}.
*/
- private Stack/* <Iterator<String>> */dirs = new Stack/*
<Iterator<String>> */();
+ private Stack/* <Iterator<T>> */dirs = new Stack/* <Iterator<T>> */();
/**
* The bundles files being lookup.
*/
- private Iterator/* <String> */bundleCandidates = null;
+ private Iterator/* <T> */bundleCandidates = null;
- private String currentDir = null;
+ private Object/* T */currentDir = null;
- FSManifestIterator() {
- dirs.add(Collections.singleton("").iterator());
+ FSManifestIterator(Object /* T */root) {
+ dirs.add(Collections.singleton(root).iterator());
}
/**
@@ -79,7 +85,7 @@ public abstract class AbstractFSManifest
if (currentDir == null) {
// so get the next one
if (((Iterator) dirs.peek()).hasNext()) {
- currentDir = (String) ((Iterator) dirs.peek()).next();
+ currentDir = ((Iterator) dirs.peek()).next();
try {
bundleCandidates =
listBundleFiles(currentDir).iterator();
} catch (IOException e) {
@@ -94,7 +100,7 @@ public abstract class AbstractFSManifest
dirs.pop();
}
} else if (bundleCandidates.hasNext()) {
- String bundleCandidate = (String) bundleCandidates.next();
+ Object/* T */bundleCandidate = bundleCandidates.next();
JarInputStream in = null;
try {
in = new
JarInputStream(getInputStream(bundleCandidate));
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/FSManifestIterable.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/FSManifestIterable.java?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/FSManifestIterable.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/FSManifestIterable.java
Sun Jan 15 19:07:16 2012
@@ -26,13 +26,12 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public class FSManifestIterable extends AbstractFSManifestIterable {
+public class FSManifestIterable extends AbstractFSManifestIterable/* <File> */{
/**
* List of directory name that usually contains jars but are not bundles
@@ -63,21 +62,14 @@ public class FSManifestIterable extends
private FilenameFilter bundleFilter = DEFAULT_BUNLDE_FILTER;
- private String root;
-
- private final String basePath;
-
/**
* Default constructor
*
* @param root
* the root directory of the file system to lookup
- * @param basePath
- * path the found locations should be append to
*/
- public FSManifestIterable(File root, String basePath) {
- this.basePath = basePath;
- this.root = root.getAbsolutePath();
+ public FSManifestIterable(File root) {
+ super(root);
}
public FilenameFilter getDirFilter() {
@@ -96,9 +88,9 @@ public class FSManifestIterable extends
this.bundleFilter = bundleFilter;
}
- protected URI buildBundleURI(String location) {
+ protected URI buildBundleURI(Object/* File */location) {
try {
- return new URI(new File(basePath +
location).toURL().toExternalForm());
+ return new URI(((File) location).toURL().toExternalForm());
} catch (MalformedURLException e) {
throw new RuntimeException("Unexpected file to url conversion
error", e);
} catch (URISyntaxException e) {
@@ -106,12 +98,12 @@ public class FSManifestIterable extends
}
}
- protected InputStream getInputStream(String f) throws
FileNotFoundException {
- return new FileInputStream(new File(root, f));
+ protected InputStream getInputStream(Object/* File */f) throws
FileNotFoundException {
+ return new FileInputStream((File) f);
}
- protected List/* <String> */listBundleFiles(String dir) {
- return fileArray2pathList(new File(root, dir).listFiles(new
FileFilter() {
+ protected List/* <File> */listBundleFiles(Object/* File */dir) {
+ return Arrays.asList(((File) dir).listFiles(new FileFilter() {
public boolean accept(File f) {
if (!f.isFile()) {
return false;
@@ -121,16 +113,8 @@ public class FSManifestIterable extends
}));
}
- private List/* <String> */fileArray2pathList(File[] files) {
- ArrayList/* <String> */list = new ArrayList/* <String>
*/(files.length);
- for (int i = 0; i < files.length; i++) {
- list.add(files[i].getAbsolutePath().substring(root.length() + 1));
- }
- return list;
- }
-
- protected List/* <String> */listDirs(String dir) {
- return fileArray2pathList(new File(root, dir).listFiles(new
FileFilter() {
+ protected List/* <File> */listDirs(Object/* File */dir) {
+ return Arrays.asList(((File) dir).listFiles(new FileFilter() {
public boolean accept(File f) {
if (!f.isDirectory()) {
return false;
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepositoryManifestIterable.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepositoryManifestIterable.java?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepositoryManifestIterable.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/RepositoryManifestIterable.java
Sun Jan 15 19:07:16 2012
@@ -28,7 +28,7 @@ import java.util.List;
import org.apache.ivy.plugins.repository.Repository;
import org.apache.ivy.plugins.resolver.util.ResolverHelper;
-public class RepositoryManifestIterable extends AbstractFSManifestIterable {
+public class RepositoryManifestIterable extends AbstractFSManifestIterable/*
<String> */{
private final Repository repo;
@@ -39,12 +39,13 @@ public class RepositoryManifestIterable
* the root directory of the file system to lookup
*/
public RepositoryManifestIterable(Repository repo) {
+ super("");
this.repo = repo;
}
- protected URI buildBundleURI(String location) throws IOException {
+ protected URI buildBundleURI(Object/* String */location) throws
IOException {
try {
- return new URI(repo.getResource(location).getName());
+ return new URI(repo.getResource((String) location).getName());
} catch (URISyntaxException e) {
throw new RuntimeException(
"Unsupported repository type, resources names cannot be
transformed into uri",
@@ -52,16 +53,16 @@ public class RepositoryManifestIterable
}
}
- protected InputStream getInputStream(String f) throws IOException {
- return repo.getResource(f).openStream();
+ protected InputStream getInputStream(Object/* String */f) throws
IOException {
+ return repo.getResource((String) f).openStream();
}
- protected List/* <String> */listBundleFiles(String dir) throws IOException
{
- return asList(ResolverHelper.listAll(repo, dir));
+ protected List/* <String> */listBundleFiles(Object/* String */dir) throws
IOException {
+ return asList(ResolverHelper.listAll(repo, (String) dir));
}
- protected List/* <String> */listDirs(String dir) throws IOException {
- return asList(ResolverHelper.listAll(repo, dir));
+ protected List/* <String> */listDirs(Object/* String */dir) throws
IOException {
+ return asList(ResolverHelper.listAll(repo, (String) dir));
}
private List/* <String> */asList(String[] array) {
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/repo/BundleRepoTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/repo/BundleRepoTest.java?rev=1231729&r1=1231728&r2=1231729&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/repo/BundleRepoTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/repo/BundleRepoTest.java
Sun Jan 15 19:07:16 2012
@@ -47,7 +47,7 @@ public class BundleRepoTest extends Test
private File ivyrepo = new File("test/test-repo/ivyrepo");
public void testFS() throws Exception {
- FSManifestIterable it = new FSManifestIterable(bundlerepo, "");
+ FSManifestIterable it = new FSManifestIterable(bundlerepo);
BundleRepoDescriptor repo = new
BundleRepoDescriptor(bundlerepo.toURI(),
ExecutionEnvironmentProfileProvider.getInstance());
repo.populate(it.iterator());
@@ -91,7 +91,7 @@ public class BundleRepoTest extends Test
}
public void testXMLSerialisation() throws SAXException, ParseException,
IOException {
- FSManifestIterable it = new FSManifestIterable(bundlerepo, "");
+ FSManifestIterable it = new FSManifestIterable(bundlerepo);
BundleRepoDescriptor repo = new
BundleRepoDescriptor(bundlerepo.toURI(),
ExecutionEnvironmentProfileProvider.getInstance());
repo.populate(it.iterator());