Search in sources :

Example 1 with MavenProjectProperties

use of com.google.cloud.tools.jib.maven.MavenProjectProperties in project jib by GoogleContainerTools.

the class SyncMapMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    checkJibVersion();
    if (MojoCommon.shouldSkipJibExecution(this)) {
        return;
    }
    // add check that means this is only for jars
    if (!"jar".equals(getProject().getPackaging())) {
        throw new MojoExecutionException("Skaffold sync is currently only available for 'jar' style Jib projects, but the packaging of " + getProject().getArtifactId() + " is '" + getProject().getPackaging() + "'");
    }
    // add check for exploded containerization
    try {
        if (!ContainerizingMode.EXPLODED.equals(ContainerizingMode.from(getContainerizingMode()))) {
            throw new MojoExecutionException("Skaffold sync is currently only available for Jib projects in 'exploded' containerizing mode, but the containerizing mode of " + getProject().getArtifactId() + " is '" + getContainerizingMode() + "'");
        }
    } catch (InvalidContainerizingModeException ex) {
        throw new MojoExecutionException("Invalid containerizing mode", ex);
    }
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
        MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
        MavenRawConfiguration configuration = new MavenRawConfiguration(this);
        try {
            String syncMapJson = PluginConfigurationProcessor.getSkaffoldSyncMap(configuration, projectProperties, skaffold.sync.excludes.stream().map(File::toPath).map(Path::toAbsolutePath).collect(Collectors.toSet()));
            System.out.println();
            System.out.println("BEGIN JIB JSON: SYNCMAP/1");
            System.out.println(syncMapJson);
        } catch (Exception ex) {
            throw new MojoExecutionException("Failed to generate a Jib file map for sync with Skaffold", ex);
        }
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProjectProperties(com.google.cloud.tools.jib.maven.MavenProjectProperties) MavenRawConfiguration(com.google.cloud.tools.jib.maven.MavenRawConfiguration) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)

Example 2 with MavenProjectProperties

use of com.google.cloud.tools.jib.maven.MavenProjectProperties in project jib by google.

the class SyncMapMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    checkJibVersion();
    if (MojoCommon.shouldSkipJibExecution(this)) {
        return;
    }
    // add check that means this is only for jars
    if (!"jar".equals(getProject().getPackaging())) {
        throw new MojoExecutionException("Skaffold sync is currently only available for 'jar' style Jib projects, but the packaging of " + getProject().getArtifactId() + " is '" + getProject().getPackaging() + "'");
    }
    // add check for exploded containerization
    try {
        if (!ContainerizingMode.EXPLODED.equals(ContainerizingMode.from(getContainerizingMode()))) {
            throw new MojoExecutionException("Skaffold sync is currently only available for Jib projects in 'exploded' containerizing mode, but the containerizing mode of " + getProject().getArtifactId() + " is '" + getContainerizingMode() + "'");
        }
    } catch (InvalidContainerizingModeException ex) {
        throw new MojoExecutionException("Invalid containerizing mode", ex);
    }
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
        MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
        MavenRawConfiguration configuration = new MavenRawConfiguration(this);
        try {
            String syncMapJson = PluginConfigurationProcessor.getSkaffoldSyncMap(configuration, projectProperties, skaffold.sync.excludes.stream().map(File::toPath).map(Path::toAbsolutePath).collect(Collectors.toSet()));
            System.out.println();
            System.out.println("BEGIN JIB JSON: SYNCMAP/1");
            System.out.println(syncMapJson);
        } catch (Exception ex) {
            throw new MojoExecutionException("Failed to generate a Jib file map for sync with Skaffold", ex);
        }
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProjectProperties(com.google.cloud.tools.jib.maven.MavenProjectProperties) MavenRawConfiguration(com.google.cloud.tools.jib.maven.MavenRawConfiguration) TempDirectoryProvider(com.google.cloud.tools.jib.filesystem.TempDirectoryProvider) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvalidContainerizingModeException(com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)

Aggregations

TempDirectoryProvider (com.google.cloud.tools.jib.filesystem.TempDirectoryProvider)2 MavenProjectProperties (com.google.cloud.tools.jib.maven.MavenProjectProperties)2 MavenRawConfiguration (com.google.cloud.tools.jib.maven.MavenRawConfiguration)2 InvalidContainerizingModeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)2 Path (java.nio.file.Path)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2