fixed stubs layout and added information to MANIFEST file (#18)

This commit is contained in:
Mariusz Smykuła
2016-04-28 22:36:49 +02:00
parent 5a23d9a7b5
commit 467fd230f2
8 changed files with 67 additions and 15 deletions

View File

@@ -271,7 +271,12 @@
<version>${aetherVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>

View File

@@ -57,7 +57,7 @@ class ConvertMojo extends AbstractMojo {
AccurestConfigProperties config = new AccurestConfigProperties()
config.contractsDslDir = insideProject ? contractsDirectory : source
config.stubsOutputDir = insideProject ? new File(outputDirectory, 'mappings') : destination
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}")
@@ -72,8 +72,7 @@ class ConvertMojo extends AbstractMojo {
Resource testResource = new Resource(directory: contractsDirectory.absolutePath)
MavenResourcesExecution mavenResourcesExecution =
new MavenResourcesExecution([testResource],
new File(outputDirectory, 'contracts'), project, 'UTF-8',
[], [], mavenSession);
new File(outputDirectory, 'accurest'), project, 'UTF-8', [], [], mavenSession);
mavenResourcesExecution.injectProjectBuildFilters = false
mavenResourcesExecution.overwrite = true
mavenResourcesExecution.includeEmptyDirs = false

View File

@@ -1,6 +1,7 @@
package io.codearte.accurest.maven
import groovy.transform.CompileStatic
import org.apache.maven.model.Plugin
import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugin.MojoExecutionException
import org.apache.maven.plugin.MojoFailureException
@@ -12,6 +13,7 @@ import org.apache.maven.project.MavenProject
import org.apache.maven.project.MavenProjectHelper
import org.codehaus.plexus.archiver.Archiver
import org.codehaus.plexus.archiver.jar.JarArchiver
import org.codehaus.plexus.archiver.jar.Manifest
@Mojo(name = 'generateStubs', defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true)
@CompileStatic
@@ -36,7 +38,7 @@ class GenerateStubsMojo extends AbstractMojo {
private MavenProject project
@Component(role = Archiver.class, hint = "jar")
private JarArchiver jarArchiver;
private JarArchiver archiver;
@Parameter(defaultValue = 'true')
private boolean attachContracts
@@ -64,18 +66,32 @@ class GenerateStubsMojo extends AbstractMojo {
try {
if (attachContracts) {
jarArchiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN, ACCUREST_FILE_PATTERN] as String[], [] as String[]);
archiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN, ACCUREST_FILE_PATTERN] as String[], [] as String[]);
} else {
log.info("Skipping attaching accurest contracts")
jarArchiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN] as String[], [ACCUREST_FILE_PATTERN] as String[]);
archiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN] as String[], [ACCUREST_FILE_PATTERN] as String[]);
}
jarArchiver.setCompress(true);
jarArchiver.setDestFile(stubsJarFile);
jarArchiver.createArchive();
archiver.setCompress(true);
archiver.setDestFile(stubsJarFile);
archiver.addConfiguredManifest(createManifest());
archiver.createArchive();
} catch (Exception e) {
throw new MojoFailureException("Exception while packaging ${classifier} jar.", e);
}
return stubsJarFile
}
private Manifest createManifest() {
Manifest manifest = new Manifest();
Plugin accurestMavenPlugin = project.getBuildPlugins().find { it.artifactId == 'accurest-maven-plugin' }
manifest.addConfiguredAttribute(new Manifest.Attribute("Accurest-Maven-Plugin-Version", accurestMavenPlugin.version));
if (accurestMavenPlugin.getDependencies()) {
String accurestVersion = accurestMavenPlugin.getDependencies().find {
it.artifactId == 'accurest-core'
}.version
manifest.addConfiguredAttribute(new Manifest.Attribute("Accurest-Version", accurestVersion));
}
return manifest
}
}

View File

@@ -2,6 +2,7 @@ package io.codearte.accurest.maven;
import static io.takari.maven.testing.TestMavenRuntime.newParameter;
import static io.takari.maven.testing.TestResources.assertFileContents;
import static io.takari.maven.testing.TestResources.assertFilesNotPresent;
import static io.takari.maven.testing.TestResources.assertFilesPresent;
import java.io.File;
@@ -26,6 +27,7 @@ public class PluginUnitTest {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "convert");
assertFilesPresent(basedir, "target/accurest/mappings/Sample.json");
assertFilesNotPresent(basedir, "target/accurest/mappings/Messaging.json");
}
@Test
@@ -35,6 +37,13 @@ public class PluginUnitTest {
assertFilesPresent(basedir, "target/accurest/mappings/Sample.json");
}
@Test
public void shouldCopyContracts() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "convert");
assertFilesPresent(basedir, "target/accurest/accurest/Sample.groovy");
assertFilesPresent(basedir, "target/accurest/accurest/Messaging.groovy");
}
@Test
public void shouldGenerateWireMockStubsInSelectedLocation() throws Exception {
File basedir = resources.getBasedir("basic");

View File

@@ -0,0 +1,23 @@
import io.codearte.accurest.dsl.GroovyDsl
GroovyDsl.make {
label 'some_label'
input {
messageFrom('jms:input')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
}
outputMessage {
sentTo('jms:output')
body([
bookName: 'foo'
])
headers {
header('BOOK-NAME', 'foo')
}
}
}

View File

@@ -45,13 +45,13 @@
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<version>0.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.3.0</version>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<!-- end::dependencies[] -->

View File

@@ -46,7 +46,7 @@
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<version>0.4.1</version>
<scope>test</scope>
<!-- end::dependencies[] -->
</dependency>

View File

@@ -45,13 +45,13 @@
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<version>0.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.3.0</version>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<!-- end::dependencies[] -->