-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#26 Added the new parameters to the CLI interface and refactoring
- Loading branch information
Showing
39 changed files
with
1,178 additions
and
154 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
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
13 changes: 11 additions & 2 deletions
13
swagger-brake-cli/src/main/java/io/redskap/swagger/brake/cli/SwaggerBrakeMain.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,15 +1,24 @@ | ||
package io.redskap.swagger.brake.cli; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.SimpleCommandLinePropertySource; | ||
|
||
@SuppressFBWarnings("DM_EXIT") | ||
public class SwaggerBrakeMain { | ||
public static void main(String[] args) { | ||
Cli cli = createCliInterface(args); | ||
int exitCode = cli.start(); | ||
if (exitCode > 0) { | ||
System.exit(exitCode); | ||
} | ||
} | ||
|
||
public static Cli createCliInterface(String[] args) { | ||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(CliConfiguration.class); | ||
ConfigurableEnvironment environment = context.getEnvironment(); | ||
environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args)); | ||
Cli cli = context.getBean(Cli.class); | ||
cli.start(); | ||
return context.getBean(Cli.class); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
swagger-brake-cli/src/main/java/io/redskap/swagger/brake/cli/options/CliOption.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,38 @@ | ||
package io.redskap.swagger.brake.cli.options; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum CliOption { | ||
OLD_API_PATH("old-api"), | ||
NEW_API_PATH("new-api"), | ||
HELP("help"), | ||
VERBOSE("verbose"), | ||
|
||
OUTPUT_FORMAT("output-format"), | ||
OUTPUT_PATH("output-path"), | ||
|
||
MAVEN_REPO_URL("maven-repo-url"), | ||
MAVEN_SNAPSHOT_REPO_URL("maven-snapshot-repo-url"), | ||
MAVEN_REPO_USERNAME("maven-repo-username"), | ||
MAVEN_REPO_PASSWORD("maven-repo-password"), | ||
ARTIFACT_ID("artifactId"), | ||
GROUP_ID("groupId"), | ||
CURRENT_ARTIFACT_VERSION("current-artifact-version"), | ||
|
||
DEPRECATED_API_DELETION_ALLOWED("deprecated-api-deletion-allowed"), | ||
|
||
API_FILENAME("api-filename"), | ||
BETA_API_EXTENSION_NAME("beta-api-extension-name"); | ||
|
||
|
||
private final String cliOptionName; | ||
|
||
public String asName() { | ||
return cliOptionName; | ||
} | ||
|
||
public String asCliOption() { | ||
return "--" + cliOptionName; | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
swagger-brake-cli/src/main/java/io/redskap/swagger/brake/cli/options/CliOptions.java
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
...ger-brake-cli/src/main/java/io/redskap/swagger/brake/cli/options/CliOptionsValidator.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,63 @@ | ||
package io.redskap.swagger.brake.cli.options; | ||
|
||
import static io.redskap.swagger.brake.cli.options.CliOption.*; | ||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.toList; | ||
import static org.apache.commons.lang3.StringUtils.isBlank; | ||
import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.redskap.swagger.brake.runner.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CliOptionsValidator { | ||
public static final Map<CliOption, Function<Options, String>> MAVEN_CONFIG_MAP = ImmutableMap.of( | ||
MAVEN_REPO_URL, Options::getMavenRepoUrl, | ||
MAVEN_SNAPSHOT_REPO_URL, Options::getMavenSnapshotRepoUrl, | ||
CURRENT_ARTIFACT_VERSION, Options::getCurrentArtifactVersion, | ||
GROUP_ID, Options::getGroupId, | ||
ARTIFACT_ID, Options::getArtifactId | ||
); | ||
|
||
public void validate(Options options) { | ||
if (isBlank(options.getNewApiPath())) { | ||
throw new IllegalArgumentException(format("%s must be provided.", NEW_API_PATH.asCliOption())); | ||
} | ||
if (isNotBlank(options.getOldApiPath()) && isAnyMavenConfigurationSet(options)) { | ||
throw new IllegalArgumentException(format("Maven configuration is detected along with %s. Please use only one of them.", OLD_API_PATH.asCliOption())); | ||
} | ||
if (isBlank(options.getOldApiPath()) && !isAnyMavenConfigurationSet(options)) { | ||
throw new IllegalArgumentException(format("Either %s must be provided or a Maven configuration.", OLD_API_PATH.asCliOption())); | ||
} | ||
if (isAnyMavenConfigurationSet(options)) { | ||
if (!isFullMavenConfigurationSet(options)) { | ||
Collection<CliOption> missingMavenCliOptions = findMissingMavenConfiguration(options); | ||
List<String> mavenCliOptionsFormatted = missingMavenCliOptions.stream().map(CliOption::asCliOption).collect(toList()); | ||
String joinedMavenCliOptions = StringUtils.join(mavenCliOptionsFormatted, ","); | ||
throw new IllegalArgumentException(format("Partial Maven configuration detected, make sure you set %s as well.", joinedMavenCliOptions)); | ||
} | ||
} | ||
} | ||
|
||
private boolean isFullMavenConfigurationSet(Options options) { | ||
return findMissingMavenConfiguration(options).isEmpty(); | ||
} | ||
|
||
private boolean isAnyMavenConfigurationSet(Options options) { | ||
return findMissingMavenConfiguration(options).size() < MAVEN_CONFIG_MAP.size(); | ||
} | ||
|
||
private Collection<CliOption> findMissingMavenConfiguration(Options options) { | ||
return MAVEN_CONFIG_MAP.entrySet().stream() | ||
.filter(e -> isBlank(e.getValue().apply(options))) | ||
.map(Map.Entry::getKey) | ||
.collect(toList()); | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...ke-cli/src/main/java/io/redskap/swagger/brake/cli/options/handler/ApiFilenameHandler.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
12 changes: 6 additions & 6 deletions
12
...ake-cli/src/main/java/io/redskap/swagger/brake/cli/options/handler/ArtifactIdHandler.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
12 changes: 6 additions & 6 deletions
12
...c/main/java/io/redskap/swagger/brake/cli/options/handler/BetaApiExtensionNameHandler.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
5 changes: 3 additions & 2 deletions
5
...rake-cli/src/main/java/io/redskap/swagger/brake/cli/options/handler/CliOptionHandler.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,11 +1,12 @@ | ||
package io.redskap.swagger.brake.cli.options.handler; | ||
|
||
import io.redskap.swagger.brake.cli.options.CliOption; | ||
import io.redskap.swagger.brake.runner.Options; | ||
|
||
public interface CliOptionHandler { | ||
void handle(String propertyValue, Options options); | ||
void handle(String optionValue, Options options); | ||
|
||
String getHandledPropertyName(); | ||
CliOption getHandledCliOption(); | ||
|
||
String getHelpMessage(); | ||
} |
Oops, something went wrong.