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

Commit

Permalink
Merge pull request #3 from CJSCommonPlatform/add-generator-properties…
Browse files Browse the repository at this point in the history
…-interface

Add GeneratorProperties interface for custom implementation of proper…
  • Loading branch information
allanmckenzie committed Sep 25, 2017
2 parents ce48e93 + e70c69a commit e398e8a
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
## Unreleased
### Added
- GeneratorFactory interface to allow factory creation of Generators
- GeneratorProperties interface for custom implementation of property class

## [1.7.0] - 2017-08-17
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

public class GeneratorConfig {

private final Path outputDirectory;
private final String basePackageName;
private final Path sourceDirectory;
private final Map<String, String> generatorProperties;
private final GeneratorProperties generatorProperties;
private final List<Path> sourcePaths;

public GeneratorConfig(final Path sourceDirectory,
final Path outputDirectory,
final String basePackageName,
final Map<String, String> generatorProperties,
final GeneratorProperties generatorProperties,
final List<Path> sourcePaths) {
this.outputDirectory = outputDirectory;
this.basePackageName = basePackageName;
Expand All @@ -36,7 +35,7 @@ public Path getSourceDirectory() {
return sourceDirectory;
}

public Map<String, String> getGeneratorProperties() {
public GeneratorProperties getGeneratorProperties() {
return generatorProperties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package uk.gov.justice.maven.generator.io.files.parser.core;

public interface GeneratorProperties {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.gov.justice.maven.generator.io.files.parser.generator;

import uk.gov.justice.maven.generator.io.files.parser.common.BasicGoalConfig;
import uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

/**
* POJO to hold config for the generate goal.
Expand All @@ -17,7 +17,7 @@ public class GenerateGoalConfig extends BasicGoalConfig {

private final String basePackageName;

private final Map<String, String> properties;
private final GeneratorProperties properties;

private final List<Path> sourcePaths;

Expand All @@ -27,7 +27,7 @@ public GenerateGoalConfig(final String generatorName,
final String basePackageName,
final List<String> includes,
final List<String> excludes,
final Map<String, String> properties,
final GeneratorProperties properties,
final List<Path> sourcePaths) {
super(sourceDirectory, includes, excludes);
this.generatorName = generatorName;
Expand All @@ -49,7 +49,7 @@ public String getBasePackageName() {
return basePackageName;
}

public Map<String, String> getProperties() {
public GeneratorProperties getProperties() {
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import uk.gov.justice.maven.generator.io.files.parser.FileParser;
import uk.gov.justice.maven.generator.io.files.parser.common.BasicMojo;
import uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties;
import uk.gov.justice.maven.generator.io.files.parser.io.FileTreeScannerFactory;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class GenerateMojo extends BasicMojo {
private String basePackageName;

@Parameter(property = "generatorProperties", required = false)
private Map<String, String> generatorProperties;
private GeneratorProperties generatorProperties;

@Parameter(property = "skipGeneration", defaultValue = "false")
private boolean skip = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.IsEqual.equalTo;

import uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig;
import uk.gov.justice.maven.generator.io.files.parser.generator.property.TestGeneratorProperties;
import uk.gov.justice.maven.generator.io.files.parser.test.utils.BetterAbstractMojoTestCase;

import java.io.File;
Expand Down Expand Up @@ -53,8 +55,12 @@ public void testShouldGenerateFromValidRaml() throws Exception {
assertThat(config.getSourceDirectory(), equalTo(expectedSourceDirectory));
assertThat(config.getOutputDirectory(), equalTo(expectedOutputDirectory));
assertThat(config.getBasePackageName(), equalTo("uk.gov.justice.api"));
assertThat(config.getGeneratorProperties().get("property1"), equalTo("propertyValueABC"));
assertThat(config.getGeneratorProperties().get("property2"), equalTo("propertyValueDDD"));

final TestGeneratorProperties customGeneratorProperties = (TestGeneratorProperties) config.getGeneratorProperties();
assertThat(customGeneratorProperties.getProperty1(), equalTo("propertyValueABC"));
assertThat(customGeneratorProperties.getProperty2(), equalTo("propertyValueDDD"));

assertThat(customGeneratorProperties.getNestedProperty(), hasItems("test1", "test2", "test3"));

assertThat((project.getCompileSourceRoots()), hasItem(expectedOutputDirectory.toString()));
assertThat((project.getTestCompileSourceRoots()), hasItem(expectedOutputDirectory.toString()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.maven.generator.io.files.parser.generator.property;

import uk.gov.justice.maven.generator.io.files.parser.core.GeneratorProperties;

import java.util.List;

import org.apache.maven.plugins.annotations.Parameter;

public class TestGeneratorProperties implements GeneratorProperties {

@Parameter
private String property1;

@Parameter
private String property2;

@Parameter
private List<String> nestedProperty;

public String getProperty1() {
return property1;
}

public String getProperty2() {
return property2;
}

public List<String> getNestedProperty() {
return nestedProperty;
}
}
8 changes: 7 additions & 1 deletion generator-plugin/src/test/resources/generate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
<parserName>uk.gov.justice.maven.generator.io.files.parser.RamlFileParser</parserName>
<basePackageName>uk.gov.justice.api</basePackageName>
<sourceDirectory>${basedir}/src/raml</sourceDirectory>
<generatorProperties>
<generatorProperties implementation="uk.gov.justice.maven.generator.io.files.parser.generator.property.TestGeneratorProperties">
<property1>propertyValueABC</property1>
<property2>propertyValueDDD</property2>

<nestedProperty>
<property>test1</property>
<property>test2</property>
<property>test3</property>
</nestedProperty>
</generatorProperties>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion generator-plugin/src/test/resources/skip-execution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parserName>uk.gov.justice.maven.generator.io.files.parser.RamlFileParser</parserName>
<basePackageName>uk.gov.justice.api</basePackageName>
<sourceDirectory>${basedir}/src/raml</sourceDirectory>
<generatorProperties>
<generatorProperties implementation="uk.gov.justice.maven.generator.io.files.parser.generator.property.TestGeneratorProperties">
<property1>propertyValueABC</property1>
<property2>propertyValueDDD</property2>
</generatorProperties>
Expand Down

0 comments on commit e398e8a

Please sign in to comment.