Feature/create stubs (#10)
* removed warnings and simplified * automate stub generation
This commit is contained in:
11
pom.xml
11
pom.xml
@@ -282,6 +282,17 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-archiver</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-archiver</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.takari.maven.plugins</groupId>
|
||||
<artifactId>takari-plugin-testing</artifactId>
|
||||
|
||||
@@ -9,14 +9,13 @@ import org.apache.maven.model.path.PathTranslator
|
||||
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 javax.inject.Inject
|
||||
|
||||
@Mojo(name = 'convert', requiresProject = false, defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
|
||||
@Mojo(name = 'convert', requiresProject = false, defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES)
|
||||
@CompileStatic
|
||||
class ConvertMojo extends AbstractMojo {
|
||||
|
||||
@@ -35,7 +34,7 @@ class ConvertMojo extends AbstractMojo {
|
||||
@Parameter(property = 'accurest.skip', defaultValue = 'false')
|
||||
private boolean skip
|
||||
|
||||
@Component
|
||||
@Parameter(defaultValue = '${session}', readonly = true)
|
||||
private MavenSession mavenSession
|
||||
|
||||
private final PathTranslator translator
|
||||
|
||||
@@ -1,19 +1,67 @@
|
||||
package io.codearte.accurest.maven
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import org.apache.maven.model.path.PathTranslator
|
||||
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.project.MavenProjectHelper
|
||||
import org.codehaus.plexus.archiver.Archiver
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
@Mojo(name = 'generateStubs', defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
|
||||
@Mojo(name = 'generateStubs', defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true)
|
||||
@CompileStatic
|
||||
@Deprecated
|
||||
class GenerateStubsMojo extends ConvertMojo {
|
||||
class GenerateStubsMojo extends AbstractMojo {
|
||||
|
||||
@Inject
|
||||
GenerateStubsMojo(PathTranslator translator) {
|
||||
super(translator)
|
||||
@Parameter(defaultValue = '${project.build.directory}', readonly = true, required = true)
|
||||
private File projectBuildDirectory
|
||||
|
||||
@Parameter(property = 'stubsDirectory', defaultValue = '${project.build.directory}/mappings')
|
||||
private File outputDirectory
|
||||
|
||||
@Parameter(property = 'accurest.skip', defaultValue = 'false')
|
||||
private boolean skip
|
||||
|
||||
@Component
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
@Parameter(defaultValue = '${project}', readonly = true)
|
||||
private MavenProject project
|
||||
|
||||
@Component(role = Archiver.class, hint = "jar")
|
||||
private JarArchiver jarArchiver;
|
||||
|
||||
void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
if (skip) {
|
||||
log.info("Skipping accurest execution: accurest.skip=${skip}")
|
||||
return
|
||||
}
|
||||
|
||||
File stubJarFile = createStubJar(outputDirectory)
|
||||
projectHelper.attachArtifact(project, 'jar', 'stubs', stubJarFile)
|
||||
}
|
||||
|
||||
private File createStubJar(File stubsOutputDir) {
|
||||
if (!stubsOutputDir.exists()) {
|
||||
throw new MojoExecutionException("Stubs could not be found: $stubsOutputDir.\nPlease make sure that accurest:convert was invoked");
|
||||
}
|
||||
String stubArchiveName = project.getBuild().getFinalName() + "-stubs.jar";
|
||||
File stubJarFile = new File(projectBuildDirectory, stubArchiveName);
|
||||
|
||||
try {
|
||||
jarArchiver.addDirectory(stubsOutputDir);
|
||||
jarArchiver.setCompress(true);
|
||||
jarArchiver.setDestFile(stubJarFile);
|
||||
jarArchiver.createArchive();
|
||||
} catch (Exception e) {
|
||||
throw new MojoFailureException('Exception while packaging.', e);
|
||||
}
|
||||
return stubJarFile
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ import io.codearte.accurest.config.TestMode
|
||||
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.plugins.annotations.LifecyclePhase
|
||||
import org.apache.maven.plugins.annotations.Mojo
|
||||
import org.apache.maven.plugins.annotations.Parameter
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope
|
||||
import org.apache.maven.project.MavenProject
|
||||
|
||||
import static java.lang.String.format
|
||||
@@ -42,7 +45,7 @@ class GenerateTestsMojo extends AbstractMojo {
|
||||
@Parameter
|
||||
private String nameSuffixForTests
|
||||
|
||||
@Component
|
||||
@Parameter(defaultValue = '${project}', readonly = true)
|
||||
private MavenProject project
|
||||
|
||||
@Parameter(property = 'accurest.skip', defaultValue = 'false')
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.apache.maven.model.path.PathTranslator
|
||||
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.Mojo
|
||||
import org.apache.maven.plugins.annotations.Parameter
|
||||
import org.eclipse.aether.RepositorySystemSession
|
||||
@@ -49,7 +48,7 @@ class RunMojo extends AbstractMojo {
|
||||
|
||||
private String stubsClassifier = 'stubs'
|
||||
|
||||
@Component
|
||||
@Parameter(defaultValue = '${session}', readonly = true)
|
||||
private MavenSession mavenSession
|
||||
|
||||
private final LocalStubRunner localStubRunner
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>convert</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>generateTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
@@ -115,30 +116,6 @@
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>-->
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.codearte.accurest</groupId>
|
||||
<artifactId>stubs-assembly-descriptor</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>stubs</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- accurest test dependencies -->
|
||||
@@ -50,12 +53,6 @@
|
||||
<version>2.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@@ -76,6 +73,7 @@
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>convert</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>generateTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
@@ -85,31 +83,6 @@
|
||||
<baseClassForTests>hello.BaseMockMvcTest</baseClassForTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.codearte.accurest</groupId>
|
||||
<artifactId>stubs-assembly-descriptor</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>stubs</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user