use of org.apache.tools.ant.DirectoryScanner in project ant-ivy by apache.
the class IvyCacheFilesetTest method testEmptyConf.
@Test
public void testEmptyConf() {
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml");
fileset.setSetid("emptyconf-setid");
fileset.setConf("empty");
fileset.execute();
Object ref = project.getReference("emptyconf-setid");
assertNotNull(ref);
assertTrue(ref instanceof FileSet);
FileSet fs = (FileSet) ref;
DirectoryScanner directoryScanner = fs.getDirectoryScanner(project);
directoryScanner.scan();
assertEquals(0, directoryScanner.getIncludedFiles().length);
}
use of org.apache.tools.ant.DirectoryScanner in project ant-ivy by apache.
the class IvyCacheFilesetTest method testSimple.
@Test
public void testSimple() {
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml");
fileset.setSetid("simple-setid");
fileset.execute();
Object ref = project.getReference("simple-setid");
assertNotNull(ref);
assertTrue(ref instanceof FileSet);
FileSet fs = (FileSet) ref;
DirectoryScanner directoryScanner = fs.getDirectoryScanner(project);
assertEquals(1, directoryScanner.getIncludedFiles().length);
assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), new File(directoryScanner.getBasedir(), directoryScanner.getIncludedFiles()[0]).getAbsolutePath());
}
use of org.apache.tools.ant.DirectoryScanner 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.DirectoryScanner in project datanucleus-core by datanucleus.
the class EnhancerTask method getFiles.
protected File[] getFiles() {
List<File> v = new ArrayList<File>();
final int size = filesets.size();
for (int i = 0; i < size; i++) {
FileSet fs = filesets.get(i);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
ds.scan();
String[] f = ds.getIncludedFiles();
for (int j = 0; j < f.length; j++) {
String pathname = f[j];
File file = new File(ds.getBasedir(), pathname);
file = getProject().resolveFile(file.getPath());
v.add(file);
}
}
return v.toArray(new File[v.size()]);
}
use of org.apache.tools.ant.DirectoryScanner in project datanucleus-core by datanucleus.
the class SchemaToolTask method getFiles.
protected File[] getFiles() {
List<File> v = new ArrayList<File>();
Iterator<FileSet> filesetIter = filesets.iterator();
while (filesetIter.hasNext()) {
FileSet fs = filesetIter.next();
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
ds.scan();
String[] f = ds.getIncludedFiles();
for (int j = 0; j < f.length; j++) {
String pathname = f[j];
File file = new File(ds.getBasedir(), pathname);
file = getProject().resolveFile(file.getPath());
v.add(file);
}
}
return v.toArray(new File[v.size()]);
}
Aggregations