Search in sources :

Example 51 with PathMatcher

use of java.nio.file.PathMatcher in project fabric8 by jboss-fuse.

the class MatchersTest method testMavenGroupId.

@Test
public void testMavenGroupId() {
    PathMatcher matcher = Maven.parse("mvn:groupId:org.apache,org.foo");
    assertTrue(matcher.matches(Paths.get("org")));
    assertTrue(matcher.matches(Paths.get("org/apache")));
    assertTrue(matcher.matches(Paths.get("org/apache/foo.jar")));
    assertTrue(matcher.matches(Paths.get("org/foo")));
    assertTrue(matcher.matches(Paths.get("org/foo/foo/bar.jar")));
    assertFalse(matcher.matches(Paths.get("org/jboss")));
    assertFalse(matcher.matches(Paths.get("org/jboss/foo.jar")));
    assertFalse(matcher.matches(Paths.get("com/jboss/foo.jar")));
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 52 with PathMatcher

use of java.nio.file.PathMatcher in project fabric8 by jboss-fuse.

the class MatchersTest method testLogical.

@Test
public void testLogical() {
    PathMatcher matcher = Logical.parse("log:(org/{apache,foo}/** or **) and(not **example**)");
    assertTrue(matcher.matches(Paths.get("org/foo/foo.java")));
    assertFalse(matcher.matches(Paths.get("org/foo/example.java")));
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 53 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class WorkflowRunHelper method doMigrate.

private ImmutableList<DestinationEffect> doMigrate(O rev, @Nullable O lastRev, Console processConsole, Metadata metadata, Changes changes, @Nullable String destinationBaseline, @Nullable O changeIdentityRevision) throws IOException, RepoException, ValidationException {
    Path checkoutDir = workdir.resolve("checkout");
    try (ProfilerTask ignored = profiler().start("prepare_workdir")) {
        processConsole.progress("Cleaning working directory");
        if (Files.exists(workdir)) {
            FileUtil.deleteRecursively(workdir);
        }
        Files.createDirectories(checkoutDir);
    }
    processConsole.progress("Checking out the change");
    try (ProfilerTask ignored = profiler().start("origin.checkout", profiler().taskType(workflow.getOrigin().getType()))) {
        originReader.checkout(rev, checkoutDir);
    }
    // Remove excluded origin files.
    PathMatcher originFiles = workflow.getOriginFiles().relativeTo(checkoutDir);
    processConsole.progress("Removing excluded origin files");
    int deleted = FileUtil.deleteFilesRecursively(checkoutDir, FileUtil.notPathMatcher(originFiles));
    if (deleted != 0) {
        processConsole.info(String.format("Removed %d files from workdir that do not match origin_files", deleted));
    }
    Path originCopy = null;
    if (workflow.getReverseTransformForCheck() != null) {
        try (ProfilerTask ignored = profiler().start("reverse_copy")) {
            workflow.getConsole().progress("Making a copy or the workdir for reverse checking");
            originCopy = Files.createDirectories(workdir.resolve("origin"));
            FileUtil.copyFilesRecursively(checkoutDir, originCopy, FAIL_OUTSIDE_SYMLINKS);
        }
    }
    TransformWork transformWork = new TransformWork(checkoutDir, metadata, changes, workflow.getConsole(), new MigrationInfo(getOriginLabelName(), writer), resolvedRef).withLastRev(lastRev).withCurrentRev(rev);
    try (ProfilerTask ignored = profiler().start("transforms")) {
        workflow.getTransformation().transform(transformWork);
    }
    if (workflow.getReverseTransformForCheck() != null) {
        workflow.getConsole().progress("Checking that the transformations can be reverted");
        Path reverse;
        try (ProfilerTask ignored = profiler().start("reverse_copy")) {
            reverse = Files.createDirectories(workdir.resolve("reverse"));
            FileUtil.copyFilesRecursively(checkoutDir, reverse, FAIL_OUTSIDE_SYMLINKS);
        }
        try (ProfilerTask ignored = profiler().start("reverse_transform")) {
            workflow.getReverseTransformForCheck().transform(new TransformWork(reverse, new Metadata(transformWork.getMessage(), transformWork.getAuthor()), changes, workflow.getConsole(), new MigrationInfo(/*originLabel=*/
            null, null), resolvedRef));
        }
        String diff;
        try {
            diff = new String(DiffUtil.diff(originCopy, reverse, workflow.isVerbose(), workflow.getGeneralOptions().getEnvironment()), StandardCharsets.UTF_8);
        } catch (InsideGitDirException e) {
            throw new ValidationException("Cannot use 'reversible_check = True' because Copybara temporary directory (%s) is" + " inside a git directory (%s). Please remove the git repository or use %s flag.", e.getPath(), e.getGitDirPath(), OUTPUT_ROOT_FLAG);
        }
        if (!diff.trim().isEmpty()) {
            workflow.getConsole().error("Non reversible transformations:\n" + DiffUtil.colorize(workflow.getConsole(), diff));
            throw new ValidationException("Workflow '%s' is not reversible", workflow.getName());
        }
    }
    workflow.getConsole().progress("Checking that destination_files covers all files in transform result");
    new ValidateDestinationFilesVisitor(workflow.getDestinationFiles(), checkoutDir).verifyFilesToWrite();
    // TODO(malcon): Pass metadata object instead
    TransformResult transformResult = new TransformResult(checkoutDir, rev, transformWork.getAuthor(), transformWork.getMessage(), resolvedRef, workflow.getName(), changes, rawSourceRef);
    if (destinationBaseline != null) {
        transformResult = transformResult.withBaseline(destinationBaseline);
    }
    transformResult = transformResult.withAskForConfirmation(workflow.isAskForConfirmation()).withIdentity(workflow.getMigrationIdentity(changeIdentityRevision, transformWork));
    ImmutableList<DestinationEffect> result;
    try (ProfilerTask ignored = profiler().start("destination.write", profiler().taskType(workflow.getDestination().getType()))) {
        result = writer.write(transformResult, processConsole);
    }
    Verify.verifyNotNull(result, "Destination returned a null result.");
    Verify.verify(!result.isEmpty(), "Destination " + writer + " returned an empty set of effects");
    return result;
}
Also used : Path(java.nio.file.Path) ValidationException(com.google.copybara.exception.ValidationException) InsideGitDirException(com.google.copybara.util.InsideGitDirException) PathMatcher(java.nio.file.PathMatcher) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask)

Example 54 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method testSimpleIncludeWithExclusion.

@Test
public void testSimpleIncludeWithExclusion() throws IOException, ValidationException, RepoException {
    PathMatcher pathMatcher = createPathMatcher("glob(['b*','foo'], exclude =['baz'])");
    assertThat(pathMatcher.matches(workdir.resolve("foo"))).isTrue();
    assertThat(pathMatcher.matches(workdir.resolve("bar"))).isTrue();
    assertThat(pathMatcher.matches(workdir.resolve("baz"))).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 55 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method unionTest.

@Test
public void unionTest() throws Exception {
    Glob glob = parseGlob("glob(['foo/**', 'bar/**']) + glob(['baz/**'])");
    assertThat(glob.roots()).containsExactly("foo", "bar", "baz");
    PathMatcher matcher = glob.relativeTo(workdir);
    assertThat(matcher.matches(workdir.resolve("foo/a"))).isTrue();
    assertThat(matcher.matches(workdir.resolve("bar/a"))).isTrue();
    assertThat(matcher.matches(workdir.resolve("baz/a"))).isTrue();
    assertThat(matcher.matches(workdir.resolve("other"))).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Glob.createGlob(com.google.copybara.util.Glob.createGlob) Test(org.junit.Test)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5