use of com.google.devtools.build.buildjar.jarhelper.JarCreator in project bazel by bazelbuild.
the class GenClass method writeOutputJar.
/** Writes the generated class files to the output jar. */
private static void writeOutputJar(GenClassOptions options) throws IOException {
JarCreator output = new JarCreator(options.outputJar().toString());
output.setCompression(true);
output.setNormalize(true);
output.addDirectory(options.tempDir().toString());
output.execute();
}
use of com.google.devtools.build.buildjar.jarhelper.JarCreator 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 com.google.devtools.build.buildjar.jarhelper.JarCreator in project bazel by bazelbuild.
the class SimpleJavaLibraryBuilder method buildGensrcJar.
public void buildGensrcJar(JavaLibraryBuildRequest build) throws IOException {
JarCreator jar = new JarCreator(build.getGeneratedSourcesOutputJar());
try {
jar.setNormalize(true);
jar.setCompression(build.compressJar());
jar.addDirectory(build.getSourceGenDir());
} finally {
jar.execute();
}
}
Aggregations