in src/main/java/org/apache/easyant/tasks/ImportAntscripts.java [81:230]
public void execute() throws BuildException {
long startTime = System.currentTimeMillis();
if (getOwningTarget() == null || !"".equals(getOwningTarget().getName())) {
throw new BuildException("import only allowed as a top-level task");
}
if (ivyfile == null) {
throw new BuildException("ivyfile is required");
}
if (ivysettings == null) {
throw new BuildException("ivysettings is required");
}
boolean refresh = false;
String refreshValue = getProject().getProperty("easyant.refresh");
if (refreshValue != null) {
refresh = Boolean.parseBoolean(refreshValue);
}
// configure ivy, which may be the local retrieve repo, depending of the setup
Ivy ivy = getIvy();
ivy.pushContext();
try {
ModuleDescriptor md = getMd(ivy, ivyfile);
ArtifactDownloadReport[] artifacts;
List<ModuleDescriptor> dependencies = new ArrayList<ModuleDescriptor>();
// first, let's resolve the ant scripts, just the scripts, not their possible jar dependencies, thus only
// the configuration "default"
XmlReportParser xmlreport = null;
if (!refresh) {
// first try to relad the resolve from the last report
xmlreport = getResolveReport(ivy, md.getModuleRevisionId().getModuleId(), "default", ivyfile);
}
if (xmlreport != null) {
// collect the ant scripts
artifacts = xmlreport.getArtifactReports();
// collect the descriptor associated with each ant script
ModuleRevisionId[] depIds = xmlreport.getDependencyRevisionIds();
for (ModuleRevisionId depId : depIds) {
File depIvyFile = xmlreport.getMetadataArtifactReport(depId).getLocalFile();
dependencies.add(getMd(ivy, depIvyFile));
}
} else {
// do a full resolve
// if in a retrieved setup, clean the repo and repopulate it
maybeClearLocalRepo();
maybeRetrieve(md, "default");
// launch the actual resolve
ResolveReport resolveReport = resolve(ivy, md, "default");
ConfigurationResolveReport confReport = resolveReport.getConfigurationReport("default");
// collect the ant scripts
artifacts = confReport.getAllArtifactsReports();
// collect the descriptor associated with each ant script
Set<ModuleRevisionId> mrids = confReport.getModuleRevisionIds();
for (ModuleRevisionId mrid : mrids) {
dependencies.add(confReport.getDependency(mrid).getDescriptor());
}
}
int nbPaths = 1;
// save the collection of ant scripts as a path
Path antScriptsPath = makePath("easyant.antscripts", sortArtifacts(ivy, artifacts, dependencies));
// now, for each ant script descriptor, search for an ivy configuration which is used by the ant script
// itself
for (ModuleDescriptor depmd : dependencies) {
log("Searching for external conf for " + depmd.getModuleRevisionId(), Project.MSG_VERBOSE);
String[] confs = depmd.getConfigurationsNames();
log("configurations for " + depmd.getModuleRevisionId() + " : " + Arrays.toString(confs),
Project.MSG_DEBUG);
// some trick here: launching a resolve on a module won't resolve the artifacts of the module itself but
// only of its dependencies. So we'll create a mock one which will depend on the real one
String mockOrg = "_easyant_mocks_";
String mockName = depmd.getModuleRevisionId().getOrganisation() + "__"
+ depmd.getModuleRevisionId().getName();
ModuleRevisionId mockmrid = ModuleRevisionId.newInstance(mockOrg, mockName, depmd.getModuleRevisionId()
.getBranch(), depmd.getRevision(), depmd.getExtraAttributes());
DefaultModuleDescriptor mock = new DefaultModuleDescriptor(mockmrid, depmd.getStatus(),
depmd.getPublicationDate(), depmd.isDefault());
DefaultDependencyDescriptor mockdd = new DefaultDependencyDescriptor(depmd.getModuleRevisionId(), false);
for (String conf : confs) {
mock.addConfiguration(new Configuration(conf));
mockdd.addDependencyConfiguration(conf, conf);
}
mock.addDependency(mockdd);
for (String conf : confs) {
if (conf.equals("default")) {
continue;
}
nbPaths++;
log("Found configuration " + conf, Project.MSG_VERBOSE);
// same process than for the ant script:
// * trust the last resolve report
// * or launch a full resolve
// A full resolve might trigger a retrieve to populate the local repo
XmlReportParser xmldepreport = null;
if (!refresh) {
xmldepreport = getResolveReport(ivy, mock.getModuleRevisionId().getModuleId(), conf, null);
}
if (xmldepreport != null) {
artifacts = xmldepreport.getArtifactReports();
} else {
maybeRetrieve(mock, conf);
ResolveReport resolveReport = resolve(ivy, mock, conf);
ConfigurationResolveReport confReport = resolveReport.getConfigurationReport(conf);
artifacts = confReport.getAllArtifactsReports();
}
// finally make the resolved artifact a path which can be used by the ant script itself
makePath(depmd.getModuleRevisionId().getModuleId().toString() + "[" + conf + "]",
Arrays.asList(artifacts));
}
}
log(nbPaths + " paths resolved in " + (System.currentTimeMillis() - startTime) + "ms.", Project.MSG_VERBOSE);
log("Importing " + antScriptsPath.size() + " ant scripts", Project.MSG_VERBOSE);
Iterator<?> itScripts = antScriptsPath.iterator();
while (itScripts.hasNext()) {
log("\t" + itScripts.next(), Project.MSG_VERBOSE);
}
ImportTask importTask = new ImportTask();
importTask.setProject(getProject());
importTask.setOwningTarget(getOwningTarget());
importTask.setLocation(getLocation());
importTask.add(antScriptsPath);
importTask.execute();
} finally {
ivy.popContext();
}
}