Search in sources :

Example 91 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class AddTranslations method execute.

public void execute() throws BuildException {
    Map<String, String> externalFiles = getExternalFileLocations();
    DirectoryScanner ds = getDirectoryScanner(dir);
    String[] srcFiles = ds.getIncludedFiles();
    for (int i = 0; i < srcFiles.length; i++) {
        try {
            addTranslationsFromFile(new File(dir, srcFiles[i]), externalFiles);
        } catch (IOException ioe) {
            if (verbose)
                ioe.printStackTrace(System.out);
            System.out.println("'" + srcFiles[i] + "' does not appear to " + "be a valid translations zipfile - skipping.");
        }
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException) File(java.io.File)

Example 92 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class MergeJars method copyFileSet.

private void copyFileSet(FileSet fileset, ZipOutputStream out) throws IOException {
    String prefix = null;
    String fullPath = null;
    if (fileset instanceof ZipFileSet) {
        ZipFileSet zfs = (ZipFileSet) fileset;
        fullPath = zfs.getFullpath(getProject());
        prefix = zfs.getPrefix(getProject());
        if (prefix != null && !prefix.endsWith("/"))
            prefix = prefix + "/";
    }
    DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
    String[] srcFiles = ds.getIncludedFiles();
    if (fullPath != null && srcFiles.length > 1)
        throw new BuildException("fullpath specified for fileset matching multiple files");
    File dir = fileset.getDir(getProject());
    for (int i = 0; i < srcFiles.length; i++) {
        String filename = srcFiles[i];
        File inputFile = new File(dir, filename);
        FileInputStream in = new FileInputStream(inputFile);
        filename = filename.replace(File.separatorChar, '/');
        if (fullPath != null)
            filename = fullPath;
        else if (prefix != null)
            filename = prefix + filename;
        ZipEntry zipEntry = new ZipEntry(filename);
        zipEntry.setTime(inputFile.lastModified());
        copyFile(zipEntry, out, in);
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ZipEntry(java.util.zip.ZipEntry) BuildException(org.apache.tools.ant.BuildException) ZipFileSet(org.apache.tools.ant.types.ZipFileSet) JarFile(java.util.jar.JarFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 93 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class PackageLaunchProfile method calculateContentToken.

private String calculateContentToken() throws IOException {
    List<File> files = new ArrayList<File>();
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        for (String name : ds.getIncludedFiles()) files.add(new File(ds.getBasedir(), name));
    }
    if (files.isEmpty())
        throw new BuildException("You must designate at least one file " + "to include in the launch profile.");
    Collections.sort(files, FILENAME_SORTER);
    Checksum ck = new Adler32();
    for (File f : files) calcChecksum(f, ck);
    return Long.toString(Math.abs(ck.getValue()), Character.MAX_RADIX);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) Checksum(java.util.zip.Checksum) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Adler32(java.util.zip.Adler32)

Example 94 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project tomcat70 by apache.

the class CheckEol method execute.

/**
 * 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);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 95 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project georocket by georocket.

the class ImportCommand method doRun.

@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
    long start = System.currentTimeMillis();
    // resolve file patterns
    Queue<String> queue = new ArrayDeque<>();
    for (String p : patterns) {
        // convert Windows backslashes to slashes (necessary for Files.newDirectoryStream())
        if (SystemUtils.IS_OS_WINDOWS) {
            p = FilenameUtils.separatorsToUnix(p);
        }
        // collect paths and glob patterns
        List<String> roots = new ArrayList<>();
        List<String> globs = new ArrayList<>();
        String[] parts = p.split("/");
        boolean rootParsed = false;
        for (String part : parts) {
            if (!rootParsed) {
                if (hasGlobCharacter(part)) {
                    globs.add(part);
                    rootParsed = true;
                } else {
                    roots.add(part);
                }
            } else {
                globs.add(part);
            }
        }
        if (globs.isEmpty()) {
            // string does not contain a glob pattern at all
            queue.add(p);
        } else {
            // string contains a glob pattern
            if (roots.isEmpty()) {
                // there are not paths in the string. start from the current
                // working directory
                roots.add(".");
            }
            // add all files matching the pattern
            String root = String.join("/", roots);
            String glob = String.join("/", globs);
            Project project = new Project();
            FileSet fs = new FileSet();
            fs.setDir(new File(root));
            fs.setIncludes(glob);
            DirectoryScanner ds = fs.getDirectoryScanner(project);
            Arrays.stream(ds.getIncludedFiles()).map(path -> Paths.get(root, path).toString()).forEach(queue::add);
        }
    }
    if (queue.isEmpty()) {
        error("given pattern didn't match any files");
        return;
    }
    Vertx vertx = new Vertx(this.vertx);
    GeoRocketClient client = createClient();
    int queueSize = queue.size();
    doImport(queue, client, vertx, exitCode -> {
        client.close();
        if (exitCode == 0) {
            String m = "file";
            if (queueSize > 1) {
                m += "s";
            }
            System.out.println("Successfully imported " + queueSize + " " + m + " in " + DurationFormat.formatUntilNow(start));
        }
        handler.handle(exitCode);
    });
}
Also used : AsyncFile(io.vertx.core.file.AsyncFile) Arrays(java.util.Arrays) OptionParserException(de.undercouch.underline.OptionParserException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) Observable(rx.Observable) Pair(org.apache.commons.lang3.tuple.Pair) FileSet(org.apache.tools.ant.types.FileSet) WriteStream(io.vertx.core.streams.WriteStream) FileSystem(io.vertx.rxjava.core.file.FileSystem) Project(org.apache.tools.ant.Project) UnknownAttributes(de.undercouch.underline.UnknownAttributes) Pump(io.vertx.core.streams.Pump) AsyncResult(io.vertx.core.AsyncResult) Splitter(com.google.common.base.Splitter) OptionDesc(de.undercouch.underline.OptionDesc) PrintWriter(java.io.PrintWriter) OpenOptions(io.vertx.core.file.OpenOptions) ObservableFuture(io.vertx.rx.java.ObservableFuture) SystemUtils(org.apache.commons.lang3.SystemUtils) InputReader(de.undercouch.underline.InputReader) DurationFormat(io.georocket.util.DurationFormat) IOException(java.io.IOException) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) GeoRocketClient(io.georocket.client.GeoRocketClient) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Paths(java.nio.file.Paths) RxHelper(io.vertx.rx.java.RxHelper) Optional(java.util.Optional) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) ArgumentType(de.undercouch.underline.Option.ArgumentType) Handler(io.vertx.core.Handler) FilenameUtils(org.apache.commons.io.FilenameUtils) Vertx(io.vertx.rxjava.core.Vertx) FileSet(org.apache.tools.ant.types.FileSet) ArrayList(java.util.ArrayList) Vertx(io.vertx.rxjava.core.Vertx) GeoRocketClient(io.georocket.client.GeoRocketClient) ArrayDeque(java.util.ArrayDeque) Project(org.apache.tools.ant.Project) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) AsyncFile(io.vertx.core.file.AsyncFile) File(java.io.File)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)150 File (java.io.File)122 FileSet (org.apache.tools.ant.types.FileSet)84 BuildException (org.apache.tools.ant.BuildException)73 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)32 Project (org.apache.tools.ant.Project)14 Resource (org.apache.tools.ant.types.Resource)11 Test (org.junit.Test)11 FileResource (org.apache.tools.ant.types.resources.FileResource)8 HashMap (java.util.HashMap)7 Path (org.apache.tools.ant.types.Path)7 Hashtable (java.util.Hashtable)6 PatternSet (org.apache.tools.ant.types.PatternSet)6 FileWriter (java.io.FileWriter)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 StringTokenizer (java.util.StringTokenizer)5 Vector (java.util.Vector)5 DirSet (org.apache.tools.ant.types.DirSet)5