Search in sources :

Example 41 with JibPluginExtensionException

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

the class JibLayerFilterExtension method getParentDependencies.

private List<Dependency> getParentDependencies(MavenData mavenData) throws JibPluginExtensionException {
    if (mavenData.getMavenProject().getParent() == null) {
        throw new JibPluginExtensionException(getClass(), "Try to get parent dependencies, but project has no parent.");
    }
    if (dependencyResolver == null) {
        throw new JibPluginExtensionException(getClass(), "Try to get parent dependencies, but ProjectDependenciesResolver is null. Please use a " + "more recent Jib plugin version to fix this.");
    }
    try {
        DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(mavenData.getMavenProject().getParent(), mavenData.getMavenSession().getRepositorySession());
        request.setResolutionFilter(new ScopeDependencyFilter("test"));
        DependencyResolutionResult resolutionResult = dependencyResolver.resolve(request);
        return resolutionResult.getDependencies();
    } catch (DependencyResolutionException ex) {
        throw new JibPluginExtensionException(getClass(), "Error when getting parent dependencies", ex);
    }
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest)

Example 42 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException 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)

Example 43 with JibPluginExtensionException

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

the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_noQuarkusRunnerJar.

@Test
public void testExtendContainerBuildPlan_noQuarkusRunnerJar() throws IOException {
    Files.delete(tempFolder.getRoot().toPath().resolve("target").resolve("my-app-runner.jar"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    try {
        new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), mavenData, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibQuarkusExtension.class, ex.getExtensionClass());
        assertThat(ex.getMessage(), endsWith(File.separator + "my-app-runner.jar doesn't exist; did you run the Qaurkus Maven plugin " + "('compile' and 'quarkus:build' Maven goals)?"));
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 44 with JibPluginExtensionException

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

the class JibNativeImageExtensionTest method testExecutableNotFound.

@Test
public void testExecutableNotFound() {
    Map<String, String> properties = Collections.singletonMap("imageName", "theExecutable");
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    try {
        new JibNativeImageExtension().extendContainerBuildPlan(buildPlan, properties, Optional.empty(), mavenData, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals("Native-image executable does not exist or not a file: " + tempFolder.getRoot().toPath().resolve("theExecutable") + "\nDid you run the 'native-image:native-image' goal?", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 45 with JibPluginExtensionException

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

the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_noQuarkusRunnerJar.

@Test
public void testExtendContainerBuildPlan_noQuarkusRunnerJar() throws IOException {
    Files.delete(tempFolder.getRoot().toPath().resolve("build").resolve("my-app-runner.jar"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    try {
        new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), gradleData, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibQuarkusExtension.class, ex.getExtensionClass());
        assertThat(ex.getMessage(), endsWith(File.separator + "my-app-runner.jar doesn't exist; did you run the Qaurkus Gradle plugin " + "('quarkusBuild' task)?"));
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Aggregations

JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)45 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)22 Optional (java.util.Optional)20 Test (org.junit.Test)18 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)16 IOException (java.io.IOException)14 CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)12 TempDirectoryProvider (com.google.cloud.tools.jib.filesystem.TempDirectoryProvider)12 BuildStepsExecutionException (com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException)12 ExtraDirectoryNotFoundException (com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException)12 IncompatibleBaseImageJavaVersionException (com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException)12 InvalidAppRootException (com.google.cloud.tools.jib.plugins.common.InvalidAppRootException)12 InvalidContainerVolumeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException)12 InvalidContainerizingModeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)12 InvalidCreationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException)12 InvalidFilesModificationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException)12 InvalidPlatformException (com.google.cloud.tools.jib.plugins.common.InvalidPlatformException)12 InvalidWorkingDirectoryException (com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException)12 MainClassInferenceException (com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)12 GlobalConfig (com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig)12