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

The following examples show how to use org.apache.tools.ant.types.FileSet#setDir() . 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 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 3
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 4
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithRootExclude() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");
    fs.setExcludes("E2/**");

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

    String[] files = getFiles(buildlist);

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

    assertListOfFiles("test/buildlist/", new String[] {"B"}, files);
}
 
Example 5
Source File: AntBuildResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    TestHelper.cleanCache();
    project = TestHelper.newProject();
    project.setProperty("ivy.cache.dir", TestHelper.cache.getAbsolutePath());

    AntWorkspaceResolver antWorkspaceResolver = new AntWorkspaceResolver();
    antWorkspaceResolver.setName("test-workspace");
    wa = antWorkspaceResolver.createArtifact();
    FileSet fileset = new FileSet();
    fileset.setProject(project);
    fileset.setDir(new File("test/workspace"));
    fileset.setIncludes("*/ivy.xml");
    antWorkspaceResolver.addConfigured(fileset);
    antWorkspaceResolver.setProject(project);

    configure = new IvyConfigure();
    configure.setProject(project);
    configure.setFile(new File("test/workspace/ivysettings.xml"));
    configure.addConfiguredWorkspaceResolver(antWorkspaceResolver);
    configure.execute();
}
 
Example 6
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 7
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelativePathToParent() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlists/testRelativePathToParent"));
    fs.setIncludes("**/build.xml");

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

    String[] files = getFiles(buildlist);

    assertEquals(5, files.length);

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

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

    String[] files = getFiles(buildlist);

    assertEquals(2, files.length); // We must have only A and C

    assertListOfFiles("test/buildlist/", new String[] {"C", "A"}, files);
}
 
Example 9
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 10
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRestartFrom() {
    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");
    buildlist.setRestartFrom("C");

    String[] files = getFiles(buildlist);

    assertEquals(4, files.length);

    assertListOfFiles("test/buildlist/", new String[] {"C", "A", "D", "E"}, files);
}
 
Example 11
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 12
Source File: IvyBuildListTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRootCircular() {
    FileSet fs = new FileSet();
    fs.setDir(new File("test/buildlist"));
    fs.setIncludes("**/build.xml");

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

    String[] files = getFiles(buildlist);

    assertEquals(2, files.length); // F and G should be in the list
}
 
Example 13
Source File: PlayConfigurationLoadTask.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public void execute() {
    if (applicationDir == null) {
        throw new BuildException("No applicationDir set!");
    }

    // Add the properties from application.conf as ant properties
    for (Map.Entry<String,String> entry: properties().entrySet()) {
        String key = entry.getKey();
        String value = project.replaceProperties(entry.getValue());
        project.setProperty(prefix + key, value);
        project.log("Loaded property '" + prefix + key + "'='" + value + "'", Project.MSG_VERBOSE);
    }

    // Add the module classpath as an ant property
    Path path = new Path(project);
    FilenameSelector endsToJar = new FilenameSelector();
    endsToJar.setName("*.jar");

    for (File module: modules()) {
        File moduleLib = new File(module, "lib");
        if (moduleLib.exists()) {
            FileSet fileSet = new FileSet();
            fileSet.setDir(moduleLib);
            fileSet.addFilename(endsToJar);
            path.addFileset(fileSet);
            project.log("Added fileSet to path: " + fileSet, Project.MSG_VERBOSE);
        } else {
            project.log("Ignoring non existing lib dir: " + moduleLib.getAbsolutePath(), Project.MSG_VERBOSE);
        }
    }
    project.addReference(modulesClasspath, path);
    project.log("Generated classpath '" + modulesClasspath + "':" + project.getReference(modulesClasspath), Project.MSG_VERBOSE);
}
 
Example 14
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 15
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addImplicitFileset()
{
  if (baseDir != null) {
    final FileSet fileset = (FileSet) getImplicitFileSet().clone();
    fileset.setDir(baseDir);
    srcFilesets.add(fileset);
  }
}
 
Example 16
Source File: MakeLNBM.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileSet getFileSet() {
       FileSet fs = fileset;		//makes in apperance to excludes and includes files defined in XML
       fs.setDir (topdir);

if (isStandardInclude) {
  fs.createInclude ().setName ("netbeans/"); //NOI18N
  fs.createExclude ().setName ("netbeans/update_tracking/*.xml"); //NOI18N
}

fs.createInclude ().setName ("Info/info.xml"); //NOI18N
       return fs;
   }
 
Example 17
Source File: ExclusionsFromLicenseInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void execute() throws BuildException {
    try (FileOutputStream fos = new FileOutputStream(new File(getProject().getBaseDir(), exclusionFile));
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bw = new BufferedWriter(osw)) {
        Path nballPath = nball.toPath();
        List<File> licenseinfofiles = Files.walk(nballPath)
                .filter(p -> p.endsWith("licenseinfo.xml"))
                .map(p -> p.toFile())
                .collect(Collectors.toList());

        FileSet licenseinfoFileset = new FileSet();
        licenseinfoFileset.setProject(getProject());
        licenseinfoFileset.setDir(nball.getAbsoluteFile());

        for(File licenseInfoFile: licenseinfofiles) {
            Licenseinfo li = Licenseinfo.parse(licenseInfoFile);
            for(Fileset fs: li.getFilesets()) {
                for(File f: fs.getFiles()) {
                    Path relativePath = nball.toPath().relativize(f.toPath());
                    licenseinfoFileset.appendIncludes(new String[]{relativePath.toString()});
                    bw.write(relativePath.toString());
                    bw.newLine();
                }
            }
        }
        
        getProject().addReference(this.licenseinfoFileset, licenseinfoFileset);
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}
 
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;
        }
    }
}