Skip to content

Commit

Permalink
output-format CLI parameter has been renamed to output-formats to con…
Browse files Browse the repository at this point in the history
…form the plugin naming as well + minor logging added
  • Loading branch information
galovics committed Jul 20, 2020
1 parent 846968f commit 4f32cb3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ incompatible API change unintentionally.

The available releases can be found [here](https://github.com/redskap/swagger-brake/releases)

The master branch represents the ongoing development of the tool. For the
release versions, you can check out the corresponding tags.

On top of the CLI, there are Maven and Gradle plugins also available for
easier integration into any existing pipeline.

Expand Down Expand Up @@ -47,13 +50,13 @@ Three types are supported:
- JSON
- HTML

It can be configured via the `--output-format` argument. The values can be `STDOUT`,`JSON`,`HTML`.
It can be configured via the `--output-formats` argument. The values can be `STDOUT`,`JSON`,`HTML`.
For file types (e.g. `JSON`,`HTML`) it's necessary to set the `--output-path` argument as well, where
to save the results.

Multiple reporters can be set up at the same time by separating the types with commas:
```bash
--output-format=JSON,HTML
--output-formats=JSON,HTML
```

## API deprecation handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum CliOption {
HELP("help"),
VERBOSE("verbose"),

OUTPUT_FORMAT("output-format"),
OUTPUT_FORMATS("output-formats"),
OUTPUT_PATH("output-path"),

MAVEN_REPO_URL("maven-repo-url"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Options provide() {
for (CliOptionHandler handler : handlers) {
CliOption handledOption = handler.getHandledCliOption();
String propertyValue = environment.getProperty(handledOption.asName());
log.debug("Handling command line argument {} with value of {}", handledOption, propertyValue);
log.debug("Handling command line argument {} with value of {}", handledOption.asCliOption(), propertyValue);
handler.handle(propertyValue, options);
}
cliOptionsValidator.validate(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Component
@Slf4j
public class OutputFormatHandler implements CliOptionHandler {
public class OutputFormatsHandler implements CliOptionHandler {
@Override
public void handle(String optionValue, Options options) {
Set<OutputFormat> formats = ImmutableSet.of(OutputFormat.STDOUT);
Expand All @@ -37,12 +37,12 @@ public void handle(String optionValue, Options options) {

@Override
public CliOption getHandledCliOption() {
return CliOption.OUTPUT_FORMAT;
return CliOption.OUTPUT_FORMATS;
}

@Override
public String getHelpMessage() {
List<String> values = Arrays.stream(OutputFormat.values()).map(Enum::name).map(String::toLowerCase).collect(toList());
return format("Specifies the output format. Possible values are: %s", StringUtils.join(values, ", "));
return format("Specifies the output formats as a list separated by commas. Possible values are: %s", StringUtils.join(values, ", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import io.redskap.swagger.brake.runner.OutputFormat;
import org.junit.Test;

public class OutputFormatHandlerTest {
private OutputFormatHandler underTest = new OutputFormatHandler();
public class OutputFormatsHandlerTest {
private OutputFormatsHandler underTest = new OutputFormatsHandler();

@Test
public void testHandleShouldSetFormatToStandardOutWhenPropertyValueIsNull() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package io.redskap.swagger.brake.report;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

import java.util.Collection;
import java.util.stream.Collectors;

import io.redskap.swagger.brake.runner.Options;
import io.redskap.swagger.brake.runner.OutputFormat;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class ReporterFactory {
private final Collection<CheckableReporter> reporters;

Expand All @@ -19,14 +23,15 @@ public class ReporterFactory {
* @return the {@link Reporter} instance.
*/
public Reporter create(Options options) {
Collection<Reporter> reporters = options.getOutputFormats().stream().map(this::findReporters).flatMap(Collection::stream).collect(Collectors.toSet());
Collection<Reporter> reporters = options.getOutputFormats().stream().map(this::findReporters).flatMap(Collection::stream).collect(toSet());
if (reporters.isEmpty()) {
throw new IllegalStateException("No suitable reporters could be loaded");
}
log.debug("The following reporters will be used {}", reporters.stream().map(Reporter::getClass).map(Class::getSimpleName).collect(toList()));
return new CompositeReporter(reporters);
}

private Collection<Reporter> findReporters(OutputFormat outputFormat) {
return reporters.stream().filter(r -> r.canReport(outputFormat)).collect(Collectors.toList());
return reporters.stream().filter(r -> r.canReport(outputFormat)).collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ArtifactDownloaderHandler {
public void handle(Options options) {
if (isLatestArtifactDownloadEnabled(options)) {
try {
log.debug("Latest artifact will be downloaded");
String groupId = options.getGroupId();
String artifactId = options.getArtifactId();
log.info("Downloading latest artifact with groupId '{}' artifactId '{}'", groupId, artifactId);
Expand All @@ -45,6 +46,8 @@ public void handle(Options options) {
}
} else if (isLatestArtifactDownloadWronglyConfigured(options)) {
log.warn("Seems like latest artifact resolution is intended to be used but missing some of the parameters");
} else {
log.debug("Latest artifact resolution will be skipped due to configuration settings");
}
}

Expand All @@ -60,7 +63,7 @@ private boolean isAnyRepoSet(Options options) {
}

private boolean isLatestArtifactDownloadWronglyConfigured(Options options) {
return !isAnyRepoSet(options)
return isAnyRepoSet(options)
|| isNotBlank(options.getGroupId())
|| isNotBlank(options.getArtifactId())
|| isNotBlank(options.getCurrentArtifactVersion());
Expand Down

0 comments on commit 4f32cb3

Please sign in to comment.