Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Add skipGeneration flag to skip code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Rich committed May 13, 2016
1 parent 39bd7db commit 43efab8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
1 change: 1 addition & 0 deletions raml-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<skip>false</skip>
<goalPrefix>raml</goalPrefix>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class GenerateMojo extends BasicMojo {
@Parameter(property = "outputDirectory", defaultValue = "${project.build.directory}/generated-sources")
private File outputDirectory;


/**
* Base package name used for generated Java classes.
*/
Expand All @@ -44,24 +43,32 @@ public class GenerateMojo extends BasicMojo {
@Parameter(property = "generatorProperties", required = false)
private Map<String, String> generatorProperties;

@Parameter(property = "skipGeneration", defaultValue = "false")
private boolean skip = false;

@Override
public void execute() throws MojoExecutionException {

configureDefaultFileIncludes();
if (!skip) {
configureDefaultFileIncludes();

project.addCompileSourceRoot(outputDirectory.getPath());
project.addTestCompileSourceRoot(outputDirectory.getPath());
project.addCompileSourceRoot(outputDirectory.getPath());
project.addTestCompileSourceRoot(outputDirectory.getPath());

final List<Path> sourcePaths = new ArrayList<>();
project.getCompileSourceRoots().stream().forEach(root -> sourcePaths.add(Paths.get(root)));
final List<Path> sourcePaths = new ArrayList<>();
project.getCompileSourceRoots().stream().forEach(root -> sourcePaths.add(Paths.get(root)));

try {
FileUtils.forceMkdir(outputDirectory);
new GenerateGoalProcessor(new GeneratorFactory(), new FileTreeScannerFactory())
.generate(configuration(sourcePaths));
} catch (Exception e) {
throw new MojoExecutionException("Failed to apply generator to raml", e);
try {
FileUtils.forceMkdir(outputDirectory);
new GenerateGoalProcessor(new GeneratorFactory(), new FileTreeScannerFactory())
.generate(configuration(sourcePaths));
} catch (Exception e) {
throw new MojoExecutionException("Failed to apply generator to raml", e);
}
} else {
getLog().info("Skipping generation plugin execution as generation.skip flag is enabled.");
}

}

private GenerateGoalConfig configuration(final List<Path> sourcePaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public void testShouldNotTryToInstatiateGeneratorIfNoRamlFiles() throws Exceptio

GenerateMojo mojo = (GenerateMojo) lookupConfiguredMojo(pom, "generate");
mojo.execute();


}

public void testShouldGenerateFromOnlyIncludedRaml() throws Exception {
Expand Down Expand Up @@ -130,4 +128,13 @@ public void testShouldIncludeRamlFilesFromTheClasspath() throws Exception {
hasProperty("title", equalTo("external-2.raml"))));
}

public void testShouldSkipExecution() throws Exception {
File pom = getTestFile("src/test/resources/skip-execution/pom.xml");
GenerateMojo mojo = (GenerateMojo) lookupConfiguredMojo(pom, "generate");

mojo.execute();

List<Pair<Raml, GeneratorConfig>> capturedGeneratorArgs = DummyGeneratorCaptor.getInstance().capturedArgs();
assertThat(capturedGeneratorArgs, hasSize(0));
}
}
30 changes: 30 additions & 0 deletions raml-maven-plugin/src/test/resources/skip-execution/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>uk.gov.justice.raml.test</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<artifactId>raml-maven-plugin</artifactId>
<groupId>uk.gov.justice.maven</groupId>
<configuration>
<generatorName>uk.gov.justice.raml.maven.generator.DummyGenerator
</generatorName>
<basePackageName>uk.gov.justice.api</basePackageName>
<sourceDirectory>${basedir}/src/raml</sourceDirectory>
<generatorProperties>
<property1>propertyValueABC</property1>
<property2>propertyValueDDD</property2>
</generatorProperties>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#%RAML 0.8
title: example.raml

0 comments on commit 43efab8

Please sign in to comment.