in src/java/org/apache/ivy/ant/IvyBuildList.java [227:345]
public void doExecute() throws BuildException {
if (reference == null) {
throw new BuildException("reference should be provided in ivy build list");
}
if (buildFileSets.isEmpty()) {
throw new BuildException(
"at least one nested fileset should be provided in ivy build list");
}
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
ivyFilePath = getProperty(ivyFilePath, settings, "ivy.buildlist.ivyfilepath");
Path path = new Path(getProject());
Map<ModuleDescriptor, File> buildFiles = new HashMap<>();
List<File> independent = new ArrayList<>();
List<File> noDescriptor = new ArrayList<>();
Collection<ModuleDescriptor> mds = new ArrayList<>();
Set<MapMatcher> rootModules = convert(roots, root, settings);
Set<MapMatcher> leafModules = convert(leafs, leaf, settings);
Set<MapMatcher> restartFromModules = convert(Collections.<BuildListModule>emptyList(), restartFrom, settings);
for (FileSet fs : buildFileSets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
for (String build : ds.getIncludedFiles()) {
File buildFile = new File(ds.getBasedir(), build);
File ivyFile = getIvyFileFor(buildFile);
if (!ivyFile.exists()) {
onMissingDescriptor(buildFile, ivyFile, noDescriptor);
} else {
try {
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance()
.parseDescriptor(settings, ivyFile.toURI().toURL(),
doValidate(settings));
buildFiles.put(md, buildFile);
mds.add(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);
}
}
}
}
}
List<ModuleDescriptor> leafModuleDescriptors =
findModuleDescriptors(mds, leafModules, "leaf");
List<ModuleDescriptor> rootModuleDescriptors =
findModuleDescriptors(mds, rootModules, "root");
List<ModuleDescriptor> restartFromModuleDescriptors =
findModuleDescriptors(mds, restartFromModules, "restartFrom");
if (!rootModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on roots [" + extractModuleNames(rootModules) + "]");
mds = filterModulesFromRoot(mds, rootModuleDescriptors);
}
if (!leafModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on leafs [" + extractModuleNames(leafModules) + "]");
mds = filterModulesFromLeaf(mds, leafModuleDescriptors);
}
List<ModuleDescriptor> sortedModules = ivy.sortModuleDescriptors(mds, SortOptions.DEFAULT);
if (!OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
for (File buildFile : noDescriptor) {
addBuildFile(path, buildFile);
}
}
for (File buildFile : independent) {
addBuildFile(path, buildFile);
}
if (isReverse()) {
Collections.reverse(sortedModules);
}
// Remove modules that are before the restartFrom point
// Independent modules (without valid ivy file) can not be addressed
// so they are not removed from build path.
if (!restartFromModuleDescriptors.isEmpty()) {
boolean foundRestartFrom = false;
List<ModuleDescriptor> keptModules = new ArrayList<>();
// Only accept one (first) module
ModuleDescriptor restartFromModuleDescriptor = restartFromModuleDescriptors.get(0);
for (ModuleDescriptor md : sortedModules) {
if (md.equals(restartFromModuleDescriptor)) {
foundRestartFrom = true;
}
if (foundRestartFrom) {
keptModules.add(md);
}
}
sortedModules = keptModules;
}
StringBuilder order = new StringBuilder();
for (ModuleDescriptor md : sortedModules) {
if (order.length() > 0) {
order.append(", ");
}
order.append(md.getModuleRevisionId().getModuleId());
addBuildFile(path, buildFiles.get(md));
}
if (OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
for (File buildFile : noDescriptor) {
addBuildFile(path, buildFile);
}
}
getProject().addReference(getReference(), path);
getProject().setProperty("ivy.sorted.modules", order.toString());
}