Java Code Examples for org.apache.tools.ant.DirectoryScanner#getBasedir()

The following examples show how to use org.apache.tools.ant.DirectoryScanner#getBasedir() . 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: Txt2Html.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Perform the conversion
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute()
    throws BuildException
{
    int count = 0;

    // Step through each file and convert.
    Iterator<FileSet> iter = filesets.iterator();
    while( iter.hasNext() ) {
        FileSet fs = iter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        for( int i = 0; i < files.length; i++ ) {
            File from = new File( basedir, files[i] );
            File to = new File( todir, files[i] + ".html" );
            if( !to.exists() ||
                (from.lastModified() > to.lastModified()) )
            {
                log( "Converting file '" + from.getAbsolutePath() +
                    "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE );
                try {
                    convert( from, to );
                }
                catch( IOException e ) {
                    throw new BuildException( "Could not convert '" +
                        from.getAbsolutePath() + "' to '" +
                        to.getAbsolutePath() + "'", e );
                }
                count++;
            }
        }
        if( count > 0 ) {
            log( "Converted " + count + " file" + (count > 1 ? "s" : "") +
                " to " + todir.getAbsolutePath() );
        }
    }
}
 
Example 2
Source File: MXJC2Task.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Extracts files in the given {@link FileSet}.
 */
private InputSource[] toInputSources( FileSet fs ) {
    DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    String[] includedFiles = ds.getIncludedFiles();
    File baseDir = ds.getBasedir();
    
    ArrayList<InputSource> lst = new ArrayList<InputSource>();

    for (String value : includedFiles) {
        lst.add(getInputSource(new File(baseDir, value)));
    }
    
    return lst.toArray(new InputSource[lst.size()]);
}
 
Example 3
Source File: MXJC2Task.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Extracts {@link File} objects that the given {@link FileSet}
 * represents and adds them all to the given {@link List}.
 */
private void addIndividualFilesTo( FileSet fs, List<File> lst ) {
    DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    String[] includedFiles = ds.getIncludedFiles();
    File baseDir = ds.getBasedir();

    for (String value : includedFiles) {
        lst.add(new File(baseDir, value));
    }
}
 
Example 4
Source File: MergeXmlFiles.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
    try {
        System.out.println("Merging xml files in " + destFile);
        DirectoryScanner directoryScanner = filesets.get(0).getDirectoryScanner();
        File basedir = directoryScanner.getBasedir();
        String[] includedFiles = directoryScanner.getIncludedFiles();
        Document merge = merge(basedir, includedFiles);
        print(merge, destFile);
        System.out.println("Merging done!");
    } catch (Exception e) {
        e.printStackTrace();
        throw new BuildException(e);
    }
}
 
Example 5
Source File: FileArchive.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static File[] scanFileSet(FileSet fs) {
    Project prj = fs.getProject();
    DirectoryScanner scanner = fs.getDirectoryScanner(prj);
    scanner.scan();
    File basedir = scanner.getBasedir();
    String[] fileNames = scanner.getIncludedFiles();
    File[] ret = new File[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
        String fileName = fileNames[i];
        ret[i] = new File(basedir, fileName);
    }
    return ret;
}
 
Example 6
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 7
Source File: Txt2Html.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Perform the conversion
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute()
    throws BuildException
{
    int count = 0;

    // Step through each file and convert.
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        for( int i = 0; i < files.length; i++ ) {
            File from = new File( basedir, files[i] );
            File to = new File( todir, files[i] + ".html" );
            if( !to.exists() ||
                (from.lastModified() > to.lastModified()) )
            {
                log( "Converting file '" + from.getAbsolutePath() +
                    "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE );
                try {
                    convert( from, to );
                }
                catch( IOException e ) {
                    throw new BuildException( "Could not convert '" +
                        from.getAbsolutePath() + "' to '" +
                        to.getAbsolutePath() + "'", e );
                }
                count++;
            }
        }
        if( count > 0 ) {
            log( "Converted " + count + " file" + (count > 1 ? "s" : "") +
                " to " + todir.getAbsolutePath() );
        }
    }
}
 
