Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a skipPom parameter, skipping a project if packaging is pom #1388

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/asciidoc/inc/_global-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ By default a progress meter is printed out on the console, which is omitted when
| If set dont push any images even when `{plugin}:push` is called.
| `docker.skip.push`

| *skipPom*
| If set to `true` this plugin will skip every projects, where `project.packaging` is set to `pom`. Property: `docker.skip.pom`
Copy link
Contributor

@mabrarov mabrarov Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the table:

broken-screenshot

There should be 3 columns in each row:

| *skipPom*
| If set to `true` this plugin will skip every projects, where `project.packaging` is set to `pom`.
| `docker.skip.pom`

fixed-screenshot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mabrarov: Thanks a lot for noticing, Could you please create a PR to fix this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is it #1448

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged it into master. Thanks a lot for your quick PR :-)


| *skipRun*
| If set dont create and start any containers with `{plugin}:start` or `{plugin}:run`
| `docker.skip.run`
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/fabric8/maven/docker/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ public class BuildMojo extends AbstractBuildSupportMojo {
@Parameter(property = "docker.skip.build", defaultValue = "false")
protected boolean skipBuild;

@Parameter(property = "docker.skip.pom", defaultValue = "false")
protected boolean skipPom;

@Parameter(property = "docker.name", defaultValue = "")
protected String name;

@Parameter(defaultValue = "${project.packaging}", required = true)
protected String packaging;

/**
* Skip Sending created tarball to docker daemon
*/
Expand Down Expand Up @@ -145,7 +151,7 @@ private void processImageConfig(ServiceHub hub, ImageConfiguration aImageConfig)
BuildImageConfiguration buildConfig = aImageConfig.getBuildConfiguration();

if (buildConfig != null) {
if(buildConfig.skip()) {
if(buildConfig.skip() || (skipPom && packaging.equalsIgnoreCase("pom"))) {
log.info("%s : Skipped building", aImageConfig.getDescription());
} else {
buildAndTag(hub, aImageConfig);
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/io/fabric8/maven/docker/BuildMojoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.fabric8.maven.docker;

import java.io.File;
import java.io.IOException;
import java.util.Collections;

import io.fabric8.maven.docker.access.BuildOptions;
import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.BuildService;
import io.fabric8.maven.docker.service.ImagePullManager;
import mockit.Deencapsulation;
import mockit.Mocked;
import mockit.Tested;
import mockit.Verifications;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;

public class BuildMojoTest extends BaseMojoTest {
@Tested(fullyInitialized = false)
private BuildMojo buildMojo;

@Mocked
private BuildService buildService;

@Test
public void skipWhenPom() throws IOException, MojoExecutionException {
Deencapsulation.setField(serviceHub, "buildService", buildService);
givenMavenProject(buildMojo);
givenPackaging("pom");
givenSkipPom(true);

whenMojoExecutes();

thenBuildNotRun();
}

@Test
public void noSkipWhenNotPom() throws IOException, MojoExecutionException {
Deencapsulation.setField(serviceHub, "buildService", buildService);
givenMavenProject(buildMojo);
givenResolvedImages(buildMojo, Collections.singletonList(singleImageWithBuild()));
givenPackaging("jar");
givenSkipPom(true);

whenMojoExecutes();

thenBuildRun();
}

private void thenBuildRun() throws DockerAccessException, MojoExecutionException {
new Verifications() {{
buildService.buildImage((ImageConfiguration)any, (ImagePullManager) any, (BuildService.BuildContext)any, (File)any); times = 1;
}};
}

private void thenBuildNotRun() throws DockerAccessException, MojoExecutionException {
new Verifications() {{
buildService.buildImage((ImageConfiguration)any, (ImagePullManager) any, (BuildService.BuildContext)any, (File)any); times = 0;
}};
}

private void givenPackaging(String packaging) {
Deencapsulation.setField(buildMojo, "packaging", packaging);
}

private void givenSkipPom(boolean skipPom) {
Deencapsulation.setField(buildMojo, "skipPom", skipPom);
}

private void whenMojoExecutes() throws IOException, MojoExecutionException {
buildMojo.executeInternal(serviceHub);
}
}