Java Code Examples for org.apache.tools.ant.types.FileSet#setIncludes()

The following examples show how to use org.apache.tools.ant.types.FileSet#setIncludes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileFinder.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Returns an array with the file names of the specified file pattern that have been found in the workspace.
 *
 * @param workspace
 *         root directory of the workspace
 *
 * @return the file names of all found files
 */
public String[] find(final File workspace) {
    try {
        FileSet fileSet = new FileSet();
        Project antProject = new Project();
        fileSet.setProject(antProject);
        fileSet.setDir(workspace);
        fileSet.setIncludes(includesPattern);
        TypeSelector selector = new TypeSelector();
        FileType fileType = new FileType();
        fileType.setValue(FileType.FILE);
        selector.setType(fileType);
        fileSet.addType(selector);
        if (StringUtils.isNotBlank(excludesPattern)) {
            fileSet.setExcludes(excludesPattern);
        }
        fileSet.setFollowSymlinks(followSymlinks);

        return fileSet.getDirectoryScanner(antProject).getIncludedFiles();
    }
    catch (BuildException ignored) {
        return new String[0]; // as fallback do not return any file
    }
}
 
Example 2
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLeaf() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/**");

    buildlist.addFileset(fs);
    buildlist.setLeaf("C");
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(3, files.length); // B should be filtered out

    assertListOfFiles("test/buildlist/", new String[] {"C", "A", "D"}, files);
}
 
Example 3
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLeafExclude() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/**");

    buildlist.addFileset(fs);
    buildlist.setLeaf("C");
    buildlist.setExcludeLeaf(true);
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(2, files.length); // B and C should be filtered out

    assertListOfFiles("test/buildlist/", new String[] {"A", "D"}, files);
}
 
Example 4
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoParents() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlists/testTwoParents"));
    fs.setIncludes("**/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");
    buildlist.setHaltonerror(false);

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlists/testTwoParents/", new String[] {"bootstrap-parent",
            "master-parent", "croatia", "ireland", "germany"}, files);
}
 
Example 5
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithModuleWithSameNameAndDifferentOrg() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("F/build.xml,G/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(6, files.length);

    assertListOfFiles("test/buildlist/", new String[] {"B", "C", "A", "D"}, files);

    // the order of E and E2 is undefined
    List<URI> other = new ArrayList<>();
    other.add(new File(files[4]).getAbsoluteFile().toURI());
    other.add(new File(files[5]).getAbsoluteFile().toURI());
    Collections.sort(other);

    assertEquals(new File("test/buildlist/E/build.xml").getAbsoluteFile().toURI(), other.get(0));
    assertEquals(new File("test/buildlist/E2/build.xml").getAbsoluteFile().toURI(),
        other.get(1));
}
 
Example 6
Source File: UploadFileSetToS3TaskTests.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteMultipleFiles() throws IOException {
    UploadFileSetToS3Task task = new UploadFileSetToS3Task();
    task.setProject(new Project());
    FileSet fileset = new FileSet();
    fileset.setDir(testFile1.getParentFile());
    fileset.setIncludes("*.txt");
    task.addFileset(fileset);
    task.setBucketName(BUCKET_NAME);
    task.setKeyPrefix(KEY_PREFIX);
    task.execute();
    resFile1 = File.createTempFile(RES_FILE_1, TESTFILE_SUFFIX);
    resFile2 = File.createTempFile(RES_FILE_2, TESTFILE_SUFFIX);
    resFile3 = File.createTempFile(RES_FILE_3, TESTFILE_SUFFIX);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX
            + fileName1), resFile1);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX
            + fileName2), resFile2);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX
            + fileName3), resFile3);
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
}
 
Example 7
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoParents() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlists/testNoParents"));
    fs.setIncludes("**/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");
    buildlist.setHaltonerror(false);

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlists/testNoParents/", new String[] {"bootstrap-parent",
            "ireland", "germany", "master-parent", "croatia"}, files);
}
 
