use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib by GoogleContainerTools.
the class BuildDockerMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
checkJibVersion();
if (MojoCommon.shouldSkipJibExecution(this)) {
return;
}
Path dockerExecutable = getDockerClientExecutable();
boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
if (!isDockerInstalled) {
throw new MojoExecutionException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
}
MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
} catch (InvalidAppRootException ex) {
throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidContainerizingModeException ex) {
throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
} catch (InvalidWorkingDirectoryException ex) {
throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidPlatformException ex) {
throw new MojoExecutionException("<from><platforms> contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
} catch (InvalidContainerVolumeException ex) {
throw new MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
} catch (InvalidFilesModificationTimeException ex) {
throw new MojoExecutionException("<container><filesModificationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
} catch (InvalidCreationTimeException ex) {
throw new MojoExecutionException("<container><creationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
} catch (JibPluginExtensionException ex) {
String extensionName = ex.getExtensionClass().getName();
throw new MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
} catch (IncompatibleBaseImageJavaVersionException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
} catch (InvalidImageReferenceException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
} catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (BuildStepsExecutionException ex) {
throw new MojoExecutionException(ex.getMessage(), ex.getCause());
} catch (ExtraDirectoryNotFoundException ex) {
throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
} finally {
tempDirectoryProvider.close();
MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
getLog().info("");
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib by GoogleContainerTools.
the class BuildTarMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
checkJibVersion();
if (MojoCommon.shouldSkipJibExecution(this)) {
return;
}
MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
PluginConfigurationProcessor.createJibBuildRunnerForTarImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
} catch (InvalidAppRootException ex) {
throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidContainerizingModeException ex) {
throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
} catch (InvalidWorkingDirectoryException ex) {
throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidPlatformException ex) {
throw new MojoExecutionException("<from><platforms> contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
} catch (InvalidContainerVolumeException ex) {
throw new MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
} catch (InvalidFilesModificationTimeException ex) {
throw new MojoExecutionException("<container><filesModificationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
} catch (InvalidCreationTimeException ex) {
throw new MojoExecutionException("<container><creationTime> should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
} catch (JibPluginExtensionException ex) {
String extensionName = ex.getExtensionClass().getName();
throw new MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
} catch (IncompatibleBaseImageJavaVersionException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
} catch (InvalidImageReferenceException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
} catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (BuildStepsExecutionException ex) {
throw new MojoExecutionException(ex.getMessage(), ex.getCause());
} catch (ExtraDirectoryNotFoundException ex) {
throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
} finally {
tempDirectoryProvider.close();
MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
getLog().info("");
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException 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.extension.JibPluginExtensionException 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.extension.JibPluginExtensionException 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);
}
}
Aggregations