use of org.apache.tools.ant.types.Path in project ant-ivy by apache.
the class IvyCachePathTest method testWithResolveId.
@Test
public void testWithResolveId() {
IvyResolve resolve = new IvyResolve();
resolve.setProject(project);
resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
resolve.setResolveId("withResolveId");
resolve.execute();
// resolve another ivy file
resolve = new IvyResolve();
resolve.setProject(project);
resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
resolve.execute();
path.setResolveId("withResolveId");
path.setPathid("withresolveid-pathid");
path.execute();
Object ref = project.getReference("withresolveid-pathid");
assertNotNull(ref);
assertTrue(ref instanceof Path);
Path p = (Path) ref;
assertEquals(1, p.size());
assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), new File(p.list()[0]).getAbsolutePath());
}
use of org.apache.tools.ant.types.Path in project ant-ivy by apache.
the class AddPathTask method setProject.
public void setProject(Project project) {
super.setProject(project);
toAdd = new Path(project);
}
use of org.apache.tools.ant.types.Path in project ant-ivy by apache.
the class AddPathTask method execute.
public void execute() throws BuildException {
Object element = getProject().getReference(toPath);
if (element == null) {
throw new BuildException("destination path not found: " + toPath);
}
if (!(element instanceof Path)) {
throw new BuildException("destination path is not a path: " + element.getClass());
}
Path dest = (Path) element;
if (first) {
// now way to add path elements at te beginning of the existing path: we do the opposite
// and replace the reference
toAdd.append(dest);
getProject().addReference(toPath, toAdd);
} else {
dest.append(toAdd);
}
}
use of org.apache.tools.ant.types.Path in project ant-ivy by apache.
the class IvyBuildList method doExecute.
@Override
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<String> rootModuleNames = new LinkedHashSet<>();
if (!"*".equals(root)) {
StringTokenizer st = new StringTokenizer(root, delimiter);
while (st.hasMoreTokens()) {
rootModuleNames.add(st.nextToken());
}
}
Set<String> leafModuleNames = new LinkedHashSet<>();
if (!"*".equals(leaf)) {
StringTokenizer st = new StringTokenizer(leaf, delimiter);
while (st.hasMoreTokens()) {
leafModuleNames.add(st.nextToken());
}
}
Set<String> restartFromModuleNames = new LinkedHashSet<>();
if (!"*".equals(restartFrom)) {
StringTokenizer st = new StringTokenizer(restartFrom, delimiter);
// Only accept one (first) module
restartFromModuleNames.add(st.nextToken());
}
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 = convertModuleNamesToModuleDescriptors(mds, leafModuleNames, "leaf");
List<ModuleDescriptor> rootModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, rootModuleNames, "root");
List<ModuleDescriptor> restartFromModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, restartFromModuleNames, "restartFrom");
if (!rootModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on roots " + rootModuleNames);
mds = filterModulesFromRoot(mds, rootModuleDescriptors);
}
if (!leafModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on leafs " + leafModuleNames);
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);
}
// so they are not removed from build path.
if (!restartFromModuleDescriptors.isEmpty()) {
boolean foundRestartFrom = false;
List<ModuleDescriptor> keptModules = new ArrayList<>();
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());
}
use of org.apache.tools.ant.types.Path in project ant-ivy by apache.
the class IvyCachePath method doExecute.
public void doExecute() throws BuildException {
prepareAndCheck();
if (pathid == null) {
if (id == null) {
throw new BuildException("pathid is required in ivy classpath");
}
pathid = id;
log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN);
}
try {
Path path = new Path(getProject());
getProject().addReference(pathid, path);
for (ArtifactDownloadReport adr : getArtifactReports()) {
File f = adr.getLocalFile();
if (adr.getUnpackedLocalFile() != null) {
f = adr.getUnpackedLocalFile();
}
addToPath(path, f);
}
} catch (Exception ex) {
throw new BuildException("impossible to build ivy path: " + ex, ex);
}
}
Aggregations