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

The following examples show how to use org.apache.tools.ant.types.FileSet#getDirectoryScanner() . 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: RccTask.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * Invoke the Hadoop record compiler on each record definition file
 */
public void execute() throws BuildException {
  if (src == null && filesets.size()==0) {
    throw new BuildException("There must be a file attribute or a fileset child element");
  }
  if (src != null) {
    doCompile(src);
  }
  Project myProject = getProject();
  for (int i = 0; i < filesets.size(); i++) {
    FileSet fs = filesets.get(i);
    DirectoryScanner ds = fs.getDirectoryScanner(myProject);
    File dir = fs.getDir(myProject);
    String[] srcs = ds.getIncludedFiles();
    for (int j = 0; j < srcs.length; j++) {
      doCompile(new File(dir, srcs[j]));
    }
  }
}
 
Example 2
Source File: BasicInstrumentationTask.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void collectClassNames() {
	logger.info( "collecting class names for extended instrumentation determination" );
	Project project = getProject();
	Iterator filesets = filesets();
	while ( filesets.hasNext() ) {
		FileSet fs = ( FileSet ) filesets.next();
		DirectoryScanner ds = fs.getDirectoryScanner( project );
		String[] includedFiles = ds.getIncludedFiles();
		File d = fs.getDir( project );
		for ( int i = 0; i < includedFiles.length; ++i ) {
			File file = new File( d, includedFiles[i] );
			try {
				collectClassNames( file );
			}
			catch ( Exception e ) {
				throw new BuildException( e );
			}
		}
	}
	logger.info( classNames.size() + " class(es) being checked" );
}
 
Example 3
Source File: UpdateSigner.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ants execute method.
 */
@Override
public void execute() {
	try {
		for (final FileSet fileset : filesets) {
			final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
			final String[] includedFiles = ds.getIncludedFiles();
			for (final String filename : includedFiles) {
				String signature = sign(ds.getBasedir().getAbsolutePath()
						+ File.separator + filename);
				System.out.println("file-signature." + filename + "=" + signature);
			}
		}
	} catch (final Exception e) {
		throw new BuildException(e);
	}
}
 
Example 4
Source File: CheckHelpSets.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void execute() throws BuildException {
    for(FileSet fs: filesets) {
        FileScanner scanner = fs.getDirectoryScanner(getProject());
        File dir = scanner.getBasedir();
        String[] files = scanner.getIncludedFiles();
        for (int i = 0; i < files.length; i++) {
            File helpset = new File(dir, files[i]);
            try {
                checkHelpSet(helpset);
            } catch (BuildException be) {
                throw be;
            } catch (Exception e) {
                throw new BuildException("Error checking helpset", e, new Location(helpset.getAbsolutePath()));
            }
        }
    }
}
 
Example 5
Source File: RccTask.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Invoke the Hadoop record compiler on each record definition file
 */
@Override
public void execute() throws BuildException {
  if (src == null && filesets.size()==0) {
    throw new BuildException("There must be a file attribute or a fileset child element");
  }
  if (src != null) {
    doCompile(src);
  }
  Project myProject = getProject();
  for (int i = 0; i < filesets.size(); i++) {
    FileSet fs = filesets.get(i);
    DirectoryScanner ds = fs.getDirectoryScanner(myProject);
    File dir = fs.getDir(myProject);
    String[] srcs = ds.getIncludedFiles();
    for (int j = 0; j < srcs.length; j++) {
      doCompile(new File(dir, srcs[j]));
    }
  }
}
 
Example 6
Source File: CreateModuleXML.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void scanModules(FileSet fs, boolean isEnabled, boolean isAutoload, boolean isEager, boolean isHidden, List<String> names) throws BuildException {
    FileScanner scan = fs.getDirectoryScanner(getProject());
    File dir = scan.getBasedir();
    for (String kid : scan.getIncludedFiles()) {
        File module = new File(dir, kid);
        scanOneModule(module, kid, isEnabled, isAutoload, isEager, isHidden, names);
    }
}
 
Example 7
Source File: CCGBankTaskSources.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the files in the specified group as an array of files. The files in
 * the returned array are in the order returned by <code>group</code>'s
 * {@link FileSet#getDirectoryScanner(Project) directory scanner}.
 */
@Override
protected File[] getFiles(FileSet group) {
	Project proj = getProject();
	DirectoryScanner scanner = group.getDirectoryScanner(proj);
	scanner.scan();
	
	String[] fileNames = scanner.getIncludedFiles();
	if(fileNames.length == 0) {
		throw new BuildException("no source files included");
	}
	
	return makeFiles(group.getDir(proj), fileNames);
}
 
Example 8
Source File: IvyCacheFilesetTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutPreviousResolveAndNonDefaultCache() {
    File cache2 = new File("build/cache2");
    cache2.mkdirs();

    try {
        project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml");
        fileset.setSetid("simple-setid");
        System.setProperty("ivy.cache.dir", cache2.getAbsolutePath());
        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", cache2)
                    .getAbsolutePath(), new File(directoryScanner.getBasedir(),
                    directoryScanner.getIncludedFiles()[0]).getAbsolutePath());
    } finally {
        Delete del = new Delete();
        del.setProject(new Project());
        del.setDir(cache2);
        del.execute();
    }
}
 