Example 8
Source File: Txt2Html.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Perform the conversion
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute()
    throws BuildException
{
    int count = 0;

    // Step through each file and convert.
    Iterator<FileSet> iter = filesets.iterator();
    while( iter.hasNext() ) {
        FileSet fs = iter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        for( int i = 0; i < files.length; i++ ) {
            File from = new File( basedir, files[i] );
            File to = new File( todir, files[i] + ".html" );
            if( !to.exists() ||
                (from.lastModified() > to.lastModified()) )
            {
                log( "Converting file '" + from.getAbsolutePath() +
                    "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE );
                try {
                    convert( from, to );
                }
                catch( IOException e ) {
                    throw new BuildException( "Could not convert '" +
                        from.getAbsolutePath() + "' to '" +
                        to.getAbsolutePath() + "'", e );
                }
                count++;
            }
        }
        if( count > 0 ) {
            log( "Converted " + count + " file" + (count > 1 ? "s" : "") +
                " to " + todir.getAbsolutePath() );
        }
    }
}
 
Example 9
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 10
Source File: VerifyJNLP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void execute() throws BuildException {
    Map<String,String> results = new LinkedHashMap<>();
    for (FileSet fs : filesets) {
        DirectoryScanner s = fs.getDirectoryScanner(getProject());
        File basedir = s.getBasedir();
        for (String incl : s.getIncludedFiles()) {
            validate(new File(basedir, incl), results);
        }
    }
    JUnitReportWriter.writeReport(this, null, failOnError ? null : report, results);
}
 
Example 11
Source File: JavadocIndex.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void execute() throws BuildException {
    if (target == null) {
        throw new BuildException ("Target must be set"); // NOI18N
    }
    if (set == null) {
        throw new BuildException ("Set of files must be provided: " + set); // NOI18N
    }
    
    DirectoryScanner scan =  set.getDirectoryScanner(this.getProject());
    File bdir = scan.getBasedir();
    for (String n : scan.getIncludedFiles()) {
        File f = new File(bdir, n);
        parseForClasses (f);
    }

    try {
        log ("Generating list of all classes to " + target);
        try (PrintStream ps = new PrintStream (new BufferedOutputStream (
                new FileOutputStream (target)
        ))) {
            if (target.getName ().endsWith (".xml")) {
                printClassesAsXML (ps);
            } else {
                printClassesAsHtml (ps);
            }
        }
    } catch (IOException ex) {
        throw new BuildException (ex);
    }
}
 
Example 12
Source File: SignCode.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void execute() throws BuildException {

    List<File> filesToSign = new ArrayList<>();

    // Process the filesets and populate the list of files that need to be
    // signed.
    for (FileSet fileset : filesets) {
        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        if (files.length > 0) {
            for (int i = 0; i < files.length; i++) {
                File file = new File(basedir, files[i]);
                filesToSign.add(file);
            }
        }
    }

    // Set up the TLS client
    System.setProperty("javax.net.ssl.keyStore", keyStore);
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);

    try {
        String signingSetID = makeSigningRequest(filesToSign);
        downloadSignedFiles(filesToSign, signingSetID);
    } catch (SOAPException | IOException e) {
        throw new BuildException(e);
    }
}
 
Example 13
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 14
Source File: CheckEol.java    From tomcatsrc 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 15
Source File: DownloadBinaries.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws BuildException {
    boolean success = true;
    for (FileSet fs : manifests) {
        DirectoryScanner scanner = fs.getDirectoryScanner(getProject());
        File basedir = scanner.getBasedir();
        for (String include : scanner.getIncludedFiles()) {
            File manifest = new File(basedir, include);
            log("Scanning: " + manifest, Project.MSG_VERBOSE);
            try {
                try (InputStream is = new FileInputStream(manifest)) {
                    BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    String line;
                    while ((line = r.readLine()) != null) {
                        if (line.startsWith("#")) {
                            continue;
                        }
                        if (line.trim().length() == 0) {
                            continue;
                        }
                        String[] hashAndFile = line.split(" ", 2);
                        if (hashAndFile.length < 2) {
                            throw new BuildException("Bad line '" + line + "' in " + manifest, getLocation());
                        }

                        if (MavenCoordinate.isMavenFile(hashAndFile[1])) {
                            MavenCoordinate mc = MavenCoordinate.fromGradleFormat(hashAndFile[1]);
                            success &= fillInFile(hashAndFile[0], mc.toArtifactFilename(), manifest, () -> mavenFile(mc));
                        } else {
                            success &= fillInFile(hashAndFile[0], hashAndFile[1], manifest, () -> legacyDownload(hashAndFile[0] + "-" + hashAndFile[1]));
                        }
                    }
                }
            } catch (IOException x) {
                throw new BuildException("Could not open " + manifest + ": " + x, x, getLocation());
            }
        }
    }
    if(! success) {
        throw new BuildException("Failed to download binaries - see log message for the detailed reasons.", getLocation());
    }
}
 
Example 16
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);
    }
}
 
Example 17
Source File: TestResult.java    From junit-plugin with MIT License 2 votes vote down vote up
/**
 * Collect reports from the given {@link DirectoryScanner}, while
 * filtering out all files that were created before the given time.
 * @param buildTime Build time.
 * @param results Directory scanner.
 * @param pipelineTestDetails A {@link PipelineTestDetails} instance containing Pipeline-related additional arguments.
 *
 * @throws IOException if an error occurs.
 * @since 1.22
 */
public void parse(long buildTime, DirectoryScanner results, PipelineTestDetails pipelineTestDetails) throws IOException {
    String[] includedFiles = results.getIncludedFiles();
    File baseDir = results.getBasedir();
    parse(buildTime,baseDir, pipelineTestDetails,includedFiles);
}
 
Example 18
Source File: FlakyTestResult.java    From flaky-test-handler-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Collect reports from the given {@link DirectoryScanner}, while
 * filtering out all files that were created before the given time.
 *
 * @param buildTime time of build
 * @param results directory scanner for result files
 * @throws IOException throws exception when opening result files fails
 */
public void parse(long buildTime, DirectoryScanner results) throws IOException {
  String[] includedFiles = results.getIncludedFiles();
  File baseDir = results.getBasedir();
  parse(buildTime,baseDir,includedFiles);
}