Example 8
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testAbsolutePathToParent() {
    project.setProperty("master-parent.dir", new File(
            "test/buildlists/testAbsolutePathToParent/master-parent").getAbsolutePath());

    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlists/testAbsolutePathToParent"));
    fs.setIncludes("**/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");
    buildlist.setHaltonerror(false);

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlists/testAbsolutePathToParent/", new String[] {
            "bootstrap-parent", "master-parent", "croatia", "ireland", "germany"}, files);
}
 
Example 9
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithTwoLeafs() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/**");

    buildlist.addFileset(fs);
    buildlist.setLeaf("C,E");
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(4, files.length); // B should be filtered out

    assertListOfFiles("test/buildlist/", new String[] {"C", "A", "D", "E"}, files);
}
 
Example 10
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneParent() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlists/testOneParent"));
    fs.setIncludes("**/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");
    buildlist.setHaltonerror(false);

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlists/testOneParent/", new String[] {"bootstrap-parent",
            "master-parent", "croatia", "ireland", "germany"}, files);
}
 
Example 11
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/build.xml,F/build.xml,G/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlist/", new String[] {"B", "C", "A", "D", "E"}, files);
}
 
Example 12
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testReverse() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/build.xml,F/build.xml,G/build.xml");

    buildlist.addFileset(fs);
    buildlist.setReverse(true);
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

    assertListOfFiles("test/buildlist/", new String[] {"E", "D", "A", "C", "B"}, files);
}
 
Example 13
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithRoot() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/**");

    buildlist.addFileset(fs);
    buildlist.setRoot("C");
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(2, files.length); // A and D should be filtered out

    assertListOfFiles("test/buildlist/", new String[] {"B", "C"}, files);
}
 
Example 14
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnMissingDescriptor() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/build.xml,F/build.xml,G/build.xml");

    buildlist.addFileset(fs);
    buildlist.setOnMissingDescriptor("tail"); // IVY-805: new String instance

    String[] files = getFiles(buildlist);

    assertEquals(6, files.length);

    assertListOfFiles("test/buildlist/", new String[] {"B", "C", "A", "D", "E", "H"}, files);
}
 
Example 15
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithLeafCircular() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");

    buildlist.addFileset(fs);
    buildlist.setLeaf("F");
    buildlist.setOnMissingDescriptor("skip");

    String[] files = getFiles(buildlist);

    assertEquals(2, files.length);
}
 
Example 16
Source File: BundleLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processBundlePath()
{
  if (null!=bundlePath && 0<bundlePath.length()) {
    final URL baseUrl = getBaseURL();
    // Create a file set for each entry in the bundle path.
    final String[] urls = Util.splitwords(this.bundlePath, ";", '"');
    for (final String url2 : urls) {
      log("Processing URL '" + url2 + "' from bundlePath '"
          + this.bundlePath + "'.", Project.MSG_DEBUG);
      try {
        final URL url = new URL(baseUrl, url2.trim());
        if ("file".equals(url.getProtocol())) {
          final String path = url.getPath();
          final File dir = new File(path.replace('/', File.separatorChar));
          log("Adding file set with dir '" + dir
              + "' for bundlePath file URL with path '" + path + "'.",
              Project.MSG_VERBOSE);
          final FileSet fs = new FileSet();
          fs.setDir(dir);
          fs.setExcludes("**/*-source.jar,**/*-javadoc.jar");
          fs.setIncludes("**/*.jar");
          fs.setProject(getProject());
          filesets.add(fs);
        }
      } catch (final MalformedURLException e) {
        throw new BuildException("Invalid URL, '" + url2
                                 + "' found in bundlePath: '"
                                 + bundlePath + "'.", e);
      }
    }
  }
}
 
Example 17
Source File: AntTask.java    From forbidden-apis with Apache License 2.0 5 votes vote down vote up
/** Sets a directory as base for class files. The implicit pattern '**&#47;*.class' is used to only scan class files. */
public void setDir(File dir) {
  final FileSet fs = new FileSet();
  fs.setProject(getProject());
  fs.setDir(dir);
  // needed if somebody sets restrictClassFilename=false:
  fs.setIncludes("**/*.class");
  classFiles.add(fs);
}
 
