Search in sources :

Example 51 with DirectoryScanner

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);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Test(org.junit.Test)

Example 52 with DirectoryScanner

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());
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File) Test(org.junit.Test)

Example 53 with DirectoryScanner

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());
}
Also used : Path(org.apache.tools.ant.types.Path) LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IvySettings(org.apache.ivy.core.settings.IvySettings) Ivy(org.apache.ivy.Ivy) BuildException(org.apache.tools.ant.BuildException) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) StringTokenizer(java.util.StringTokenizer) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 54 with DirectoryScanner

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()]);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 55 with DirectoryScanner

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()]);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)150 File (java.io.File)122 FileSet (org.apache.tools.ant.types.FileSet)84 BuildException (org.apache.tools.ant.BuildException)73 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)32 Project (org.apache.tools.ant.Project)14 Resource (org.apache.tools.ant.types.Resource)11 Test (org.junit.Test)11 FileResource (org.apache.tools.ant.types.resources.FileResource)8 HashMap (java.util.HashMap)7 Path (org.apache.tools.ant.types.Path)7 Hashtable (java.util.Hashtable)6 PatternSet (org.apache.tools.ant.types.PatternSet)6 FileWriter (java.io.FileWriter)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 StringTokenizer (java.util.StringTokenizer)5 Vector (java.util.Vector)5 DirSet (org.apache.tools.ant.types.DirSet)5