--- apache-ivy-2.0.0-beta1-src-2\apache-ivy-2.0.0-beta1\src\java\org\apache\ivy\ant\IvyBuildList.java Wed Dec 5 00:07:20 2007 +++ apache-ivy-2.0.0-beta1-src\apache-ivy-2.0.0-beta1\src\java\org\apache\ivy\ant\IvyBuildList.java Mon Jan 14 09:12:23 2008 @@ -41,6 +41,7 @@ import org.apache.ivy.util.Message; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.DirSet; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; @@ -51,6 +52,8 @@ public class IvyBuildList extends IvyTask { private List buildFileSets = new ArrayList(); // List (FileSet) + private List buildDirSets = new ArrayList(); // List (DirSet) + private String reference; private boolean haltOnError = true; @@ -77,6 +80,10 @@ buildFileSets.add(buildFiles); } + public void addDirset(DirSet builDirset) { + buildDirSets.add(builDirset); + } + public String getReference() { return reference; } @@ -138,9 +145,9 @@ if (reference == null) { throw new BuildException("reference should be provided in ivy build list"); } - if (buildFileSets.isEmpty()) { + if (buildFileSets.isEmpty() && buildDirSets.isEmpty()) { throw new BuildException( - "at least one nested fileset should be provided in ivy build list"); + "at least one nested fileset or buildset should be provided in ivy build list"); } Ivy ivy = getIvyInstance(); @@ -176,36 +183,29 @@ String[] builds = ds.getIncludedFiles(); for (int i = 0; i < builds.length; i++) { File buildFile = new File(ds.getBasedir(), builds[i]); - File ivyFile = getIvyFileFor(buildFile); - if (!ivyFile.exists()) { - if (skipBuildWithoutIvy) { - Message.debug("skipping " + buildFile + ": ivy file " + ivyFile - + " doesn't exist"); - } else { - Message.verbose("no ivy file for " + buildFile + ": ivyfile=" + ivyFile - + ": adding it at the beginning of the path"); - Message.verbose("\t(set skipbuildwithoutivy to true if you don't want this" - + " file to be added to the path)"); - independent.add(buildFile); - } - } else { - try { - ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance() - .parseDescriptor(settings, ivyFile.toURL(), doValidate(settings)); - buildFiles.put(md, buildFile); - mdsMap.put(md.getModuleRevisionId().getModuleId().getName(), md); - Message.debug("Add " + md.getModuleRevisionId().getModuleId()); - } catch (Exception ex) { - if (haltOnError) { - throw new BuildException("impossible to parse ivy file for " - + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex, ex); - } else { - Message.warn("impossible to parse ivy file for " + buildFile - + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage()); - Message.info("\t=> adding it at the beginning of the path"); - independent.add(buildFile); - } - } + ModuleDescriptor md = parseModule(settings, buildFile.getParentFile()); + if (md == null) { + independent.add(buildFile); + } + else { + buildFiles.put(md, buildFile); + mdsMap.put(md.getModuleRevisionId().getModuleId().getName(), md); + } + } + } + for (ListIterator iter = buildDirSets.listIterator(); iter.hasNext();) { + DirSet dirSet = (DirSet) iter.next(); + DirectoryScanner ds = dirSet.getDirectoryScanner(getProject()); + String[] dirs = ds.getIncludedDirectories(); + for (int i = 0; i < dirs.length; i++) { + File moduleDir = new File(ds.getBasedir(), dirs[i]); + ModuleDescriptor md = parseModule(settings, moduleDir); + if (md == null) { + independent.add(moduleDir); + } + else { + buildFiles.put(md, moduleDir); + mdsMap.put(md.getModuleRevisionId().getModuleId().getName(), md); } } } @@ -251,6 +251,40 @@ getProject().setProperty("ivy.sorted.modules", order.toString()); } + private ModuleDescriptor parseModule(IvySettings settings, File moduleDir) { + File ivyFile = getIvyFileFor(moduleDir); + if (!ivyFile.exists()) { + if (skipBuildWithoutIvy) { + Message.debug("skipping " + moduleDir + ": ivy file " + ivyFile + + " doesn't exist"); + return null; // TODO Incorrect + } else { + Message.verbose("no ivy file for " + moduleDir + ": ivyfile=" + ivyFile + + ": adding it at the beginning of the path"); + Message.verbose("\t(set skipbuildwithoutivy to true if you don't want this" + + " file to be added to the path)"); + return null; + } + } else { + try { + ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance() + .parseDescriptor(settings, ivyFile.toURL(), doValidate(settings)); + Message.debug("Add " + md.getModuleRevisionId().getModuleId()); + return md; + } catch (Exception ex) { + if (haltOnError) { + throw new BuildException("impossible to parse ivy file for " + + moduleDir + ": ivyfile=" + ivyFile + " exception=" + ex, ex); + } else { + Message.warn("impossible to parse ivy file for " + moduleDir + + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage()); + Message.info("\t=> adding it at the beginning of the path"); + return null; + } + } + } + } + private List convertModuleNamesToModuleDescriptors(Map mdsMap, Set moduleNames, String kind) { List mds = new ArrayList(); for (Iterator iter = moduleNames.iterator(); iter.hasNext();) { @@ -407,13 +441,21 @@ } private void addBuildFile(Path path, File buildFile) { - FileSet fs = new FileSet(); - fs.setFile(buildFile); - path.addFileset(fs); + + if (buildFile.isFile()) { + FileSet fs = new FileSet(); + fs.setFile(buildFile); + path.addFileset(fs); + } else { + DirSet ds = new DirSet(); + ds.setDir(buildFile.getParentFile()); + ds.setIncludes(buildFile.getName()); + path.addDirset(ds); + } } - private File getIvyFileFor(File buildFile) { - return new File(buildFile.getParentFile(), ivyFilePath); + private File getIvyFileFor(File buildDir) { + return new File(buildDir, ivyFilePath); } public boolean isHaltonerror() {