Search in sources :

Example 6 with ExtensionLogger

use of com.google.cloud.tools.jib.plugins.extension.ExtensionLogger in project jib-extensions by GoogleContainerTools.

the class JibQuarkusExtension method extendContainerBuildPlan.

@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Void> config, MavenData mavenData, ExtensionLogger logger) throws JibPluginExtensionException {
    try {
        logger.log(LogLevel.LIFECYCLE, "Running Quarkus Jib extension");
        readJibConfigurations(mavenData.getMavenProject());
        Build build = mavenData.getMavenProject().getBuild();
        Path outputDirectory = Paths.get(build.getDirectory());
        Path jar = outputDirectory.resolve(build.getFinalName() + "-runner.jar");
        if (!Files.isRegularFile(jar)) {
            throw new JibPluginExtensionException(getClass(), jar + " doesn't exist; did you run the Qaurkus Maven plugin " + "('compile' and 'quarkus:build' Maven goals)?");
        }
        ContainerBuildPlan.Builder planBuilder = buildPlan.toBuilder();
        planBuilder.setLayers(Collections.emptyList());
        // dependency layers
        addDependencyLayers(mavenData.getMavenSession(), planBuilder, outputDirectory.resolve("lib"));
        // Quarkus runner JAR layer
        AbsoluteUnixPath appRootJar = appRoot.resolve("app.jar");
        FileEntriesLayer jarLayer = FileEntriesLayer.builder().setName("quarkus jar").addEntry(jar, appRootJar).build();
        planBuilder.addLayer(jarLayer);
        // Preserve extra directories layers.
        String extraFilesLayerName = JavaContainerBuilder.LayerType.EXTRA_FILES.getName();
        buildPlan.getLayers().stream().filter(layer -> layer.getName().startsWith(extraFilesLayerName)).forEach(planBuilder::addLayer);
        // set entrypoint
        List<String> entrypoint = new ArrayList<>();
        entrypoint.add("java");
        entrypoint.addAll(jvmFlags);
        entrypoint.add("-jar");
        entrypoint.add(appRootJar.toString());
        planBuilder.setEntrypoint(entrypoint);
        return planBuilder.build();
    } catch (IOException ex) {
        throw new JibPluginExtensionException(getClass(), Verify.verifyNotNull(ex.getMessage()), ex);
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension) Arrays(java.util.Arrays) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ExtensionLogger(com.google.cloud.tools.jib.plugins.extension.ExtensionLogger) Build(org.apache.maven.model.Build) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ArrayList(java.util.ArrayList) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) Artifact(org.apache.maven.artifact.Artifact) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Verify(com.google.common.base.Verify) MavenSession(org.apache.maven.execution.MavenSession) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) LogLevel(com.google.cloud.tools.jib.plugins.extension.ExtensionLogger.LogLevel) File(java.io.File) Objects(java.util.Objects) List(java.util.List) Plugin(org.apache.maven.model.Plugin) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) MavenData(com.google.cloud.tools.jib.maven.extension.MavenData) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Collections(java.util.Collections) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) Build(org.apache.maven.model.Build) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Aggregations

ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)6 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)6 ExtensionLogger (com.google.cloud.tools.jib.plugins.extension.ExtensionLogger)6 LogLevel (com.google.cloud.tools.jib.plugins.extension.ExtensionLogger.LogLevel)6 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)6 Path (java.nio.file.Path)6 Collections (java.util.Collections)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Verify (com.google.common.base.Verify)5 Paths (java.nio.file.Paths)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 JibMavenPluginExtension (com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension)4 MavenData (com.google.cloud.tools.jib.maven.extension.MavenData)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)3 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)3 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)3