From b7ae9da22e680e0d5b4ff74c6b1fb6e11de501ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Smyku=C5=82a?= Date: Sun, 1 May 2016 10:25:26 +0200 Subject: [PATCH] add shutdown for wiremock server (#21) --- .../groovy/io/codearte/accurest/maven/RunMojo.groovy | 12 +++++++++--- .../accurest/maven/stubrunner/LocalStubRunner.groovy | 6 ++++-- .../maven/stubrunner/RemoteStubRunner.groovy | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy b/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy index 7dd0381ef3..81a870abc0 100644 --- a/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy +++ b/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy @@ -3,6 +3,8 @@ package io.codearte.accurest.maven import groovy.transform.CompileStatic import io.codearte.accurest.maven.stubrunner.LocalStubRunner import io.codearte.accurest.maven.stubrunner.RemoteStubRunner +import io.codearte.accurest.stubrunner.BatchStubRunner +import io.codearte.accurest.stubrunner.StubRunner import io.codearte.accurest.stubrunner.StubRunnerOptions import org.apache.maven.execution.MavenSession import org.apache.maven.plugin.AbstractMojo @@ -63,17 +65,21 @@ class RunMojo extends AbstractMojo { log.info("Skipping accurest execution: accurest.skip=${skip}") return } - + BatchStubRunner batchStubRunner if (!stubs) { StubRunnerOptions options = new StubRunnerOptions(httpPort, httpPort + 1, "", false, stubsClassifier) - localStubRunner.run(resolveStubsDirectory().absolutePath, options) + StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().absolutePath, options) + batchStubRunner = new BatchStubRunner(Arrays.asList(stubRunner)) } else { StubRunnerOptions options = new StubRunnerOptions(minPort, maxPort, "", false, stubsClassifier) - remoteStubRunner.run(stubs, options, repoSession) + batchStubRunner = remoteStubRunner.run(stubs, options, repoSession) } if (!insideProject) { pressAnyKeyToContinue() + if (batchStubRunner) { + batchStubRunner.close() + } } } diff --git a/src/main/groovy/io/codearte/accurest/maven/stubrunner/LocalStubRunner.groovy b/src/main/groovy/io/codearte/accurest/maven/stubrunner/LocalStubRunner.groovy index 5239b412a6..73d6a7f16c 100644 --- a/src/main/groovy/io/codearte/accurest/maven/stubrunner/LocalStubRunner.groovy +++ b/src/main/groovy/io/codearte/accurest/maven/stubrunner/LocalStubRunner.groovy @@ -13,8 +13,10 @@ import javax.inject.Named @Slf4j class LocalStubRunner { - void run(String contractsDir, StubRunnerOptions options) { + StubRunner run(String contractsDir, StubRunnerOptions options) { log.info("Launching StubRunner with contracts from ${contractsDir}") - new StubRunner(options, contractsDir, new StubConfiguration(contractsDir)).runStubs() + StubRunner stubRunner = new StubRunner(options, contractsDir, new StubConfiguration(contractsDir)) + stubRunner.runStubs() + return stubRunner } } diff --git a/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy b/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy index ca37885758..0de360b01b 100644 --- a/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy +++ b/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy @@ -21,7 +21,7 @@ class RemoteStubRunner { this.aetherStubDownloaderFactory = aetherStubDownloaderFactory } - void run(String stubs, StubRunnerOptions options, RepositorySystemSession repositorySystemSession) { + BatchStubRunner run(String stubs, StubRunnerOptions options, RepositorySystemSession repositorySystemSession) { AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession) try { log.debug("Launching StubRunner with args: $options") @@ -30,6 +30,7 @@ class RemoteStubRunner { .buildBatchStubRunner() RunningStubs runningCollaborators = stubRunner.runStubs() log.info(runningCollaborators.toString()) + return stubRunner } catch (Exception e) { log.error("An exception occurred while trying to execute the stubs: ${e.message}") throw e