diff --git a/README.md b/README.md index 1af0bd330..7385f3e5a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ The project is very much Work In Progress and will be published on maven central # Release Notes BOAT is still under development and subject to change. +## 0.14.5 +* *Boat Marina* + * Added `boat-markers` directory in target to keep track of successful and unsuccessful actions on OpenAPI specs + ## 0.14.4 * *Boat Marina* diff --git a/boat-engine/pom.xml b/boat-engine/pom.xml index 933173d22..91adfaca6 100644 --- a/boat-engine/pom.xml +++ b/boat-engine/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT boat-engine jar diff --git a/boat-maven-plugin/pom.xml b/boat-maven-plugin/pom.xml index 6b5eaced6..7ccc7291f 100644 --- a/boat-maven-plugin/pom.xml +++ b/boat-maven-plugin/pom.xml @@ -6,7 +6,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT boat-maven-plugin diff --git a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateFromDirectoryDocMojo.java b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateFromDirectoryDocMojo.java index 01324b2e1..e61e648a0 100644 --- a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateFromDirectoryDocMojo.java +++ b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateFromDirectoryDocMojo.java @@ -7,7 +7,13 @@ import org.codehaus.plexus.util.DirectoryScanner; import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; /** @@ -17,67 +23,107 @@ @Slf4j public class GenerateFromDirectoryDocMojo extends GenerateMojo { - @Parameter(defaultValue = "**/*-api-*.yaml") - protected String openApiFileFilters; + @Parameter(defaultValue = "**/*-api-*.yaml") + protected String openApiFileFilters; + @Parameter(property = "markersDirectory", defaultValue = "${project.build.directory}/boat-markers") + protected File markersDirectory; - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - if (inputSpec != null) { - File inputSpecFile = new File(inputSpec); - fileInputExecute(inputSpecFile); - } else { - log.info("Input read as Artifact"); - super.execute(); + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + if (inputSpec != null) { + File inputSpecFile = new File(inputSpec); + fileInputExecute(inputSpecFile); + } else { + log.info("Input read as Artifact"); + super.execute(); + } } - } - private void fileInputExecute(File inputSpecFile) throws MojoExecutionException, MojoFailureException { + private void fileInputExecute(File inputSpecFile) throws MojoExecutionException, MojoFailureException { - if (inputSpecFile.isDirectory()) { - log.info("inputSpec is being read as a directory"); + if (inputSpecFile.isDirectory()) { + log.info("inputSpec is being read as a directory"); - File[] inputSpecs; - File outPutDirectory = output; + File[] inputSpecs; + File outPutDirectory = output; - inputSpecs = findAllOpenApiSpecs(inputSpecFile); + inputSpecs = findAllOpenApiSpecs(inputSpecFile); - if (inputSpecs.length == 0) { - throw new MojoExecutionException("No OpenAPI specs found in: " + inputSpec); - } + if (inputSpecs.length == 0) { + throw new MojoExecutionException("No OpenAPI specs found in: " + inputSpec); + } - for (File f : inputSpecs) { - inputSpec = f.getPath(); - output = new File(outPutDirectory.getPath(), f.getName().substring(0, f.getName().lastIndexOf("."))); + List success = new ArrayList<>(); + List failed = new ArrayList<>(); + for (File f : inputSpecs) { + inputSpec = f.getPath(); + output = new File(outPutDirectory.getPath(), f.getName().substring(0, f.getName().lastIndexOf("."))); - if (!output.exists()) { - output.mkdir(); - } + if (!output.exists()) { + try { + Files.createDirectory(output.toPath()); + } catch (IOException e) { + log.error("Failed to create output directory", e); + } + } + + log.info(" Generating docs for spec {} in directory", f.getName()); + try { + super.execute(); + success.add(f); + } catch (MojoExecutionException | MojoFailureException e) { + log.error("Failed to generate doc for spec: {}", inputSpec); + failed.add(f); + } + } + + if (markersDirectory != null) { + try { + if (!markersDirectory.exists()) { + Files.createDirectory(markersDirectory.toPath()); + } + + Files.write(new File(markersDirectory, "success.lst").toPath(), + listOfFilesToString(success).getBytes(StandardCharsets.UTF_8), + StandardOpenOption.CREATE, + StandardOpenOption.APPEND); + Files.write(new File(markersDirectory, "failed.lst").toPath(), + listOfFilesToString(failed).getBytes(StandardCharsets.UTF_8), + StandardOpenOption.CREATE, + StandardOpenOption.APPEND); + + } catch (IOException e) { + log.error("Failed to write BOAT markers to: {}", markersDirectory, e); + throw new MojoExecutionException("Failed to write BOAT markers", e); + + } + + } + + + } else { + + log.info("inputSpec being read as a single file"); + super.execute(); - log.info(" Generating docs for spec {} in directory", f.getName()); - try { - super.execute(); - } catch (MojoExecutionException | MojoFailureException e) { - log.error("Failed to generate doc for spec: {}", inputSpec); } - } + } - } else { + private String listOfFilesToString(List files) { + return files.stream() + .map(File::getPath) + .collect(Collectors.joining("\n")); + } - log.info("inputSpec being read as a single file"); - super.execute(); + private File[] findAllOpenApiSpecs(File specDirectory) { + DirectoryScanner directoryScanner = new DirectoryScanner(); + directoryScanner.setBasedir(specDirectory); + directoryScanner.setIncludes(openApiFileFilters.replace(" ", "").split(",")); + directoryScanner.scan(); + String[] includedFiles = directoryScanner.getIncludedFiles(); + return Arrays.stream(includedFiles).map(pathname -> new File(specDirectory, pathname)) + .collect(Collectors.toList()).toArray(new File[]{}); } - } - - private File[] findAllOpenApiSpecs(File specDirectory) { - DirectoryScanner directoryScanner = new DirectoryScanner(); - directoryScanner.setBasedir(specDirectory); - directoryScanner.setIncludes(openApiFileFilters.replace(" ", "").split(",")); - directoryScanner.scan(); - - String[] includedFiles = directoryScanner.getIncludedFiles(); - return Arrays.stream(includedFiles).map(pathname -> new File(specDirectory, pathname)) - .collect(Collectors.toList()).toArray(new File[]{}); - } } diff --git a/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GeneratorTests.java b/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GeneratorTests.java index 9e9848e82..839e21df8 100644 --- a/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GeneratorTests.java +++ b/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GeneratorTests.java @@ -16,6 +16,8 @@ import org.sonatype.plexus.build.incremental.DefaultBuildContext; import java.io.File; import java.util.*; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.jupiter.api.Assertions.*; @Slf4j @@ -80,6 +82,7 @@ void testBoatDocs() throws MojoExecutionException, MojoFailureException { mojo.skipIfSpecIsUnchanged = false; mojo.bundleSpecs = true; mojo.dereferenceComponents = true; + mojo.markersDirectory = new File("target/boat-markers"); mojo.execute(); assertThat(output.list()).containsExactlyInAnyOrder("index.html", ".openapi-generator-ignore", ".openapi-generator"); @@ -112,10 +115,82 @@ void testBoatDocsWithDirectory() throws MojoExecutionException, MojoFailureExcep mojo.bundleSpecs = true; mojo.dereferenceComponents = true; mojo.openApiFileFilters = "**/*.yaml"; + mojo.markersDirectory = new File("target/boat-markers"); mojo.execute(); + + assertThat(output.list()).contains("link", "petstore", "petstore-new-non-breaking", "upto"); } + @Test + void testBoatDocsWithDirectoryAndInvalidFiles() throws MojoExecutionException, MojoFailureException { + + String spec = System.getProperty("spec", getClass().getResource("/oas-examples").getFile()); + + log.info("Generating docs for: {}", spec); + + GenerateDocMojo mojo = new GenerateDocMojo(); + File input = new File(spec); + File output = new File("target/boat-docs-directory"); + if (!output.exists()) { + output.mkdirs(); + } + + DefaultBuildContext defaultBuildContext = new DefaultBuildContext(); + defaultBuildContext.enableLogging(new ConsoleLogger()); + + mojo.getLog(); + mojo.buildContext = defaultBuildContext; + mojo.project = new MavenProject(); + mojo.inputSpec = input.getAbsolutePath(); + mojo.output = output; + mojo.skip = false; + mojo.skipIfSpecIsUnchanged = false; + mojo.bundleSpecs = true; + mojo.dereferenceComponents = true; + mojo.openApiFileFilters = "**/*.yaml"; + mojo.markersDirectory = new File("target/boat-markers"); + mojo.execute(); + + + assertThat(output.list()).contains("link", "petstore", "petstore-new-non-breaking", "upto"); + } + + @Test + void testBoatDocsWithNonExistingMarkersDirectory() { + + assertThatExceptionOfType(MojoExecutionException.class).isThrownBy(() -> { + String spec = System.getProperty("spec", getClass().getResource("/boat-doc-oas-examples").getFile()); + + log.info("Generating docs for: {}", spec); + + GenerateDocMojo mojo = new GenerateDocMojo(); + File input = new File(spec); + File output = new File("target/boat-docs-directory"); + if (!output.exists()) { + output.mkdirs(); + } + + DefaultBuildContext defaultBuildContext = new DefaultBuildContext(); + defaultBuildContext.enableLogging(new ConsoleLogger()); + + mojo.getLog(); + mojo.buildContext = defaultBuildContext; + mojo.project = new MavenProject(); + mojo.inputSpec = input.getAbsolutePath(); + mojo.output = output; + mojo.skip = false; + mojo.skipIfSpecIsUnchanged = false; + mojo.bundleSpecs = true; + mojo.dereferenceComponents = true; + mojo.openApiFileFilters = "**/*.yaml"; + mojo.markersDirectory = new File(" //43243 \\d a1r1\4t 11t134 t835jyz"); + mojo.execute(); + }); + + + } + @Test void testBundledBoatDocs() throws MojoExecutionException, MojoFailureException { diff --git a/boat-quay/boat-quay-lint/pom.xml b/boat-quay/boat-quay-lint/pom.xml index 0403175a1..c883989ab 100644 --- a/boat-quay/boat-quay-lint/pom.xml +++ b/boat-quay/boat-quay-lint/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss boat-quay - 0.14.4 + 0.14.5-SNAPSHOT boat-quay-lint jar diff --git a/boat-quay/boat-quay-rules/pom.xml b/boat-quay/boat-quay-rules/pom.xml index d78041544..a53a5361e 100644 --- a/boat-quay/boat-quay-rules/pom.xml +++ b/boat-quay/boat-quay-rules/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss boat-quay - 0.14.4 + 0.14.5-SNAPSHOT boat-quay-rules jar diff --git a/boat-quay/pom.xml b/boat-quay/pom.xml index 00b35528e..ac3a4928e 100644 --- a/boat-quay/pom.xml +++ b/boat-quay/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT diff --git a/boat-scaffold/pom.xml b/boat-scaffold/pom.xml index 978ef6167..50716b726 100644 --- a/boat-scaffold/pom.xml +++ b/boat-scaffold/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT boat-scaffold @@ -86,7 +86,7 @@ com.backbase.oss boat-trail-resources - 0.14.4 + 0.14.5-SNAPSHOT test @@ -139,7 +139,7 @@ target/boat-spring-templates-tests true - pom.xml + **/pom.xml true diff --git a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatSpringTemplatesTests.java b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatSpringTemplatesTests.java index b39601179..18196919b 100644 --- a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatSpringTemplatesTests.java +++ b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatSpringTemplatesTests.java @@ -167,7 +167,7 @@ private void invoke(Method m) { void generate(Combination param) { this.param = param; - this.files = generateFrom(null); + this.files = generateFrom(null, param.name); // used in development // this.files = generateFrom("openapi-generator-originals/JavaSpring-4.3.1"); @@ -263,13 +263,13 @@ private boolean contentMatches(String path, Predicate lineMatch) { } } - private List generateFrom(String templates) { + private List generateFrom(String templates, String combination) { final File input = new File("src/test/resources/boat-spring/openapi.yaml"); final CodegenConfigurator gcf = new CodegenConfigurator(); gcf.setGeneratorName(BoatSpringCodeGen.NAME); gcf.setInputSpec(input.getAbsolutePath()); - gcf.setOutputDir(TEST_OUTPUT); + gcf.setOutputDir(TEST_OUTPUT + "/" + combination); GlobalSettings.setProperty(CodegenConstants.APIS, ""); GlobalSettings.setProperty(CodegenConstants.API_DOCS, "true"); diff --git a/boat-terminal/pom.xml b/boat-terminal/pom.xml index 7f13d67c6..bf650a969 100644 --- a/boat-terminal/pom.xml +++ b/boat-terminal/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT boat-terminal diff --git a/boat-trail-resources/pom.xml b/boat-trail-resources/pom.xml index e937d7e44..5d74b6387 100644 --- a/boat-trail-resources/pom.xml +++ b/boat-trail-resources/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT boat-trail-resources diff --git a/pom.xml b/pom.xml index c1e084858..4e08a5a1e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT pom Backbase Open Api Tools will help you converting RAML to OpenAPI plus many more diff --git a/tests/pom.xml b/tests/pom.xml index d06cd09a1..261eb9bef 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -5,7 +5,7 @@ com.backbase.oss backbase-openapi-tools - 0.14.4 + 0.14.5-SNAPSHOT tests