From 64a178b76fa1b5b31d1656bfc9da842a99e40ecf Mon Sep 17 00:00:00 2001 From: Volkmar Vogel Date: Sat, 9 Feb 2019 01:19:03 +0100 Subject: [PATCH 01/13] start integration alexa --- alexa-plugin/build.gradle | 19 ++++++++++ .../alexa/MultiPlatformIntentHandler.kt | 7 ++++ .../MultiPlatformIntentHandlerRegistry.kt | 6 +++ build.gradle | 1 + settings.gradle | 3 +- spring-sample/build.gradle | 2 + .../intenthandler/FallbackIntentHandler.kt | 15 +++++++- .../LocationPermissionIntentHandler.kt | 20 +++++++++- .../intenthandler/SignInIntentHandler.kt | 21 +++++++++- .../intenthandler/WelcomeIntentHandler.kt | 38 ++++++++++++++++++- 10 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 alexa-plugin/build.gradle create mode 100644 alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt create mode 100644 alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt diff --git a/alexa-plugin/build.gradle b/alexa-plugin/build.gradle new file mode 100644 index 0000000..8b28e2f --- /dev/null +++ b/alexa-plugin/build.gradle @@ -0,0 +1,19 @@ +group 'org.rewedigital.voice.dialog' +version rootProject.ext.versions.alexa + +apply plugin: 'kotlin' +apply plugin: 'maven-publish' +apply from: '../docu.gradle' + +dependencies { + implementation project(":core") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation "com.amazon.alexa:ask-sdk-core:2.11.2" +} + +publishing.publications { + maven(MavenPublication) { + artifactId = 'alexa-plugin' + from components.java + } +} \ No newline at end of file diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt new file mode 100644 index 0000000..f4de3e8 --- /dev/null +++ b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt @@ -0,0 +1,7 @@ +package org.rewedigital.dialog.alexa + +import com.amazon.ask.dispatcher.request.handler.RequestHandler +import org.rewedigital.dialog.handler.DialogflowIntentHandler + + +interface MultiPlatformIntentHandler : DialogflowIntentHandler, RequestHandler \ No newline at end of file diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt new file mode 100644 index 0000000..d948bb5 --- /dev/null +++ b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt @@ -0,0 +1,6 @@ +package org.rewedigital.dialog.alexa + + +interface MultiPlatformIntentHandlerRegistry { + fun provideIntentHandlers(): List +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8c49619..8158f0d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ buildscript { ext.versions.kotlin = '1.3.21' ext.versions.dokka = '0.9.17' ext.versions.core = '1.0' + ext.versions.alexa = '0.1' ext.versions.ssml = '1.0' ext.versions.ssml_plugin = '1.0' ext.versions.spring_plugin = '1.0' diff --git a/settings.gradle b/settings.gradle index 8a6e1e6..ac3de3c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,4 +4,5 @@ include 'ssml' include 'ssml-plugin' include 'spring-sample' include 'spring-plugin' -include 'konversation-plugin' \ No newline at end of file +include 'konversation-plugin' +include 'alexa-plugin' \ No newline at end of file diff --git a/spring-sample/build.gradle b/spring-sample/build.gradle index aafb34d..535cc50 100644 --- a/spring-sample/build.gradle +++ b/spring-sample/build.gradle @@ -47,11 +47,13 @@ dependencies { implementation project(":ssml-plugin") implementation project(":spring-plugin") implementation project(":konversation-plugin") + implementation project(":alexa-plugin") implementation('org.springframework.boot:spring-boot-starter-web') implementation('com.fasterxml.jackson.module:jackson-module-kotlin') implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation "com.amazon.alexa:ask-sdk-core:2.11.2" testImplementation('org.springframework.boot:spring-boot-starter-test') } diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt index 01369ce..de42985 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt @@ -1,12 +1,23 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.FallbackIntentHandler +import java.util.* @FallbackIntentHandler -class FallbackIntentHandler : DialogflowIntentHandler { +class FallbackIntentHandler : MultiPlatformIntentHandler { + + override fun canHandle(input: HandlerInput?): Boolean { + return false + } + + override fun handle(input: HandlerInput?): Optional { + return Optional.empty() + } override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { return false diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt index e644407..bad7ae8 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt @@ -1,13 +1,29 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import com.amazon.ask.request.Predicates +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.IntentHandler +import org.rewedigital.dialog.ssml.SsmlBuilder +import java.util.* @IntentHandler -class LocationPermissionIntentHandler : DialogflowIntentHandler { +class LocationPermissionIntentHandler : MultiPlatformIntentHandler { + + override fun canHandle(input: HandlerInput): Boolean { + return input.matches(Predicates.intentName("input.location_permission")) + } + + override fun handle(input: HandlerInput): Optional { + return input.responseBuilder + .withSpeech(SsmlBuilder("To use this feature we need your permission.").asSsmlString()) + .withAskForPermissionsConsentCard(listOf("read::alexa:device:all:address")) + .build() + } override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { return handler.action?.equals("input.location_permission") ?: false diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt index 0b2bb68..24ed875 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt @@ -1,13 +1,30 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import com.amazon.ask.request.Predicates +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.IntentHandler +import org.rewedigital.dialog.ssml.SsmlBuilder +import java.util.* @IntentHandler -class SignInIntentHandler : DialogflowIntentHandler { +class SignInIntentHandler : MultiPlatformIntentHandler { + + override fun canHandle(input: HandlerInput): Boolean { + return input.matches(Predicates.intentName("input.sign_in")) + } + + override fun handle(input: HandlerInput): Optional { + input.attributesManager.sessionAttributes["LAST_INTENT_HANDLER"] = this.javaClass.simpleName + return input.responseBuilder + .withSpeech(SsmlBuilder("Please link your Account.").asSsmlString()) + .withLinkAccountCard() + .build() + } override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { return handler.action?.equals("input.sign_in") ?: false diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt index f2ff94a..e351162 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt @@ -1,16 +1,50 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.LaunchRequest +import com.amazon.ask.model.Response +import com.amazon.ask.request.Predicates +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.IntentHandler import org.rewedigital.dialog.ssml.Emphasis import org.rewedigital.dialog.ssml.SsmlBuilder import org.rewedigital.dialog.utils.withGoogleSimpleResponse +import java.util.* @IntentHandler -class WelcomeIntentHandler : DialogflowIntentHandler { +class WelcomeIntentHandler : MultiPlatformIntentHandler { + + override fun canHandle(input: HandlerInput): Boolean { + return input.matches(Predicates.requestType(LaunchRequest::class.java)) + } + + override fun handle(input: HandlerInput): Optional { + input.attributesManager.sessionAttributes["LAST_INTENT_HANDLER"] = this.javaClass.simpleName + + val ssmlBuilder = SsmlBuilder() + when (input.request.locale) { + "de" -> ssmlBuilder + .appendText("Willkommen bei deinem ") + .appendEmphasis(Emphasis.STRONG, "Demo Assistenten. ") + .appendAudio("https://actions.google.com/sounds/v1/alarms/beep_short.ogg") + .appendBreak() + .appendSlowText("Wie kann ich dir helfen?") + "en" -> ssmlBuilder + .appendText("Welcome to your ") + .appendEmphasis(Emphasis.STRONG, "Demo Assistant. ") + .appendAudio("https://actions.google.com/sounds/v1/alarms/beep_short.ogg") + .appendBreak() + .appendSlowText("How can I help?") + } + + return input.responseBuilder + .withShouldEndSession(false) + .withSpeech(ssmlBuilder.asSsmlString()) + .build() + } override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { return handler.action?.equals("input.welcome") ?: false From 700efce3528812f2b9f689548a2451708dff9443 Mon Sep 17 00:00:00 2001 From: Volkmar Vogel Date: Fri, 15 Feb 2019 11:02:17 +0100 Subject: [PATCH 02/13] add support for alexa --- .../alexa/MultiPlatformIntentHandler.kt | 14 ++++++- .../MultiPlatformIntentHandlerRegistry.kt | 6 --- .../alexa/MultiPlatformRequestInterceptor.kt | 13 ++++++ .../alexa/MultiPlatformResponseInterceptor.kt | 15 +++++++ spring-sample/build.gradle | 10 ++++- .../dialog/springsample/alexa/AlexaConfig.kt | 29 ++++++++++++++ .../springsample/alexa/IntentHandlerConfig.kt | 29 ++++++++++++++ .../springsample/alexa/InterceptorConfig.kt | 40 +++++++++++++++++++ .../springsample/alexa/ServletConfig.kt | 15 +++++++ .../DialogflowIntentController.kt | 2 +- .../intenthandler/FallbackIntentHandler.kt | 18 +++------ .../KonversationExampleIntentHandler.kt | 16 +++++--- .../LocationPermissionIntentHandler.kt | 15 +++---- .../LocationPermissionResultIntentHandler.kt | 16 +++++--- .../MoreUiElementsIntentHandler.kt | 18 ++++++--- .../intenthandler/SignInIntentHandler.kt | 11 ++--- .../SignInResultIntentHandler.kt | 16 +++++--- .../intenthandler/UiElementsIntentHandler.kt | 17 +++++--- .../intenthandler/WelcomeIntentHandler.kt | 12 +++--- .../interceptors/LoggingInterceptor.kt | 21 ++++++++-- 20 files changed, 258 insertions(+), 75 deletions(-) delete mode 100644 alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt create mode 100644 alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformRequestInterceptor.kt create mode 100644 alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformResponseInterceptor.kt create mode 100644 spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt create mode 100644 spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt create mode 100644 spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt create mode 100644 spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/ServletConfig.kt rename spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/{ => dialogflow}/DialogflowIntentController.kt (94%) diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt index f4de3e8..842d098 100644 --- a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt +++ b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandler.kt @@ -1,7 +1,19 @@ package org.rewedigital.dialog.alexa +import com.amazon.ask.dispatcher.request.handler.HandlerInput import com.amazon.ask.dispatcher.request.handler.RequestHandler +import com.amazon.ask.model.Response import org.rewedigital.dialog.handler.DialogflowIntentHandler +import java.util.* -interface MultiPlatformIntentHandler : DialogflowIntentHandler, RequestHandler \ No newline at end of file +interface MultiPlatformIntentHandler : DialogflowIntentHandler, RequestHandler { + + override fun canHandle(input: HandlerInput) = canHandleAlexa(input) + + override fun handle(input: HandlerInput) = handleAlexa(input) + + fun canHandleAlexa(input: HandlerInput): Boolean + + fun handleAlexa(input: HandlerInput): Optional +} \ No newline at end of file diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt deleted file mode 100644 index d948bb5..0000000 --- a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformIntentHandlerRegistry.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.rewedigital.dialog.alexa - - -interface MultiPlatformIntentHandlerRegistry { - fun provideIntentHandlers(): List -} \ No newline at end of file diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformRequestInterceptor.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformRequestInterceptor.kt new file mode 100644 index 0000000..83e3fa9 --- /dev/null +++ b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformRequestInterceptor.kt @@ -0,0 +1,13 @@ +package org.rewedigital.dialog.alexa + +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import org.rewedigital.dialog.interceptors.RequestInterceptor + + +interface MultiPlatformRequestInterceptor : RequestInterceptor, + com.amazon.ask.dispatcher.request.interceptor.RequestInterceptor { + + override fun process(input: HandlerInput) = onAlexaRequest(input) + + fun onAlexaRequest(input: HandlerInput) +} \ No newline at end of file diff --git a/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformResponseInterceptor.kt b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformResponseInterceptor.kt new file mode 100644 index 0000000..0d138ad --- /dev/null +++ b/alexa-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/MultiPlatformResponseInterceptor.kt @@ -0,0 +1,15 @@ +package org.rewedigital.dialog.alexa + +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.interceptors.ResponseInterceptor +import java.util.* + + +interface MultiPlatformResponseInterceptor : ResponseInterceptor, + com.amazon.ask.dispatcher.request.interceptor.ResponseInterceptor { + + override fun process(input: HandlerInput, response: Optional) = onAlexaResponse(input, response) + + fun onAlexaResponse(input: HandlerInput, response: Optional) +} \ No newline at end of file diff --git a/spring-sample/build.gradle b/spring-sample/build.gradle index 535cc50..7d6c305 100644 --- a/spring-sample/build.gradle +++ b/spring-sample/build.gradle @@ -42,6 +42,8 @@ repositories { } dependencies { + def askSdkVersion = '2.11.2' + implementation project(":core") implementation project(":ssml") implementation project(":ssml-plugin") @@ -53,10 +55,16 @@ dependencies { implementation('com.fasterxml.jackson.module:jackson-module-kotlin') implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation "com.amazon.alexa:ask-sdk-core:2.11.2" + implementation("com.amazon.alexa:ask-sdk-core:$askSdkVersion") + implementation("com.amazon.alexa:ask-sdk-servlet-support:$askSdkVersion") + implementation("com.amazon.alexa:ask-sdk-apache-client:$askSdkVersion") testImplementation('org.springframework.boot:spring-boot-starter-test') } +configurations { + all*.exclude module: 'spring-boot-starter-logging' +} + dokka { externalDocumentationLink { url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/core/") diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt new file mode 100644 index 0000000..9d68a98 --- /dev/null +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt @@ -0,0 +1,29 @@ +package org.rewedigital.dialog.springsample.alexa + +import com.amazon.ask.Skill +import com.amazon.ask.builder.CustomSkillBuilder +import com.amazon.ask.services.ApacheHttpApiClient +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class AlexaConfig { + + @Bean + fun provideSkill( + intentHandlerHolder: IntentHandlerConfig.IntentHandlerHolder, + interceptorHolder: InterceptorConfig.InterceptorHolder + ): Skill = + CustomSkillBuilder() + .addRequestHandlers(intentHandlerHolder.intentHandlers) + .apply { + interceptorHolder.requestInterceptors.forEach { + addRequestInterceptor(it) + } + interceptorHolder.responseInterceptors.forEach { + addResponseInterceptor(it) + } + } + .withApiClient(ApacheHttpApiClient.standard()) + .build() +} \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt new file mode 100644 index 0000000..0d95d10 --- /dev/null +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt @@ -0,0 +1,29 @@ +package org.rewedigital.dialog.springsample.alexa + +import com.amazon.ask.dispatcher.request.handler.RequestHandler +import org.rewedigital.dialog.spring.annotations.IntentHandler +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import java.lang.instrument.IllegalClassFormatException + + +@Configuration +class IntentHandlerConfig { + + data class IntentHandlerHolder(val intentHandlers: List) + + @Bean + fun provideIntentHandlerHolder(context: ApplicationContext): IntentHandlerHolder { + + val allIntentHandler = + context + .getBeanNamesForAnnotation(IntentHandler::class.java) + .map { + context.getBean(it) as? RequestHandler + ?: throw IllegalClassFormatException("Your IntentHandler must implement the interface MultiPlatformIntentHandler") + } + + return IntentHandlerHolder(allIntentHandler) + } +} \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt new file mode 100644 index 0000000..82f88bf --- /dev/null +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt @@ -0,0 +1,40 @@ +package org.rewedigital.dialog.springsample.alexa + +import com.amazon.ask.dispatcher.request.interceptor.RequestInterceptor +import com.amazon.ask.dispatcher.request.interceptor.ResponseInterceptor +import org.rewedigital.dialog.spring.annotations.Interceptor +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + + +@Configuration +class InterceptorConfig { + + data class InterceptorHolder( + val requestInterceptors: List, + val responseInterceptors: List + ) + + @Bean + fun provideInterceptorHolder(context: ApplicationContext): InterceptorHolder { + + val requestInterceptors = mutableListOf() + val responseInterceptors = mutableListOf() + + context.getBeanNamesForAnnotation(Interceptor::class.java) + .forEach { beanName -> + context.getBean(beanName) + .also { bean -> + if (bean is RequestInterceptor) { + requestInterceptors.add(bean) + } + if (bean is ResponseInterceptor) { + responseInterceptors.add(bean) + } + } + } + + return InterceptorHolder(requestInterceptors, responseInterceptors) + } +} \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/ServletConfig.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/ServletConfig.kt new file mode 100644 index 0000000..8c78594 --- /dev/null +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/ServletConfig.kt @@ -0,0 +1,15 @@ +package org.rewedigital.dialog.springsample.alexa + +import com.amazon.ask.Skill +import com.amazon.ask.servlet.SkillServlet +import org.springframework.boot.web.servlet.ServletRegistrationBean +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class ServletConfig { + + @Bean + fun provideAlexaSkillServlet(skill: Skill) = + ServletRegistrationBean(SkillServlet(skill), "/alexaIntent") +} \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/DialogflowIntentController.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/dialogflow/DialogflowIntentController.kt similarity index 94% rename from spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/DialogflowIntentController.kt rename to spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/dialogflow/DialogflowIntentController.kt index 42227a7..b9a436b 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/DialogflowIntentController.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/dialogflow/DialogflowIntentController.kt @@ -1,4 +1,4 @@ -package org.rewedigital.dialog.springsample +package org.rewedigital.dialog.springsample.dialogflow import org.rewedigital.dialog.model.dialogflow.WebhookRequest import org.rewedigital.dialog.model.dialogflow.WebhookResponse diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt index de42985..f87a40e 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/FallbackIntentHandler.kt @@ -4,26 +4,18 @@ import com.amazon.ask.dispatcher.request.handler.HandlerInput import com.amazon.ask.model.Response import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.FallbackIntentHandler import java.util.* @FallbackIntentHandler class FallbackIntentHandler : MultiPlatformIntentHandler { - override fun canHandle(input: HandlerInput?): Boolean { - return false - } + override fun canHandleAlexa(input: HandlerInput) = false - override fun handle(input: HandlerInput?): Optional { - return Optional.empty() - } + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return false - } + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = false - override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { - return handler.responseBuilder.withText("Fallback!!!") - } + override fun handleDialogflowIntent(handler: DialogflowHandler) = + handler.responseBuilder.withText("Fallback!!!") } \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/KonversationExampleIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/KonversationExampleIntentHandler.kt index 2ae659b..addd8f6 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/KonversationExampleIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/KonversationExampleIntentHandler.kt @@ -1,20 +1,26 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.IntentHandler import org.rewedigital.dialog.utils.loadKonversation import org.rewedigital.dialog.utils.withGoogleReprompts import org.rewedigital.dialog.utils.withGoogleSimpleResponse import org.rewedigital.dialog.utils.withGoogleSuggestions +import java.util.* @IntentHandler -class KonversationExampleIntentHandler : DialogflowIntentHandler { +class KonversationExampleIntentHandler : MultiPlatformIntentHandler { - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.welcome2") ?: false - } + override fun canHandleAlexa(input: HandlerInput) = false + + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() + + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.welcome2") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt index bad7ae8..a8a4339 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionIntentHandler.kt @@ -14,20 +14,17 @@ import java.util.* @IntentHandler class LocationPermissionIntentHandler : MultiPlatformIntentHandler { - override fun canHandle(input: HandlerInput): Boolean { - return input.matches(Predicates.intentName("input.location_permission")) - } + override fun canHandleAlexa(input: HandlerInput): Boolean = + input.matches(Predicates.intentName("input.location_permission")) - override fun handle(input: HandlerInput): Optional { - return input.responseBuilder + override fun handleAlexa(input: HandlerInput): Optional = + input.responseBuilder .withSpeech(SsmlBuilder("To use this feature we need your permission.").asSsmlString()) .withAskForPermissionsConsentCard(listOf("read::alexa:device:all:address")) .build() - } - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.location_permission") ?: false - } + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.location_permission") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionResultIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionResultIntentHandler.kt index 680ced9..204a727 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionResultIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/LocationPermissionResultIntentHandler.kt @@ -1,17 +1,23 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.spring.annotations.IntentHandler +import java.util.* @IntentHandler -class LocationPermissionResultIntentHandler : DialogflowIntentHandler { +class LocationPermissionResultIntentHandler : MultiPlatformIntentHandler { - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.location_permission.result") ?: false - } + override fun canHandleAlexa(input: HandlerInput) = false + + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() + + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.location_permission.result") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/MoreUiElementsIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/MoreUiElementsIntentHandler.kt index 935b806..a134808 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/MoreUiElementsIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/MoreUiElementsIntentHandler.kt @@ -1,21 +1,27 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.model.google.GoogleCarouselItem import org.rewedigital.dialog.model.google.OptionInfo import org.rewedigital.dialog.spring.annotations.IntentHandler +import java.util.* @IntentHandler -class MoreUiElementsIntentHandler : DialogflowIntentHandler { +class MoreUiElementsIntentHandler : MultiPlatformIntentHandler { - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return (handler.action?.equals("input.more") ?: false) + override fun canHandleAlexa(input: HandlerInput) = false + + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() + + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + ((handler.action?.equals("input.more") ?: false) && (handler.getContextParam("default-context", "LAST_INTENT_HANDLER") as? String) - .equals(UiElementsIntentHandler::class.java.simpleName) - } + .equals(UiElementsIntentHandler::class.java.simpleName)) override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt index 24ed875..724c2df 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInIntentHandler.kt @@ -14,11 +14,9 @@ import java.util.* @IntentHandler class SignInIntentHandler : MultiPlatformIntentHandler { - override fun canHandle(input: HandlerInput): Boolean { - return input.matches(Predicates.intentName("input.sign_in")) - } + override fun canHandleAlexa(input: HandlerInput) = input.matches(Predicates.intentName("input.sign_in")) - override fun handle(input: HandlerInput): Optional { + override fun handleAlexa(input: HandlerInput): Optional { input.attributesManager.sessionAttributes["LAST_INTENT_HANDLER"] = this.javaClass.simpleName return input.responseBuilder .withSpeech(SsmlBuilder("Please link your Account.").asSsmlString()) @@ -26,9 +24,8 @@ class SignInIntentHandler : MultiPlatformIntentHandler { .build() } - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.sign_in") ?: false - } + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.sign_in") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInResultIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInResultIntentHandler.kt index 6bacd5d..6a4a932 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInResultIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/SignInResultIntentHandler.kt @@ -1,18 +1,24 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder import org.rewedigital.dialog.model.google.Status import org.rewedigital.dialog.spring.annotations.IntentHandler +import java.util.* @IntentHandler -class SignInResultIntentHandler : DialogflowIntentHandler { +class SignInResultIntentHandler : MultiPlatformIntentHandler { - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.sign_in.result") ?: false - } + override fun canHandleAlexa(input: HandlerInput) = false + + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() + + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.sign_in.result") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/UiElementsIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/UiElementsIntentHandler.kt index 667380d..88e276d 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/UiElementsIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/UiElementsIntentHandler.kt @@ -1,20 +1,25 @@ package org.rewedigital.dialog.springsample.intenthandler +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response +import org.rewedigital.dialog.alexa.MultiPlatformIntentHandler import org.rewedigital.dialog.handler.DialogflowHandler -import org.rewedigital.dialog.handler.DialogflowIntentHandler import org.rewedigital.dialog.handler.DialogflowResponseBuilder -import org.rewedigital.dialog.model.google.GoogleBasicCard import org.rewedigital.dialog.model.google.GoogleButton import org.rewedigital.dialog.model.google.OpenUrlAction import org.rewedigital.dialog.spring.annotations.IntentHandler +import java.util.* @IntentHandler -class UiElementsIntentHandler : DialogflowIntentHandler { +class UiElementsIntentHandler : MultiPlatformIntentHandler { - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.ui_elements") ?: false - } + override fun canHandleAlexa(input: HandlerInput) = false + + override fun handleAlexa(input: HandlerInput): Optional = Optional.empty() + + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.ui_elements") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt index e351162..edcdf9b 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/intenthandler/WelcomeIntentHandler.kt @@ -17,11 +17,10 @@ import java.util.* @IntentHandler class WelcomeIntentHandler : MultiPlatformIntentHandler { - override fun canHandle(input: HandlerInput): Boolean { - return input.matches(Predicates.requestType(LaunchRequest::class.java)) - } + override fun canHandleAlexa(input: HandlerInput) = + input.matches(Predicates.requestType(LaunchRequest::class.java)) - override fun handle(input: HandlerInput): Optional { + override fun handleAlexa(input: HandlerInput): Optional { input.attributesManager.sessionAttributes["LAST_INTENT_HANDLER"] = this.javaClass.simpleName val ssmlBuilder = SsmlBuilder() @@ -46,9 +45,8 @@ class WelcomeIntentHandler : MultiPlatformIntentHandler { .build() } - override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { - return handler.action?.equals("input.welcome") ?: false - } + override fun canHandleDialogflowIntent(handler: DialogflowHandler) = + handler.action?.equals("input.welcome") ?: false override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { handler.setContextParam("default-context", "LAST_INTENT_HANDLER", this.javaClass.simpleName) diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/interceptors/LoggingInterceptor.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/interceptors/LoggingInterceptor.kt index 001a674..4078dee 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/interceptors/LoggingInterceptor.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/interceptors/LoggingInterceptor.kt @@ -1,15 +1,30 @@ package org.rewedigital.dialog.springsample.interceptors +import com.amazon.ask.dispatcher.request.handler.HandlerInput +import com.amazon.ask.model.Response import com.fasterxml.jackson.databind.ObjectMapper -import org.rewedigital.dialog.interceptors.RequestInterceptor -import org.rewedigital.dialog.interceptors.ResponseInterceptor +import org.rewedigital.dialog.alexa.MultiPlatformRequestInterceptor +import org.rewedigital.dialog.alexa.MultiPlatformResponseInterceptor import org.rewedigital.dialog.model.dialogflow.WebhookRequest import org.rewedigital.dialog.model.dialogflow.WebhookResponse import org.rewedigital.dialog.spring.annotations.Interceptor +import java.util.* @Interceptor -class LoggingInterceptor(private val objectMapper: ObjectMapper) : RequestInterceptor, ResponseInterceptor { +class LoggingInterceptor(private val objectMapper: ObjectMapper) : + MultiPlatformRequestInterceptor, + MultiPlatformResponseInterceptor { + + override fun onAlexaRequest(input: HandlerInput) { + println(input.requestEnvelope.toString()) + } + + override fun onAlexaResponse(input: HandlerInput, response: Optional) { + response.ifPresent { + println(it.toString()) + } + } override fun onDialogflowRequest(webhookRequest: WebhookRequest) { println(objectMapper.writeValueAsString(webhookRequest)) From 83b3ffba754763eaf4441abd009989572c6e4800 Mon Sep 17 00:00:00 2001 From: Volkmar Vogel Date: Fri, 22 Feb 2019 13:51:30 +0100 Subject: [PATCH 03/13] extract alexa configs --- alexa-spring-plugin/build.gradle | 34 +++++++++++++++++++ .../alexa/spring}/IntentHandlerConfig.kt | 2 +- .../dialog/alexa/spring}/InterceptorConfig.kt | 2 +- .../main/resources/META-INF/spring.factories | 1 + konversation-plugin/build.gradle | 3 +- settings.gradle | 3 +- spring-plugin/build.gradle | 3 +- spring-sample/build.gradle | 1 + .../dialog/springsample/alexa/AlexaConfig.kt | 2 ++ ssml-plugin/build.gradle | 5 +-- 10 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 alexa-spring-plugin/build.gradle rename {spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa => alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring}/IntentHandlerConfig.kt (95%) rename {spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa => alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring}/InterceptorConfig.kt (96%) create mode 100644 alexa-spring-plugin/src/main/resources/META-INF/spring.factories diff --git a/alexa-spring-plugin/build.gradle b/alexa-spring-plugin/build.gradle new file mode 100644 index 0000000..6d30224 --- /dev/null +++ b/alexa-spring-plugin/build.gradle @@ -0,0 +1,34 @@ +group 'org.rewedigital.voice.dialog' +version rootProject.ext.versions.alexa + +apply plugin: 'kotlin' +apply plugin: 'kotlin-spring' +apply plugin: 'maven-publish' +apply from: '../docu.gradle' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath("org.jetbrains.kotlin:kotlin-allopen:${rootProject.ext.versions.kotlin}") + } +} + +dependencies { + implementation project(":core") + implementation project(":alexa-plugin") + implementation project(":spring-plugin") + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation "org.jetbrains.kotlin:kotlin-reflect" + implementation "org.springframework:spring-context:5.1.4.RELEASE" + implementation "com.amazon.alexa:ask-sdk-core:2.11.2" +} + +publishing.publications { + maven(MavenPublication) { + artifactId = 'alexa-spring-plugin' + from components.java + } +} \ No newline at end of file diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt b/alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/IntentHandlerConfig.kt similarity index 95% rename from spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt rename to alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/IntentHandlerConfig.kt index 0d95d10..2d69bb1 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/IntentHandlerConfig.kt +++ b/alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/IntentHandlerConfig.kt @@ -1,4 +1,4 @@ -package org.rewedigital.dialog.springsample.alexa +package org.rewedigital.dialog.alexa.spring import com.amazon.ask.dispatcher.request.handler.RequestHandler import org.rewedigital.dialog.spring.annotations.IntentHandler diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt b/alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/InterceptorConfig.kt similarity index 96% rename from spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt rename to alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/InterceptorConfig.kt index 82f88bf..a5a2320 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/InterceptorConfig.kt +++ b/alexa-spring-plugin/src/main/kotlin/org/rewedigital/dialog/alexa/spring/InterceptorConfig.kt @@ -1,4 +1,4 @@ -package org.rewedigital.dialog.springsample.alexa +package org.rewedigital.dialog.alexa.spring import com.amazon.ask.dispatcher.request.interceptor.RequestInterceptor import com.amazon.ask.dispatcher.request.interceptor.ResponseInterceptor diff --git a/alexa-spring-plugin/src/main/resources/META-INF/spring.factories b/alexa-spring-plugin/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..1847672 --- /dev/null +++ b/alexa-spring-plugin/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.rewedigital.dialog.alexa.spring.IntentHandlerConfig,org.rewedigital.dialog.alexa.spring.InterceptorConfig \ No newline at end of file diff --git a/konversation-plugin/build.gradle b/konversation-plugin/build.gradle index cf58c90..512bd13 100644 --- a/konversation-plugin/build.gradle +++ b/konversation-plugin/build.gradle @@ -7,8 +7,9 @@ apply from: '../docu.gradle' apply plugin: 'com.novoda.bintray-release' dependencies { + implementation project(":core") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" compile 'org.rewedigital.voice:konversation:1.0-rc1' } diff --git a/settings.gradle b/settings.gradle index ac3de3c..8dde0c3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,4 +5,5 @@ include 'ssml-plugin' include 'spring-sample' include 'spring-plugin' include 'konversation-plugin' -include 'alexa-plugin' \ No newline at end of file +include 'alexa-plugin' +include 'alexa-spring-plugin' \ No newline at end of file diff --git a/spring-plugin/build.gradle b/spring-plugin/build.gradle index b22f263..7af005b 100644 --- a/spring-plugin/build.gradle +++ b/spring-plugin/build.gradle @@ -19,7 +19,8 @@ apply from: '../docu.gradle' apply plugin: 'com.novoda.bintray-release' dependencies { - implementation "org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" + implementation project(":core") + implementation "org.jetbrains.kotlin:kotlin-reflect" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.springframework:spring-context:5.1.4.RELEASE" diff --git a/spring-sample/build.gradle b/spring-sample/build.gradle index 7d6c305..1915c99 100644 --- a/spring-sample/build.gradle +++ b/spring-sample/build.gradle @@ -50,6 +50,7 @@ dependencies { implementation project(":spring-plugin") implementation project(":konversation-plugin") implementation project(":alexa-plugin") + implementation project(":alexa-spring-plugin") implementation('org.springframework.boot:spring-boot-starter-web') implementation('com.fasterxml.jackson.module:jackson-module-kotlin') diff --git a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt index 9d68a98..c5c5633 100644 --- a/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt +++ b/spring-sample/src/main/kotlin/org/rewedigital/dialog/springsample/alexa/AlexaConfig.kt @@ -3,6 +3,8 @@ package org.rewedigital.dialog.springsample.alexa import com.amazon.ask.Skill import com.amazon.ask.builder.CustomSkillBuilder import com.amazon.ask.services.ApacheHttpApiClient +import org.rewedigital.dialog.alexa.spring.IntentHandlerConfig +import org.rewedigital.dialog.alexa.spring.InterceptorConfig import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration diff --git a/ssml-plugin/build.gradle b/ssml-plugin/build.gradle index 84b6529..66dff65 100644 --- a/ssml-plugin/build.gradle +++ b/ssml-plugin/build.gradle @@ -9,9 +9,10 @@ apply from: '../docu.gradle' apply plugin: 'com.novoda.bintray-release' dependencies { + implementation project(":core") + implementation project(":ssml") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" - implementation "org.rewedigital.voice:ssml-builder:${rootProject.ext.versions.ssml}" } dokka { From 4fd1c7d4a9428c586a37aa3d1dc0091d9bf8d7d6 Mon Sep 17 00:00:00 2001 From: Volkmar Vogel Date: Fri, 22 Feb 2019 14:48:15 +0100 Subject: [PATCH 04/13] add alexa support to the README --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3adbe09..092348d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ write your own voice application fast. ## Top features - Dialogflow V2 API reference implementation written in Kotlin -- Interceper API for adding e.g. tracking +- Multiplatform support, one service for Alexa and Google Assistant +- Intercepter API for adding e.g. tracking - Spring reference implementation - SSML builder for creating rich responses - Plugin for Konversation to distinct the dialogs from code @@ -110,6 +111,57 @@ the spring-sample project as template for your own project. When you use our plu injection. The best it that we use it also for discovering your intent handler automatically. For the fallback intent you should use the annotation `@FallbackIntentHandler`, if it is missing you service won't start up. +## Adding Multiplatform Support + +You can add the Alexa plugin to build a service which can serve Alexa and the Google Assistant at once. You just have +to change your IntentHandler to implement the MultiplatformIntentHandler. + + class WelcomeIntentHandler : MultiPlatformIntentHandler { + + override fun canHandleAlexa(input: HandlerInput) = + input.matches(Predicates.requestType(LaunchRequest::class.java)) + + override fun handleAlexa(input: HandlerInput): Optional { + return input.responseBuilder + .withSpeech("Welcome to Dialog!") + .build() + } + + override fun canHandleDialogflowIntent(handler: DialogflowHandler): Boolean { + return handler.action?.equals("input.welcome") ?: false + } + + override fun handleDialogflowIntent(handler: DialogflowHandler): DialogflowResponseBuilder { + return handler.responseBuilder.withText("Welcome to Dialog!") + } + } + +If you're using Dialog with Spring you can add the `alexa-spring-plugin` which will automatically provide a Bean of +`IntentHandlerHolder`. This call contains the list of all Alexa `RequestHandler` which can be added to the +`CustomSkillBuilder` like in the following example. + + @Configuration + class AlexaConfig { + + @Bean + fun provideSkill( + intentHandlerHolder: IntentHandlerConfig.IntentHandlerHolder, + interceptorHolder: InterceptorConfig.InterceptorHolder + ): Skill = + CustomSkillBuilder() + .addRequestHandlers(intentHandlerHolder.intentHandlers) + .apply { + interceptorHolder.requestInterceptors.forEach { + addRequestInterceptor(it) + } + interceptorHolder.responseInterceptors.forEach { + addResponseInterceptor(it) + } + } + .withApiClient(ApacheHttpApiClient.standard()) + .build() + } + ## License The MIT license (MIT) From d1b7d631c8213e3f7ff5f55401fdeee130d80597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Tue, 26 Feb 2019 14:59:43 +0100 Subject: [PATCH 05/13] Preparation for publishing the new module --- alexa-plugin/build.gradle | 95 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/alexa-plugin/build.gradle b/alexa-plugin/build.gradle index 8b28e2f..5b83c32 100644 --- a/alexa-plugin/build.gradle +++ b/alexa-plugin/build.gradle @@ -1,19 +1,108 @@ +import java.nio.file.Paths + group 'org.rewedigital.voice.dialog' version rootProject.ext.versions.alexa +description = 'The Alexa plugin for Dialog to write voice applications for Dialogflow and Alexa.' apply plugin: 'kotlin' apply plugin: 'maven-publish' apply from: '../docu.gradle' +apply plugin: 'com.novoda.bintray-release' dependencies { - implementation project(":core") + //implementation project(":core") + implementation "org.rewedigital.voice:dialog:1.0" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "com.amazon.alexa:ask-sdk-core:2.11.2" } +dokka { + externalDocumentationLink { + url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/core/") + packageListUrl = Paths.get("$rootDir/docs/core/package-list").toUri().toURL() + } +} + +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} + +task sourcesJar(type: Jar, dependsOn: classes) { + archiveClassifier = 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { + archiveClassifier = 'javadoc' + from "$buildDir/javadoc" +} + publishing.publications { - maven(MavenPublication) { - artifactId = 'alexa-plugin' + alexaPlugin(MavenPublication) { + groupId = project.group + artifactId = project.name from components.java + version = project.version + artifact sourcesJar { + archiveClassifier = 'sources' + } + artifact javadocJar { + archiveClassifier = 'javadoc' + } + pom { + name = project.name + description = project.description + url = "https://github.com/rewe-digital-incubator/${rootProject.name}" + licenses { + license { + name = 'MIT License' + url = 'https://opensource.org/licenses/MIT' + distribution = 'repo' + } + } + developers { + def maintainers = [:] + file("$rootDir/MAINTAINERS").text.eachLine { line -> + def (name, mail) = line.split('<') + maintainers[name.trim()] = mail.replace('>','').trim() + } + maintainers.entrySet().forEach { dev -> + developer { + name = dev.key + email = dev.value + } + } + } + + scm { + connection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" + developerConnection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" + url = "https://rewe-digital-incubator.github.io/${rootProject.name}/" + } + } + } +} + +publish { + userOrg = 'rewe-digital' + groupId = project.group + artifactId = project.name + repoName = rootProject.name + publishVersion = project.version + desc = project.description + bintrayUser = project.properties['bintray.user'] + bintrayKey = project.properties['bintray.apikey'] + dryRun = true + publications = ['alexaPlugin'] +} + +allprojects { + afterEvaluate { project -> + project.publishing.publications.forEach { publication -> + if(publication.name == 'maven') { + project.publishing.publications.remove(publication) + } + } } } \ No newline at end of file From 58a5e7172272f1b82f3d1cc523ae0d76fdb8c5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Thu, 28 Feb 2019 23:07:04 +0100 Subject: [PATCH 06/13] Optimize the way how the artifacts are published --- alexa-plugin/build.gradle | 95 +++----------------------------- core/build.gradle | 79 ++------------------------ konversation-plugin/build.gradle | 2 +- publish.gradle | 84 ++++++++++++++++++++++++++++ ssml-plugin/build.gradle | 75 ++----------------------- 5 files changed, 103 insertions(+), 232 deletions(-) create mode 100644 publish.gradle diff --git a/alexa-plugin/build.gradle b/alexa-plugin/build.gradle index 5b83c32..cc43d58 100644 --- a/alexa-plugin/build.gradle +++ b/alexa-plugin/build.gradle @@ -2,16 +2,19 @@ import java.nio.file.Paths group 'org.rewedigital.voice.dialog' version rootProject.ext.versions.alexa -description = 'The Alexa plugin for Dialog to write voice applications for Dialogflow and Alexa.' +description 'The Alexa plugin for Dialog to write voice applications for Dialogflow and Alexa.' apply plugin: 'kotlin' apply plugin: 'maven-publish' apply from: '../docu.gradle' -apply plugin: 'com.novoda.bintray-release' + +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} dependencies { - //implementation project(":core") - implementation "org.rewedigital.voice:dialog:1.0" + implementation project(":core") implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "com.amazon.alexa:ask-sdk-core:2.11.2" } @@ -23,86 +26,4 @@ dokka { } } -task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { - outputFormat = 'javadoc' - outputDirectory = "$buildDir/javadoc" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - alexaPlugin(MavenPublication) { - groupId = project.group - artifactId = project.name - from components.java - version = project.version - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - pom { - name = project.name - description = project.description - url = "https://github.com/rewe-digital-incubator/${rootProject.name}" - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - def maintainers = [:] - file("$rootDir/MAINTAINERS").text.eachLine { line -> - def (name, mail) = line.split('<') - maintainers[name.trim()] = mail.replace('>','').trim() - } - maintainers.entrySet().forEach { dev -> - developer { - name = dev.key - email = dev.value - } - } - } - - scm { - connection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" - developerConnection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" - url = "https://rewe-digital-incubator.github.io/${rootProject.name}/" - } - } - } -} - -publish { - userOrg = 'rewe-digital' - groupId = project.group - artifactId = project.name - repoName = rootProject.name - publishVersion = project.version - desc = project.description - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = true - publications = ['alexaPlugin'] -} - -allprojects { - afterEvaluate { project -> - project.publishing.publications.forEach { publication -> - if(publication.name == 'maven') { - project.publishing.publications.remove(publication) - } - } - } -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle index 6e98326..a0413cc 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,85 +1,18 @@ apply plugin: 'kotlin' apply plugin: 'maven-publish' -apply plugin: 'com.novoda.bintray-release' apply from: '../docu.gradle' -group "org.rewedigital.voice" -version "${rootProject.ext.versions.core}" - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" -} +group 'org.rewedigital.voice:dialog' +version rootProject.ext.versions.core +description 'Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to write your own voice applications fast.' task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - core(MavenPublication) { - groupId = "org.rewedigital.voice" - artifactId = "dialog" - version = "${rootProject.ext.versions.core}" - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - from components.java - pom { - name = 'dialog' - description = 'Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to write your own voice application fast.' - url = 'https://github.com/rewe-digital-incubator/dialog' - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - // TODO use the MAINTAINERS file - developer { - name = 'Volkmar Vogel' - email = 'volkmar.vogel@rewe-digital.com' - } - developer { - name = 'René Kilczan' - email = 'rene.kilczan@rewe-digital.com' - } - } - - scm { - connection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - developerConnection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - url = 'https://github.com/rewe-digital-incubator/dialog' - } - } - } -} +apply from: '../publish.gradle' -publish { - userOrg = 'rewe-digital' - groupId = 'org.rewedigital.voice' - artifactId = 'core' - repoName = 'dialog' - publishVersion = rootProject.ext.versions.core - desc = 'Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to write your own voice applications fast.' - website = 'https://github.com/rewe-digital-incubator/dialog' - licences = ['MIT'] - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = false - publications = ['core'] +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } \ No newline at end of file diff --git a/konversation-plugin/build.gradle b/konversation-plugin/build.gradle index 512bd13..1edffad 100644 --- a/konversation-plugin/build.gradle +++ b/konversation-plugin/build.gradle @@ -78,6 +78,6 @@ publish { licences = ['MIT'] bintrayUser = project.properties['bintray.user'] bintrayKey = project.properties['bintray.apikey'] - dryRun = false + dryRun = true publications = ['konversationPlugin'] } \ No newline at end of file diff --git a/publish.gradle b/publish.gradle new file mode 100644 index 0000000..f4be1a2 --- /dev/null +++ b/publish.gradle @@ -0,0 +1,84 @@ +apply plugin: 'com.novoda.bintray-release' + +// small hack to override the artifact ID via group name, if it is clean the project name will be used as artifactId +def groupID, artifactID +if(project.group.contains(":")) { + (groupID, artifactID) = project.group.split(":") +} else { + groupID = project.group + artifactID = project.name +} + +logger.info("desc: " + project.description) +logger.info("group: " + groupID) +logger.info("version: " + project.version) +logger.info("artifactId: " + artifactID) + +task sourcesJar(type: Jar, dependsOn: classes) { + archiveClassifier = 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { + archiveClassifier = 'javadoc' + from "$buildDir/javadoc" +} + +publish { + userOrg = 'rewe-digital' + groupId = groupID + artifactId = artifactID + repoName = rootProject.name + publishVersion = project.version + desc = project.description + bintrayUser = project.properties['bintray.user'] + bintrayKey = project.properties['bintray.apikey'] + dryRun = true + publications = ['maven'] +} + +publishing.publications.all { publication -> + if (publication.name == 'maven') { + artifact(jar) + publication.artifacts.all { artifact -> + if (artifact.classifier == 'javadoc') { + artifact.builtBy javadocJar + } + if (artifact.classifier == 'sources') { + artifact.builtBy sourcesJar + } + } + + publication.pom { + name = project.name + description = project.description + url = "https://rewe-digital-incubator.github.io/${rootProject.name}/${project.name}" + licenses { + license { + name = 'MIT License' + url = 'https://opensource.org/licenses/MIT' + distribution = 'repo' + } + } + developers { + def maintainers = [:] + file("$rootDir/MAINTAINERS").text.eachLine { line -> + def (name, mail) = line.split('<') + maintainers[name.trim()] = mail.replace('>','').trim() + } + maintainers.entrySet().forEach { dev -> + developer { + name = dev.key + email = dev.value + } + } + } + + scm { + connection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" + developerConnection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" + url = "https://github.com/rewe-digital-incubator/${rootProject.name}" + } + } + } +} \ No newline at end of file diff --git a/ssml-plugin/build.gradle b/ssml-plugin/build.gradle index 66dff65..def7d91 100644 --- a/ssml-plugin/build.gradle +++ b/ssml-plugin/build.gradle @@ -1,6 +1,7 @@ import java.nio.file.Paths group 'org.rewedigital.voice.dialog' +description 'This is the SSML-Builder plugin for Dialog to write voice applications fast.' version rootProject.ext.versions.ssml_plugin apply plugin: 'kotlin' @@ -9,10 +10,9 @@ apply from: '../docu.gradle' apply plugin: 'com.novoda.bintray-release' dependencies { - implementation project(":core") - implementation project(":ssml") - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation project(':core') //"org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" + implementation project(':ssml-builder') //"org.rewedigital.voice:ssml-builder:${rootProject.ext.versions.ssml}" } dokka { @@ -27,71 +27,4 @@ task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputDirectory = "$buildDir/javadoc" } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - ssmlPlugin(MavenPublication) { - groupId = 'org.rewedigital.voice.dialog' - artifactId = 'ssml-plugin' - from components.java - version = "${rootProject.ext.versions.core}" - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - pom { - name = 'dialog' - description = 'This is the SSML-Builder plugin for Dialog to write voice applications fast.' - url = 'https://github.com/rewe-digital-incubator/dialog' - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - // TODO use the MAINTAINERS file - developer { - name = 'Volkmar Vogel' - email = 'volkmar.vogel@rewe-digital.com' - } - developer { - name = 'René Kilczan' - email = 'rene.kilczan@rewe-digital.com' - } - } - - scm { - connection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - developerConnection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - url = 'https://github.com/rewe-digital-incubator/dialog' - } - } - } -} - -publish { - userOrg = 'rewe-digital' - groupId = 'org.rewedigital.voice.dialog' - artifactId = 'ssml-plugin' - repoName = 'dialog' - publishVersion = rootProject.ext.versions.core - desc = 'This is the SSML-Builder plugin for Dialog to write voice applications fast.' - website = 'https://github.com/rewe-digital-incubator/dialog' - licences = ['MIT'] - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = false - publications = ['ssmlPlugin'] -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file From 4c70685a452a082779fed5314021f19c47fe6e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Thu, 28 Feb 2019 23:12:43 +0100 Subject: [PATCH 07/13] Fix module name in dependency --- ssml-plugin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssml-plugin/build.gradle b/ssml-plugin/build.gradle index def7d91..e9baa75 100644 --- a/ssml-plugin/build.gradle +++ b/ssml-plugin/build.gradle @@ -12,7 +12,7 @@ apply plugin: 'com.novoda.bintray-release' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation project(':core') //"org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" - implementation project(':ssml-builder') //"org.rewedigital.voice:ssml-builder:${rootProject.ext.versions.ssml}" + implementation project(':ssml') //"org.rewedigital.voice:ssml-builder:${rootProject.ext.versions.ssml}" } dokka { From 52a35b1a84d9b77473784da1d4c898815e33a31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Wed, 6 Mar 2019 20:24:52 +0100 Subject: [PATCH 08/13] Use maven as publication name --- publish.gradle | 30 +++++++++++++++--------------- ssml-plugin/build.gradle | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/publish.gradle b/publish.gradle index f4be1a2..921beac 100644 --- a/publish.gradle +++ b/publish.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.novoda.bintray-release' // small hack to override the artifact ID via group name, if it is clean the project name will be used as artifactId def groupID, artifactID -if(project.group.contains(":")) { +if (project.group.contains(":")) { (groupID, artifactID) = project.group.split(":") } else { groupID = project.group @@ -37,19 +37,20 @@ publish { publications = ['maven'] } -publishing.publications.all { publication -> - if (publication.name == 'maven') { - artifact(jar) - publication.artifacts.all { artifact -> - if (artifact.classifier == 'javadoc') { - artifact.builtBy javadocJar - } - if (artifact.classifier == 'sources') { - artifact.builtBy sourcesJar - } +publishing.publications { + maven(MavenPublication) { + groupId = groupID + artifactId = artifactID + from components.java + version = project.version + artifact sourcesJar { + archiveClassifier = 'sources' } - - publication.pom { + artifact javadocJar { + archiveClassifier = 'javadoc' + } + + pom { name = project.name description = project.description url = "https://rewe-digital-incubator.github.io/${rootProject.name}/${project.name}" @@ -64,7 +65,7 @@ publishing.publications.all { publication -> def maintainers = [:] file("$rootDir/MAINTAINERS").text.eachLine { line -> def (name, mail) = line.split('<') - maintainers[name.trim()] = mail.replace('>','').trim() + maintainers[name.trim()] = mail.replace('>', '').trim() } maintainers.entrySet().forEach { dev -> developer { @@ -73,7 +74,6 @@ publishing.publications.all { publication -> } } } - scm { connection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" developerConnection = "scm:git:git://github.com/rewe-digital-incubator/${rootProject.name}.git" diff --git a/ssml-plugin/build.gradle b/ssml-plugin/build.gradle index e9baa75..2c7d563 100644 --- a/ssml-plugin/build.gradle +++ b/ssml-plugin/build.gradle @@ -11,8 +11,8 @@ apply plugin: 'com.novoda.bintray-release' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation project(':core') //"org.rewedigital.voice:dialog:${rootProject.ext.versions.core}" - implementation project(':ssml') //"org.rewedigital.voice:ssml-builder:${rootProject.ext.versions.ssml}" + implementation project(':core') + implementation project(':ssml') } dokka { From e6fd24b53f8c0ac892da59b55db27d32a563d6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Wed, 6 Mar 2019 20:29:21 +0100 Subject: [PATCH 09/13] Add patched version of the novoda plugin to the project --- build.gradle | 3 +- buildSrc/build.gradle | 55 ++++++++++++++ .../release/BintrayConfiguration.groovy | 72 ++++++++++++++++++ .../release/GradlePluginPropertyFinder.groovy | 38 ++++++++++ .../MavenPublicationAttachments.groovy | 42 ++++++++++ .../gradle/release/PropertyFinder.groovy | 43 +++++++++++ .../gradle/release/PublishExtension.groovy | 76 +++++++++++++++++++ .../gradle/release/ReleasePlugin.groovy | 57 ++++++++++++++ .../internal/AndroidAttachments.groovy | 53 +++++++++++++ .../release/internal/JavaAttachments.groovy | 31 ++++++++ 10 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy create mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy diff --git a/build.gradle b/build.gradle index 09a00bf..0738fdb 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,8 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0' classpath "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}" - classpath 'com.novoda:bintray-release:0.9' + // Until https://github.com/novoda/bintray-release/pull/267 is merged we use the plugin from buildSrc + // classpath 'com.novoda:bintray-release:0.9' } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..2dd2cbe --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,55 @@ +buildscript { + repositories { + jcenter() + mavenCentral() + maven { url 'https://plugins.gradle.org/m2/' } + } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.0' + // classpath 'com.google.googlejavaformat:google-java-format:1.3' + } +} + +plugins { + id 'groovy' + id 'java-gradle-plugin' + id 'com.novoda.build-properties' version '0.4.1' +} + +version = '0.9' + +//apply plugin: 'com.novoda.bintray-release' +//apply from: 'publish.gradle' +//apply from: 'compat.gradle' + +dependencies { + implementation 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + + testImplementation 'junit:junit:4.12' + testImplementation 'com.google.truth:truth:0.42' + + testRuntime files(pluginUnderTestMetadata) + + repositories { + jcenter() + mavenCentral() + } +} + +compileGroovy { + sourceCompatibility = '1.6' + targetCompatibility = '1.6' +} + +gradlePlugin { + plugins { + binrayRelease { + id = 'com.novoda.bintray-release' + implementationClass = 'com.novoda.gradle.release.ReleasePlugin' + } + legacy { + id = 'bintray-release' + implementationClass = 'com.novoda.gradle.release.ReleasePlugin' + } + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy new file mode 100644 index 0000000..f8f3819 --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy @@ -0,0 +1,72 @@ +package com.novoda.gradle.release + +import org.gradle.api.Project + +class BintrayConfiguration { + + PublishExtension extension + + BintrayConfiguration(PublishExtension extension) { + this.extension = extension + } + + void configure(Project project) { + initDefaults() + deriveDefaultsFromProject(project) + + PropertyFinder propertyFinder = new PropertyFinder(project, extension) + + project.bintray { + user = propertyFinder.bintrayUser + key = propertyFinder.bintrayKey + publish = extension.autoPublish + dryRun = propertyFinder.dryRun + override = propertyFinder.override + + publications = extension.publications ?: project.plugins.hasPlugin('com.android.library') ? ['release'] : [ 'maven' ] + + pkg { + repo = extension.repoName + userOrg = extension.userOrg + name = extension.uploadName + desc = extension.desc + websiteUrl = extension.website + issueTrackerUrl = extension.issueTracker + vcsUrl = extension.repository + + licenses = extension.licences + version { + name = propertyFinder.publishVersion + attributes = extension.versionAttributes + } + } + } + project.tasks.bintrayUpload.mustRunAfter(project.tasks.uploadArchives) + } + + private void initDefaults() { + if (extension.uploadName.isEmpty()) { + extension.uploadName = extension.artifactId + } + + if (extension.website.contains('github.com')) { + if (extension.issueTracker.isEmpty()) { + extension.issueTracker = "${extension.website}/issues" + } + if (extension.repository.isEmpty()) { + extension.repository = "${extension.website}.git" + } + } + } + + private void deriveDefaultsFromProject(Project project) { + if (extension.versionAttributes.isEmpty()) { + def gradlePluginPropertyFinder = new GradlePluginPropertyFinder(project) + String bestPluginId = gradlePluginPropertyFinder.findBestGradlePluginId() + if (bestPluginId != null) { + extension.versionAttributes << ['gradle-plugin': "$bestPluginId:$extension.groupId:$extension.artifactId"] + project.logger.info "Using plugin identifier '" + extension.versionAttributes.get('gradle-plugins') + "' for gradle portal." + } + } + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy new file mode 100644 index 0000000..185fae6 --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy @@ -0,0 +1,38 @@ +package com.novoda.gradle.release + +import org.gradle.api.Project +import org.gradle.api.file.FileCollection +import org.gradle.api.file.FileTree + +class GradlePluginPropertyFinder { + private static final String FILE_EXTENSION_PROPERTIES = ".properties" + private final Project project + + GradlePluginPropertyFinder(Project project) { + this.project = project + } + + String findBestGradlePluginId() { + FileTree pluginFiles = project.fileTree(dir: 'src/main/resources/META-INF/gradle-plugins') + if (pluginFiles.isEmpty()) { + return null + } + FileCollection filteredPluginFiles = pluginFiles.filter { + it.name.endsWith(FILE_EXTENSION_PROPERTIES) && + isNamespacedPropertyFile(it) + } + if (filteredPluginFiles.isEmpty()) { + return null + } + File bestPluginFile = filteredPluginFiles.first() + return removePropertyFileExtension(bestPluginFile) + } + + private boolean isNamespacedPropertyFile(File file) { + return file.name.substring(0, file.name.length() - FILE_EXTENSION_PROPERTIES.length()).contains('.') + } + + private String removePropertyFileExtension(File bestPluginFile) { + bestPluginFile.name.substring(0, bestPluginFile.name.length() - FILE_EXTENSION_PROPERTIES.length()) + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy new file mode 100644 index 0000000..53d94ce --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy @@ -0,0 +1,42 @@ +package com.novoda.gradle.release + +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.component.SoftwareComponent +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.bundling.Jar +import org.gradle.api.tasks.javadoc.Javadoc + +class MavenPublicationAttachments { + + private final SoftwareComponent softwareComponent + private final List allArtifactSources + + MavenPublicationAttachments(SoftwareComponent softwareComponent, def ... allArtifactSources) { + this(softwareComponent, Arrays.asList(allArtifactSources).asImmutable()) + } + + MavenPublicationAttachments(SoftwareComponent softwareComponent, List allArtifactSources) { + this.softwareComponent = softwareComponent + this.allArtifactSources = allArtifactSources + } + + final void attachTo(MavenPublication publication) { + allArtifactSources.each { publication.artifact it } + publication.from softwareComponent + } + + protected static Task sourcesJarTask(Project project, String publicationName, def ... sourcePaths) { + return project.task("genereateSourcesJarFor${publicationName.capitalize()}Publication", type: Jar) { Jar jar -> + jar.classifier = 'sources' + jar.from sourcePaths + } + } + + protected static Task javadocsJarTask(Project project, String publicationName, Javadoc javadoc) { + return project.task("genereateJavadocsJarFor${publicationName.capitalize()}Publication", type: Jar) { Jar jar -> + jar.classifier = 'javadoc' + jar.from project.files(javadoc) + } + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy new file mode 100644 index 0000000..39e3cda --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy @@ -0,0 +1,43 @@ +package com.novoda.gradle.release + +import org.gradle.api.Project; + +class PropertyFinder { + + private final Project project + private final PublishExtension extension + + PropertyFinder(Project project, PublishExtension extension) { + this.extension = extension + this.project = project + } + + def getBintrayUser() { + getString(project, 'bintrayUser', extension.bintrayUser) + } + + def getBintrayKey() { + getString(project, 'bintrayKey', extension.bintrayKey) + } + + def getDryRun() { + getBoolean(project, 'dryRun', extension.dryRun) + } + + def getOverride() { + getBoolean(project, 'override', extension.override) + } + + def getPublishVersion() { + getString(project, 'publishVersion', extension.publishVersion) + } + + private String getString(Project project, String propertyName, String defaultValue) { + project.hasProperty(propertyName) ? project.getProperty(propertyName) : defaultValue + } + + private boolean getBoolean(Project project, String propertyName, boolean defaultValue) { + project.hasProperty(propertyName) ? Boolean.parseBoolean(project.getProperty(propertyName)) : defaultValue + } + +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy new file mode 100644 index 0000000..b3cca1d --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy @@ -0,0 +1,76 @@ +package com.novoda.gradle.release + +import groovy.transform.PackageScope + +/** + * A gradle extension which will be used to configure the plugin. + * + * Most of the properties will be used to setup the `bintray-Extension` in BintrayConfiguration. + * See also: https://github.com/bintray/gradle-bintray-plugin#plugin-dsl + * + * Some properties are mandatory and have to be validated before any action on it happen. + * The other ones are all optional or provide a default value. + * + * Optional doesn't mean they aren't needed but that they will handled correctly by the plugin! + */ +class PublishExtension { + + String repoName = 'maven' + String userOrg + + String groupId + String artifactId + + String publishVersion + + Map versionAttributes = [:] + + String[] licences = ['Apache-2.0'] + + String uploadName = '' + + String desc + + String website = '' + String issueTracker = '' + String repository = '' + boolean autoPublish = true + + String bintrayUser = '' + String bintrayKey = '' + boolean dryRun = true + boolean override = false + + String[] publications + + /** + * Validate all mandatory properties for this extension. + * + * Will throw a Exception if not setup correctly. + */ + @PackageScope + void validate() { + String extensionError = ""; + if (userOrg == null) { + extensionError += "Missing userOrg. " + } + if (groupId == null) { + extensionError += "Missing groupId. " + } + if (artifactId == null) { + extensionError += "Missing artifactId. " + } + if (publishVersion == null) { + extensionError += "Missing publishVersion. " + } + if (desc == null) { + extensionError += "Missing desc. " + } + + if (extensionError) { + String prefix = "Have you created the publish closure? " + throw new IllegalStateException(prefix + extensionError) + } + } + +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy new file mode 100644 index 0000000..cdf36c8 --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy @@ -0,0 +1,57 @@ +package com.novoda.gradle.release + +import com.jfrog.bintray.gradle.BintrayPlugin +import com.novoda.gradle.release.internal.AndroidAttachments +import com.novoda.gradle.release.internal.JavaAttachments +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.publish.PublicationContainer +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication + +class ReleasePlugin implements Plugin { + + @Override + void apply(Project project) { + PublishExtension extension = project.extensions.create('publish', PublishExtension) + project.afterEvaluate { + extension.validate() + attachArtifacts(extension, project) + new BintrayConfiguration(extension).configure(project) + } + project.apply([plugin: 'maven-publish']) + new BintrayPlugin().apply(project) + } + + private static void attachArtifacts(PublishExtension extension, Project project) { + project.plugins.withId('com.android.library') { + project.android.libraryVariants.all { variant -> + String publicationName = variant.name + MavenPublication publication = createPublication(publicationName, project, extension) + new AndroidAttachments(publicationName, project, variant).attachTo(publication) + } + } + project.plugins.withId('java') { + def mavenConfig = project.publishing.publications.find {it.name == 'maven'} + if(mavenConfig == null) { + String publicationName = 'maven' + MavenPublication publication = createPublication(publicationName, project, extension) + new JavaAttachments(publicationName, project).attachTo(publication) + } + } + } + + private static MavenPublication createPublication(String publicationName, Project project, PublishExtension extension) { + PropertyFinder propertyFinder = new PropertyFinder(project, extension) + String groupId = extension.groupId + String artifactId = extension.artifactId + String version = propertyFinder.publishVersion + + PublicationContainer publicationContainer = project.extensions.getByType(PublishingExtension).publications + return publicationContainer.create(publicationName, MavenPublication) { MavenPublication publication -> + publication.groupId = groupId + publication.artifactId = artifactId + publication.version = version + } as MavenPublication + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy new file mode 100644 index 0000000..73f99e0 --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy @@ -0,0 +1,53 @@ +package com.novoda.gradle.release.internal + +import com.novoda.gradle.release.MavenPublicationAttachments +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.component.SoftwareComponent +import org.gradle.api.tasks.javadoc.Javadoc +import org.gradle.util.GradleVersion + +class AndroidAttachments extends MavenPublicationAttachments { + + private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_1 = 'com.novoda.release.internal.compat.gradle4_1.AndroidSoftwareComponentCompat_Gradle_4_1' + private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_5 = 'com.novoda.release.internal.compat.gradle4_5.AndroidSoftwareComponentCompat_Gradle_4_5' + private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_8 = 'com.novoda.release.internal.compat.gradle4_8.AndroidSoftwareComponentCompat_Gradle_4_8' + + AndroidAttachments(String publicationName, Project project, def variant) { + super(androidComponentFrom(project), + androidSourcesJarTask(project, publicationName, variant), + androidJavadocsJarTask(project, publicationName, variant), + androidArchivePath(variant)) + } + + private static SoftwareComponent androidComponentFrom(Project project) { + def currentGradleVersion = GradleVersion.current() + if (currentGradleVersion >= GradleVersion.version('4.8')) { + def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_8) + return project.objects.newInstance(clazz) as SoftwareComponent + } + if (currentGradleVersion >= GradleVersion.version('4.5')) { + def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_5) + return project.objects.newInstance(clazz) as SoftwareComponent + } + def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_1) + return clazz.newInstance(project.objects, project.configurations) as SoftwareComponent + } + + private static Task androidSourcesJarTask(Project project, String publicationName, def variant) { + def sourcePaths = variant.sourceSets.collect { it.javaDirectories }.flatten() + return sourcesJarTask(project, publicationName, sourcePaths) + } + + private static Task androidJavadocsJarTask(Project project, String publicationName, def variant) { + Javadoc javadoc = project.task("javadoc${publicationName.capitalize()}", type: Javadoc) { Javadoc javadoc -> + javadoc.source = variant.javaCompiler.source + javadoc.classpath = variant.javaCompiler.classpath + } as Javadoc + return javadocsJarTask(project, publicationName, javadoc) + } + + private static def androidArchivePath(def variant) { + return variant.outputs[0].packageLibrary + } +} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy new file mode 100644 index 0000000..6cb0a0e --- /dev/null +++ b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy @@ -0,0 +1,31 @@ +package com.novoda.gradle.release.internal + +import com.novoda.gradle.release.MavenPublicationAttachments +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.component.SoftwareComponent +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.javadoc.Javadoc + +class JavaAttachments extends MavenPublicationAttachments { + + JavaAttachments(String publicationName, Project project) { + super(javaComponentFrom(project), + javaSourcesJarTask(project, publicationName), + javaJavadocsJarTask(project, publicationName)) + } + + private static SoftwareComponent javaComponentFrom(Project project) { + return project.components.getByName('java') + } + + private static Task javaSourcesJarTask(Project project, String publicationName) { + JavaCompile javaCompile = project.compileJava + return sourcesJarTask(project, publicationName, javaCompile.source) + } + + private static Task javaJavadocsJarTask(Project project, String publicationName) { + Javadoc javadoc = project.javadoc + return javadocsJarTask(project, publicationName, javadoc) + } +} From 22e3a3c58cf761aca98c0e25085cdc847cea0c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Thu, 7 Mar 2019 07:22:43 +0100 Subject: [PATCH 10/13] Use smarter way to publish the artifacts --- alexa-plugin/build.gradle | 19 +++---- alexa-spring-plugin/build.gradle | 34 ++++++------ core/build.gradle | 11 ++-- konversation-plugin/build.gradle | 73 ++----------------------- spring-plugin/build.gradle | 92 ++++---------------------------- spring-sample/build.gradle | 40 ++++---------- ssml-plugin/build.gradle | 2 - ssml/build.gradle | 80 +++------------------------ 8 files changed, 63 insertions(+), 288 deletions(-) diff --git a/alexa-plugin/build.gradle b/alexa-plugin/build.gradle index cc43d58..4a9eb2a 100644 --- a/alexa-plugin/build.gradle +++ b/alexa-plugin/build.gradle @@ -1,18 +1,10 @@ -import java.nio.file.Paths +apply plugin: 'kotlin' +apply from: '../docu.gradle' group 'org.rewedigital.voice.dialog' version rootProject.ext.versions.alexa description 'The Alexa plugin for Dialog to write voice applications for Dialogflow and Alexa.' -apply plugin: 'kotlin' -apply plugin: 'maven-publish' -apply from: '../docu.gradle' - -task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { - outputFormat = 'javadoc' - outputDirectory = "$buildDir/javadoc" -} - dependencies { implementation project(":core") implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" @@ -22,8 +14,13 @@ dependencies { dokka { externalDocumentationLink { url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/core/") - packageListUrl = Paths.get("$rootDir/docs/core/package-list").toUri().toURL() + packageListUrl = java.nio.file.Paths.get("$rootDir/docs/core/package-list").toUri().toURL() } } +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} + apply from: '../publish.gradle' \ No newline at end of file diff --git a/alexa-spring-plugin/build.gradle b/alexa-spring-plugin/build.gradle index 6d30224..e67fdd4 100644 --- a/alexa-spring-plugin/build.gradle +++ b/alexa-spring-plugin/build.gradle @@ -1,11 +1,11 @@ -group 'org.rewedigital.voice.dialog' -version rootProject.ext.versions.alexa - apply plugin: 'kotlin' apply plugin: 'kotlin-spring' -apply plugin: 'maven-publish' apply from: '../docu.gradle' +group 'org.rewedigital.voice.dialog' +version rootProject.ext.versions.alexa +description 'The Alexa plugin for the Spring plugin of Dialog.' + buildscript { repositories { jcenter() @@ -16,19 +16,19 @@ buildscript { } dependencies { - implementation project(":core") - implementation project(":alexa-plugin") - implementation project(":spring-plugin") + implementation project(':core') + implementation project(':alexa-plugin') + implementation project(':spring-plugin') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.jetbrains.kotlin:kotlin-reflect" - implementation "org.springframework:spring-context:5.1.4.RELEASE" - implementation "com.amazon.alexa:ask-sdk-core:2.11.2" + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation 'org.springframework:spring-context:5.1.4.RELEASE' + implementation 'com.amazon.alexa:ask-sdk-core:2.11.2' } -publishing.publications { - maven(MavenPublication) { - artifactId = 'alexa-spring-plugin' - from components.java - } -} \ No newline at end of file +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} + +apply from: '../publish.gradle' \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle index a0413cc..3a8f66a 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,18 +1,17 @@ apply plugin: 'kotlin' -apply plugin: 'maven-publish' apply from: '../docu.gradle' group 'org.rewedigital.voice:dialog' version rootProject.ext.versions.core description 'Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to write your own voice applications fast.' +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" +} + task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" } -apply from: '../publish.gradle' - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file diff --git a/konversation-plugin/build.gradle b/konversation-plugin/build.gradle index 1edffad..8fa88f4 100644 --- a/konversation-plugin/build.gradle +++ b/konversation-plugin/build.gradle @@ -1,10 +1,9 @@ -group 'org.rewedigital.voice' -version rootProject.ext.versions.konversation_plugin - apply plugin: 'kotlin' -apply plugin: 'maven-publish' apply from: '../docu.gradle' -apply plugin: 'com.novoda.bintray-release' + +group 'org.rewedigital.voice' +version rootProject.ext.versions.konversation_plugin +description 'This is the Konversation plugin for Dialog to write voice applications fast.' dependencies { implementation project(":core") @@ -18,66 +17,4 @@ task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputDirectory = "$buildDir/javadoc" } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - konversationPlugin(MavenPublication) { - groupId = 'org.rewedigital.voice.dialog' - artifactId = 'konversation-plugin' - from components.java - version = "${rootProject.ext.versions.core}" - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - pom { - name = 'dialog' - description = 'This is the Konversation plugin for Dialog to write voice applications fast.' - url = 'https://github.com/rewe-digital-incubator/dialog' - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - developer { - name = 'René Kilczan' - email = 'rene.kilczan@rewe-digital.com' - } - } - - scm { - connection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - developerConnection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - url = 'https://github.com/rewe-digital-incubator/dialog' - } - } - } -} - -publish { - userOrg = 'rewe-digital' - groupId = 'org.rewedigital.voice.dialog' - artifactId = 'konversation-plugin' - repoName = 'dialog' - publishVersion = rootProject.ext.versions.core - desc = 'This is the Konversation plugin for Dialog to write voice applications fast.' - website = 'https://github.com/rewe-digital-incubator/dialog' - licences = ['MIT'] - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = true - publications = ['konversationPlugin'] -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file diff --git a/spring-plugin/build.gradle b/spring-plugin/build.gradle index 7af005b..bdcd3cb 100644 --- a/spring-plugin/build.gradle +++ b/spring-plugin/build.gradle @@ -1,8 +1,3 @@ -import java.nio.file.Paths - -group 'org.rewedigital.voice.dialog' -version rootProject.ext.versions.spring_plugin - buildscript { repositories { jcenter() @@ -14,22 +9,24 @@ buildscript { apply plugin: 'kotlin' apply plugin: 'kotlin-spring' -apply plugin: 'maven-publish' apply from: '../docu.gradle' -apply plugin: 'com.novoda.bintray-release' + +group 'org.rewedigital.voice.dialog' +version rootProject.ext.versions.spring_plugin +description 'This is the Spring plugin from Dialog to write voice applications fast.' dependencies { - implementation project(":core") - - implementation "org.jetbrains.kotlin:kotlin-reflect" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.springframework:spring-context:5.1.4.RELEASE" + implementation project(':core') + + implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + implementation 'org.springframework:spring-context:5.1.4.RELEASE' } dokka { externalDocumentationLink { url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/core/") - packageListUrl = Paths.get("$rootDir/docs/core/package-list").toUri().toURL() + packageListUrl = java.nio.file.Paths.get("$rootDir/docs/core/package-list").toUri().toURL() } externalDocumentationLink { url = new URL("https://docs.spring.io/spring-framework/docs/current/javadoc-api/") @@ -42,71 +39,4 @@ task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputDirectory = "$buildDir/javadoc" } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - springPlugin(MavenPublication) { - groupId = 'org.rewedigital.voice.dialog' - artifactId = 'spring-plugin' - from components.java - version = "${rootProject.ext.versions.core}" - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - pom { - name = 'dialog' - description = 'This is the Spring plugin from Dialog to write voice applications fast.' - url = 'https://github.com/rewe-digital-incubator/dialog' - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - // TODO use the MAINTAINERS file - developer { - name = 'Volkmar Vogel' - email = 'volkmar.vogel@rewe-digital.com' - } - developer { - name = 'René Kilczan' - email = 'rene.kilczan@rewe-digital.com' - } - } - - scm { - connection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - developerConnection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - url = 'https://github.com/rewe-digital-incubator/dialog' - } - } - } -} - -publish { - userOrg = 'rewe-digital' - groupId = 'org.rewedigital.voice' - artifactId = 'spring-plugin' - repoName = 'dialog' - publishVersion = rootProject.ext.versions.core - desc = 'Dialog is a Dialogflow v2 API implementation written in Kotlin. With some great optional extensions you can use to write your own voice application fast.' - website = 'https://github.com/rewe-digital-incubator/dialog' - licences = ['MIT'] - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = false - publications = ['springPlugin'] -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file diff --git a/spring-sample/build.gradle b/spring-sample/build.gradle index 1915c99..9a458b2 100644 --- a/spring-sample/build.gradle +++ b/spring-sample/build.gradle @@ -1,7 +1,5 @@ -import java.nio.file.Paths - -group = 'org.rewedigital.voice' -version = '1.0.0-SNAPSHOT' +group 'org.rewedigital.voice' +version '1.0.0-SNAPSHOT' buildscript { ext { @@ -21,7 +19,6 @@ apply plugin: 'kotlin-spring' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' -apply from: '../docu.gradle' sourceCompatibility = 1.8 compileKotlin { @@ -37,25 +34,21 @@ compileTestKotlin { } } -repositories { - mavenCentral() -} - dependencies { def askSdkVersion = '2.11.2' - implementation project(":core") - implementation project(":ssml") - implementation project(":ssml-plugin") - implementation project(":spring-plugin") - implementation project(":konversation-plugin") - implementation project(":alexa-plugin") - implementation project(":alexa-spring-plugin") + implementation project(':core') + implementation project(':ssml') + implementation project(':ssml-plugin') + implementation project(':spring-plugin') + implementation project(':konversation-plugin') + implementation project(':alexa-plugin') + implementation project(':alexa-spring-plugin') implementation('org.springframework.boot:spring-boot-starter-web') implementation('com.fasterxml.jackson.module:jackson-module-kotlin') - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8') + implementation('org.jetbrains.kotlin:kotlin-reflect') implementation("com.amazon.alexa:ask-sdk-core:$askSdkVersion") implementation("com.amazon.alexa:ask-sdk-servlet-support:$askSdkVersion") implementation("com.amazon.alexa:ask-sdk-apache-client:$askSdkVersion") @@ -64,15 +57,4 @@ dependencies { configurations { all*.exclude module: 'spring-boot-starter-logging' -} - -dokka { - externalDocumentationLink { - url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/core/") - packageListUrl = Paths.get("$rootDir/docs/core/package-list").toUri().toURL() - } - externalDocumentationLink { - url = new URL("https://github.com/rewe-digital-incubator/${rootProject.name}/blob/master/docs/spring-plugin/") - packageListUrl = Paths.get("$rootDir/docs/spring-plugin/package-list").toUri().toURL() - } } \ No newline at end of file diff --git a/ssml-plugin/build.gradle b/ssml-plugin/build.gradle index 2c7d563..968c9a4 100644 --- a/ssml-plugin/build.gradle +++ b/ssml-plugin/build.gradle @@ -5,9 +5,7 @@ description 'This is the SSML-Builder plugin for Dialog to write voice applicati version rootProject.ext.versions.ssml_plugin apply plugin: 'kotlin' -apply plugin: 'maven-publish' apply from: '../docu.gradle' -apply plugin: 'com.novoda.bintray-release' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" diff --git a/ssml/build.gradle b/ssml/build.gradle index dd5f4c2..0fc34f5 100644 --- a/ssml/build.gradle +++ b/ssml/build.gradle @@ -1,13 +1,12 @@ -group 'org.rewedigital.voice' -version rootProject.ext.versions.ssml - apply plugin: 'kotlin' -apply plugin: 'maven-publish' apply from: '../docu.gradle' -apply plugin: 'com.novoda.bintray-release' + +group 'org.rewedigital.voice' +version rootProject.ext.versions.ssml +description 'This library helps you to creates Speech Synthesis Markup Language (SSML) for your voice applications.' dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' } task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { @@ -15,71 +14,4 @@ task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputDirectory = "$buildDir/javadoc" } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: dokkaJavadoc) { - archiveClassifier = 'javadoc' - from "$buildDir/javadoc" -} - -publishing.publications { - ssmlBuilder(MavenPublication) { - groupId = 'org.rewedigital.voice' - artifactId = 'ssml-builder' - from components.java - version = "${rootProject.ext.versions.core}" - artifact sourcesJar { - archiveClassifier = 'sources' - } - artifact javadocJar { - archiveClassifier = 'javadoc' - } - pom { - name = 'dialog' - description = 'This library helps you to creates Speech Synthesis Markup Language (SSML) for your voice applications.' - url = 'https://github.com/rewe-digital-incubator/dialog' - licenses { - license { - name = 'MIT License' - url = 'https://opensource.org/licenses/MIT' - distribution = 'repo' - } - } - developers { - // TODO use the MAINTAINERS file - developer { - name = 'Volkmar Vogel' - email = 'volkmar.vogel@rewe-digital.com' - } - developer { - name = 'René Kilczan' - email = 'rene.kilczan@rewe-digital.com' - } - } - - scm { - connection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - developerConnection = 'scm:git:git://github.com/rewe-digital-incubator/dialog.git' - url = 'https://github.com/rewe-digital-incubator/dialog' - } - } - } -} - -publish { - userOrg = 'rewe-digital' - groupId = 'org.rewedigital.voice' - artifactId = 'ssml-builder' - repoName = 'dialog' - publishVersion = rootProject.ext.versions.core - desc = 'This library helps you to creates Speech Synthesis Markup Language (SSML) for your voice applications.' - website = 'https://github.com/rewe-digital-incubator/dialog' - licences = ['MIT'] - bintrayUser = project.properties['bintray.user'] - bintrayKey = project.properties['bintray.apikey'] - dryRun = false - publications = ['ssmlBuilder'] -} \ No newline at end of file +apply from: '../publish.gradle' \ No newline at end of file From 7c91d9ab6bb952c79c0c135981848c8772e7db6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Thu, 7 Mar 2019 08:29:05 +0100 Subject: [PATCH 11/13] Correct group of the konversation plugin --- konversation-plugin/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/konversation-plugin/build.gradle b/konversation-plugin/build.gradle index 8fa88f4..9588c72 100644 --- a/konversation-plugin/build.gradle +++ b/konversation-plugin/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'kotlin' apply from: '../docu.gradle' -group 'org.rewedigital.voice' +group 'org.rewedigital.voice.dialog' version rootProject.ext.versions.konversation_plugin description 'This is the Konversation plugin for Dialog to write voice applications fast.' From 92e400165ddaf230137d78aa87fbac17d84a9498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Wed, 20 Mar 2019 15:19:23 +0100 Subject: [PATCH 12/13] Use snapshot build from bintray plugin --- build.gradle | 4 +- buildSrc/build.gradle | 55 -------------- .../release/BintrayConfiguration.groovy | 72 ------------------ .../release/GradlePluginPropertyFinder.groovy | 38 ---------- .../MavenPublicationAttachments.groovy | 42 ---------- .../gradle/release/PropertyFinder.groovy | 43 ----------- .../gradle/release/PublishExtension.groovy | 76 ------------------- .../gradle/release/ReleasePlugin.groovy | 57 -------------- .../internal/AndroidAttachments.groovy | 53 ------------- .../release/internal/JavaAttachments.groovy | 31 -------- 10 files changed, 2 insertions(+), 469 deletions(-) delete mode 100644 buildSrc/build.gradle delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy delete mode 100644 buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy diff --git a/build.gradle b/build.gradle index 0738fdb..6cf1c33 100644 --- a/build.gradle +++ b/build.gradle @@ -15,13 +15,13 @@ buildscript { repositories { mavenLocal() jcenter() + maven { url 'https://novoda.bintray.com/snapshots' } } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0' classpath "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}" - // Until https://github.com/novoda/bintray-release/pull/267 is merged we use the plugin from buildSrc - // classpath 'com.novoda:bintray-release:0.9' + classpath 'com.novoda:bintray-release:SNAPSHOT-13' } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle deleted file mode 100644 index 2dd2cbe..0000000 --- a/buildSrc/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -buildscript { - repositories { - jcenter() - mavenCentral() - maven { url 'https://plugins.gradle.org/m2/' } - } - dependencies { - classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.0' - // classpath 'com.google.googlejavaformat:google-java-format:1.3' - } -} - -plugins { - id 'groovy' - id 'java-gradle-plugin' - id 'com.novoda.build-properties' version '0.4.1' -} - -version = '0.9' - -//apply plugin: 'com.novoda.bintray-release' -//apply from: 'publish.gradle' -//apply from: 'compat.gradle' - -dependencies { - implementation 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - - testImplementation 'junit:junit:4.12' - testImplementation 'com.google.truth:truth:0.42' - - testRuntime files(pluginUnderTestMetadata) - - repositories { - jcenter() - mavenCentral() - } -} - -compileGroovy { - sourceCompatibility = '1.6' - targetCompatibility = '1.6' -} - -gradlePlugin { - plugins { - binrayRelease { - id = 'com.novoda.bintray-release' - implementationClass = 'com.novoda.gradle.release.ReleasePlugin' - } - legacy { - id = 'bintray-release' - implementationClass = 'com.novoda.gradle.release.ReleasePlugin' - } - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy deleted file mode 100644 index f8f3819..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/BintrayConfiguration.groovy +++ /dev/null @@ -1,72 +0,0 @@ -package com.novoda.gradle.release - -import org.gradle.api.Project - -class BintrayConfiguration { - - PublishExtension extension - - BintrayConfiguration(PublishExtension extension) { - this.extension = extension - } - - void configure(Project project) { - initDefaults() - deriveDefaultsFromProject(project) - - PropertyFinder propertyFinder = new PropertyFinder(project, extension) - - project.bintray { - user = propertyFinder.bintrayUser - key = propertyFinder.bintrayKey - publish = extension.autoPublish - dryRun = propertyFinder.dryRun - override = propertyFinder.override - - publications = extension.publications ?: project.plugins.hasPlugin('com.android.library') ? ['release'] : [ 'maven' ] - - pkg { - repo = extension.repoName - userOrg = extension.userOrg - name = extension.uploadName - desc = extension.desc - websiteUrl = extension.website - issueTrackerUrl = extension.issueTracker - vcsUrl = extension.repository - - licenses = extension.licences - version { - name = propertyFinder.publishVersion - attributes = extension.versionAttributes - } - } - } - project.tasks.bintrayUpload.mustRunAfter(project.tasks.uploadArchives) - } - - private void initDefaults() { - if (extension.uploadName.isEmpty()) { - extension.uploadName = extension.artifactId - } - - if (extension.website.contains('github.com')) { - if (extension.issueTracker.isEmpty()) { - extension.issueTracker = "${extension.website}/issues" - } - if (extension.repository.isEmpty()) { - extension.repository = "${extension.website}.git" - } - } - } - - private void deriveDefaultsFromProject(Project project) { - if (extension.versionAttributes.isEmpty()) { - def gradlePluginPropertyFinder = new GradlePluginPropertyFinder(project) - String bestPluginId = gradlePluginPropertyFinder.findBestGradlePluginId() - if (bestPluginId != null) { - extension.versionAttributes << ['gradle-plugin': "$bestPluginId:$extension.groupId:$extension.artifactId"] - project.logger.info "Using plugin identifier '" + extension.versionAttributes.get('gradle-plugins') + "' for gradle portal." - } - } - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy deleted file mode 100644 index 185fae6..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/GradlePluginPropertyFinder.groovy +++ /dev/null @@ -1,38 +0,0 @@ -package com.novoda.gradle.release - -import org.gradle.api.Project -import org.gradle.api.file.FileCollection -import org.gradle.api.file.FileTree - -class GradlePluginPropertyFinder { - private static final String FILE_EXTENSION_PROPERTIES = ".properties" - private final Project project - - GradlePluginPropertyFinder(Project project) { - this.project = project - } - - String findBestGradlePluginId() { - FileTree pluginFiles = project.fileTree(dir: 'src/main/resources/META-INF/gradle-plugins') - if (pluginFiles.isEmpty()) { - return null - } - FileCollection filteredPluginFiles = pluginFiles.filter { - it.name.endsWith(FILE_EXTENSION_PROPERTIES) && - isNamespacedPropertyFile(it) - } - if (filteredPluginFiles.isEmpty()) { - return null - } - File bestPluginFile = filteredPluginFiles.first() - return removePropertyFileExtension(bestPluginFile) - } - - private boolean isNamespacedPropertyFile(File file) { - return file.name.substring(0, file.name.length() - FILE_EXTENSION_PROPERTIES.length()).contains('.') - } - - private String removePropertyFileExtension(File bestPluginFile) { - bestPluginFile.name.substring(0, bestPluginFile.name.length() - FILE_EXTENSION_PROPERTIES.length()) - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy deleted file mode 100644 index 53d94ce..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/MavenPublicationAttachments.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package com.novoda.gradle.release - -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.component.SoftwareComponent -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.bundling.Jar -import org.gradle.api.tasks.javadoc.Javadoc - -class MavenPublicationAttachments { - - private final SoftwareComponent softwareComponent - private final List allArtifactSources - - MavenPublicationAttachments(SoftwareComponent softwareComponent, def ... allArtifactSources) { - this(softwareComponent, Arrays.asList(allArtifactSources).asImmutable()) - } - - MavenPublicationAttachments(SoftwareComponent softwareComponent, List allArtifactSources) { - this.softwareComponent = softwareComponent - this.allArtifactSources = allArtifactSources - } - - final void attachTo(MavenPublication publication) { - allArtifactSources.each { publication.artifact it } - publication.from softwareComponent - } - - protected static Task sourcesJarTask(Project project, String publicationName, def ... sourcePaths) { - return project.task("genereateSourcesJarFor${publicationName.capitalize()}Publication", type: Jar) { Jar jar -> - jar.classifier = 'sources' - jar.from sourcePaths - } - } - - protected static Task javadocsJarTask(Project project, String publicationName, Javadoc javadoc) { - return project.task("genereateJavadocsJarFor${publicationName.capitalize()}Publication", type: Jar) { Jar jar -> - jar.classifier = 'javadoc' - jar.from project.files(javadoc) - } - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy deleted file mode 100644 index 39e3cda..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/PropertyFinder.groovy +++ /dev/null @@ -1,43 +0,0 @@ -package com.novoda.gradle.release - -import org.gradle.api.Project; - -class PropertyFinder { - - private final Project project - private final PublishExtension extension - - PropertyFinder(Project project, PublishExtension extension) { - this.extension = extension - this.project = project - } - - def getBintrayUser() { - getString(project, 'bintrayUser', extension.bintrayUser) - } - - def getBintrayKey() { - getString(project, 'bintrayKey', extension.bintrayKey) - } - - def getDryRun() { - getBoolean(project, 'dryRun', extension.dryRun) - } - - def getOverride() { - getBoolean(project, 'override', extension.override) - } - - def getPublishVersion() { - getString(project, 'publishVersion', extension.publishVersion) - } - - private String getString(Project project, String propertyName, String defaultValue) { - project.hasProperty(propertyName) ? project.getProperty(propertyName) : defaultValue - } - - private boolean getBoolean(Project project, String propertyName, boolean defaultValue) { - project.hasProperty(propertyName) ? Boolean.parseBoolean(project.getProperty(propertyName)) : defaultValue - } - -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy deleted file mode 100644 index b3cca1d..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/PublishExtension.groovy +++ /dev/null @@ -1,76 +0,0 @@ -package com.novoda.gradle.release - -import groovy.transform.PackageScope - -/** - * A gradle extension which will be used to configure the plugin. - * - * Most of the properties will be used to setup the `bintray-Extension` in BintrayConfiguration. - * See also: https://github.com/bintray/gradle-bintray-plugin#plugin-dsl - * - * Some properties are mandatory and have to be validated before any action on it happen. - * The other ones are all optional or provide a default value. - * - * Optional doesn't mean they aren't needed but that they will handled correctly by the plugin! - */ -class PublishExtension { - - String repoName = 'maven' - String userOrg - - String groupId - String artifactId - - String publishVersion - - Map versionAttributes = [:] - - String[] licences = ['Apache-2.0'] - - String uploadName = '' - - String desc - - String website = '' - String issueTracker = '' - String repository = '' - boolean autoPublish = true - - String bintrayUser = '' - String bintrayKey = '' - boolean dryRun = true - boolean override = false - - String[] publications - - /** - * Validate all mandatory properties for this extension. - * - * Will throw a Exception if not setup correctly. - */ - @PackageScope - void validate() { - String extensionError = ""; - if (userOrg == null) { - extensionError += "Missing userOrg. " - } - if (groupId == null) { - extensionError += "Missing groupId. " - } - if (artifactId == null) { - extensionError += "Missing artifactId. " - } - if (publishVersion == null) { - extensionError += "Missing publishVersion. " - } - if (desc == null) { - extensionError += "Missing desc. " - } - - if (extensionError) { - String prefix = "Have you created the publish closure? " - throw new IllegalStateException(prefix + extensionError) - } - } - -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy deleted file mode 100644 index cdf36c8..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/ReleasePlugin.groovy +++ /dev/null @@ -1,57 +0,0 @@ -package com.novoda.gradle.release - -import com.jfrog.bintray.gradle.BintrayPlugin -import com.novoda.gradle.release.internal.AndroidAttachments -import com.novoda.gradle.release.internal.JavaAttachments -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.publish.PublicationContainer -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication - -class ReleasePlugin implements Plugin { - - @Override - void apply(Project project) { - PublishExtension extension = project.extensions.create('publish', PublishExtension) - project.afterEvaluate { - extension.validate() - attachArtifacts(extension, project) - new BintrayConfiguration(extension).configure(project) - } - project.apply([plugin: 'maven-publish']) - new BintrayPlugin().apply(project) - } - - private static void attachArtifacts(PublishExtension extension, Project project) { - project.plugins.withId('com.android.library') { - project.android.libraryVariants.all { variant -> - String publicationName = variant.name - MavenPublication publication = createPublication(publicationName, project, extension) - new AndroidAttachments(publicationName, project, variant).attachTo(publication) - } - } - project.plugins.withId('java') { - def mavenConfig = project.publishing.publications.find {it.name == 'maven'} - if(mavenConfig == null) { - String publicationName = 'maven' - MavenPublication publication = createPublication(publicationName, project, extension) - new JavaAttachments(publicationName, project).attachTo(publication) - } - } - } - - private static MavenPublication createPublication(String publicationName, Project project, PublishExtension extension) { - PropertyFinder propertyFinder = new PropertyFinder(project, extension) - String groupId = extension.groupId - String artifactId = extension.artifactId - String version = propertyFinder.publishVersion - - PublicationContainer publicationContainer = project.extensions.getByType(PublishingExtension).publications - return publicationContainer.create(publicationName, MavenPublication) { MavenPublication publication -> - publication.groupId = groupId - publication.artifactId = artifactId - publication.version = version - } as MavenPublication - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy deleted file mode 100644 index 73f99e0..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/AndroidAttachments.groovy +++ /dev/null @@ -1,53 +0,0 @@ -package com.novoda.gradle.release.internal - -import com.novoda.gradle.release.MavenPublicationAttachments -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.component.SoftwareComponent -import org.gradle.api.tasks.javadoc.Javadoc -import org.gradle.util.GradleVersion - -class AndroidAttachments extends MavenPublicationAttachments { - - private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_1 = 'com.novoda.release.internal.compat.gradle4_1.AndroidSoftwareComponentCompat_Gradle_4_1' - private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_5 = 'com.novoda.release.internal.compat.gradle4_5.AndroidSoftwareComponentCompat_Gradle_4_5' - private static final String ANDROID_SOFTWARE_COMPONENT_COMPAT_4_8 = 'com.novoda.release.internal.compat.gradle4_8.AndroidSoftwareComponentCompat_Gradle_4_8' - - AndroidAttachments(String publicationName, Project project, def variant) { - super(androidComponentFrom(project), - androidSourcesJarTask(project, publicationName, variant), - androidJavadocsJarTask(project, publicationName, variant), - androidArchivePath(variant)) - } - - private static SoftwareComponent androidComponentFrom(Project project) { - def currentGradleVersion = GradleVersion.current() - if (currentGradleVersion >= GradleVersion.version('4.8')) { - def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_8) - return project.objects.newInstance(clazz) as SoftwareComponent - } - if (currentGradleVersion >= GradleVersion.version('4.5')) { - def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_5) - return project.objects.newInstance(clazz) as SoftwareComponent - } - def clazz = this.classLoader.loadClass(ANDROID_SOFTWARE_COMPONENT_COMPAT_4_1) - return clazz.newInstance(project.objects, project.configurations) as SoftwareComponent - } - - private static Task androidSourcesJarTask(Project project, String publicationName, def variant) { - def sourcePaths = variant.sourceSets.collect { it.javaDirectories }.flatten() - return sourcesJarTask(project, publicationName, sourcePaths) - } - - private static Task androidJavadocsJarTask(Project project, String publicationName, def variant) { - Javadoc javadoc = project.task("javadoc${publicationName.capitalize()}", type: Javadoc) { Javadoc javadoc -> - javadoc.source = variant.javaCompiler.source - javadoc.classpath = variant.javaCompiler.classpath - } as Javadoc - return javadocsJarTask(project, publicationName, javadoc) - } - - private static def androidArchivePath(def variant) { - return variant.outputs[0].packageLibrary - } -} diff --git a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy b/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy deleted file mode 100644 index 6cb0a0e..0000000 --- a/buildSrc/src/main/groovy/com/novoda/gradle/release/internal/JavaAttachments.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package com.novoda.gradle.release.internal - -import com.novoda.gradle.release.MavenPublicationAttachments -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.component.SoftwareComponent -import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.api.tasks.javadoc.Javadoc - -class JavaAttachments extends MavenPublicationAttachments { - - JavaAttachments(String publicationName, Project project) { - super(javaComponentFrom(project), - javaSourcesJarTask(project, publicationName), - javaJavadocsJarTask(project, publicationName)) - } - - private static SoftwareComponent javaComponentFrom(Project project) { - return project.components.getByName('java') - } - - private static Task javaSourcesJarTask(Project project, String publicationName) { - JavaCompile javaCompile = project.compileJava - return sourcesJarTask(project, publicationName, javaCompile.source) - } - - private static Task javaJavadocsJarTask(Project project, String publicationName) { - Javadoc javadoc = project.javadoc - return javadocsJarTask(project, publicationName, javadoc) - } -} From 76fe5dee18924318bfb99d6270151ecf0b658f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kilczan?= Date: Wed, 20 Mar 2019 15:20:05 +0100 Subject: [PATCH 13/13] Prepare release of 1.0.1 --- build.gradle | 12 ++++++------ publish.gradle | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 6cf1c33..353b9a6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,12 +5,12 @@ buildscript { ext.versions = [:] ext.versions.kotlin = '1.3.21' ext.versions.dokka = '0.9.17' - ext.versions.core = '1.0' - ext.versions.alexa = '0.1' - ext.versions.ssml = '1.0' - ext.versions.ssml_plugin = '1.0' - ext.versions.spring_plugin = '1.0' - ext.versions.konversation_plugin = '1.0' + ext.versions.core = '1.0.1' + ext.versions.alexa = '1.0.1' + ext.versions.ssml = '1.0.1' + ext.versions.ssml_plugin = '1.0.1' + ext.versions.spring_plugin = '1.0.1' + ext.versions.konversation_plugin = '1.0.1' repositories { mavenLocal() diff --git a/publish.gradle b/publish.gradle index 921beac..5327aa6 100644 --- a/publish.gradle +++ b/publish.gradle @@ -33,7 +33,7 @@ publish { desc = project.description bintrayUser = project.properties['bintray.user'] bintrayKey = project.properties['bintray.apikey'] - dryRun = true + dryRun = false publications = ['maven'] }