Example 9
Source File: CreatePackageTask.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void applyFilesets(String key, Vector<FileSet> filesets) {
ArrayList<String> filenames = new ArrayList<String>();
for (FileSet fileset : filesets) {
    DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
    String[] files = ds.getIncludedFiles();
    for (String filename : files) {
	filenames.add(ds.getBasedir() + File.separator + filename);
    }
}

deployConfig.setFilenames(key, filenames);
   }
 
Example 10
Source File: AbstractProcessTask.java    From cglib with Apache License 2.0 5 votes vote down vote up
protected Collection getFiles() {
    Map fileMap = new HashMap();
    Project p = getProject();
    for (int i = 0; i < filesets.size(); i++) {
        FileSet fs = (FileSet)filesets.elementAt(i);
        DirectoryScanner ds = fs.getDirectoryScanner(p);
        String[] srcFiles = ds.getIncludedFiles();
        File dir = fs.getDir(p);
        for (int j = 0; j < srcFiles.length; j++) {
             File src = new File(dir, srcFiles[j]);
             fileMap.put(src.getAbsolutePath(), src);
        }
    }
    return fileMap.values();
}
 
Example 11
Source File: MakeJNLP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void generateVersionXMLFiles() throws IOException {
    FileSet fs = new FileSet();
    fs.setIncludes("**/*.jar");
    for (File directory : jarDirectories) {
        fs.setDir(directory);
        DirectoryScanner scan = fs.getDirectoryScanner(getProject());
        StringWriter writeVersionXML = new StringWriter();
        writeVersionXML.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writeVersionXML.append("<jnlp-versions>\n");
        for (String jarName : scan.getIncludedFiles()) {
            File jar = new File(scan.getBasedir(), jarName);
            JarFile jarFile = new JarFile(jar);
            String version = getJarVersion(jarFile);
            if (version != null) {
                writeVersionXML.append("    <resource>\n        <pattern>\n            <name>");
                writeVersionXML.append(jar.getName());
                writeVersionXML.append("</name>\n            <version-id>");
                writeVersionXML.append(version);
                writeVersionXML.append("</version-id>\n        </pattern>\n        <file>");
                writeVersionXML.append(jar.getName());
                writeVersionXML.append("</file>\n    </resource>\n");
            } else {
                writeVersionXML.append("    <!-- No version found for ");
                writeVersionXML.append(jar.getName());
                writeVersionXML.append(" -->\n");
            }
        }
        writeVersionXML.append("</jnlp-versions>\n");
        writeVersionXML.close();

        File versionXML = new File(directory, "version.xml");
        FileWriter w = new FileWriter(versionXML);
        w.write(writeVersionXML.toString());
        w.close();
    }
}
 
Example 12
Source File: IvyCacheFilesetTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 13
Source File: EtlExecuteTask.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
public void execute() throws BuildException {
    List<File> files = new ArrayList<File>();

    try {
        if (filesets.isEmpty()) { //if no files - use file default name
            files.add(launcher.resolveFile(getProject().getBaseDir(), null));
        } else {
            for (FileSet fs : filesets) {
                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
                File srcDir = fs.getDir(getProject());

                String srcFiles[] = ds.getIncludedFiles();

                for (String fName : srcFiles) {
                    File file = launcher.resolveFile(srcDir, fName);
                    files.add(file);
                }
            }
        }
    } catch (FileNotFoundException e) {
        throw new BuildException(e.getMessage(), e);
    }

    if (fork) {
        fork(files);
    } else {
        execute(files);
    }
}
 
Example 14
Source File: AbstractCajaAntTask.java    From caja with Apache License 2.0 5 votes vote down vote up
public void addConfiguredFileSet(FileSet fs) {
  DirectoryScanner scanner = fs.getDirectoryScanner(getProject());
  File baseDir = scanner.getBasedir();
  scanner.scan();
  String[] includedFiles = scanner.getIncludedFiles();
  Arrays.sort(includedFiles);
  for (String localPath : includedFiles) {
    files.add(new File(baseDir, localPath));
  }
}
 
