Fixes to accurest run command, changed default contracts directory and other small changes (#24)
This commit is contained in:
26
pom.xml
26
pom.xml
@@ -30,14 +30,14 @@
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<mavenVersion>3.2.5</mavenVersion>
|
||||
<mavenPluginPluginVersion>3.4</mavenPluginPluginVersion>
|
||||
<maven.version>3.2.5</maven.version>
|
||||
<maven.plugin.plugin.version>3.4</maven.plugin.plugin.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<accurest.version>1.1.0-M4</accurest.version>
|
||||
|
||||
<aetherVersion>1.1.0</aetherVersion>
|
||||
<accurest.version>1.1.0-M4</accurest.version>
|
||||
<aether.version>1.1.0</aether.version>
|
||||
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
@@ -95,7 +95,10 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addSources</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>removeStubs</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -115,7 +118,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>${mavenPluginPluginVersion}</version><!--$NO-MVN-MAN-VER$-->
|
||||
<version>${maven.plugin.plugin.version}</version><!--$NO-MVN-MAN-VER$-->
|
||||
<configuration>
|
||||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||
</configuration>
|
||||
@@ -285,7 +288,7 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.aether</groupId>
|
||||
<artifactId>aether-api</artifactId>
|
||||
<version>${aetherVersion}</version>
|
||||
<version>${aether.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -321,14 +324,14 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -348,7 +351,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>${mavenPluginPluginVersion}</version>
|
||||
<version>${maven.plugin.plugin.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -379,7 +382,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-compat</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<version>${maven.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -392,6 +395,7 @@
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
@@ -400,7 +404,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>${mavenPluginPluginVersion}</version>
|
||||
<version>${maven.plugin.plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package io.codearte.accurest.maven
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import io.codearte.accurest.config.AccurestConfigProperties
|
||||
import io.codearte.accurest.wiremock.DslToWireMockClientConverter
|
||||
import io.codearte.accurest.wiremock.RecursiveFilesConverter
|
||||
import org.apache.maven.execution.MavenSession
|
||||
import org.apache.maven.model.Resource
|
||||
import org.apache.maven.plugin.AbstractMojo
|
||||
import org.apache.maven.plugin.MojoExecutionException
|
||||
import org.apache.maven.plugin.MojoFailureException
|
||||
import org.apache.maven.plugins.annotations.Component
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase
|
||||
import org.apache.maven.plugins.annotations.Mojo
|
||||
import org.apache.maven.plugins.annotations.Parameter
|
||||
import org.apache.maven.project.MavenProject
|
||||
import org.apache.maven.shared.filtering.MavenFilteringException
|
||||
import org.apache.maven.shared.filtering.MavenResourcesExecution
|
||||
import org.apache.maven.shared.filtering.MavenResourcesFiltering
|
||||
|
||||
@Mojo(name = 'convert', requiresProject = false, defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES)
|
||||
@CompileStatic
|
||||
class ConvertMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(defaultValue = '${basedir}/src/test/accurest')
|
||||
private File contractsDirectory
|
||||
|
||||
@Parameter(defaultValue = '${project.build.directory}/accurest')
|
||||
private File outputDirectory
|
||||
|
||||
@Parameter(property = 'contractsDirectory', defaultValue = '${basedir}')
|
||||
private File source
|
||||
|
||||
@Parameter(property = 'stubsDirectory', defaultValue = '${basedir}')
|
||||
private File destination
|
||||
|
||||
@Parameter(property = 'accurest.skip', defaultValue = 'false')
|
||||
private boolean skip
|
||||
|
||||
@Parameter(defaultValue = '${session}', readonly = true)
|
||||
private MavenSession mavenSession
|
||||
|
||||
@Parameter(defaultValue = '${project}', readonly = true)
|
||||
private MavenProject project
|
||||
|
||||
@Component(role = MavenResourcesFiltering.class, hint = "default")
|
||||
private MavenResourcesFiltering mavenResourcesFiltering;
|
||||
|
||||
void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
if (skip) {
|
||||
log.info("Skipping accurest execution: accurest.skip=${skip}")
|
||||
return
|
||||
}
|
||||
|
||||
copyContracts()
|
||||
|
||||
AccurestConfigProperties config = new AccurestConfigProperties()
|
||||
config.contractsDslDir = insideProject ? contractsDirectory : source
|
||||
config.stubsOutputDir = insideProject ? new File(outputDirectory, 'mappings') : destination
|
||||
|
||||
log.info('Converting from accurest contracts written in GroovyDSL to WireMock stubs mappings')
|
||||
log.info(" Accurest contracts directory: ${config.contractsDslDir}")
|
||||
log.info("WireMock stubs mappings directory: ${config.stubsOutputDir}")
|
||||
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), config)
|
||||
converter.processFiles()
|
||||
}
|
||||
|
||||
private void copyContracts() {
|
||||
log.info("Copying accurest contracts")
|
||||
Resource testResource = new Resource(directory: contractsDirectory.absolutePath)
|
||||
MavenResourcesExecution mavenResourcesExecution =
|
||||
new MavenResourcesExecution([testResource],
|
||||
new File(outputDirectory, 'accurest'), project, 'UTF-8', [], [], mavenSession);
|
||||
mavenResourcesExecution.injectProjectBuildFilters = false
|
||||
mavenResourcesExecution.overwrite = true
|
||||
mavenResourcesExecution.includeEmptyDirs = false
|
||||
mavenResourcesExecution.filterFilenames = false
|
||||
try {
|
||||
mavenResourcesFiltering.filterResources(mavenResourcesExecution);
|
||||
} catch (MavenFilteringException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInsideProject() {
|
||||
return mavenSession.request.projectPresent
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.codearte.accurest.maven
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
import org.apache.maven.execution.MavenSession
|
||||
import org.apache.maven.model.Resource
|
||||
import org.apache.maven.plugin.MojoExecutionException
|
||||
import org.apache.maven.project.MavenProject
|
||||
import org.apache.maven.shared.filtering.MavenFilteringException
|
||||
import org.apache.maven.shared.filtering.MavenResourcesExecution
|
||||
import org.apache.maven.shared.filtering.MavenResourcesFiltering
|
||||
|
||||
@CompileStatic
|
||||
@Slf4j
|
||||
class CopyContracts {
|
||||
|
||||
private final MavenProject project
|
||||
private final MavenSession mavenSession
|
||||
private final MavenResourcesFiltering mavenResourcesFiltering
|
||||
|
||||
CopyContracts(MavenProject project, MavenSession mavenSession, MavenResourcesFiltering mavenResourcesFiltering) {
|
||||
this.project = project
|
||||
this.mavenSession = mavenSession
|
||||
this.mavenResourcesFiltering = mavenResourcesFiltering
|
||||
}
|
||||
|
||||
void copy(File contractsDirectory, File outputDirectory) {
|
||||
log.info('Copying accurest contracts')
|
||||
Resource testResource = new Resource(directory: contractsDirectory.absolutePath)
|
||||
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
|
||||
resources: [testResource],
|
||||
outputDirectory: new File(outputDirectory, 'accurest'),
|
||||
mavenProject: project,
|
||||
encoding: 'UTF-8',
|
||||
mavenSession: mavenSession);
|
||||
mavenResourcesExecution.injectProjectBuildFilters = false
|
||||
mavenResourcesExecution.overwrite = true
|
||||
mavenResourcesExecution.includeEmptyDirs = false
|
||||
mavenResourcesExecution.filterFilenames = false
|
||||
try {
|
||||
mavenResourcesFiltering.filterResources(mavenResourcesExecution);
|
||||
} catch (MavenFilteringException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import static java.lang.String.format
|
||||
@CompileStatic
|
||||
class GenerateTestsMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(property = 'accurest.contractsDirectory', defaultValue = '${project.basedir}/src/test/accurest')
|
||||
@Parameter(property = 'accurest.contractsDirectory', defaultValue = '${project.basedir}/src/test/resources/accurest')
|
||||
private File contractsDirectory
|
||||
|
||||
@Parameter(defaultValue = '${project.build.directory}/generated-test-sources/accurest')
|
||||
|
||||
@@ -67,7 +67,7 @@ class RunMojo extends AbstractMojo {
|
||||
}
|
||||
BatchStubRunner batchStubRunner
|
||||
if (!stubs) {
|
||||
StubRunnerOptions options = new StubRunnerOptions(httpPort, httpPort + 1, "", false, stubsClassifier)
|
||||
StubRunnerOptions options = new StubRunnerOptions(httpPort, httpPort, "", false, stubsClassifier)
|
||||
StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().absolutePath, options)
|
||||
batchStubRunner = new BatchStubRunner(Arrays.asList(stubRunner))
|
||||
} else {
|
||||
@@ -77,11 +77,10 @@ class RunMojo extends AbstractMojo {
|
||||
batchStubRunner = remoteStubRunner.run(options, repoSession)
|
||||
}
|
||||
|
||||
if (!insideProject) {
|
||||
pressAnyKeyToContinue()
|
||||
if (batchStubRunner) {
|
||||
batchStubRunner.close()
|
||||
}
|
||||
pressAnyKeyToContinue()
|
||||
|
||||
if (batchStubRunner) {
|
||||
batchStubRunner.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
95
src/main/java/io.codearte.accurest.maven/ConvertMojo.java
Normal file
95
src/main/java/io.codearte.accurest.maven/ConvertMojo.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
import groovy.transform.CompileStatic;
|
||||
import io.codearte.accurest.config.AccurestConfigProperties;
|
||||
import io.codearte.accurest.wiremock.DslToWireMockClientConverter;
|
||||
import io.codearte.accurest.wiremock.RecursiveFilesConverter;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.*;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.shared.filtering.MavenFilteringException;
|
||||
import org.apache.maven.shared.filtering.MavenResourcesExecution;
|
||||
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* Convert Accurest contracts into WireMock stubs mappings.
|
||||
*
|
||||
* This goal allow to generate `stubs-jar` or execute `accurest:run` with generated WireMock mappings.
|
||||
*
|
||||
*/
|
||||
@Mojo(name = "convert", requiresProject = false, defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES)
|
||||
@CompileStatic
|
||||
public class ConvertMojo extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* Directory containing Accurest contracts written using the GroovyDSL
|
||||
*/
|
||||
@Parameter(defaultValue = "${basedir}/src/test/resources/accurest")
|
||||
private File contractsDirectory;
|
||||
|
||||
/**
|
||||
* Directory where the generated WireMock stubs from Groovy DSL should be placed.
|
||||
* You can then mention them in your packaging task to create jar with stubs
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}/accurest")
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* Directory containing contracts written using the GroovyDSL
|
||||
*
|
||||
* This parameter is only used when goal is executed outside of maven project.
|
||||
*/
|
||||
@Parameter(property = "contractsDirectory", defaultValue = "${basedir}")
|
||||
private File source;
|
||||
|
||||
@Parameter(property = "stubsDirectory", defaultValue = "${basedir}")
|
||||
private File destination;
|
||||
|
||||
@Parameter(property = "accurest.skip", defaultValue = "false")
|
||||
private boolean skip;
|
||||
|
||||
@Parameter(defaultValue = "${session}", readonly = true)
|
||||
private MavenSession mavenSession;
|
||||
|
||||
@Parameter(defaultValue = "${project}", readonly = true)
|
||||
private MavenProject project;
|
||||
|
||||
@Component(role = MavenResourcesFiltering.class, hint = "default")
|
||||
private MavenResourcesFiltering mavenResourcesFiltering;
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
if (skip) {
|
||||
getLog().info(String.format("Skipping accurest execution: accurest.skip=%s", skip));
|
||||
return;
|
||||
}
|
||||
|
||||
new CopyContracts(project, mavenSession, mavenResourcesFiltering).copy(contractsDirectory, outputDirectory);
|
||||
|
||||
final AccurestConfigProperties config = new AccurestConfigProperties();
|
||||
config.setContractsDslDir(isInsideProject() ? contractsDirectory : source);
|
||||
config.setStubsOutputDir(isInsideProject() ? new File(outputDirectory, "mappings") : destination);
|
||||
|
||||
getLog().info("Converting from accurest contracts written in GroovyDSL to WireMock stubs mappings");
|
||||
getLog().info(String.format(" Accurest contracts directory: %s", config.getContractsDslDir()));
|
||||
getLog().info(String.format("WireMock stubs mappings directory: %s", config.getStubsOutputDir()));
|
||||
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), config);
|
||||
converter.processFiles();
|
||||
}
|
||||
|
||||
private boolean isInsideProject() {
|
||||
return mavenSession.getRequest().isProjectPresent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -81,6 +81,7 @@
|
||||
<goal>generateTests</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<contractsDirectory>src/test/accurest</contractsDirectory>
|
||||
<basePackageForTests>com.blogspot.toomuchcoding.frauddetection</basePackageForTests>
|
||||
<testMode>MOCKMVC</testMode>
|
||||
<testFramework>JUNIT</testFramework>
|
||||
|
||||
Reference in New Issue
Block a user