Skip to content

Commit f898132

Browse files
doyleyoungrohanKanojia
authored andcommitted
Stop should respect docker.skip when docker.executeStopOnVMShutdown is set
1 parent 3dd6acd commit f898132

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

doc/changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# ChangeLog
22

3-
* **0.40-SNAPSHOT** :
3+
* **0.40.0-SNAPSHOT** :
4+
- `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
5+
- Prevent concurrent access to secDispatcher during password decryption ([1533](https://github.com/fabric8io/docker-maven-plugin/pull/1533)) @joserebelo
6+
- Support for `docker run --sysctl` parameters ([1530](https://github.com/fabric8io/docker-maven-plugin/issues/1530)) @jpraet
7+
- Migrate to JUnit5 and Mockito for testing ([1550](https://github.com/fabric8io/docker-maven-plugin/pull/1550)) @chonton
8+
- Multi-architecture images using buildx ([1502](https://github.com/fabric8io/docker-maven-plugin/issues/1502)) @chonton
49

510
* **0.39.1** (2022-02-27):
611
- determineFinalArgValue respect default value if key exists but value is null ([1528](https://github.com/fabric8io/docker-maven-plugin/issues/1528)) @twendelmuth

src/main/java/io/fabric8/maven/docker/StopMojo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class StopMojo extends AbstractDockerMojo {
7272
@Parameter(property = "docker.stopNamePattern")
7373
String stopNamePattern;
7474

75+
@Parameter(property = "docker.skip", defaultValue = "false")
76+
protected boolean skip;
77+
7578
/**
7679
* If true, the containers are not stopped right away, but when the build is finished (success or failed).
7780
*/
@@ -80,6 +83,10 @@ public class StopMojo extends AbstractDockerMojo {
8083

8184
@Override
8285
public void execute() throws MojoExecutionException, MojoFailureException {
86+
if(skip) {
87+
return;
88+
}
89+
8390
if (this.executeStopOnVMShutdown) {
8491
this.executeStopOnVMShutdown = false;
8592
if (!invokedTogetherWithDockerStart()) {
@@ -109,6 +116,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
109116

110117
@Override
111118
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, IOException, ExecException {
119+
if(skip) {
120+
return;
121+
}
122+
112123
QueryService queryService = hub.getQueryService();
113124
RunService runService = hub.getRunService();
114125

src/test/java/io/fabric8/maven/docker/StopMojoTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
import org.apache.maven.plugin.MojoExecutionException;
88
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.DisplayName;
910
import org.junit.jupiter.api.Test;
11+
import org.apache.maven.plugin.MojoFailureException;
1012

1113
import io.fabric8.maven.docker.access.DockerAccessException;
1214
import io.fabric8.maven.docker.access.ExecException;
@@ -30,6 +32,30 @@ class StopMojoTest extends MojoTestBase {
3032
@Mock
3133
private Container runningInstance;
3234

35+
@Test
36+
@DisplayName("Mock project with skipRun set no actions are performed.")
37+
void respectDockerSkip() throws MojoExecutionException, ExecException, IOException {
38+
givenMavenProject();
39+
stopMojo.skip = true;
40+
41+
whenMojoExecutes();
42+
43+
thenNoContainerLookupByImageOccurs();
44+
thenNoContainerIsStopped();
45+
}
46+
47+
@Test
48+
@DisplayName("Mock project with skip set then no actions performed on execute.")
49+
void respectDockerSkipEvenIfExecuteCalled() throws MojoExecutionException, ExecException, IOException, MojoFailureException {
50+
givenMavenProject();
51+
stopMojo.skip = true;
52+
53+
stopMojo.execute();
54+
55+
thenNoContainerLookupByImageOccurs();
56+
thenNoContainerIsStopped();
57+
}
58+
3359
/**
3460
* Mock project with no images, no containers are stopped.
3561
*/

0 commit comments

Comments
 (0)