Example 15
Source File: JNLPUpdateManifestBranding.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
    Set<String> filePaths = new HashSet<>();
    File tmpFile = null;
    for (FileSet fs : filesets) {
        if (fs != null) {
            DirectoryScanner scan = fs.getDirectoryScanner(getProject());
            for (String f : scan.getIncludedFiles()) {
                filePaths.add(fs.getDir().getAbsolutePath() + File.separatorChar + f.replace(File.separatorChar, '/'));
            }
        }
    }
    try {
        for (String filePathIter : filePaths) {
            File jarFile = new File(filePathIter);
            if (isSigned(jarFile) == null) {
                tmpFile = extendLibraryManifest(getProject(), jarFile, jarFile, codebase, permissions, appName);
            }
            if (tmpFile != null) {
                sign(tmpFile, jarFile);
                deleteTmpFile(tmpFile);
            } else {
                sign(jarFile, jarFile);
            }

        }
    } catch (IOException | ManifestException ex) {
        getProject().log(
                "Failed to extend libraries manifests: " + ex.getMessage(), //NOI18N
                Project.MSG_WARN);
    }
}
 
Example 16
Source File: WriteDataToDatabaseCommand.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    public void execute(DatabaseTaskBase task, Database model) throws BuildException
    {
        if ((_singleDataFile != null) && !_fileSets.isEmpty())
        {
            throw new BuildException("Please use either the datafile attribute or the sub fileset element, but not both");
        }

        Platform   platform   = getPlatform();
        DataReader dataReader = null;

// GemStone changes BEGIN
        boolean ignoreEndEx = true;
        platform.setAddIdentityUsingAlterTable(_addIdentityUsingAlterTable);
// GemStone changes END
        platform.setIdentityOverrideOn(_useExplicitIdentityValues);
        try
        {
            dataReader = getDataIO().getConfiguredDataReader(platform, model);
            dataReader.getSink().start();
            if (_singleDataFile != null)
            {
                readSingleDataFile(task, dataReader, _singleDataFile);
            }
            else
            {
                for (Iterator it = _fileSets.iterator(); it.hasNext();)
                {
                    FileSet          fileSet    = (FileSet)it.next();
                    File             fileSetDir = fileSet.getDir(task.getProject());
                    DirectoryScanner scanner    = fileSet.getDirectoryScanner(task.getProject());
                    String[]         files      = scanner.getIncludedFiles();
    
                    for (int idx = 0; (files != null) && (idx < files.length); idx++)
                    {
                        readSingleDataFile(task, dataReader, new File(fileSetDir, files[idx]));
                    }
                }
            }
// GemStone changes BEGIN
            ignoreEndEx = false;
// GemStone changes END
        }
        catch (Exception ex)
        {
            handleException(ex, ex.getMessage());
// GemStone changes BEGIN
            ignoreEndEx = false;
// GemStone changes END
        }
        finally
        {
            if (dataReader != null)
            {
// GemStone changes BEGIN
              if (ignoreEndEx) {
                try {
                  dataReader.getSink().end();
                  writeAddIdentityUsingAlterTable(platform, model);
                } catch (DataSinkException dse) {
                  // keep the original thrown exception
                }
              }
              else {
// GemStone changes END
                dataReader.getSink().end();
// GemStone changes BEGIN
                writeAddIdentityUsingAlterTable(platform, model);
              }
// GemStone changes END
            }
        }
    }
 
Example 17
Source File: CheckEol.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Perform the check
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute() throws BuildException {

    Mode mode = null;
    if ("\n".equals(eoln)) {
        mode = Mode.LF;
    } else if ("\r\n".equals(eoln)) {
        mode = Mode.CRLF;
    } else {
        log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.",
                Project.MSG_VERBOSE);
        return;
    }

    int count = 0;

    List<CheckFailure> errors = new ArrayList<CheckFailure>();

    // Step through each file and check.
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        if (files.length > 0) {
            log("Checking line ends in " + files.length + " file(s)");
            for (int i = 0; i < files.length; i++) {
                File file = new File(basedir, files[i]);
                log("Checking file '" + file + "' for correct line ends",
                        Project.MSG_DEBUG);
                try {
                    check(file, errors, mode);
                } catch (IOException e) {
                    throw new BuildException("Could not check file '"
                            + file.getAbsolutePath() + "'", e);
                }
                count++;
            }
        }
    }
    if (count > 0) {
        log("Done line ends check in " + count + " file(s), "
                + errors.size() + " error(s) found.");
    }
    if (errors.size() > 0) {
        String message = "The following files have wrong line ends: "
                + errors;
        // We need to explicitly write the message to the log, because
        // long BuildException messages may be trimmed. E.g. I observed
        // this problem with Eclipse IDE 3.7.
        log(message, Project.MSG_ERR);
        throw new BuildException(message);
    }
}
 
