Search in sources :

Example 6 with JarCreator

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();
}
Also used : JarCreator(com.google.devtools.build.buildjar.jarhelper.JarCreator)

Example 7 with JarCreator

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();
    }
}
Also used : Path(java.nio.file.Path) JarCreator(com.google.devtools.build.buildjar.jarhelper.JarCreator) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with JarCreator

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();
    }
}
Also used : JarCreator(com.google.devtools.build.buildjar.jarhelper.JarCreator)

Aggregations

JarCreator (com.google.devtools.build.buildjar.jarhelper.JarCreator)8 Path (java.nio.file.Path)2 ResourceJarBuilder (com.google.devtools.build.buildjar.resourcejar.ResourceJarBuilder)1 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Instrumenter (org.jacoco.core.instr.Instrumenter)1 OfflineInstrumentationAccessGenerator (org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator)1