use of java.nio.file.attribute.BasicFileAttributes in project bazel by bazelbuild.
the class VanillaJavaBuilder method getSources.
/** Returns the sources to compile, including any source jar entries. */
private ImmutableList<JavaFileObject> getSources(OptionsParser optionsParser, StandardJavaFileManager fileManager) throws IOException {
final ImmutableList.Builder<JavaFileObject> sources = ImmutableList.builder();
sources.addAll(fileManager.getJavaFileObjectsFromStrings(optionsParser.getSourceFiles()));
for (String sourceJar : optionsParser.getSourceJars()) {
for (final Path root : getJarFileSystem(Paths.get(sourceJar)).getRootDirectories()) {
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
if (path.getFileName().toString().endsWith(".java")) {
sources.add(new SourceJarFileObject(root, path));
}
return FileVisitResult.CONTINUE;
}
});
}
}
return sources.build();
}
use of java.nio.file.attribute.BasicFileAttributes in project bazel by bazelbuild.
the class SimpleJavaLibraryBuilder method buildJar.
public void buildJar(JavaLibraryBuildRequest build) throws IOException {
JarCreator jar = new JarCreator(build.getOutputJar());
try {
jar.setNormalize(true);
jar.setCompression(build.compressJar());
for (String resourceJar : build.getResourceJars()) {
for (Path root : getJarFileSystem(Paths.get(resourceJar)).getRootDirectories()) {
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
// TODO(b/28452451): omit directories entries from jar files
if (dir.getNameCount() > 0) {
jar.addEntry(root.relativize(dir).toString(), dir);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
jar.addEntry(root.relativize(path).toString(), path);
return FileVisitResult.CONTINUE;
}
});
}
}
jar.addDirectory(build.getClassDir());
jar.addRootEntries(build.getRootResourceFiles());
addResourceEntries(jar, build.getResourceFiles());
addMessageEntries(jar, build.getMessageFiles());
} finally {
jar.execute();
}
}
use of java.nio.file.attribute.BasicFileAttributes in project bazel by bazelbuild.
the class JavacTurbineTest method compileLib.
private void compileLib(Path jar, Collection<Path> classpath, Iterable<? extends JavaFileObject> units) throws IOException {
final Path outdir = temp.newFolder().toPath();
JavacFileManager fm = new JavacFileManager(new Context(), false, UTF_8);
fm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Collections.singleton(outdir));
fm.setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
List<String> options = Arrays.asList("-d", outdir.toString());
JavacTool tool = JavacTool.create();
JavacTask task = tool.getTask(new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), fm, null, options, null, units);
assertThat(task.call()).isTrue();
try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(jar))) {
Files.walkFileTree(outdir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
JarEntry je = new JarEntry(outdir.relativize(path).toString());
jos.putNextEntry(je);
Files.copy(path, jos);
return FileVisitResult.CONTINUE;
}
});
}
}
use of java.nio.file.attribute.BasicFileAttributes in project cryptomator by cryptomator.
the class UpgradeVersion4to5 method upgrade.
@Override
protected void upgrade(Vault vault, Cryptor cryptor) throws UpgradeFailedException {
Path dataDir = vault.getPath().resolve("d");
if (!Files.isDirectory(dataDir)) {
// empty vault. no migration needed.
return;
}
try {
Files.walkFileTree(dataDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (BASE32_PATTERN.matcher(file.getFileName().toString()).find() && attrs.size() > cryptor.fileHeaderCryptor().headerSize()) {
migrate(file, attrs, cryptor);
} else {
LOG.info("Skipping irrelevant file {}.", file);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
LOG.error("Migration failed.", e);
throw new UpgradeFailedException(localization.getString("upgrade.version4to5.err.io"));
}
LOG.info("Migration finished.");
}
use of java.nio.file.attribute.BasicFileAttributes in project che by eclipse.
the class Resource method accept.
@Override
public void accept(final IResourceProxyVisitor visitor, final int depth, final int memberFlags) throws CoreException {
java.io.File file = workspace.getFile(getFullPath());
int maxDepth = depth == IResource.DEPTH_INFINITE ? Integer.MAX_VALUE : depth;
try {
final ResourceProxy resourceProxy = new ResourceProxy();
final int workspacePath = workspace.getAbsoluteWorkspacePath().length();
Files.walkFileTree(file.toPath(), Collections.<FileVisitOption>emptySet(), maxDepth, new FileVisitor<java.nio.file.Path>() {
@Override
public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs) throws IOException {
FileVisitResult result = FileVisitResult.CONTINUE;
try {
String string = file.toString();
IPath path = new Path(string.substring(workspacePath));
resourceProxy.info = workspace.getResourceInfo(path);
resourceProxy.fullPath = path;
boolean shouldContinue = true;
switch(depth) {
case DEPTH_ZERO:
shouldContinue = false;
break;
case DEPTH_ONE:
shouldContinue = !Resource.this.path.equals(path.removeLastSegments(1));
break;
case DEPTH_INFINITE:
shouldContinue = true;
break;
}
boolean visit = visitor.visit(resourceProxy) && shouldContinue;
result = visit ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE;
} catch (CoreException e) {
throw new WrappedRuntimeException(e);
} finally {
resourceProxy.reset();
}
return result;
}
@Override
public FileVisitResult visitFileFailed(java.nio.file.Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.getPluginId(), e.getMessage(), e));
}
}
Aggregations