Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #128 from gigaSproule/feature/add-scala
Browse files Browse the repository at this point in the history
Feature/add scala
  • Loading branch information
gigaSproule authored Nov 29, 2018
2 parents 6863dc9 + 00f0b2a commit 1e1e91f
Show file tree
Hide file tree
Showing 33 changed files with 947 additions and 28 deletions.
29 changes: 18 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ plugins {
id 'maven-publish'
id 'java'
id 'groovy'
id 'scala'
id 'idea'
id 'jacoco' // Currently this does not exclude methods generated via Annotations (toString in this plugin)
id 'java-gradle-plugin'
id "com.gradle.plugin-publish" version "0.10.0"
id "com.jfrog.bintray" version "1.8.4"
id 'com.gradle.plugin-publish' version '0.10.0'
id 'com.jfrog.bintray' version '1.8.4'
id 'net.researchgate.release' version '2.7.0'
id 'com.github.ben-manes.versions' version '0.20.0'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
id 'com.dorongold.task-tree' version '1.3'
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
id 'com.dorongold.task-tree' version '1.3.1'
}

repositories {
Expand Down Expand Up @@ -43,14 +44,14 @@ task createClasspathManifest {
doLast {
outputDir.mkdirs()
println(sourceSets.test.runtimeClasspath.asPath)
file("${outputDir}/plugin-classpath.txt").text = (sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath).join("\n")
file("${outputDir}/plugin-classpath.txt").text = (sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath).join('\n')
}
}

dependencies {
def jacksonVersion = '2.9.7'
def springVersion = '5.1.0.RELEASE'
def kotlinVersion = '1.2.71'
def springVersion = '5.1.3.RELEASE'
def kotlinVersion = '1.3.10'

compile gradleApi()
compile localGroovy()
Expand All @@ -61,10 +62,12 @@ dependencies {
compile 'com.github.jknack:handlebars:4.1.0'
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.module:jackson-module-jaxb-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.module:jackson-module-scala_2.12:${jacksonVersion}"
compile 'javax.xml.bind:jaxb-api:2.3.0'

//These should be pinned here until reflections/reflections#194 has been resolved
compile 'io.swagger:swagger-jersey2-jaxrs:1.5.13'
//These should be pinned here until ronmamo/reflections#194 has been resolved
compile 'io.swagger:swagger-jersey2-jaxrs:1.5.21'
compile 'io.swagger:swagger-scala-module_2.12:1.0.4'

compile 'javax.ws.rs:javax.ws.rs-api:2.1.1'
compile 'com.sun.jersey:jersey-server:1.19.4'
Expand All @@ -73,8 +76,10 @@ dependencies {

testCompile gradleTestKit()

testCompile 'org.scala-lang:scala-library:2.12.7'
testCompile "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
testCompile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
testCompile 'org.scala-lang:scala-library:2.12.7'
testCompile 'cglib:cglib-nodep:3.2.8'
testCompile 'org.objenesis:objenesis:2.6'
testCompile('org.spockframework:spock-core:1.2-groovy-2.4') {
Expand All @@ -96,8 +101,8 @@ artifacts {

test {
testLogging {
events "failed"
exceptionFormat "full"
events 'failed'
exceptionFormat 'full'
}
options {
systemProperties(System.getProperties())
Expand All @@ -110,6 +115,8 @@ compileTestJava.classpath += files(compileTestGroovy.destinationDir)
compileTestGroovy.dependsOn = compileTestGroovy.taskDependencies.getDependencies(compileTestGroovy) - compileTestJava
compileTestKotlin.dependsOn compileTestGroovy
compileTestKotlin.classpath += files(compileTestGroovy.destinationDir)
compileTestScala.dependsOn compileTestGroovy
compileTestScala.classpath += files(compileTestGroovy.destinationDir)
testClasses.dependsOn tasks.compileTestKotlin

if (project.hasProperty('bintray_user') && project.hasProperty('bintray_apiKey')) {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Sep 29 17:44:24 BST 2018
#Thu Nov 29 22:20:24 GMT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
2 changes: 1 addition & 1 deletion sample/kotlin-spring-boot-jaxrs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
kotlinVersion = '1.2.41'
kotlinVersion = '1.3.10'
springBootVersion = '1.5.4.RELEASE'
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class Application
class SampleApplication

fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
SpringApplication.run(SampleApplication::class.java, *args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import org.springframework.context.annotation.Configuration
@Configuration
class SampleConfig : ResourceConfig() {
init {
register(SampleResource::class)
this.register(SampleResource::class)
}
}
2 changes: 1 addition & 1 deletion sample/kotlin-spring-boot-mvc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
kotlinVersion = '1.2.41'
kotlinVersion = '1.3.10'
springBootVersion = '1.5.4.RELEASE'
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class Application
class SampleApplication

fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
SpringApplication.run(SampleApplication::class.java, *args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController
@Api(value = "/sample", description = "Sample REST for Integration Testing")
class SampleController {

@RequestMapping(method = arrayOf(RequestMethod.GET), path = arrayOf("/sample"), produces = arrayOf("application/json"))
@RequestMapping(method = [RequestMethod.GET], path = ["/sample"], produces = ["application/json"])
@ApiOperation(value = "Return hello message", response = String::class)
fun home(): String {
return "{\"Hello\": \"World!\"}"
Expand Down
64 changes: 64 additions & 0 deletions sample/scala-spring-boot-jaxrs/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'com.benjaminsproule:swagger-gradle-plugin:+'
}
}

apply plugin: 'scala'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.benjaminsproule.swagger'

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

group = 'com.benjaminsproule'
version = '0.0.1-SNAPSHOT'

dependencies {
compile 'org.scala-lang:scala-library:2.12.7'
compile 'org.springframework.boot:spring-boot-starter-jersey'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'io.swagger:swagger-annotations:1.5.15'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
}

swagger {
apiSource {
springmvc = false
locations = ['com.benjaminsproule.sample']
schemes = ['http', 'https']
host = 'www.example.com:8080'
basePath = '/sample'
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
description = 'This is a sample.'
termsOfService = 'http://www.example.com/termsOfService'
contact {
email = '[email protected]'
name = 'Name'
url = 'http://www.example.com'
}
license {
url = 'http://www.apache.org/licenses/LICENSE-2.0.html'
name = 'Apache 2.0'
}
}
swaggerDirectory = "${project.buildDir}/swagger-ui"
securityDefinition {
json = 'securityDefinition.json'
}
}
}
1 change: 1 addition & 0 deletions sample/scala-spring-boot-jaxrs/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'scala-spring-boot-jaxrs'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
},
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "http://swagger.io/api/oauth/dialog",
"flow": "implicit",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.benjaminsproule.sample.scala

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class SampleApplication extends App {
SpringApplication.run(classOf[SampleApplication], args: _ *)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.benjaminsproule.sample.scala

import org.glassfish.jersey.server.ResourceConfig
import org.springframework.context.annotation.Configuration

@Configuration
class SampleConfig extends ResourceConfig {
register(classOf[SampleResource])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.benjaminsproule.sample.scala

import io.swagger.annotations.{Api, ApiOperation}
import javax.ws.rs.{GET, Path, Produces}
import org.springframework.stereotype.Controller

@Controller
@Path("/sample")
@Produces(Array("application/json"))
@Api(value = "/sample", description = "Sample REST for Integration Testing")
class SampleResource {
@GET
@ApiOperation(value = "Return hello message", response = classOf[String])
def home: String = {
"{\"Hello\": \"World!\"}"
}
}
62 changes: 62 additions & 0 deletions sample/scala-spring-boot-mvc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
classpath 'com.benjaminsproule:swagger-gradle-plugin:+'
}
}

apply plugin: 'scala'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.benjaminsproule.swagger'

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

group = 'com.benjaminsproule'
version = '0.0.1-SNAPSHOT'

dependencies {
compile 'org.scala-lang:scala-library:2.12.7'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'io.swagger:swagger-annotations:1.5.15'
}

swagger {
apiSource {
springmvc = true
locations = ['com.benjaminsproule.sample']
schemes = ['http', 'https']
host = 'www.example.com:8080'
basePath = '/sample'
info {
title = 'Swagger Gradle Plugin Sample'
version = 'v1'
description = 'This is a sample.'
termsOfService = 'http://www.example.com/termsOfService'
contact {
email = '[email protected]'
name = 'Name'
url = 'http://www.example.com'
}
license {
url = 'http://www.apache.org/licenses/LICENSE-2.0.html'
name = 'Apache 2.0'
}
}
swaggerDirectory = "${project.buildDir}/swagger-ui"
securityDefinition {
json = 'securityDefinition.json'
}
}
}
1 change: 1 addition & 0 deletions sample/scala-spring-boot-mvc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'scala-spring-boot-mvc'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
},
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "http://swagger.io/api/oauth/dialog",
"flow": "implicit",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.benjaminsproule.sample.scala

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class SampleApplication extends App {
SpringApplication.run(classOf[SampleApplication], args: _ *)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.benjaminsproule.sample.scala

import io.swagger.annotations.{Api, ApiOperation}
import org.springframework.web.bind.annotation.{RequestMapping, RequestMethod, RestController}

@RestController
@Api(value = "/sample", description = "Sample REST for Integration Testing")
class SampleController {

@RequestMapping(method = Array(RequestMethod.GET), path = Array("/sample"), produces = Array("application/json"))
@ApiOperation(value = "Return hello message", response = classOf[String])
def home: String = {
"{\"Hello\": \"World!\"}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class GradleSwaggerPlugin implements Plugin<Project> {
SwaggerExtension swaggerExtension = project.extensions.create('swagger', SwaggerExtension, project)

def createdClassFinder = new ClassFinder(project)
def customReaderClassFinder = new ClassFinder(project, getClass().getClassLoader())
def generateSwaggerDocsTask = project.task(type: GenerateSwaggerDocsTask,
dependsOn: 'classes',
group: 'swagger',
description: 'Generates swagger documentation',
GenerateSwaggerDocsTask.TASK_NAME,
{
classFinder = createdClassFinder
readerFactory = new ReaderFactory(createdClassFinder)
readerFactory = new ReaderFactory(createdClassFinder, customReaderClassFinder)
generatorFactory = new GeneratorFactory(createdClassFinder)
apiSourceValidator = new ApiSourceValidator(new InfoValidator(new LicenseValidator()), new SecurityDefinitionValidator(new ScopeValidator()), new TagValidator(new ExternalDocsValidator()))
}) as GenerateSwaggerDocsTask
Expand Down
Loading

0 comments on commit 1e1e91f

Please sign in to comment.