Example 18
Source File: CustomJavac.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * See issue #196556. Sometimes {@code <depend>} leaves behind individual
     * class files for nested classes when their enclosing classes do not exist.
     * This can cause javac to try to read the nested classes and fail.
     */
    private void cleanUpDependDebris() {
        File d = getDestdir();
        if (!d.isDirectory()) {
            return;
}
        FileSet classes = new FileSet();
        classes.setDir(d);
        classes.setIncludes("**/*$*.class");
        final String whiteListRaw = getProject().getProperty("nbjavac.ignore.missing.enclosing"); //NOI18N
        final String[] whiteList = whiteListRaw == null ? new String[0] : whiteListRaw.split("\\s*,\\s*");  //NOI18N
        for (String clazz : classes.getDirectoryScanner(getProject()).getIncludedFiles()) {
            if (isIgnored(whiteList, clazz)) {
                log(clazz + " ignored from the enclosing check due to ignore list", Project.MSG_VERBOSE);
                continue;
            }
            int i = clazz.indexOf('$');
            File enclosing = new File(d, clazz.substring(0, i) + ".class");
            if (!enclosing.isFile()) {
                File enclosed = new File(d, clazz);
                log(clazz + " will be deleted since " + enclosing.getName() + " is missing", Project.MSG_VERBOSE);
                if (!enclosed.delete()) {
                    throw new BuildException("could not delete " + enclosed, getLocation());
                }
            }
        }
    }
 
Example 19
Source File: FileUtil.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
public static void setPermissionOnDirectory(String dirPath, String permission) {
  Chmod chmod = new Chmod();
  chmod.setProject(new Project());
  FileSet fileSet = new FileSet();
  fileSet.setDir(new File(dirPath));
  fileSet.setIncludes("**");
  chmod.addFileset(fileSet);
  chmod.setPerm(permission);
  chmod.execute();
}
 
Example 20
Source File: CustomJavac.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * See issue #166888. If there are any existing class files with no matching
 * source file, assume this is an incremental build and the source file has
 * since been deleted. In that case, delete the whole classes dir. (Could
 * merely delete the stale class file, but if an annotation processor also
 * created associated resources, these may be stale too. Kill them all and
 * let JSR 269 sort it out.)
 */
private void cleanUpStaleClasses() {
    File d = getDestdir();
    if (!d.isDirectory()) {
        return;
    }
    List<File> sources = new ArrayList<>();
    for (String s : getSrcdir().list()) {
        sources.add(new File(s));
    }
    if (generatedClassesDir.isDirectory()) {
        sources.add(generatedClassesDir);
    }
    FileSet classes = new FileSet();
    classes.setDir(d);
    classes.setIncludes("**/*.class");
    classes.setExcludes("**/*$*.class");
    String startTimeProp = getProject().getProperty("module.build.started.time");
    Date startTime;
    try {
        startTime = startTimeProp != null ? new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse(startTimeProp) : null;
    } catch (ParseException x) {
        throw new BuildException(x);
    }
    for (String clazz : classes.getDirectoryScanner(getProject()).getIncludedFiles()) {
        if (startTime != null && new File(d, clazz).lastModified() > startTime.getTime()) {
            // Ignore recently created classes. Hack to get contrib/j2ee.blueprints and the like
            // to build; these generate classes and resources before main compilation step.
            continue;
        }
        String java = clazz.substring(0, clazz.length() - ".class".length()) + ".java";
        boolean found = false;
        for (File source : sources) {
            if (new File(source, java).isFile()) {
                found = true;
                break;
            }
        }
        if (!found) {
            // XXX might be a false negative in case this was a nonpublic outer class
            // (could check for "ClassName.java" in bytecode to see)
            log(new File(d, clazz) + " appears to be stale, rebuilding all module sources", Project.MSG_WARN);
            Delete delete = new Delete();
            delete.setProject(getProject());
            delete.setOwningTarget(getOwningTarget());
            delete.setLocation(getLocation());
            FileSet deletables = new FileSet();
            deletables.setDir(d);
            delete.addFileset(deletables);
            delete.init();
            delete.execute();
            break;
        }
    }
}