Search in sources :

Example 6 with ExtensionConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by google.

the class GradleProjectProperties method runPluginExtensions.

@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
    if (extensionConfigs.isEmpty()) {
        log(LogEvent.debug("No Jib plugin extensions configured to load"));
        return jibContainerBuilder;
    }
    List<JibGradlePluginExtension<?>> loadedExtensions = extensionLoader.get();
    JibGradlePluginExtension<?> extension = null;
    ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
    try {
        for (ExtensionConfiguration config : extensionConfigs) {
            extension = findConfiguredExtension(loadedExtensions, config);
            log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
            buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
            // to validate image reference
            ImageReference.parse(buildPlan.getBaseImage());
        }
        return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
    } catch (InvalidImageReferenceException ex) {
        throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibGradlePluginExtension(com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension) ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Example 7 with ExtensionConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by google.

the class MavenProjectProperties method runPluginExtensions.

@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
    if (extensionConfigs.isEmpty()) {
        log(LogEvent.debug("No Jib plugin extensions configured to load"));
        return jibContainerBuilder;
    }
    // Add the injected extensions at first to prefer them over the ones from JDK service
    // loader.
    // Extensions might support both approaches (injection and JDK service loader) at the same
    // time for compatibility reasons.
    List<JibMavenPluginExtension<?>> loadedExtensions = new ArrayList<>(injectedExtensions);
    loadedExtensions.addAll(extensionLoader.get());
    JibMavenPluginExtension<?> extension = null;
    ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
    try {
        for (ExtensionConfiguration config : extensionConfigs) {
            extension = findConfiguredExtension(loadedExtensions, config);
            log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
            buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
            // to validate image reference
            ImageReference.parse(buildPlan.getBaseImage());
        }
        return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
    } catch (InvalidImageReferenceException ex) {
        throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension) ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) ArrayList(java.util.ArrayList) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Example 8 with ExtensionConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by google.

the class MavenProjectPropertiesExtensionTest method testRunPluginExtensions_wrongExtraConfigType.

@Test
public void testRunPluginExtensions_wrongExtraConfigType() {
    FooExtension extension = new FooExtension((buildPlan, properties, extraConfig, mavenData, logger) -> buildPlan);
    loadedExtensions = Arrays.asList(extension);
    ExtensionConfiguration extensionConfig = new BaseExtensionConfig<>(FooExtension.class.getName(), Collections.emptyMap(), "string <configuration>");
    try {
        mavenProjectProperties.runPluginExtensions(Arrays.asList(extensionConfig), containerBuilder);
        Assert.fail();
    } catch (JibPluginExtensionException ex) {
        Assert.assertEquals(FooExtension.class, ex.getExtensionClass());
        Assert.assertEquals("extension-specific <configuration> for FooExtension is not of type com.google.cloud" + ".tools.jib.maven.MavenProjectPropertiesExtensionTest$ExtensionDefinedFooConfig " + "but java.lang.String; specify the correct type with <pluginExtension>" + "<configuration implementation=\"com.google.cloud.tools.jib.maven." + "MavenProjectPropertiesExtensionTest$ExtensionDefinedFooConfig\">", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) Test(org.junit.Test)

Example 9 with ExtensionConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by GoogleContainerTools.

the class GradleProjectPropertiesExtensionTest method testRunPluginExtensions_ignoreUnexpectedExtraConfig.

@Test
public void testRunPluginExtensions_ignoreUnexpectedExtraConfig() throws JibPluginExtensionException {
    BaseExtension<Void> extension = new BaseExtension<>((buildPlan, properties, extraConfig, mavenData, logger) -> buildPlan, null);
    loadedExtensions = Arrays.asList(extension);
    ExtensionConfiguration extensionConfig = new BaseExtensionConfig<>(BaseExtension.class.getName(), Collections.emptyMap(), (ignored) -> {
    });
    try {
        gradleProjectProperties.runPluginExtensions(Arrays.asList(extensionConfig), containerBuilder);
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        Assert.assertEquals("extension BaseExtension does not expect extension-specific configuration; remove the " + "inapplicable 'pluginExtension.configuration' from Gradle build script", ex.getMessage());
    }
}
Also used : ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) Test(org.junit.Test)

Example 10 with ExtensionConfiguration

use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by GoogleContainerTools.

the class GradleProjectProperties method runPluginExtensions.

@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
    if (extensionConfigs.isEmpty()) {
        log(LogEvent.debug("No Jib plugin extensions configured to load"));
        return jibContainerBuilder;
    }
    List<JibGradlePluginExtension<?>> loadedExtensions = extensionLoader.get();
    JibGradlePluginExtension<?> extension = null;
    ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
    try {
        for (ExtensionConfiguration config : extensionConfigs) {
            extension = findConfiguredExtension(loadedExtensions, config);
            log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
            buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
            // to validate image reference
            ImageReference.parse(buildPlan.getBaseImage());
        }
        return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
    } catch (InvalidImageReferenceException ex) {
        throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibGradlePluginExtension(com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension) ExtensionConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Aggregations

ExtensionConfiguration (com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration)10 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)6 Test (org.junit.Test)6 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)4 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)4 JibGradlePluginExtension (com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension)2 JibMavenPluginExtension (com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension)2 ArrayList (java.util.ArrayList)2