Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion boat-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-engine</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion boat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-maven-plugin</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<File> success = new ArrayList<>();
List<File> 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<File> 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[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion boat-quay/boat-quay-lint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>boat-quay</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-quay-lint</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion boat-quay/boat-quay-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>boat-quay</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-quay-rules</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion boat-quay/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>


Expand Down
6 changes: 3 additions & 3 deletions boat-scaffold/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-scaffold</artifactId>

Expand Down Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>com.backbase.oss</groupId>
<artifactId>boat-trail-resources</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -139,7 +139,7 @@
<projectsDirectory>target/boat-spring-templates-tests</projectsDirectory>
<failIfNoProjects>true</failIfNoProjects>
<pomIncludes>
<pomInclude>pom.xml</pomInclude>
<pomInclude>**/pom.xml</pomInclude>
</pomIncludes>
<streamLogs>true</streamLogs>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -263,13 +263,13 @@ private boolean contentMatches(String path, Predicate<String> lineMatch) {
}
}

private List<File> generateFrom(String templates) {
private List<File> 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");
Expand Down
2 changes: 1 addition & 1 deletion boat-terminal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>

<artifactId>boat-terminal</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion boat-trail-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.backbase.oss</groupId>
<artifactId>backbase-openapi-tools</artifactId>
<version>0.14.4</version>
<version>0.14.5-SNAPSHOT</version>
</parent>
<artifactId>boat-trail-resources</artifactId>

Expand Down
Loading