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()));
}
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"));
}
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"));
}
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"));
}
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);
}
}
}
}
Aggregations