Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
undo other fixes
change default value for expandSuperTypes to false
  • Loading branch information
wakingrufus committed Nov 11, 2020
1 parent 7dd3b15 commit dbd29cf
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
}

group = 'com.github.wakingrufus'
version = "1.1.3"
version = "1.1.4"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ class GradleSwaggerPlugin implements Plugin<Project> {
generateSwaggerDocsTask.enabled = false
}
project.afterEvaluate {
project.configurations {
swagger {
extendsFrom(project.configurations.runtime)
canBeResolved = true
}
}
project.dependencies {
swagger project.sourceSets.main.output
}
swaggerExtension.apiSourceExtensions.each { apiSourceExtension ->
if (apiSourceExtension.attachSwaggerArtifact && apiSourceExtension.swaggerDirectory) {
apiSourceExtension.outputFormats.each { outputFormat ->
Expand Down Expand Up @@ -70,20 +61,7 @@ class GradleSwaggerPlugin implements Plugin<Project> {
}.findAll {
it != null
}
generateSwaggerDocsTask.inputFiles = project.configurations.getByName("swagger").files()

// // Workaround for an issue in the generateSwaggerDocumentation plugin
// // check https://github.com/gigaSproule/swagger-gradle-plugin/issues/158#issuecomment-585823379
// def fixSwagger = project.task("fixGenerateSwaggerDocumentation") {
// doLast {
// project.configurations.runtimeClasspath.resolve()
// .collect { it.toURI().toURL() }
// .each { project.buildscript.classLoader.addURL it }
// }
// }
// generateSwaggerDocsTask.dependsOn fixSwagger
generateSwaggerDocsTask.inputFiles = project.configurations.getByName("runtime").files()
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,37 @@ class ClassFinder {
if (classLoader) {
return classLoader
}
URL[] urls = project.configurations.swagger.files.collect { File file ->
file.toURI().toURL()
}.toArray(new URL[0])
return new URLClassLoader(urls, getClass().getClassLoader())

def urls = []
def classpaths = [project.configurations.compileClasspath.resolve()]
if (project.configurations.hasProperty('runtimeClasspath')) {
classpaths += project.configurations.runtimeClasspath.resolve()
} else {
classpaths += project.configurations.runtime.resolve()
}
classpaths.flatten().each {

urls += it.toURI().toURL()
}

if (project.sourceSets.main.output.hasProperty('classesDirs')) {
project.sourceSets.main.output.classesDirs.each {
if (it.exists()) {
urls += it.toURI().toURL()
}

}
} else {
urls += project.sourceSets.main.output.classesDir.toURI().toURL()
}

urls += project.sourceSets.main.output.resourcesDir.toURI().toURL()

(urls as URL[]).each {

}


return new URLClassLoader(urls as URL[], getClass().getClassLoader())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApiSourceExtension {
boolean useJAXBAnnotationProcessorAsPrimary = true
boolean jsonExampleValues = false
boolean attachSwaggerArtifact
boolean expandSuperTypes = true
boolean expandSuperTypes = false
String tagStrategy // null | "class"
File descriptionFile
List<String> swaggerExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,55 @@ import spock.lang.Specification

class ClassFinderTest extends Specification {

// def 'ClassFinder scans both compile and runtime dependencies'() {
// setup:
// def compileClasspath = Mock(Configuration)
// def runtimeClasspath = Mock(Configuration)
// compileClasspath.resolve() >> [new File('externaltestdata/compile')]
// runtimeClasspath.resolve() >> [new File('externaltestdata/runtime')]
//
// def configurations = Mock(ConfigurationContainer)
// configurations.metaClass.compileClasspath = compileClasspath
// configurations.metaClass.runtimeClasspath = runtimeClasspath
// configurations.hasProperty('runtimeClasspath') >> true
//
// def project = ProjectBuilder.builder().build()
// project.plugins.apply JavaPlugin
// project.metaClass.configurations = configurations
//
// def classFinder = new ClassFinder(project)
//
// when:
// def compileClass = classFinder.loadClass('TestCompileClass')
// def runtimeClass = classFinder.loadClass('TestRuntimeClass')
//
// then:
// assert compileClass != null
// assert runtimeClass != null
// }
//
// def 'ClassFinder uses runtime instead of runtimeClasspath if runtimeClasspath does not exist'() {
// setup:
// def compileClasspath = Mock(Configuration)
// def runtime = Mock(Configuration)
// compileClasspath.resolve() >> [new File('externaltestdata/compile')]
// runtime.resolve() >> [new File('externaltestdata/runtime')]
//
// def configurations = Mock(ConfigurationContainer)
// configurations.metaClass.compileClasspath = compileClasspath
// configurations.metaClass.runtime = runtime
// configurations.hasProperty('runtimeClasspath') >> false
//
// def project = ProjectBuilder.builder().build()
// project.plugins.apply JavaPlugin
// project.metaClass.configurations = configurations
//
// def classFinder = new ClassFinder(project)
//
// when:
// def runtimeClass = classFinder.loadClass('TestRuntimeClass')
//
// then:
// assert runtimeClass != null
// }
def 'ClassFinder scans both compile and runtime dependencies'() {
setup:
def compileClasspath = Mock(Configuration)
def runtimeClasspath = Mock(Configuration)
compileClasspath.resolve() >> [new File('externaltestdata/compile')]
runtimeClasspath.resolve() >> [new File('externaltestdata/runtime')]

def configurations = Mock(ConfigurationContainer)
configurations.metaClass.compileClasspath = compileClasspath
configurations.metaClass.runtimeClasspath = runtimeClasspath
configurations.hasProperty('runtimeClasspath') >> true

def project = ProjectBuilder.builder().build()
project.plugins.apply JavaPlugin
project.metaClass.configurations = configurations

def classFinder = new ClassFinder(project)

when:
def compileClass = classFinder.loadClass('TestCompileClass')
def runtimeClass = classFinder.loadClass('TestRuntimeClass')

then:
assert compileClass != null
assert runtimeClass != null
}

def 'ClassFinder uses runtime instead of runtimeClasspath if runtimeClasspath does not exist'() {
setup:
def compileClasspath = Mock(Configuration)
def runtime = Mock(Configuration)
compileClasspath.resolve() >> [new File('externaltestdata/compile')]
runtime.resolve() >> [new File('externaltestdata/runtime')]

def configurations = Mock(ConfigurationContainer)
configurations.metaClass.compileClasspath = compileClasspath
configurations.metaClass.runtime = runtime
configurations.hasProperty('runtimeClasspath') >> false

def project = ProjectBuilder.builder().build()
project.plugins.apply JavaPlugin
project.metaClass.configurations = configurations

def classFinder = new ClassFinder(project)

when:
def runtimeClass = classFinder.loadClass('TestRuntimeClass')

then:
assert runtimeClass != null
}
}

0 comments on commit dbd29cf

Please sign in to comment.