Example 18
Source File: CommentCorrecterTask.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Executes the ant task, performing initial comment correction on the set of
 * files defined in <code>filesets</code>. Overrides the <code>execute()</code>
 * method in the <code>Task</code> class.
 *
 * @throws org.apache.tools.ant.BuildException if parameters validation fails or
 *      an I/O error occurs
 */
@Override
public void execute() throws BuildException {
    if (text == null) {
        throw new BuildException(
                "The 'text' attribute is required."); // NOI18N
    }
    
    try {
        final String comment = Utils.readFile(text);
        
        for (FileSet fileset: filesets) {
            final DirectoryScanner scanner =
                    fileset.getDirectoryScanner(getProject());
            
            for (String filename: scanner.getIncludedFiles()) {
                final File file =
                        new File(fileset.getDir(getProject()), filename);
                
                log(file.getAbsolutePath());
                
                final FileHandler handler =
                        CommentCorrecter.getInstance().getHandler(file);
                if (handler != null) {
                    handler.load(file);
                    
                    final String current = handler.getCurrentComment();
                    if (current == null) {
                        log("    ...inserting " + // NOI18N
                                "the initial comment"); // NOI18N
                        handler.insertComment(comment, lineLength);
                    } else {
                        final String correct =
                                handler.getCorrectComment(comment, lineLength);
                        if (current.equals(correct)) {
                            log("    ...skipping -- " + // NOI18N
                                    "the comment is up to date"); // NOI18N
                        } else {
                            log("    ...updating " + // NOI18N
                                    "the initial comment"); // NOI18N
                            handler.updateComment(comment, lineLength);
                        }
                    }
                    
                    handler.save(file);
                } else {
                    log("   ...skipping -- " + // NOI18N
                            "not recognized by any handler"); // NOI18N
                }
            }
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}
 
Example 19
Source File: MakeHTMLTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void execute() {
  final Project proj = getProject();
  this.projectName = proj.getName();

  if (template == null) {
    throw new BuildException("template must be set");
  }
  if (title == null) {
    title = "";
  }
  if (description == null) {
    description = "";
  }

  if (filesets.isEmpty() && fromFile == null && toFile == null) {
    throw new BuildException("Need to specify tofile and fromfile or give a fileset");
  }

  if (filesets.isEmpty()) {
    // log("Project base is: " + getProject().getBaseDir());
    // log("Attempting to transform: " + fromFile);
    if (!FileUtils.isAbsolutePath(fromFile)) {
      fromFile = getProject().getBaseDir() + File.separator + fromFile;
    }
    transform(fromFile, toFile.toString());
  } else {
    if (fromFile != null) {
      throw new BuildException("Can not specify fromfile when using filesets");
    }
    if (toFile != null) {
      throw new BuildException("Can not specify tofile when using filesets");
    }

    for (final Object element : filesets) {
      final FileSet fs = (FileSet) element;
      final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
      final String[] files = ds.getIncludedFiles();

      for (final String file : files) {
        transform(new File(fs.getDir(getProject()),
                           file).getAbsolutePath(), file);
      }
    }
  }
}
 
Example 20
Source File: CheckEol.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Perform the check
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute() throws BuildException {

    Mode mode = null;
    if ("\n".equals(System.lineSeparator())) {
        mode = Mode.LF;
    } else if ("\r\n".equals(System.lineSeparator())) {
        mode = Mode.CRLF;
    } else {
        log("Line ends check skipped, because OS line ends setting is neither LF nor CRLF.",
                Project.MSG_VERBOSE);
        return;
    }

    int count = 0;

    List<CheckFailure> errors = new ArrayList<>();

    // Step through each file and check.
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        if (files.length > 0) {
            log("Checking line ends in " + files.length + " file(s)");
            for (int i = 0; i < files.length; i++) {
                File file = new File(basedir, files[i]);
                log("Checking file '" + file + "' for correct line ends",
                        Project.MSG_DEBUG);
                try {
                    check(file, errors, mode);
                } catch (IOException e) {
                    throw new BuildException("Could not check file '"
                            + file.getAbsolutePath() + "'", e);
                }
                count++;
            }
        }
    }
    if (count > 0) {
        log("Done line ends check in " + count + " file(s), "
                + errors.size() + " error(s) found.");
    }
    if (errors.size() > 0) {
        String message = "The following files have wrong line ends: "
                + errors;
        // We need to explicitly write the message to the log, because
        // long BuildException messages may be trimmed. E.g. I observed
        // this problem with Eclipse IDE 3.7.
        log(message, Project.MSG_ERR);
        throw new BuildException(message);
    }
}