use of com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger in project jib by GoogleContainerTools.
the class MavenProjectProperties method runPluginExtension.
// Unchecked casting: "getExtraConfiguration()" (Optional<Object>) to Object<T> and "extension"
// (JibMavenPluginExtension<?>) to JibMavenPluginExtension<T> where T is the extension-defined
// config type (as requested by "JibMavenPluginExtension.getExtraConfigType()").
@SuppressWarnings({ "unchecked" })
private <T> ContainerBuildPlan runPluginExtension(Optional<Class<T>> extraConfigType, JibMavenPluginExtension<?> extension, ExtensionConfiguration config, ContainerBuildPlan buildPlan) throws JibPluginExtensionException {
Optional<T> extraConfig = Optional.empty();
Optional<Object> configs = config.getExtraConfiguration();
if (configs.isPresent()) {
if (!extraConfigType.isPresent()) {
throw new IllegalArgumentException("extension " + extension.getClass().getSimpleName() + " does not expect extension-specific configuration; remove the inapplicable " + "<pluginExtension><configuration> from pom.xml");
} else if (!extraConfigType.get().isInstance(configs.get())) {
throw new JibPluginExtensionException(extension.getClass(), "extension-specific <configuration> for " + extension.getClass().getSimpleName() + " is not of type " + extraConfigType.get().getName() + " but " + configs.get().getClass().getName() + "; specify the correct type with <pluginExtension><configuration " + "implementation=\"" + extraConfigType.get().getName() + "\">");
} else {
// configs is of type Optional, so this cast always succeeds
// without the isInstance() check above. (Note generic <T> is erased at runtime.)
extraConfig = (Optional<T>) configs;
}
}
try {
return ((JibMavenPluginExtension<T>) extension).extendContainerBuildPlan(buildPlan, config.getProperties(), extraConfig, new MavenExtensionData(project, session), new PluginExtensionLogger(this::log));
} catch (RuntimeException ex) {
throw new JibPluginExtensionException(extension.getClass(), "extension crashed: " + ex.getMessage(), ex);
}
}
use of com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger in project jib by GoogleContainerTools.
the class GradleProjectProperties method runPluginExtension.
// Unchecked casting: "getExtraConfiguration().get()" (Object) to Action<T> and "extension"
// (JibGradlePluginExtension<?>) to JibGradlePluginExtension<T> where T is the extension-defined
// config type (as requested by "JibGradlePluginExtension.getExtraConfigType()").
@SuppressWarnings({ "unchecked" })
private <T> ContainerBuildPlan runPluginExtension(Optional<Class<T>> extraConfigType, JibGradlePluginExtension<?> extension, ExtensionConfiguration config, ContainerBuildPlan buildPlan) throws JibPluginExtensionException {
T extraConfig = null;
Optional<Object> configs = config.getExtraConfiguration();
if (configs.isPresent()) {
if (!extraConfigType.isPresent()) {
throw new IllegalArgumentException("extension " + extension.getClass().getSimpleName() + " does not expect extension-specific configuration; remove the inapplicable " + "'pluginExtension.configuration' from Gradle build script");
} else {
// configs.get() is of type Action, so this cast always succeeds.
// (Note generic <T> is erased at runtime.)
Action<T> action = (Action<T>) configs.get();
extraConfig = project.getObjects().newInstance(extraConfigType.get(), project);
action.execute(extraConfig);
}
}
try {
return ((JibGradlePluginExtension<T>) extension).extendContainerBuildPlan(buildPlan, config.getProperties(), Optional.ofNullable(extraConfig), () -> project, new PluginExtensionLogger(this::log));
} catch (RuntimeException ex) {
throw new JibPluginExtensionException(extension.getClass(), "extension crashed: " + ex.getMessage(), ex);
}
}
use of com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger in project jib by google.
the class GradleProjectProperties method runPluginExtension.
// Unchecked casting: "getExtraConfiguration().get()" (Object) to Action<T> and "extension"
// (JibGradlePluginExtension<?>) to JibGradlePluginExtension<T> where T is the extension-defined
// config type (as requested by "JibGradlePluginExtension.getExtraConfigType()").
@SuppressWarnings({ "unchecked" })
private <T> ContainerBuildPlan runPluginExtension(Optional<Class<T>> extraConfigType, JibGradlePluginExtension<?> extension, ExtensionConfiguration config, ContainerBuildPlan buildPlan) throws JibPluginExtensionException {
T extraConfig = null;
Optional<Object> configs = config.getExtraConfiguration();
if (configs.isPresent()) {
if (!extraConfigType.isPresent()) {
throw new IllegalArgumentException("extension " + extension.getClass().getSimpleName() + " does not expect extension-specific configuration; remove the inapplicable " + "'pluginExtension.configuration' from Gradle build script");
} else {
// configs.get() is of type Action, so this cast always succeeds.
// (Note generic <T> is erased at runtime.)
Action<T> action = (Action<T>) configs.get();
extraConfig = project.getObjects().newInstance(extraConfigType.get(), project);
action.execute(extraConfig);
}
}
try {
return ((JibGradlePluginExtension<T>) extension).extendContainerBuildPlan(buildPlan, config.getProperties(), Optional.ofNullable(extraConfig), () -> project, new PluginExtensionLogger(this::log));
} catch (RuntimeException ex) {
throw new JibPluginExtensionException(extension.getClass(), "extension crashed: " + ex.getMessage(), ex);
}
}
use of com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger in project jib by google.
the class MavenProjectProperties method runPluginExtension.
// Unchecked casting: "getExtraConfiguration()" (Optional<Object>) to Object<T> and "extension"
// (JibMavenPluginExtension<?>) to JibMavenPluginExtension<T> where T is the extension-defined
// config type (as requested by "JibMavenPluginExtension.getExtraConfigType()").
@SuppressWarnings({ "unchecked" })
private <T> ContainerBuildPlan runPluginExtension(Optional<Class<T>> extraConfigType, JibMavenPluginExtension<?> extension, ExtensionConfiguration config, ContainerBuildPlan buildPlan) throws JibPluginExtensionException {
Optional<T> extraConfig = Optional.empty();
Optional<Object> configs = config.getExtraConfiguration();
if (configs.isPresent()) {
if (!extraConfigType.isPresent()) {
throw new IllegalArgumentException("extension " + extension.getClass().getSimpleName() + " does not expect extension-specific configuration; remove the inapplicable " + "<pluginExtension><configuration> from pom.xml");
} else if (!extraConfigType.get().isInstance(configs.get())) {
throw new JibPluginExtensionException(extension.getClass(), "extension-specific <configuration> for " + extension.getClass().getSimpleName() + " is not of type " + extraConfigType.get().getName() + " but " + configs.get().getClass().getName() + "; specify the correct type with <pluginExtension><configuration " + "implementation=\"" + extraConfigType.get().getName() + "\">");
} else {
// configs is of type Optional, so this cast always succeeds
// without the isInstance() check above. (Note generic <T> is erased at runtime.)
extraConfig = (Optional<T>) configs;
}
}
try {
return ((JibMavenPluginExtension<T>) extension).extendContainerBuildPlan(buildPlan, config.getProperties(), extraConfig, new MavenExtensionData(project, session), new PluginExtensionLogger(this::log));
} catch (RuntimeException ex) {
throw new JibPluginExtensionException(extension.getClass(), "extension crashed: " + ex.getMessage(), ex);
}
}
Aggregations