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")));
}
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")));
}
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;
}
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();
}
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();
}
Aggregations