Search in sources :

Example 1 with RelativePath

use of org.gradle.api.file.RelativePath in project gradle by gradle.

the class RelativePathTest method appendPath.

@Test
public void appendPath() {
    RelativePath childPath = new RelativePath(false, "one", "two").append(new RelativePath(true, "three", "four"));
    assertPathContains(childPath, true, "one", "two", "three", "four");
    childPath = new RelativePath(false, "one", "two").append(new RelativePath(true));
    assertPathContains(childPath, true, "one", "two");
    childPath = new RelativePath(false, "one", "two").plus(new RelativePath(true, "three"));
    assertPathContains(childPath, true, "one", "two", "three");
}
Also used : RelativePath(org.gradle.api.file.RelativePath) Test(org.junit.Test)

Example 2 with RelativePath

use of org.gradle.api.file.RelativePath in project gradle by gradle.

the class RelativePathTest method prependNames.

@Test
public void prependNames() {
    RelativePath childPath = new RelativePath(false, "one", "two").prepend("three", "four");
    assertPathContains(childPath, false, "three", "four", "one", "two");
    childPath = new RelativePath(false, "one", "two").prepend();
    assertPathContains(childPath, false, "one", "two");
}
Also used : RelativePath(org.gradle.api.file.RelativePath) Test(org.junit.Test)

Example 3 with RelativePath

use of org.gradle.api.file.RelativePath in project gradle by gradle.

the class AbstractDirectoryWalker method walkDir.

@Override
public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) {
    File[] children = getChildren(file);
    if (children == null) {
        if (file.isDirectory() && !file.canRead()) {
            throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
        }
        // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
        throw new GradleException(String.format("Could not list contents of '%s'.", file));
    }
    List<FileVisitDetails> dirs = new ArrayList<FileVisitDetails>();
    for (int i = 0; !stopFlag.get() && i < children.length; i++) {
        File child = children[i];
        boolean isFile = child.isFile();
        RelativePath childPath = path.append(isFile, child.getName());
        FileVisitDetails details = new DefaultFileVisitDetails(child, childPath, stopFlag, fileSystem, fileSystem, !isFile);
        if (DirectoryFileTree.isAllowed(details, spec)) {
            if (isFile) {
                visitor.visitFile(details);
            } else {
                dirs.add(details);
            }
        }
    }
    // now handle dirs
    for (int i = 0; !stopFlag.get() && i < dirs.size(); i++) {
        FileVisitDetails dir = dirs.get(i);
        if (postfix) {
            walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
            visitor.visitDir(dir);
        } else {
            visitor.visitDir(dir);
            walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
        }
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) FileVisitDetails(org.gradle.api.file.FileVisitDetails) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) DefaultFileVisitDetails(org.gradle.api.internal.file.DefaultFileVisitDetails) File(java.io.File)

Example 4 with RelativePath

use of org.gradle.api.file.RelativePath in project zaproxy by zaproxy.

the class JFlexGenerator method generate.

private void generate(FileVisitDetails source, File baseOutputDir) {
    if (source.isDirectory()) {
        return;
    }
    RelativePath relPath = source.getRelativePath();
    List<String> args = new ArrayList<>();
    args.add("--encoding");
    args.add("UTF-8");
    args.add("--nobak");
    args.add("--quiet");
    args.add("-d");
    args.add(getOutputDir(baseOutputDir, relPath));
    args.add(source.getFile().getAbsolutePath());
    ExecResult result = getProject().javaexec(spec -> {
        spec.getMainClass().set("jflex.Main");
        spec.setClasspath(classpath).args(args).setStandardOutput(System.out).setErrorOutput(System.err).setWorkingDir(getWorkingDir(source.getFile(), relPath));
    });
    result.assertNormalExitValue();
}
Also used : RelativePath(org.gradle.api.file.RelativePath) ArrayList(java.util.ArrayList) ExecResult(org.gradle.process.ExecResult)

Example 5 with RelativePath

use of org.gradle.api.file.RelativePath in project gradle by gradle.

the class RenamingCopyAction method execute.

@Override
public void execute(FileCopyDetails fileCopyDetails) {
    RelativePath path = fileCopyDetails.getRelativePath();
    String newName = transformer.transform(path.getLastName());
    if (newName != null) {
        path = path.replaceLastName(newName);
        fileCopyDetails.setRelativePath(path);
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath)

Aggregations

RelativePath (org.gradle.api.file.RelativePath)25 File (java.io.File)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 FileVisitDetails (org.gradle.api.file.FileVisitDetails)5 DefaultFileVisitDetails (org.gradle.api.internal.file.DefaultFileVisitDetails)4 GradleException (org.gradle.api.GradleException)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Spec (org.gradle.api.specs.Spec)2 PatternSet (org.gradle.api.tasks.util.PatternSet)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1