use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by GoogleContainerTools.
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);
}
}
use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by GoogleContainerTools.
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());
}
}
use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by GoogleContainerTools.
the class MavenProjectPropertiesExtensionTest 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(), "unwanted <configuration>");
try {
mavenProjectProperties.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 pom.xml", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by google.
the class MavenProjectPropertiesExtensionTest 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(), "unwanted <configuration>");
try {
mavenProjectProperties.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 pom.xml", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtensionConfiguration in project jib by google.
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());
}
}
Aggregations