Skip to content

Commit

Permalink
Stop should respect docker.skip when docker.executeStopOnVMShutdown i…
Browse files Browse the repository at this point in the history
…s set
  • Loading branch information
doyleyoung authored and rohanKanojia committed May 29, 2022
1 parent 3dd6acd commit f898132
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ChangeLog

* **0.40-SNAPSHOT** :
* **0.40.0-SNAPSHOT** :
- `docker:stop` should respect docker.skip even when `docker.executeStopOnVMShutdown` is set to `true` ([1561](https://github.com/fabric8io/docker-maven-plugin/pull/1561)) @doyleyoung
- Prevent concurrent access to secDispatcher during password decryption ([1533](https://github.com/fabric8io/docker-maven-plugin/pull/1533)) @joserebelo
- Support for `docker run --sysctl` parameters ([1530](https://github.com/fabric8io/docker-maven-plugin/issues/1530)) @jpraet
- Migrate to JUnit5 and Mockito for testing ([1550](https://github.com/fabric8io/docker-maven-plugin/pull/1550)) @chonton
- Multi-architecture images using buildx ([1502](https://github.com/fabric8io/docker-maven-plugin/issues/1502)) @chonton

* **0.39.1** (2022-02-27):
- determineFinalArgValue respect default value if key exists but value is null ([1528](https://github.com/fabric8io/docker-maven-plugin/issues/1528)) @twendelmuth
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/fabric8/maven/docker/StopMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class StopMojo extends AbstractDockerMojo {
@Parameter(property = "docker.stopNamePattern")
String stopNamePattern;

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

/**
* If true, the containers are not stopped right away, but when the build is finished (success or failed).
*/
Expand All @@ -80,6 +83,10 @@ public class StopMojo extends AbstractDockerMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if(skip) {
return;
}

if (this.executeStopOnVMShutdown) {
this.executeStopOnVMShutdown = false;
if (!invokedTogetherWithDockerStart()) {
Expand Down Expand Up @@ -109,6 +116,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, IOException, ExecException {
if(skip) {
return;
}

QueryService queryService = hub.getQueryService();
RunService runService = hub.getRunService();

Expand Down
26 changes: 26 additions & 0 deletions src/test/java/io/fabric8/maven/docker/StopMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.apache.maven.plugin.MojoFailureException;

import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.access.ExecException;
Expand All @@ -30,6 +32,30 @@ class StopMojoTest extends MojoTestBase {
@Mock
private Container runningInstance;

@Test
@DisplayName("Mock project with skipRun set no actions are performed.")
void respectDockerSkip() throws MojoExecutionException, ExecException, IOException {
givenMavenProject();
stopMojo.skip = true;

whenMojoExecutes();

thenNoContainerLookupByImageOccurs();
thenNoContainerIsStopped();
}

@Test
@DisplayName("Mock project with skip set then no actions performed on execute.")
void respectDockerSkipEvenIfExecuteCalled() throws MojoExecutionException, ExecException, IOException, MojoFailureException {
givenMavenProject();
stopMojo.skip = true;

stopMojo.execute();

thenNoContainerLookupByImageOccurs();
thenNoContainerIsStopped();
}

/**
* Mock project with no images, no containers are stopped.
*/
Expand Down

0 comments on commit f898132

Please sign in to comment.