Logic moved to accurest-core (#25)
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -36,7 +36,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<accurest.version>1.1.0-M4</accurest.version>
|
||||
<accurest.version>1.1.0-M5</accurest.version>
|
||||
<aether.version>1.1.0</aether.version>
|
||||
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package io.codearte.accurest.maven
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.stubrunner.StubConfiguration
|
||||
import io.codearte.accurest.stubrunner.StubRunnerOptions
|
||||
|
||||
@CompileStatic
|
||||
public class EnhancedStubRunnerOptions {
|
||||
|
||||
@Delegate private final StubRunnerOptions options
|
||||
private final Collection<StubConfiguration> dependencies
|
||||
|
||||
EnhancedStubRunnerOptions(Collection<StubConfiguration> dependencies, StubRunnerOptions options) {
|
||||
this.options = options
|
||||
this.dependencies = dependencies
|
||||
}
|
||||
|
||||
EnhancedStubRunnerOptions(Integer minPortValue, Integer maxPortValue, String stubRepositoryRoot, boolean workOffline, String stubsClassifier, Collection<StubConfiguration> dependencies, StubRunnerOptions options) {
|
||||
this.options = new StubRunnerOptions(minPortValue, maxPortValue, stubRepositoryRoot, workOffline, stubsClassifier)
|
||||
this.dependencies = dependencies
|
||||
}
|
||||
|
||||
Collection<StubConfiguration> getDependencies() {
|
||||
return dependencies
|
||||
}
|
||||
|
||||
StubRunnerOptions getStubsRunnerOptions() {
|
||||
return options
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package io.codearte.accurest.maven
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.stubrunner.StubConfiguration
|
||||
import io.codearte.accurest.stubrunner.StubRunnerOptions
|
||||
import io.codearte.accurest.stubrunner.util.StubsParser
|
||||
|
||||
@CompileStatic
|
||||
public class EnhancedStubRunnerOptionsBuilder {
|
||||
|
||||
private LinkedList<String> stubs = new LinkedList<>()
|
||||
|
||||
private final StubRunnerOptions options;
|
||||
|
||||
EnhancedStubRunnerOptionsBuilder(StubRunnerOptions options) {
|
||||
this.options = options
|
||||
}
|
||||
|
||||
EnhancedStubRunnerOptionsBuilder(Integer minPortValue, Integer maxPortValue, String stubRepositoryRoot,
|
||||
boolean workOffline, String stubsClassifier) {
|
||||
this.options = new StubRunnerOptions(minPortValue, maxPortValue, stubRepositoryRoot, workOffline, stubsClassifier)
|
||||
}
|
||||
|
||||
EnhancedStubRunnerOptionsBuilder withStubs(String stubs) {
|
||||
addStub(stubsToList(stubs))
|
||||
return this
|
||||
}
|
||||
|
||||
private Collection<StubConfiguration> buildDependencies() {
|
||||
return StubsParser.fromString(stubs, options.getStubsClassifier());
|
||||
}
|
||||
|
||||
private static List<String> stubsToList(String stubIdsToPortMapping) {
|
||||
return stubIdsToPortMapping.split(',').collect { it }
|
||||
}
|
||||
|
||||
private void addStub(List<String> notations) {
|
||||
for (String notation : notations) {
|
||||
addStub(notation);
|
||||
}
|
||||
}
|
||||
|
||||
private void addStub(String notation) {
|
||||
if (StubsParser.hasPort(notation)) {
|
||||
addPort(notation);
|
||||
stubs.add(StubsParser.ivyFromStringWithPort(notation));
|
||||
} else {
|
||||
stubs.add(notation);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPort(String notation) {
|
||||
options.putStubIdsToPortMapping(StubsParser.fromStringWithPort(notation));
|
||||
}
|
||||
|
||||
EnhancedStubRunnerOptions build() {
|
||||
return new EnhancedStubRunnerOptions(buildDependencies(), options)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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 io.codearte.accurest.stubrunner.StubRunnerOptionsBuilder
|
||||
import org.apache.maven.execution.MavenSession
|
||||
import org.apache.maven.plugin.AbstractMojo
|
||||
import org.apache.maven.plugin.MojoExecutionException
|
||||
@@ -66,14 +67,14 @@ class RunMojo extends AbstractMojo {
|
||||
return
|
||||
}
|
||||
BatchStubRunner batchStubRunner
|
||||
StubRunnerOptionsBuilder optionsBuilder = new StubRunnerOptionsBuilder()
|
||||
.withStubsClassifier(stubsClassifier)
|
||||
if (!stubs) {
|
||||
StubRunnerOptions options = new StubRunnerOptions(httpPort, httpPort, "", false, stubsClassifier)
|
||||
StubRunnerOptions options = optionsBuilder.withPort(httpPort).build()
|
||||
StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().absolutePath, options)
|
||||
batchStubRunner = new BatchStubRunner(Arrays.asList(stubRunner))
|
||||
} else {
|
||||
EnhancedStubRunnerOptions options = new EnhancedStubRunnerOptionsBuilder(minPort, maxPort, "", false, stubsClassifier)
|
||||
.withStubs(stubs)
|
||||
.build()
|
||||
StubRunnerOptions options = optionsBuilder.withMinMaxPort(minPort, maxPort).build()
|
||||
batchStubRunner = remoteStubRunner.run(options, repoSession)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@ package io.codearte.accurest.maven.stubrunner
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
import io.codearte.accurest.maven.EnhancedStubRunnerOptions
|
||||
import io.codearte.accurest.stubrunner.AetherStubDownloader
|
||||
import io.codearte.accurest.stubrunner.BatchStubRunner
|
||||
import io.codearte.accurest.stubrunner.BatchStubRunnerFactory
|
||||
import io.codearte.accurest.stubrunner.RunningStubs
|
||||
import io.codearte.accurest.stubrunner.*
|
||||
import org.eclipse.aether.RepositorySystemSession
|
||||
|
||||
import javax.inject.Inject
|
||||
@@ -24,12 +20,11 @@ class RemoteStubRunner {
|
||||
this.aetherStubDownloaderFactory = aetherStubDownloaderFactory
|
||||
}
|
||||
|
||||
BatchStubRunner run(EnhancedStubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
|
||||
BatchStubRunner run(StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
|
||||
AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession)
|
||||
try {
|
||||
log.debug("Launching StubRunner with args: $options")
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options.getStubsRunnerOptions(), options.getDependencies(), stubDownloader)
|
||||
.buildBatchStubRunner()
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options, stubDownloader).buildBatchStubRunner()
|
||||
RunningStubs runningCollaborators = stubRunner.runStubs()
|
||||
log.info(runningCollaborators.toString())
|
||||
return stubRunner
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.codearte.accurest.stubrunner.StubRunnerOptions;
|
||||
|
||||
public class EnhancedStubRunnerOptionsTest {
|
||||
|
||||
private EnhancedStubRunnerOptionsBuilder builder = new EnhancedStubRunnerOptionsBuilder(new StubRunnerOptions());
|
||||
|
||||
@Test
|
||||
public void shouldAddStubCoordinatesWithPort() throws Exception {
|
||||
|
||||
//given
|
||||
builder.withStubs("foo:bar:8080");
|
||||
|
||||
//when
|
||||
EnhancedStubRunnerOptions options = builder.build();
|
||||
|
||||
//then
|
||||
assertThat(options.getDependencies())
|
||||
.hasToString("[foo:bar:+:stubs]");
|
||||
assertThat(options.getStubIdsToPortMapping())
|
||||
.hasToString("{foo:bar:+:stubs=8080}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddStubCoordinatesWithoutPort() throws Exception {
|
||||
|
||||
//given
|
||||
builder.withStubs("foo:bar");
|
||||
|
||||
//when
|
||||
EnhancedStubRunnerOptions options = builder.build();
|
||||
|
||||
//then
|
||||
assertThat(options.getDependencies())
|
||||
.hasToString("[foo:bar:+:stubs]");
|
||||
assertThat(options.getStubIdsToPortMapping())
|
||||
.hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddMultipleStubCoordinates() throws Exception {
|
||||
|
||||
//given
|
||||
builder.withStubs("foo:bar,bar:foo");
|
||||
|
||||
//when
|
||||
EnhancedStubRunnerOptions options = builder.build();
|
||||
|
||||
//then
|
||||
assertThat(options.getDependencies())
|
||||
.hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddStubCoordinatesWithVersion() throws Exception {
|
||||
|
||||
//given
|
||||
builder.withStubs("foo:1.2.3:bar");
|
||||
|
||||
//when
|
||||
EnhancedStubRunnerOptions options = builder.build();
|
||||
|
||||
//then
|
||||
assertThat(options.getDependencies())
|
||||
.hasToString("[foo:1.2.3:bar:stubs]");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user