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 #8 from CJSCommonPlatform/add-src-paths-configuration
Browse files Browse the repository at this point in the history
Add source paths to generator configuration
  • Loading branch information
mapingo committed May 12, 2016
2 parents 6e7d098 + f259050 commit c30bb8b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.raml.core;

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

public class GeneratorConfig {
Expand All @@ -9,15 +10,18 @@ public class GeneratorConfig {
private final String basePackageName;
private final Path sourceDirectory;
private final Map<String, String> generatorProperties;
private final List<Path> sourcePaths;

public GeneratorConfig(final Path sourceDirectory,
final Path outputDirectory,
final String basePackageName,
final Map<String, String> generatorProperties) {
final Map<String, String> generatorProperties,
final List<Path> sourcePaths) {
this.outputDirectory = outputDirectory;
this.basePackageName = basePackageName;
this.sourceDirectory = sourceDirectory;
this.generatorProperties = generatorProperties;
this.sourcePaths = sourcePaths;
}

public Path getOutputDirectory() {
Expand All @@ -35,4 +39,8 @@ public Path getSourceDirectory() {
public Map<String, String> getGeneratorProperties() {
return generatorProperties;
}

public List<Path> getSourcePaths() {
return sourcePaths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ public class GenerateGoalConfig extends BasicGoalConfig {

private final Map<String, String> properties;

private final List<Path> sourcePaths;

public GenerateGoalConfig(final String generatorName,
final Path sourceDirectory,
final Path outputDirectory,
final String basePackageName,
final List<String> includes,
final List<String> excludes,
final Map<String, String> properties) {
final Map<String, String> properties,
final List<Path> sourcePaths) {
super(sourceDirectory, includes, excludes);
this.generatorName = generatorName;
this.outputDirectory = outputDirectory;
this.basePackageName = basePackageName;
this.properties = properties;
this.sourcePaths = sourcePaths;
}

public String getGeneratorName() {
Expand All @@ -48,4 +52,8 @@ public String getBasePackageName() {
public Map<String, String> getProperties() {
return properties;
}

public List<Path> getSourcePaths() {
return sourcePaths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void generate(final GenerateGoalConfig config) throws IOException {
final String[] excludes = config.getExcludes().toArray(new String[config.getExcludes().size()]);

final GeneratorConfig generatorConfig = new GeneratorConfig(config.getSourceDirectory(),
config.getOutputDirectory(), config.getBasePackageName(), config.getProperties());
config.getOutputDirectory(), config.getBasePackageName(), config.getProperties(), config.getSourcePaths());

final Collection<Path> paths = scannerFactory.create().find(config.getSourceDirectory(), includes, excludes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import uk.gov.justice.raml.maven.common.BasicMojo;

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;
Expand Down Expand Up @@ -48,25 +52,28 @@ public void execute() throws MojoExecutionException {
project.addCompileSourceRoot(outputDirectory.getPath());
project.addTestCompileSourceRoot(outputDirectory.getPath());

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());
.generate(configuration(sourcePaths));
} catch (Exception e) {
throw new MojoExecutionException("Failed to apply generator to raml", e);
}
}

private GenerateGoalConfig configuration() {
private GenerateGoalConfig configuration(final List<Path> sourcePaths) {

return new GenerateGoalConfig(generatorName,
sourceDirectory.toPath(),
outputDirectory.toPath(),
basePackageName,
includes,
excludes,
generatorProperties
);
generatorProperties,
sourcePaths);

}

Expand Down

0 comments on commit c30bb8b

Please sign in to comment.