use of java.nio.file.PathMatcher in project copybara by google.
the class UnionGlob method relativeTo.
@Override
public PathMatcher relativeTo(Path base) {
PathMatcher leftMatcher = lval.relativeTo(base);
PathMatcher rightMatcher = rval.relativeTo(base);
return path -> leftMatcher.matches(path) || rightMatcher.matches(path);
}
use of java.nio.file.PathMatcher in project archiva by apache.
the class AbstractArchivaRepositoryScanningTaskExecutorTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
Path sourceRepoDir = Paths.get("src/test/repositories/default-repository");
repoDir = Paths.get("target/default-repository");
org.apache.archiva.common.utils.FileUtils.deleteDirectory(repoDir);
assertFalse("Default Test Repository should not exist.", Files.exists(repoDir));
Files.createDirectories(repoDir);
FileUtils.copyDirectoryStructure(sourceRepoDir.toFile(), repoDir.toFile());
// set the timestamps to a time well in the past
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
try (Stream<Path> stream = Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS)) {
stream.forEach(path -> {
try {
Files.setLastModifiedTime(path, FileTime.fromMillis(cal.getTimeInMillis()));
} catch (IOException e) {
e.printStackTrace();
}
});
}
PathMatcher m = FileSystems.getDefault().getPathMatcher("glob:**/.svn");
Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory).sorted(Comparator.reverseOrder()).filter(path -> m.matches(path)).forEach(path -> org.apache.archiva.common.utils.FileUtils.deleteQuietly(path));
assertTrue("Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir));
assertNotNull(archivaConfig);
// Create it
ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
repositoryConfiguration.setId(TEST_REPO_ID);
repositoryConfiguration.setName("Test Repository");
repositoryConfiguration.setLocation(repoDir.toAbsolutePath().toString());
for (ManagedRepository repo : repositoryRegistry.getManagedRepositories()) {
repositoryRegistry.removeRepository(repo);
}
repositoryRegistry.putRepository(repositoryConfiguration);
metadataRepository = mock(MetadataRepository.class);
factory.setRepository(metadataRepository);
}
use of java.nio.file.PathMatcher in project statecharts by Yakindu.
the class PomXMLGetVersionVisitor method visitFile.
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes arg1) throws IOException {
FileSystem fileSystem = FileSystems.getDefault();
PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern);
if (pathMatcher.matches(path.getFileName())) {
System.out.println("File: " + path.toAbsolutePath());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(path.toFile());
XPathFactory xpathfactory = XPathFactory.newInstance();
XPath xpath = xpathfactory.newXPath();
XPathExpression expr = xpath.compile("//project[1]/version/text()");
Object result = expr.evaluate(doc, XPathConstants.STRING);
if (result instanceof String && !((String) result).isEmpty()) {
this.version = result.toString();
} else {
// try in parent tag
expr = xpath.compile("//project[1]/parent/version/text()");
result = expr.evaluate(doc, XPathConstants.STRING);
if (result instanceof String && !((String) result).isEmpty()) {
this.version = result.toString();
} else {
System.out.println("Error: Unable to find version within pom.xmls.");
version = null;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return FileVisitResult.TERMINATE;
}
return FileVisitResult.CONTINUE;
}
use of java.nio.file.PathMatcher in project statecharts by Yakindu.
the class VersionUpdateVisitor method visitFile.
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes arg1) throws IOException {
FileSystem fileSystem = FileSystems.getDefault();
PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern);
if (pathMatcher.matches(path.getFileName())) {
searchList.add(path);
String charset = Charset.defaultCharset().name();
// System.out.println(charset);
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll(this.searchPattern, this.replacePattern);
Files.write(path, content.getBytes(charset));
fileCount++;
}
return FileVisitResult.CONTINUE;
}
use of java.nio.file.PathMatcher in project candlepin by candlepin.
the class SchemaCompatibilityTest method gatherChangesets.
private List<File> gatherChangesets() throws Exception {
final PathMatcher xmlMatcher = FileSystems.getDefault().getPathMatcher("glob:*.xml");
Path resources = Paths.get("src", "main", "resources", "db", "changelog");
final List<File> matches = new ArrayList<>();
Files.walkFileTree(resources, new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (xmlMatcher.matches(file.getFileName())) {
matches.add(file.toFile());
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
throw new IOException("Could not visit" + file);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
return matches;
}
Aggregations