Skip to content

Commit

Permalink
#12 Support for api filename configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
galovics committed Mar 15, 2020
1 parent 102fbba commit a396fc5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SwaggerBrakeExtension {
final Property<Object> mavenRepoUsername
final Property<Object> mavenRepoPassword
final Property<Boolean> deprecatedApiDeletionAllowed
final Property<Object> apiFilename

final Property<Boolean> testModeEnabled

Expand All @@ -31,6 +32,7 @@ class SwaggerBrakeExtension {
this.mavenRepoUsername = project.getObjects().property(Object)
this.mavenRepoPassword = project.getObjects().property(Object)
this.deprecatedApiDeletionAllowed = project.getObjects().property(Boolean)
this.apiFilename = project.getObjects().property(Object)
this.testModeEnabled = project.getObjects().property(Boolean)
applyDefaults(project)
}
Expand All @@ -42,9 +44,14 @@ class SwaggerBrakeExtension {
applyDefaultOutputFormat()
applyMavenRepoAuth()
applyDeprecatedApiHandling()
applyDefaultApiFilename()
applyTestMode()
}

private applyDefaultApiFilename() {
this.apiFilename.set("")
}

private applyDeprecatedApiHandling() {
this.deprecatedApiDeletionAllowed.set(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SwaggerBrakePlugin implements Plugin<Project> {
mavenRepoUsername = extension.mavenRepoUsername
mavenRepoPassword = extension.mavenRepoPassword
deprecatedApiDeletionAllowed = extension.deprecatedApiDeletionAllowed
apiFilename = extension.apiFilename
testModeEnabled = extension.testModeEnabled
}
def checkTask = project.tasks.findByName("check")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CheckBreakingChangesTask extends DefaultTask {
final Property<Object> mavenRepoPassword = getProject().getObjects().property(Object)
@Input
final Property<Boolean> deprecatedApiDeletionAllowed = getProject().getObjects().property(Boolean)
@Input
final Property<Object> apiFilename = getProject().getObjects().property(Object)

@Input
final Property<Boolean> testModeEnabled = getProject().getObjects().property(Boolean)
Expand All @@ -45,6 +47,7 @@ class CheckBreakingChangesTask extends DefaultTask {
parameter.mavenRepoUsername = mavenRepoUsername.get().toString()
parameter.mavenRepoPassword = mavenRepoPassword.get().toString()
parameter.deprecatedApiDeletionAllowed = deprecatedApiDeletionAllowed.get()
parameter.apiFilename = apiFilename.get().toString()

logger.info("The following parameters are set for the task {}", parameter)
parameterValidator.validate(parameter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class CheckBreakingChangesTaskParameter {
String mavenRepoUsername
String mavenRepoPassword
Boolean deprecatedApiDeletionAllowed
String apiFilename


@Override
String toString() {
Expand All @@ -22,7 +24,8 @@ class CheckBreakingChangesTaskParameter {
", outputFormat='" + outputFormat + '\'' +
", mavenRepoUsername='" + mavenRepoUsername + '\'' +
", mavenRepoPassword='" + mavenRepoPassword + '\'' +
", deprecatedApiDeletionAllowed='" + deprecatedApiDeletionAllowed + '\'' +
'}'
", deprecatedApiDeletionAllowed=" + deprecatedApiDeletionAllowed +
", apiFilename='" + apiFilename + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.redskap.swagger.brake.gradle.task
import com.google.common.collect.ImmutableSet
import io.redskap.swagger.brake.runner.Options
import io.redskap.swagger.brake.runner.OutputFormat
import org.apache.commons.lang3.StringUtils

class OptionsFactory {
static Options create(CheckBreakingChangesTaskParameter parameter) {
Expand All @@ -16,10 +17,15 @@ class OptionsFactory {
options.setMavenRepoUsername(parameter.mavenRepoUsername)
options.setMavenRepoPassword(parameter.mavenRepoPassword)
options.setDeprecatedApiDeletionAllowed(parameter.deprecatedApiDeletionAllowed)
options.setApiFilename(StringUtils.defaultIfBlank(parameter.apiFilename, null))
return options
}

private static Set<OutputFormat> resolveOutputFormat(CheckBreakingChangesTaskParameter parameter) {
return ImmutableSet.of(OutputFormat.valueOf(parameter.outputFormat.toUpperCase()))
def format = parameter.outputFormat
if (format == null) {
return Collections.emptySet();
}
return ImmutableSet.of(OutputFormat.valueOf(format.toUpperCase()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,28 @@ class OptionsFactoryTest extends Specification {
then:
thrown(IllegalArgumentException)
}

def "create copies apiFilename over properly when value is set"() {
given:
def parameter = new CheckBreakingChangesTaskParameter()
parameter.apiFilename = "something"

when:
def result = underTest.create(parameter)

then:
assert result.apiFilename == parameter.apiFilename
}

def "create sets null apiFilename when value is blank"() {
given:
def parameter = new CheckBreakingChangesTaskParameter()
parameter.apiFilename = ""

when:
def result = underTest.create(parameter)

then:
assert result.apiFilename == null
}
}

0 comments on commit a396fc5

Please sign in to comment.