diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100755 index 0000000..fa4f7b4 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,110 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar old mode 100644 new mode 100755 index 9cc84ea..01e6799 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties old mode 100644 new mode 100755 index c315043..00d32aa --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file diff --git a/README.md b/README.md index c160b91..b88c6bb 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -[![codebeat](https://codebeat.co/badges/36a7965b-aa57-40af-8db3-fd7e6b54fee3)](https://codebeat.co/projects/github-com-taymyr-openapi-java-develop) -[![Build Status](https://travis-ci.org/taymyr/openapi-java.svg?branch=develop)](https://travis-ci.org/taymyr/openapi-java) -[![Javadoc API](https://www.javadoc.io/badge/org.taymyr/openapi-java-api.svg?label=javadoc%20api)](https://www.javadoc.io/doc/org.taymyr/openapi-java-api) -[![Javadoc Impl](https://www.javadoc.io/badge/org.taymyr/openapi-java-impl.svg?label=javadoc%20impl)](https://www.javadoc.io/doc/org.taymyr/openapi-java-impl) -[![codecov](https://codecov.io/gh/taymyr/openapi-java/branch/develop/graph/badge.svg)](https://codecov.io/gh/taymyr/openapi-java) -[![Maven API](https://img.shields.io/maven-central/v/org.taymyr/openapi-java.svg)](https://search.maven.org/search?q=a:openapi-java%20AND%20g:org.taymyr) +[![Gitter](https://img.shields.io/badge/chat-gitter-purple.svg)](https://gitter.im/taymyr/taymyr) +[![Gitter_RU](https://img.shields.io/badge/chat-russian%20channel-purple.svg)](https://gitter.im/taymyr/taymyr_ru) +[![codebeat](https://codebeat.co/badges/e9c10a77-0084-4cc7-9328-2d224e95c558)](https://codebeat.co/projects/github-com-taymyr-lagom-openapi-java-develop) +[![Build Status](https://travis-ci.org/taymyr/lagom-openapi-java.svg?branch=develop)](https://travis-ci.org/taymyr/lagom-openapi-java) +[![Javadoc API](https://www.javadoc.io/badge/org.taymyr.lagom/lagom-openapi-java-api.svg?label=javadoc%20api)](https://www.javadoc.io/doc/org.taymyr.lagom/lagom-openapi-java-api) +[![Javadoc Impl](https://www.javadoc.io/badge/org.taymyr.lagom/lagom-openapi-java-impl.svg?label=javadoc%20impl)](https://www.javadoc.io/doc/org.taymyr.lagom/lagom-openapi-java-impl) +[![codecov](https://codecov.io/gh/taymyr/lagom-openapi-java/branch/develop/graph/badge.svg)](https://codecov.io/gh/taymyr/lagom-openapi-java) +[![Maven](https://img.shields.io/maven-central/v/org.taymyr.lagom/lagom-openapi-java.svg)](https://search.maven.org/search?q=a:lagom-openapi-java%20AND%20g:org.taymyr.lagom) # OpenAPI service for Lagom diff --git a/api/pom.xml b/api/pom.xml index 311ad55..117dc31 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -3,15 +3,24 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.taymyr - openapi-java - 0.0.1 + org.taymyr.lagom + lagom-openapi-java + 0.0.2 ../pom.xml - openapi-java-api + lagom-openapi-java-api jar Taymyr: Openapi Java API + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + org.jetbrains.kotlin + kotlin-reflect + + com.lightbend.lagom lagom-javadsl-api_${scala.binary.version} @@ -19,18 +28,58 @@ + ${project.basedir}/src/main/kotlin + + org.jetbrains.kotlin + kotlin-maven-plugin + + + -Xjsr305=strict + -Xjvm-default=enable + + + + + compile + compile + + + test-compile + test-compile + + + org.apache.maven.plugins - maven-javadoc-plugin + maven-antrun-plugin - prepare-package + ktlint + verify + + + + + + + + + + - jar + run + + + com.github.shyiko + ktlint + ${ktlint.version} + + org.apache.maven.plugins @@ -44,6 +93,29 @@ + + org.jetbrains.dokka + dokka-maven-plugin + + default + false + 8 + + + ${basedir}/src/main/kotlin + JVM + + + + + + prepare-package + + javadocJar + + + + \ No newline at end of file diff --git a/api/src/main/java/org/taymyr/openapi/OpenAPIService.java b/api/src/main/java/org/taymyr/openapi/OpenAPIService.java deleted file mode 100644 index 136fd3e..0000000 --- a/api/src/main/java/org/taymyr/openapi/OpenAPIService.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.taymyr.openapi; - -import akka.NotUsed; -import com.lightbend.lagom.javadsl.api.Descriptor; -import com.lightbend.lagom.javadsl.api.Service; -import com.lightbend.lagom.javadsl.api.ServiceCall; - -import static com.lightbend.lagom.javadsl.api.Service.pathCall; - -import static java.lang.String.format; - -/** - * OpenAPI service descriptor. - * - * @author Sergey Morgunov - */ -public interface OpenAPIService extends Service { - - /** - * Return OpenAPI specification for current service. - * @return OpenAPI specification - */ - ServiceCall openapi(); - - default Descriptor withOpenAPI(Descriptor descriptor) { - return descriptor.withCalls( - pathCall(format("/%s/openapi", descriptor.name()), this::openapi) - ); - } - -} diff --git a/api/src/main/kotlin/org/taymyr/lagom/openapi/OpenAPIService.kt b/api/src/main/kotlin/org/taymyr/lagom/openapi/OpenAPIService.kt new file mode 100644 index 0000000..8e872a5 --- /dev/null +++ b/api/src/main/kotlin/org/taymyr/lagom/openapi/OpenAPIService.kt @@ -0,0 +1,27 @@ +package org.taymyr.lagom.openapi + +import akka.NotUsed +import com.lightbend.lagom.javadsl.api.Descriptor +import com.lightbend.lagom.javadsl.api.Service +import com.lightbend.lagom.javadsl.api.Service.pathCall +import com.lightbend.lagom.javadsl.api.ServiceCall +import kotlin.reflect.jvm.javaMethod + +/** + * OpenAPI service descriptor. + */ +interface OpenAPIService : Service { + + /** + * Return OpenAPI specification for current service. + * @return OpenAPI specification + */ + fun openapi(): ServiceCall + + @JvmDefault + fun withOpenAPI(descriptor: Descriptor): Descriptor { + return descriptor.withCalls( + pathCall("/_${descriptor.name()}/openapi", OpenAPIService::openapi.javaMethod) + ) + } +} diff --git a/impl/pom.xml b/impl/pom.xml index 84b7746..ad84fab 100644 --- a/impl/pom.xml +++ b/impl/pom.xml @@ -3,12 +3,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.taymyr - openapi-java - 0.0.1 + org.taymyr.lagom + lagom-openapi-java + 0.0.2 ../pom.xml - openapi-java-impl + lagom-openapi-java-impl jar Taymyr: Openapi Java Impl @@ -17,8 +17,8 @@ kotlin-stdlib-jdk8 - org.taymyr - openapi-java-api + org.taymyr.lagom + lagom-openapi-java-api ${project.version} @@ -54,6 +54,7 @@ -Xjsr305=strict + -Xjvm-default=enable @@ -102,7 +103,6 @@ org.jacoco jacoco-maven-plugin - ${jacoco.plugin.version} diff --git a/impl/src/main/kotlin/org/taymyr/openapi/AbstractOpenAPIService.kt b/impl/src/main/kotlin/org/taymyr/lagom/openapi/AbstractOpenAPIService.kt similarity index 97% rename from impl/src/main/kotlin/org/taymyr/openapi/AbstractOpenAPIService.kt rename to impl/src/main/kotlin/org/taymyr/lagom/openapi/AbstractOpenAPIService.kt index f0a2d61..d3c8ea6 100644 --- a/impl/src/main/kotlin/org/taymyr/openapi/AbstractOpenAPIService.kt +++ b/impl/src/main/kotlin/org/taymyr/lagom/openapi/AbstractOpenAPIService.kt @@ -1,4 +1,4 @@ -package org.taymyr.openapi +package org.taymyr.lagom.openapi import akka.NotUsed import com.lightbend.lagom.javadsl.api.transport.MessageProtocol @@ -13,9 +13,6 @@ import org.taymyr.lagom.javadsl.api.transport.ResponseHeaders.ok import java.util.Optional.ofNullable import java.util.concurrent.CompletableFuture.completedFuture -/** - * @author Sergey Morgunov - */ abstract class AbstractOpenAPIService(config: Config) : OpenAPIService { private val apiSpec: String? diff --git a/impl/src/test/kotlin/org/taymyr/openapi/OpenAPIServiceTest.kt b/impl/src/test/kotlin/org/taymyr/lagom/openapi/OpenAPIServiceTest.kt similarity index 97% rename from impl/src/test/kotlin/org/taymyr/openapi/OpenAPIServiceTest.kt rename to impl/src/test/kotlin/org/taymyr/lagom/openapi/OpenAPIServiceTest.kt index 042a688..3e2e1fa 100644 --- a/impl/src/test/kotlin/org/taymyr/openapi/OpenAPIServiceTest.kt +++ b/impl/src/test/kotlin/org/taymyr/lagom/openapi/OpenAPIServiceTest.kt @@ -1,4 +1,4 @@ -package org.taymyr.openapi +package org.taymyr.lagom.openapi import com.lightbend.lagom.javadsl.api.transport.NotFound import com.typesafe.config.ConfigFactory @@ -9,9 +9,6 @@ import io.kotlintest.whenReady import org.taymyr.lagom.javadsl.api.transport.MessageProtocols.YAML import org.taymyr.lagom.javadsl.api.transport.ResponseHeaders.OK_JSON -/** - * @author Sergey Morgunov - */ class OpenAPIServiceTest : StringSpec({ "Service with incorrect config should be return 404" { diff --git a/impl/src/test/kotlin/org/taymyr/openapi/TestService.kt b/impl/src/test/kotlin/org/taymyr/lagom/openapi/TestService.kt similarity index 95% rename from impl/src/test/kotlin/org/taymyr/openapi/TestService.kt rename to impl/src/test/kotlin/org/taymyr/lagom/openapi/TestService.kt index e6c4b1a..8a510f6 100644 --- a/impl/src/test/kotlin/org/taymyr/openapi/TestService.kt +++ b/impl/src/test/kotlin/org/taymyr/lagom/openapi/TestService.kt @@ -1,4 +1,4 @@ -package org.taymyr.openapi +package org.taymyr.lagom.openapi import com.lightbend.lagom.javadsl.api.Descriptor diff --git a/mvnw b/mvnw index 5bf251c..5551fde 100755 --- a/mvnw +++ b/mvnw @@ -108,7 +108,7 @@ if $cygwin ; then CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi -# For Migwn, ensure paths are in UNIX format before anything is touched +# For Mingw, ensure paths are in UNIX format before anything is touched if $mingw ; then [ -n "$M2_HOME" ] && M2_HOME="`(cd "$M2_HOME"; pwd)`" @@ -200,8 +200,69 @@ if [ -z "$BASE_DIR" ]; then exit 1; fi +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -echo $MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java diff --git a/mvnw.cmd b/mvnw.cmd old mode 100644 new mode 100755 index 019bd74..e5cfb0a --- a/mvnw.cmd +++ b/mvnw.cmd @@ -35,6 +35,8 @@ @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off +@REM set title of command window +title %0 @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @@ -115,10 +117,26 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* if ERRORLEVEL 1 goto error goto end diff --git a/pom.xml b/pom.xml index 876077a..639db2d 100644 --- a/pom.xml +++ b/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - org.taymyr - openapi-java - 0.0.1 + org.taymyr.lagom + lagom-openapi-java + 0.0.2 pom Taymyr: Openapi Java OpenAPI service for Lagom framework @@ -28,6 +28,7 @@ taymyr Taymyr Contributors https://github.com/taymyr + contributors@taymyr.org @@ -47,7 +48,6 @@ 1.4.8 0.28.0 1.8 - 3.0.1 3.0.1 3.1.0 2.22.0 @@ -60,7 +60,6 @@ 1.8 UTF-8 UTF-8 - 3.5.1 1.8 1.8 UTF-8 @@ -75,9 +74,9 @@ ${kotlin.version} - org.apache.maven.plugins - maven-compiler-plugin - ${compiler.plugin.version} + org.jetbrains.dokka + dokka-maven-plugin + ${dokka.version} org.apache.maven.plugins @@ -94,11 +93,6 @@ jacoco-maven-plugin ${jacoco.plugin.version} - - org.apache.maven.plugins - maven-javadoc-plugin - ${javadoc.plugin.version} - org.apache.maven.plugins maven-source-plugin @@ -183,6 +177,11 @@ kotlin-stdlib-jdk8 ${kotlin.version} + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + io.github.microutils kotlin-logging