support stubs coordinates with port and specific version (#22)
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -35,7 +35,7 @@
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<accurest.version>1.1.0-M3</accurest.version>
|
||||
<accurest.version>1.1.0-M4</accurest.version>
|
||||
|
||||
<aetherVersion>1.1.0</aetherVersion>
|
||||
|
||||
@@ -388,6 +388,11 @@
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -71,8 +71,10 @@ class RunMojo extends AbstractMojo {
|
||||
StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().absolutePath, options)
|
||||
batchStubRunner = new BatchStubRunner(Arrays.asList(stubRunner))
|
||||
} else {
|
||||
StubRunnerOptions options = new StubRunnerOptions(minPort, maxPort, "", false, stubsClassifier)
|
||||
batchStubRunner = remoteStubRunner.run(stubs, options, repoSession)
|
||||
EnhancedStubRunnerOptions options = new EnhancedStubRunnerOptionsBuilder(minPort, maxPort, "", false, stubsClassifier)
|
||||
.withStubs(stubs)
|
||||
.build()
|
||||
batchStubRunner = remoteStubRunner.run(options, repoSession)
|
||||
}
|
||||
|
||||
if (!insideProject) {
|
||||
|
||||
@@ -2,8 +2,11 @@ package io.codearte.accurest.maven.stubrunner
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
import io.codearte.accurest.stubrunner.*
|
||||
import io.codearte.accurest.stubrunner.util.StubsParser
|
||||
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 org.eclipse.aether.RepositorySystemSession
|
||||
|
||||
import javax.inject.Inject
|
||||
@@ -21,12 +24,11 @@ class RemoteStubRunner {
|
||||
this.aetherStubDownloaderFactory = aetherStubDownloaderFactory
|
||||
}
|
||||
|
||||
BatchStubRunner run(String stubs, StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
|
||||
BatchStubRunner run(EnhancedStubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
|
||||
AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession)
|
||||
try {
|
||||
log.debug("Launching StubRunner with args: $options")
|
||||
Collection<StubConfiguration> collaborators = StubsParser.fromString(stubs, options.stubsClassifier)
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options, collaborators, stubDownloader)
|
||||
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options.getStubsRunnerOptions(), options.getDependencies(), stubDownloader)
|
||||
.buildBatchStubRunner()
|
||||
RunningStubs runningCollaborators = stubRunner.runStubs()
|
||||
log.info(runningCollaborators.toString())
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
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