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

Commit

Permalink
correct the ouput paths for the maven plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Nov 20, 2017
1 parent 46d2998 commit a9b90c8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

public class SchemaCatalogException extends RuntimeException {

public SchemaCatalogException(final String message) {
super(message);
}

public SchemaCatalogException(final String message, final Throwable cause) {
super(message, cause);
}
Expand Down
2 changes: 1 addition & 1 deletion catalog-generation-plugin-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<basePackageName>uk.gov.justice.events.pojo</basePackageName>
<sourceDirectory>${basedir}/src/raml/json/schema
</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources
<outputDirectory>${project.build.directory}/generated-resources
</outputDirectory>
<includes>
<include>**/*.json</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@

public class CatalogGenerationContext {

private static final String CATALOG_GENERATION_ROOT = "target/generated-catalogs";
private static final String CATALOG_PATH = "json/schema/catalog";
private static final String CATALOG_FILENAME = "schema_catalog.json";
private static final String JSON_SCHEMA_PATH = "raml/json/schema/";
public static final String AN_EMPTY_STRING = "";

public String getCatalogGenerationRoot() {
return CATALOG_GENERATION_ROOT;
}

public String getCatalogPath() {
return CATALOG_PATH;
}

public String getCatalogFilename() {
return CATALOG_FILENAME;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package uk.gov.justice.schema.catalog.generation;

import uk.gov.justice.schema.catalog.SchemaCatalogException;

public class CatalogGenerationException extends SchemaCatalogException {
public class CatalogGenerationException extends RuntimeException {

public CatalogGenerationException(final String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.util.List;

public class CatalogGenerationRunner {
Expand All @@ -24,13 +25,13 @@ public CatalogGenerationRunner(
this.urlConverter = urlConverter;
}

public void generateCatalog(final String catalogName, final List<URI> schemaFiles) {
public void generateCatalog(final String catalogName, final List<URI> schemaFiles, final Path catalogGenerationPath) {

final Catalog catalog = catalogObjectGenerator.generate(
catalogName,
asUrls(schemaFiles));

catalogWriter.write(catalog);
catalogWriter.write(catalog, catalogGenerationPath);
}

private List<URL> asUrls(final List<URI> schemaFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;

public class CatalogWriter {

private static final String CATALOG_SUB_DIRECTORY = "json/schema";

private final ObjectMapper objectMapper;
private final CatalogGenerationContext catalogGenerationContext;

Expand All @@ -23,13 +26,11 @@ public CatalogWriter(final ObjectMapper objectMapper, final CatalogGenerationCon
}

@SuppressWarnings("ResultOfMethodCallIgnored")
public void write(final Catalog catalog) {
public void write(final Catalog catalog, final Path catalogGenerationPath) {

final String catalogJson = writeAsString(catalog);

final String catalogGenerationRoot = catalogGenerationContext.getCatalogGenerationRoot();
final String catalogPath = catalogGenerationContext.getCatalogPath();
final File outputDirectory = new File(catalogGenerationRoot, catalogPath);
final String catalogJson = writeAsString(catalog);
final File outputDirectory = catalogGenerationPath.resolve(CATALOG_SUB_DIRECTORY).toFile();
outputDirectory.mkdirs();

final File outputFile = new File(outputDirectory, catalogGenerationContext.getCatalogFilename());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uk.gov.justice.schema.catalog.generation.maven.CatalogGeneratorProperties;

import java.net.URI;
import java.nio.file.Path;
import java.util.List;

import com.google.common.annotations.VisibleForTesting;
Expand All @@ -25,12 +26,14 @@ public MavenCatalogGenerator(final ObjectFactory objectFactory) {
@Override
public void run(final List<URI> schemaFiles, final GeneratorConfig generatorConfig) {

final Path catalogGenerationPath = generatorConfig.getOutputDirectory();

final CatalogGenerationRunner catalogGenerationRunner = objectFactory.catalogGenerationRunner();

final CatalogGeneratorProperties generatorProperties =
(CatalogGeneratorProperties) generatorConfig.getGeneratorProperties();
final String catalogName = generatorProperties.getCatalogName();

catalogGenerationRunner.generateCatalog(catalogName, schemaFiles);
catalogGenerationRunner.generateCatalog(catalogName, schemaFiles, catalogGenerationPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ public class CatalogGenerationContextTest {
@InjectMocks
private CatalogGenerationContext catalogGenerationContext;

@Test
public void shouldGetCatalogGenerationRoot() throws Exception {
assertThat(catalogGenerationContext.getCatalogGenerationRoot(), is("target/generated-catalogs"));
}

@Test
public void shouldGetCatalogPath() throws Exception {
assertThat(catalogGenerationContext.getCatalogPath(), is("json/schema/catalog"));
}

@Test
public void shouldGetCatalogFilename() throws Exception {
assertThat(catalogGenerationContext.getCatalogFilename(), is("schema_catalog.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -38,6 +40,7 @@ public void shouldGenerateACatalogFile() throws Exception {
final String catalogName = "catalog name";
final URI schemaFile = new URI("file:/schemaFile.json");
final URL schemaFileUrl = schemaFile.toURL();
final Path catalogGenerationPath = Paths.get(new URI("file:/path/to/catalog/generation/directory"));

final Catalog catalog = mock(Catalog.class);

Expand All @@ -46,8 +49,8 @@ public void shouldGenerateACatalogFile() throws Exception {
catalogName,
singletonList(schemaFileUrl))).thenReturn(catalog);

catalogGenerationRunner.generateCatalog(catalogName, singletonList(schemaFile));
catalogGenerationRunner.generateCatalog(catalogName, singletonList(schemaFile), catalogGenerationPath);

verify(catalogWriter).write(catalog);
verify(catalogWriter).write(catalog, catalogGenerationPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

public class CatalogWriterTest {

private static final File GENERATED_CATALOG_FILE = new File(new File("target/generated-catalogs", "json/schema/catalog"), "schema_catalog.json");
private static final File CATALOG_GENERATION_PATH = new File("target/test-output-directory");
private static final File GENERATED_CATALOG_FILE = new File(CATALOG_GENERATION_PATH + "/json/schema", "schema_catalog.json");

private final ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper();

Expand Down Expand Up @@ -55,7 +56,7 @@ public void shouldGenerateACatalogInTheCorrectLocationFromTheCatalogDomainObject
)
);

catalogWriter.write(catalog);
catalogWriter.write(catalog, CATALOG_GENERATION_PATH.toPath());

assertThat(GENERATED_CATALOG_FILE.exists(), is(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import uk.gov.justice.schema.catalog.generation.maven.CatalogGeneratorProperties;

import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.junit.Test;
Expand All @@ -34,18 +36,20 @@ public void shouldInstantiateAndRunTheCatalogGeneration() throws Exception {

final String catalogName = "my catalog";
final List<URI> schemaFiles = singletonList(new URI("/a-schema-file.json"));
final Path catalogGenerationPath = Paths.get(new URI("file:/path/to/catalog/generation/directory"));

final CatalogGenerationRunner catalogGenerationRunner = mock(CatalogGenerationRunner.class);
final GeneratorConfig generatorConfig = mock(GeneratorConfig.class);
final CatalogGeneratorProperties catalogGeneratorProperties = mock(CatalogGeneratorProperties.class);

when(generatorConfig.getOutputDirectory()).thenReturn(catalogGenerationPath);
when(objectFactory.catalogGenerationRunner()).thenReturn(catalogGenerationRunner);
when(generatorConfig.getGeneratorProperties()).thenReturn(catalogGeneratorProperties);
when(catalogGeneratorProperties.getCatalogName()).thenReturn(catalogName);

mavenCatalogGenerator.run(schemaFiles, generatorConfig);

verify(catalogGenerationRunner).generateCatalog(catalogName, schemaFiles);
verify(catalogGenerationRunner).generateCatalog(catalogName, schemaFiles, catalogGenerationPath);
}

@Test
Expand Down

0 comments on commit a9b90c8

Please sign in to comment.