Search in sources :

Example 1 with PluginExtensionLogger

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);
    }
}
Also used : PluginExtensionLogger(com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger) Optional(java.util.Optional) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension)

Example 2 with PluginExtensionLogger

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);
    }
}
Also used : PluginExtensionLogger(com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger) Action(org.gradle.api.Action) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibGradlePluginExtension(com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension)

Example 3 with PluginExtensionLogger

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);
    }
}
Also used : PluginExtensionLogger(com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger) Action(org.gradle.api.Action) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibGradlePluginExtension(com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension)

Example 4 with PluginExtensionLogger

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);
    }
}
Also used : PluginExtensionLogger(com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger) Optional(java.util.Optional) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension)

Aggregations

PluginExtensionLogger (com.google.cloud.tools.jib.plugins.common.PluginExtensionLogger)4 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)4 JibGradlePluginExtension (com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension)2 JibMavenPluginExtension (com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension)2 Optional (java.util.Optional)2 Action (org.gradle.api.Action)2