Search in sources :

Example 31 with FileSet

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

the class ScriptDefTest method testSimple.

@Test
public void testSimple() {
    buildRule.executeTarget("simple");
    // get the fileset and its basedir
    Project p = buildRule.getProject();
    FileSet fileset = p.getReference("testfileset");
    File baseDir = fileset.getDir(p);
    String log = buildRule.getLog();
    assertTrue("Expecting attribute value printed", log.contains("Attribute attr1 = test"));
    assertTrue("Expecting nested element value printed", log.contains("Fileset basedir = " + baseDir.getAbsolutePath()));
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) File(java.io.File) Test(org.junit.Test)

Example 32 with FileSet

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

the class ClassFileSetTest method testBasicSet.

/**
 * Test basic classfileset
 */
@Test
public void testBasicSet() {
    Project p = buildRule.getProject();
    buildRule.executeTarget("testbasicset");
    FileSet resultFileSet = p.getReference(RESULT_FILESET);
    DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
    String[] scannedFiles = scanner.getIncludedFiles();
    Hashtable<String, String> files = new Hashtable<>();
    for (String scannedFile : scannedFiles) {
        files.put(scannedFile, scannedFile);
    }
    assertEquals("Classfileset did not pick up expected number of " + "class files", 4, files.size());
    assertTrue("Result did not contain A.class", files.containsKey("A.class"));
    assertTrue("Result did not contain B.class", files.containsKey("B.class"));
    assertTrue("Result did not contain C.class", files.containsKey("C.class"));
    assertTrue("Result did not contain D.class", files.containsKey("D.class"));
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) Hashtable(java.util.Hashtable) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Test(org.junit.Test)

Example 33 with FileSet

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

the class ClassFileSetTest method testSmallSet.

/**
 * Test small classfileset
 */
@Test
public void testSmallSet() {
    Project p = buildRule.getProject();
    buildRule.executeTarget("testsmallset");
    FileSet resultFileSet = p.getReference(RESULT_FILESET);
    DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
    Hashtable<String, String> files = new Hashtable<>();
    for (String scannedFile : scanner.getIncludedFiles()) {
        files.put(scannedFile, scannedFile);
    }
    assertEquals("Classfileset did not pick up expected number of " + "class files", 2, files.size());
    assertTrue("Result did not contain B.class", files.containsKey("B.class"));
    assertTrue("Result did not contain C.class", files.containsKey("C.class"));
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) Hashtable(java.util.Hashtable) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Test(org.junit.Test)

Example 34 with FileSet

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

the class ClassFileSetTest method testMethodParamInner.

/**
 * Test that classes included in a method "System.out.println(Outer.Inner.class)" are included.
 */
@Test
public void testMethodParamInner() {
    Project p = buildRule.getProject();
    buildRule.executeTarget("testmethodparaminner");
    FileSet resultFileSet = p.getReference(RESULT_FILESET);
    DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p);
    Hashtable<String, String> files = new Hashtable<>();
    for (String scannedFile : scanner.getIncludedFiles()) {
        files.put(scannedFile, scannedFile);
    }
    assertEquals("Classfileset did not pick up expected number of " + "class files", 4, files.size());
    assertTrue("Result did not contain test" + File.separator + "Outer$Inner.class", files.containsKey("test" + File.separator + "Outer$Inner.class"));
    assertTrue("Result did not contain test" + File.separator + "Outer.class", files.containsKey("test" + File.separator + "Outer.class"));
    assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", files.containsKey("test" + File.separator + "ContainsOnlyInner.class"));
    assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", files.containsKey("test" + File.separator + "MethodParam.class"));
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) Hashtable(java.util.Hashtable) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Test(org.junit.Test)

Example 35 with FileSet

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

the class Zip method addResources.

/**
 * Add the given resources.
 *
 * @param rc may give additional information like fullpath or
 * permissions.
 * @param resources the resources to add
 * @param zOut the stream to write to
 * @throws IOException on error
 *
 * @since Ant 1.7
 */
protected final void addResources(final ResourceCollection rc, final Resource[] resources, final ZipOutputStream zOut) throws IOException {
    if (rc instanceof FileSet) {
        addResources((FileSet) rc, resources, zOut);
        return;
    }
    for (final Resource resource : resources) {
        String name = resource.getName();
        if (name == null) {
            continue;
        }
        name = name.replace(File.separatorChar, '/');
        if (name.isEmpty()) {
            continue;
        }
        if (resource.isDirectory() && doFilesonly) {
            continue;
        }
        File base = null;
        final FileProvider fp = resource.as(FileProvider.class);
        if (fp != null) {
            base = ResourceUtils.asFileResource(fp).getBaseDir();
        }
        if (resource.isDirectory()) {
            addDirectoryResource(resource, name, "", base, zOut, ArchiveFileSet.DEFAULT_DIR_MODE, ArchiveFileSet.DEFAULT_DIR_MODE);
        } else {
            addParentDirs(base, name, zOut, "", ArchiveFileSet.DEFAULT_DIR_MODE);
            if (fp != null) {
                final File f = (fp).getFile();
                zipFile(f, zOut, name, ArchiveFileSet.DEFAULT_FILE_MODE);
            } else {
                addResource(resource, name, "", zOut, ArchiveFileSet.DEFAULT_FILE_MODE, null, null);
            }
        }
    }
}
Also used : ArchiveFileSet(org.apache.tools.ant.types.ArchiveFileSet) FileSet(org.apache.tools.ant.types.FileSet) ZipFileSet(org.apache.tools.ant.types.ZipFileSet) FileProvider(org.apache.tools.ant.types.resources.FileProvider) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) ArchiveResource(org.apache.tools.ant.types.resources.ArchiveResource) ZipResource(org.apache.tools.ant.types.resources.ZipResource) ZipFile(org.apache.tools.zip.ZipFile) 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