-
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.
- Loading branch information
Showing
6 changed files
with
152 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Build | ||
FROM openjdk:8-jdk as baseimage | ||
|
||
WORKDIR swagger-brake | ||
COPY . . | ||
RUN sh gradlew clean build shadowJar | ||
|
||
# Actual container | ||
FROM openjdk:8-jdk | ||
WORKDIR swagger-brake | ||
COPY --from=baseimage /swagger-brake/swagger-brake-cli/build/libs/swagger-brake-*.jar swagger-brake.jar | ||
|
||
ENTRYPOINT ["java", "-jar", "swagger-brake.jar"] | ||
|
79 changes: 30 additions & 49 deletions
79
...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 |
---|---|---|
@@ -1,63 +1,44 @@ | ||
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 io.redskap.swagger.brake.runner.OptionsValidator; | ||
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)); | ||
} | ||
} | ||
public class CliOptionsValidator extends OptionsValidator { | ||
@Override | ||
protected String getMavenRepoUrlName() { | ||
return MAVEN_REPO_URL.asCliOption(); | ||
} | ||
|
||
@Override | ||
protected String getMavenSnapshotRepoUrlName() { | ||
return MAVEN_SNAPSHOT_REPO_URL.asCliOption(); | ||
} | ||
|
||
@Override | ||
protected String getCurrentArtifactVersionName() { | ||
return CURRENT_ARTIFACT_VERSION.asCliOption(); | ||
} | ||
|
||
@Override | ||
protected String getGroupIdName() { | ||
return GROUP_ID.asCliOption(); | ||
} | ||
|
||
private boolean isFullMavenConfigurationSet(Options options) { | ||
return findMissingMavenConfiguration(options).isEmpty(); | ||
@Override | ||
protected String getArtifactIdName() { | ||
return ARTIFACT_ID.asCliOption(); | ||
} | ||
|
||
private boolean isAnyMavenConfigurationSet(Options options) { | ||
return findMissingMavenConfiguration(options).size() < MAVEN_CONFIG_MAP.size(); | ||
@Override | ||
protected String getOldApiPathName() { | ||
return OLD_API_PATH.asCliOption(); | ||
} | ||
|
||
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()); | ||
@Override | ||
protected String getNewApiPathName() { | ||
return NEW_API_PATH.asCliOption(); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
swagger-brake/src/main/java/io/redskap/swagger/brake/runner/OptionsValidator.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,91 @@ | ||
package io.redskap.swagger.brake.runner; | ||
|
||
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.Map; | ||
import java.util.function.Function; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OptionsValidator { | ||
public final Map<String, Function<Options, String>> mavenConfigMap; | ||
|
||
public OptionsValidator() { | ||
mavenConfigMap = ImmutableMap.of( | ||
getMavenRepoUrlName(), Options::getMavenRepoUrl, | ||
getMavenSnapshotRepoUrlName(), Options::getMavenSnapshotRepoUrl, | ||
getCurrentArtifactVersionName(), Options::getCurrentArtifactVersion, | ||
getGroupIdName(), Options::getGroupId, | ||
getArtifactIdName(), Options::getArtifactId | ||
); | ||
} | ||
|
||
public void validate(Options options) { | ||
if (isBlank(options.getNewApiPath())) { | ||
throw new IllegalArgumentException(format("%s must be provided.", getNewApiPathName())); | ||
} | ||
if (isNotBlank(options.getOldApiPath()) && isAnyMavenConfigurationSet(options)) { | ||
throw new IllegalArgumentException(format("Maven configuration is detected along with %s. Please use only one of them.", getOldApiPathName())); | ||
} | ||
if (isBlank(options.getOldApiPath()) && !isAnyMavenConfigurationSet(options)) { | ||
throw new IllegalArgumentException(format("Either %s must be provided or a Maven configuration.", getOldApiPathName())); | ||
} | ||
if (isAnyMavenConfigurationSet(options)) { | ||
if (!isFullMavenConfigurationSet(options)) { | ||
Collection<String> missingMavenCliOptions = findMissingMavenConfiguration(options); | ||
String joinedMavenCliOptions = StringUtils.join(missingMavenCliOptions, ","); | ||
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() < mavenConfigMap.size(); | ||
} | ||
|
||
private Collection<String> findMissingMavenConfiguration(Options options) { | ||
return mavenConfigMap.entrySet().stream() | ||
.filter(e -> isBlank(e.getValue().apply(options))) | ||
.map(Map.Entry::getKey) | ||
.collect(toList()); | ||
} | ||
|
||
protected String getMavenRepoUrlName() { | ||
return "mavenRepoUrl"; | ||
} | ||
|
||
protected String getMavenSnapshotRepoUrlName() { | ||
return "mavenSnapshotRepoUrl"; | ||
} | ||
|
||
protected String getCurrentArtifactVersionName() { | ||
return "currentArtifactVersion"; | ||
} | ||
|
||
protected String getGroupIdName() { | ||
return "groupId"; | ||
} | ||
|
||
protected String getArtifactIdName() { | ||
return "artifactId"; | ||
} | ||
|
||
protected String getOldApiPathName() { | ||
return "oldApiPath"; | ||
} | ||
|
||
protected String getNewApiPathName() { | ||
return "newApiPath"; | ||
} | ||
} |
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
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