Search in sources :

Example 61 with FileSet

use of org.apache.tools.ant.types.FileSet 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 62 with FileSet

use of org.apache.tools.ant.types.FileSet 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 63 with FileSet

use of org.apache.tools.ant.types.FileSet 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 64 with FileSet

use of org.apache.tools.ant.types.FileSet in project ant-ivy by apache.

the class IvyCacheFileset method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (setid == null) {
        throw new BuildException("setid is required in ivy cachefileset");
    }
    try {
        final List<ArtifactDownloadReport> artifactDownloadReports = getArtifactReports();
        if (artifactDownloadReports.isEmpty()) {
            // generate an empty fileset
            final FileSet emptyFileSet = new EmptyFileSet();
            emptyFileSet.setProject(getProject());
            getProject().addReference(setid, emptyFileSet);
            return;
        }
        // find a common base dir of the resolved artifacts
        final File baseDir = this.requireCommonBaseDir(artifactDownloadReports);
        final FileSet fileset = new FileSet();
        fileset.setDir(baseDir);
        fileset.setProject(getProject());
        // enroll each of the artifact files into the fileset
        for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
            if (artifactDownloadReport.getLocalFile() == null) {
                continue;
            }
            final NameEntry ne = fileset.createInclude();
            ne.setName(getPath(baseDir, artifactDownloadReport.getLocalFile()));
        }
        getProject().addReference(setid, fileset);
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) BuildException(org.apache.tools.ant.BuildException) NameEntry(org.apache.tools.ant.types.PatternSet.NameEntry) File(java.io.File) BuildException(org.apache.tools.ant.BuildException) NoSuchElementException(java.util.NoSuchElementException)

Example 65 with FileSet

use of org.apache.tools.ant.types.FileSet 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)

Aggregations

FileSet (org.apache.tools.ant.types.FileSet)165 File (java.io.File)124 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)83 BuildException (org.apache.tools.ant.BuildException)49 Test (org.junit.Test)41 IOException (java.io.IOException)36 ArrayList (java.util.ArrayList)29 Project (org.apache.tools.ant.Project)22 Resource (org.apache.tools.ant.types.Resource)12 FileResource (org.apache.tools.ant.types.resources.FileResource)10 URL (java.net.URL)6 Hashtable (java.util.Hashtable)6 ArchiveFileSet (org.apache.tools.ant.types.ArchiveFileSet)6 Path (org.apache.tools.ant.types.Path)6 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)6 PrintStream (java.io.PrintStream)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)5