This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor mojo and change generator interface
- Loading branch information
1 parent
b1d35d8
commit ffa0ac6
Showing
34 changed files
with
826 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>raml-jaxrs</artifactId> | ||
<groupId>uk.gov.justice</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>io-utils</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.0.22</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
47 changes: 47 additions & 0 deletions
47
io-utils/src/main/java/uk/gov/justice/raml/io/FileTreeScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import org.codehaus.plexus.util.DirectoryScanner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.lang.String.format; | ||
|
||
/** | ||
* Utility class for searching directories. | ||
*/ | ||
public class FileTreeScanner { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FileTreeScanner.class); | ||
|
||
/** | ||
* Finding all files within a directory that fulfil a set of include and exclude patterns, using standard | ||
* Ant patterns - {@see http://ant.apache.org/manual/dirtasks.html#patterns}. | ||
* | ||
* @param baseDir the path to search under | ||
* @param includes the path patterns to include | ||
* @param excludes the path patterns to exclude | ||
* @return a list of paths to matching files under the specified directory | ||
*/ | ||
public Collection<Path> find(final Path baseDir, final String[] includes, final String[] excludes) throws IOException { | ||
|
||
LOGGER.debug(format("Finding files in: %s", baseDir.toString())); | ||
|
||
DirectoryScanner scanner = new DirectoryScanner(); | ||
scanner.setBasedir(baseDir.toFile()); | ||
scanner.setIncludes(includes); | ||
scanner.setExcludes(excludes); | ||
scanner.scan(); | ||
|
||
return Arrays.asList(scanner.getIncludedFiles()) | ||
.stream() | ||
.map(Paths::get) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
io-utils/src/test/java/uk/gov/justice/raml/io/FileTreeScannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import org.junit.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collection; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
/** | ||
* Unit tests for the {@link FileTreeScanner} class. | ||
*/ | ||
public class FileTreeScannerTest { | ||
|
||
@Test | ||
@SuppressWarnings("unchecked") | ||
public void shouldFindOnlyMatchingFiles() throws Exception { | ||
|
||
String[] includes = {"**/*.raml"}; | ||
String[] excludes = {"**/*ignore.raml"}; | ||
Path baseDir = Paths.get("src/test/resources/raml/"); | ||
|
||
FileTreeScanner fileTreeResolver = new FileTreeScanner(); | ||
|
||
Collection<Path> paths = fileTreeResolver.find(baseDir, includes, excludes); | ||
|
||
assertThat(paths, hasSize(3)); | ||
assertThat(paths, containsInAnyOrder( | ||
equalTo(Paths.get("example-1.raml")), | ||
equalTo(Paths.get("example-2.raml")), | ||
equalTo(Paths.get("subfolder/example-3.raml")))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A test file which is not raml. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
raml-generator-core/src/main/java/uk/gov/justice/raml/core/Configuration.java
This file was deleted.
Oops, something went wrong.
4 changes: 3 additions & 1 deletion
4
raml-generator-core/src/main/java/uk/gov/justice/raml/core/Generator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package uk.gov.justice.raml.core; | ||
|
||
import org.raml.model.Raml; | ||
|
||
import java.util.Set; | ||
|
||
public interface Generator { | ||
|
||
Set<String> run(String raml, Configuration configuration); | ||
Set<String> run(Raml raml, GeneratorConfig generatorConfig); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
raml-generator-core/src/main/java/uk/gov/justice/raml/core/GeneratorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package uk.gov.justice.raml.core; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class GeneratorConfig { | ||
|
||
private Path outputDirectory; | ||
private String basePackageName; | ||
private Path sourceDirectory; | ||
|
||
public GeneratorConfig(final Path sourceDirectory, final Path outputDirectory, final String basePackageName) { | ||
this.outputDirectory = outputDirectory; | ||
this.basePackageName = basePackageName; | ||
this.sourceDirectory = sourceDirectory; | ||
} | ||
|
||
public Path getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
|
||
public String getBasePackageName() { | ||
return basePackageName; | ||
} | ||
|
||
public Path getSourceDirectory() { | ||
return sourceDirectory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
raml-maven-plugin/src/main/java/uk/gov/justice/raml/jaxrs/maven/GenerateGoalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package uk.gov.justice.raml.jaxrs.maven; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* POJO to hold config for the generate goal. | ||
*/ | ||
public class GenerateGoalConfig { | ||
|
||
private final String generatorName; | ||
|
||
private final Path outputDirectory; | ||
|
||
private final Path sourceDirectory; | ||
|
||
private final String basePackageName; | ||
|
||
public GenerateGoalConfig(final String generatorName, final Path sourceDirectory, final Path outputDirectory, final String basePackageName) { | ||
this.generatorName = generatorName; | ||
this.outputDirectory = outputDirectory; | ||
this.sourceDirectory = sourceDirectory; | ||
this.basePackageName = basePackageName; | ||
} | ||
|
||
public String getGeneratorName() { | ||
return generatorName; | ||
} | ||
|
||
public Path getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
|
||
public Path getSourceDirectory() { | ||
return sourceDirectory; | ||
} | ||
|
||
public String getBasePackageName() { | ||
return basePackageName; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
raml-maven-plugin/src/main/java/uk/gov/justice/raml/jaxrs/maven/GenerateGoalProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uk.gov.justice.raml.jaxrs.maven; | ||
|
||
import uk.gov.justice.raml.core.Generator; | ||
import uk.gov.justice.raml.core.GeneratorConfig; | ||
import uk.gov.justice.raml.io.FileTreeScanner; | ||
import uk.gov.justice.raml.io.files.parser.RamlFileParser; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Service for calling a generator on some raml | ||
*/ | ||
public class GenerateGoalProcessor { | ||
|
||
private final GeneratorFactory generatorFactory; | ||
|
||
public GenerateGoalProcessor(final GeneratorFactory generatorFactory) { | ||
this.generatorFactory = generatorFactory; | ||
} | ||
|
||
public void generate(final GenerateGoalConfig config) throws IOException { | ||
|
||
final String[] includes = {"**/*.raml"}; | ||
final String[] excludes = {}; | ||
final GeneratorConfig generatorConfig = new GeneratorConfig(config.getSourceDirectory(), config.getOutputDirectory(), config.getBasePackageName()); | ||
|
||
final Generator generator = generatorFactory.create(config.getGeneratorName()); | ||
|
||
Collection<Path> paths = new FileTreeScanner().find(config.getSourceDirectory(), includes, excludes); | ||
|
||
new RamlFileParser() | ||
.parse(config.getSourceDirectory(), paths) | ||
.stream() | ||
.forEach(raml -> generator.run(raml, generatorConfig)); | ||
} | ||
|
||
} |
Oops, something went wrong.
the generator does not actually need to return anything