diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore index e6340e96..2e8ce218 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,6 @@ .yardoc .yardopts .vertx -build +build/ target out diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 9cc84ea9..00000000 Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index c3150437..00000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip diff --git a/.travis.yml b/.travis.yml index aa4633b3..36b9f8ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,4 @@ -dist: trusty -sudo: false language: java + jdk: - oraclejdk8 -- oraclejdk9 -matrix: - allow_failures: - - jdk: oraclejdk9 -addons: - apt: - packages: - - oracle-java8-installer - - oracle-java9-installer -cache: - directories: - - $HOME/.m2 -before_script: java -version -script: ./mvnw install -deploy: - skip_cleanup: true - provider: releases - api_key: ${GITHUB_OAUTH_TOKEN} - file: ./vertx-starter-main/target/vertx-starter-main-${TRAVIS_TAG}-fat.jar - on: - tags: true diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index a23a3596..00000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -### -# vert.x docker example using a Java verticle packaged as a fatjar -# To build: -# docker build -t sample/vertx-java-fat . -# To run: -# docker run -t -i -p 8080:8080 sample/vertx-java-fat -### - -FROM java:openjdk-8-jdk - -ENV CONF_FILE vertx-starter-main/conf/default-conf.json -ENV VERTICLE_FILE vertx-starter-main/target/vertx-starter-main-1.0.0-SNAPSHOT-fat.jar - -COPY . . -RUN ./mvnw clean package -EXPOSE 8080 - -ENTRYPOINT ["sh", "-c"] -CMD ["exec java -jar -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory $VERTICLE_FILE -conf $CONF_FILE"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..4ae2a03c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,51 @@ +pipeline { + agent any + stages { + stage('Build') { + steps { + sh ''' +./gradlew clean assemble +''' + stash name: 'fatJar', includes: 'build/libs/*fat.jar' + } + } + stage('Deploy') { + steps { + unstash 'fatJar' + withCredentials(bindings: [sshUserPrivateKey(credentialsId: 'jenkins_start.vertx.io', \ + keyFileVariable: 'SSH_KEY_FOR_START_VERTX_IO')]) { + sh ''' +set +x + +if [ -z ${REMOTE_USER+x} ] || [ -z ${REMOTE_HOSTNAME+x} ]; then + echo "Fatal: SSH information not set." + exit 1 +fi + +echo "Sending jar with ${REMOTE_USER}@${REMOTE_HOSTNAME}" +ssh -i "${SSH_KEY_FOR_START_VERTX_IO}" "${REMOTE_USER}"@"${REMOTE_HOSTNAME}" mkdir -p "${TEMP}" +scp -i "${SSH_KEY_FOR_START_VERTX_IO}" ./build/libs/*fat.jar "${REMOTE_USER}"@"${REMOTE_HOSTNAME}":"${TEMP}" +''' + + sh ''' +set +x + +if [ -z ${REMOTE_USER+x} ] || [ -z ${REMOTE_HOSTNAME+x} ]; then + echo "Fatal: SSH information not set." + exit 1 +fi + +echo "Deploying with ${REMOTE_USER}@${REMOTE_HOSTNAME}" + +ssh -i "${SSH_KEY_FOR_START_VERTX_IO}" "${REMOTE_USER}"@"${REMOTE_HOSTNAME}" "sudo -t bash -s" < ./scripts/deploy.sh +''' + } + } + } + } + environment { + REMOTE_USER = 'jenkins' + REMOTE_HOSTNAME = 'start.vertx.io' + TEMP= '/tmp/vertx' + } +} diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/README.md b/README.md index ad727b7f..87c52f53 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,85 @@ -# Vertx.x starter +# Vertx.x Starter -**Disclaimer**: This is a *WIP* project. Any comment, test or help is welcome! -Vert.x starter +![Travis (.org)](https://img.shields.io/travis/vert-x3/vertx-starter.svg) +![GitHub](https://img.shields.io/github/license/vert-x3/vertx-starter.svg) -## Installation +**Disclaimer**: This is a *WIP* project. Any comment, test or help is welcome! -``` - git clone https://github.com/danielpetisme/vertx-starter.git - cd vertx-starter - ./build_and_run.sh -``` +[Vert.x Starter](http://start.vertx.io) is an open-source web application for creating [Vert.x](https://vertx.io/) applications. -## Default values -Have a look to `vertx-starter-main/conf/default-conf.json` -``` -{ - "api": { - "http.port": 9090, - "prefix": "api", - "project.request": { - "version": "3.5.0", - "format": "zip", - "language": "java", - "build": "maven", - "groupId": "io.vertx", - "artifactId": "sample", - "dependencies": [ - "vertx-core", - "vertx-unit" - ] - }, - "dependencies.path": "./dependencies.json" - }, - "web": { - "http.port": 8080 - }, - "generator": { - "temp.dir": "." - } -} -``` -## Generating a project +## Quickstart Simply click on "Generate Project" on the web interface to download a project archive. -It your a CLI adept, you can achieve the same result with `curl` +It your a CLI adept, you can use any http client (curl, [httpie](https://httpie.org/)) to invoke the API. + +`$ curl -X GET http://start.vertx.io/starter.zip -d groupId=com.acme -d language=java -d vertxVersion=3.5.3 -o starter.zip` -`$ http:///starter.zip -o starter.zip` +## API -All the web ui inputs are mapped to the following attributes +## Generating a Vert.x application +`http://start.vertx.io/starter.{archiveFormat}` + +*Note*: `{archiveFromat}` can be `zip`, `tgz`, `tar.gz`, etc. if the project generator can handle the format, it will use the appropriate compression tool. + +You can provide the following query parameters to customize the project +* `type`: The type of project (`core`, `openapi`, etc.). * Basic information for the generated project `groupId`, `artifactId` -* `version`: the Vert.x version -* `build`: `maven` or `gradle` build tool -* `language`: `java`, `groovy`, `kotlin`, `js`, `scala` -* `dependencies`: a comma separated list of artifactIds of the vert.x modules +* `language`: `java` or `kotlin` +* `buildTool`: `maven` or `gradle` build tool +* `vertxVersion`: the Vert.x version +* `vertxDependencies`: a comma separated list of artifactIds of the vert.x modules Full example: ``` -$ http:///starter.zip \ --d version=3.5.0 \ --d language=java \ +$ curl -X GET http://start.vertx.io/starter.zip \ +-d type=core \ -d groupId=io.vertx \ -d artifactId=sample \ --d depencies=vertx-web,vertx-web-client \ --o starter.zip` +-d language=java \ +-d vertxVersion=3.5.0 \ +-d vertxDepencies=vertx-web,vertx-web-client \ +-o starter.zip ``` +## Vert.x Starter metadata + +The vert.x starter metadata lists all the capabilities proposed by the API. The metadata is used to build the Web UI is exposed to ease the creation of third-party clients (IDE integration, CLI, etc). + +`http://start.vertx.io/metadata` + + +## Running your own starter + +## Build from sources + +For now, the vertx-starter project is not available on Maven-Central, so you need to build it from source. + +In order to build it, you will need Java 1.8. + +### Building fat jar + +`$ ./gradlew shadowJar` + +### Running the app locally + +`$ ./gradlew vertxRun` + +### Configuration + +Vert.x starter relies on the [`vertx-boot`](https://github.com/jponge/vertx-boot) launcher. +The application is configured by [`src/main/resources/application.conf`](./src/main/resources/application.conf). +Please see the according documentation to know how to override the configuration. + +### Vert.x Project Generator +The project generation is delegated to the [vertx-project-generator](https://github.com/vert-x3/vertx-project-generator) project. +You should clone the project and configure the starter to have a complete stack locally. + +## Docker + +**WIP** + +## License + +Vert.x Starter is Open Source software released under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html). diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..efbf799b --- /dev/null +++ b/build.gradle @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +plugins { + id 'io.vertx.vertx-plugin' version '0.0.8' +} + +apply plugin: 'idea' + + +repositories { + jcenter() + mavenCentral() + maven { url 'https://repo.gradle.org/gradle/libs-releases' } +} + +group 'io.vertx' +version '2.0.0-SNAPSHOT' +description = 'A web application to generate Vert.x projects ' + +ext { + vertx_version = '3.5.3' + logback_version = '1.2.3' + gradle_tooking_api_version = '4.3' + vertx_boot_version = '0.0.2' + assertj_core_version = '3.10.0' + junit_version = '5.2.0' +} + +dependencies { + implementation 'io.vertx:vertx-web' + implementation 'io.vertx:vertx-mongo-client' + implementation 'io.vertx:vertx-web-client' + + implementation "ch.qos.logback:logback-classic:${logback_version}" + implementation "org.gradle:gradle-tooling-api:${gradle_tooking_api_version}" + implementation "io.github.jponge:vertx-boot:${vertx_boot_version}" + + testImplementation "org.assertj:assertj-core:${assertj_core_version}" + testImplementation 'io.vertx:vertx-junit5' + testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" + + //When present gradle test work but intellij not and vice-versa + testRuntime "org.junit.jupiter:junit-jupiter-engine:${junit_version}" + +} + +vertx { + vertxVersion = "${vertx_version}" + mainVerticle = 'io.github.jponge.vertx.boot.BootVerticle' + jvmArgs = ['-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory'] +} + + +test { + useJUnitPlatform() + failFast = true + jvmArgs '-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory' + +} + +apply from: 'gradle/docker.gradle' + +task wrapper(type: Wrapper) { + gradleVersion = '4.8' +} diff --git a/build_and_run.sh b/build_and_run.sh deleted file mode 100755 index fa64398d..00000000 --- a/build_and_run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -java_opts="$JAVA_OPTS -Dvertx.logger-delegate-factory-class-name=\"io.vertx.core.logging.SLF4JLogDelegateFactory\"" -jar_name="vertx-starter-main/target/vertx-starter-main-1.0.0-SNAPSHOT-fat.jar" -vertx_opts="-conf vertx-starter-main/conf/default-conf.json" - -mvn clean package -DskipTests=true && \ -mvn exec:exec -Dexec.executable="java" -Dexec.args="${java_opts} -jar ${jar_name} ${vertx_opts}" diff --git a/gradle/docker.gradle b/gradle/docker.gradle new file mode 100644 index 00000000..0466bdcf --- /dev/null +++ b/gradle/docker.gradle @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath 'com.bmuschko:gradle-docker-plugin:3.5.0' + } +} + +apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin + +task prepareDockerImageBuild(type: Copy) { + description = "Copy Dockerfile and fat jar to prepare the Docker build" + from('src/main/docker/') { + include 'Dockerfile' + } + from ("${project.buildDir}/libs") { + include "*-fat.jar" + } + into { "${project.buildDir}/docker" } + +} + +task buildDockerImage(type: com.bmuschko.gradle.docker.tasks.image.DockerBuildImage) { + description = "Build vertx-starter as Docker image" + group = "Docker" + inputDir = project.file("${project.buildDir}/docker") + tags = ["vertx-starter:latest".toString(), "vertx-starter:${project.version}".toString()] +} + +buildDockerImage.dependsOn prepareDockerImageBuild diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..758de960 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..d08426f0 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2017-2018 Daniel Petisme +# +# Licensed 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. +# + +#Mon Jul 23 14:07:08 CEST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/vertx-starter-generator/src/main/resources/templates/gradlew b/gradlew similarity index 100% rename from vertx-starter-generator/src/main/resources/templates/gradlew rename to gradlew diff --git a/vertx-starter-generator/src/main/resources/templates/gradlew.bat b/gradlew.bat similarity index 100% rename from vertx-starter-generator/src/main/resources/templates/gradlew.bat rename to gradlew.bat diff --git a/mongodb.yml b/mongodb.yml deleted file mode 100644 index c7d4e110..00000000 --- a/mongodb.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: '2' -services: - vertx-starter-mongodb: - container_name: vertx-starter-mongodb - image: mongo:3.3.12 - ports: - - "27017:27017" - # volumes: - # - $(pwd)/mongodb/:/data/db/ diff --git a/mvnw b/mvnw deleted file mode 100755 index 5bf251c0..00000000 --- a/mvnw +++ /dev/null @@ -1,225 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# 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. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Migwn, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -echo $MAVEN_PROJECTBASEDIR -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd deleted file mode 100644 index 019bd74d..00000000 --- a/mvnw.cmd +++ /dev/null @@ -1,143 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -: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 - -%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 - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 3f5bb5e1..00000000 --- a/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - 4.0.0 - - io.vertx - vertx-starter - pom - 1.0.0-SNAPSHOT - - - vertx-starter-generator - vertx-starter-web - vertx-starter-analytics - vertx-starter-main - - - - 1.8 - 3.5.0 - 1.7.25 - UTF-8 - 3.7.0 - - - - - - - io.vertx - vertx-core - ${vertx.version} - - - io.vertx - vertx-web - ${vertx.version} - - - io.vertx - vertx-unit - ${vertx.version} - - - org.slf4j - slf4j-simple - ${slf4j.version} - - - junit - junit - 4.12 - test - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - - - - - diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 00000000..85566e39 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# The script consider the fat jar is already present on the VM, and the service relies on systemd + +TEMP=${1:-/tmp/vertx} +VERTX_HOME=${VERTX_HOME:-/opt/vertx} + +if [ ! -d "${VERTX_HOME}" ]; then + mkdir -p "${VERTX_HOME}" +fi + +if [ ! -d "${TEMP}" ]; then + echo "Fatal: ${TEMP} does not exists." + exit 1 +fi + +cd "${TEMP}" || exit +JAR=$(ls *fat.jar) + +if [ ! -f "${JAR}" ]; then + echo "Fatal: No jar found in ${TEMP}." + exit 1 +fi + +echo "Found jar: ${JAR}" + +mv "${JAR}" "${VERTX_HOME}" +rm -rf "${TEMP}" +sudo chown vertx:vertx "${VERTX_HOME}/${JAR}" +sudo chmod 700 "${VERTX_HOME}/${JAR}" + +readonly vertx_starter_latest_jar="${VERTX_HOME}/vertx-starter-latest-fat.jar" + +rm "${vertx_starter_latest_jar}" +sudo -u vertx ln -s "${VERTX_HOME}/${JAR}" "${vertx_starter_latest_jar}" +sudo systemctl restart vertx-starter diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..1ce90423 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +rootProject.name = 'vertx-starter' diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile new file mode 100644 index 00000000..699bbb48 --- /dev/null +++ b/src/main/docker/Dockerfile @@ -0,0 +1,8 @@ +FROM openjdk:8-jdk-alpine + +ADD *.jar /opt/app/app.jar + +EXPOSE 8080 + +WORKDIR /opt/app +ENTRYPOINT ["java", "-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory", "-Dvertx.cacheDirBase=/tmp", "-jar", "app.jar"] diff --git a/src/main/docker/application.yml b/src/main/docker/application.yml new file mode 100644 index 00000000..961dbf4e --- /dev/null +++ b/src/main/docker/application.yml @@ -0,0 +1,10 @@ +version: '2' +services: + vertx-starter: + image: vertx-starter + ports: + - 8080:8080 + vertx-starter-mongodb: + extends: + file: mongodb.yml + service: vertx-starter-mongodb diff --git a/src/main/docker/mongodb.yml b/src/main/docker/mongodb.yml new file mode 100644 index 00000000..50630738 --- /dev/null +++ b/src/main/docker/mongodb.yml @@ -0,0 +1,9 @@ +version: '2' +services: + vertx-starter-mongodb: + container_name: vertx-starter-mongodb + image: mongo:3.3.12 + ports: + - "27017:27017" + # volumes: + # - $(pwd)/mongodb/:/data/db/ diff --git a/src/main/java/io/vertx/starter/AnalyticsVerticle.java b/src/main/java/io/vertx/starter/AnalyticsVerticle.java new file mode 100644 index 00000000..348bed89 --- /dev/null +++ b/src/main/java/io/vertx/starter/AnalyticsVerticle.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Future; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.mongo.MongoClient; +import io.vertx.starter.config.Topics; +import io.vertx.starter.service.AnalyticsService; + +public class AnalyticsVerticle extends AbstractVerticle { + + private final Logger log = LoggerFactory.getLogger(GeneratorVerticle.class); + + private MongoClient mongoClient() { + return MongoClient.createShared(vertx, config()); + } + + @Override + public void start(Future startFuture) { + AnalyticsService analyticsService = new AnalyticsService(mongoClient()); + vertx.eventBus().consumer(Topics.PROJECT_CREATED).handler(analyticsService::onProjectCreated); + + log.info( + "\n----------------------------------------------------------\n\t" + + "{} is running!\n" + + "----------------------------------------------------------", + AnalyticsVerticle.class.getSimpleName() + ); + + startFuture.complete(); + } +} diff --git a/src/main/java/io/vertx/starter/GeneratorVerticle.java b/src/main/java/io/vertx/starter/GeneratorVerticle.java new file mode 100644 index 00000000..4d9bcfe5 --- /dev/null +++ b/src/main/java/io/vertx/starter/GeneratorVerticle.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Future; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.starter.config.Topics; +import io.vertx.starter.service.GeneratorService; + +import static io.vertx.starter.config.VerticleConfigurationConstants.Generator.GENERATOR_DIR; +import static io.vertx.starter.config.VerticleConfigurationConstants.Generator.GENERATOR_OUTPUT_DIR; + +public class GeneratorVerticle extends AbstractVerticle { + + private final Logger log = LoggerFactory.getLogger(GeneratorVerticle.class); + + @Override + public void start(Future startFuture) { + GeneratorService generatorService = new GeneratorService( + config().getString(GENERATOR_DIR), + config().getString(GENERATOR_OUTPUT_DIR), + vertx + ); + vertx.eventBus().consumer(Topics.PROJECT_REQUESTED).handler(generatorService::onProjectRequested); + vertx.eventBus().consumer(Topics.PROJECT_CREATED).handler(generatorService::onProjectCreated); + + log.info( + "\n----------------------------------------------------------\n\t" + + "{} is running!\n" + + "----------------------------------------------------------", + GeneratorVerticle.class.getSimpleName() + ); + + startFuture.complete(); + } +} diff --git a/src/main/java/io/vertx/starter/WebVerticle.java b/src/main/java/io/vertx/starter/WebVerticle.java new file mode 100644 index 00000000..2b847393 --- /dev/null +++ b/src/main/java/io/vertx/starter/WebVerticle.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Future; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.web.Router; +import io.vertx.ext.web.handler.CorsHandler; +import io.vertx.ext.web.handler.StaticHandler; +import io.vertx.starter.service.StarterMetadataService; +import io.vertx.starter.web.rest.StarterResource; + +import static io.vertx.starter.config.VerticleConfigurationConstants.Web.HTTP_PORT; + +public class WebVerticle extends AbstractVerticle { + + public static final int DEFAULT_HTTP_PORT = 8080; + private final Logger log = LoggerFactory.getLogger(WebVerticle.class); + + private StarterResource starterResource; + + @Override + public void start(Future startFuture) { + starterResource = new StarterResource( + this.vertx.eventBus(), + new StarterMetadataService(this.vertx), + config().getJsonObject("project-defaults") + ); + + Router router = Router.router(vertx); + cors(router); + router.get("/starter.*").handler(starterResource::generateProject); + router.get("/metadata").handler(starterResource::getStarterMetadata); + router.route().produces("text/html").handler(StaticHandler.create()); + + int port = config().getInteger(HTTP_PORT, DEFAULT_HTTP_PORT); + vertx + .createHttpServer() + .requestHandler(router::accept) + .listen(port, ar -> { + if (ar.failed()) { + log.error("Fail to start {}: {}", WebVerticle.class.getSimpleName(), ar.cause().getMessage()); + startFuture.fail(ar.cause()); + } else { + log.info("\n----------------------------------------------------------\n\t" + + "{} is running! Access URLs:\n\t" + + "Local: \t\thttp://localhost:{}\n" + + "----------------------------------------------------------", + WebVerticle.class.getSimpleName(), port); + startFuture.complete(); + } + }); + } + + private void cors(Router router) { + router.route().handler(CorsHandler.create("*") + .allowedMethod(HttpMethod.GET) + .allowedMethod(HttpMethod.POST) + .allowedHeader("Content-Type") + .allowedHeader("Accept") + ); + } + +} diff --git a/src/main/java/io/vertx/starter/config/ProjectConstants.java b/src/main/java/io/vertx/starter/config/ProjectConstants.java new file mode 100644 index 00000000..04b798c1 --- /dev/null +++ b/src/main/java/io/vertx/starter/config/ProjectConstants.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.config; + +public interface ProjectConstants { + + String TYPE = "type"; + String GROUP_ID = "groupId"; + String ARTIFACT_ID = "artifactId"; + String LANGUAGE = "language"; + String BUILD_TOOL = "buildTool"; + String VERTX_VERSION = "vertxVersion"; + String VERTX_DEPENDENCIES = "vertxDependencies"; + String ARCHIVE_FORMAT = "archiveFormat"; +} diff --git a/src/main/java/io/vertx/starter/config/Topics.java b/src/main/java/io/vertx/starter/config/Topics.java new file mode 100644 index 00000000..045c9cb2 --- /dev/null +++ b/src/main/java/io/vertx/starter/config/Topics.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.config; + +public interface Topics { + + String PROJECT_REQUESTED = "project.requested"; + String PROJECT_CREATED = "project.created"; + +} diff --git a/src/main/java/io/vertx/starter/config/VerticleConfigurationConstants.java b/src/main/java/io/vertx/starter/config/VerticleConfigurationConstants.java new file mode 100644 index 00000000..bb6fdac9 --- /dev/null +++ b/src/main/java/io/vertx/starter/config/VerticleConfigurationConstants.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.config; + +public interface VerticleConfigurationConstants { + + interface Web { + String HTTP_PORT = "http-port"; + String PROJECT_DEFAULTS = "project-defaults"; + } + + interface Generator { + String GENERATOR_DIR = "generator-dir"; + String GENERATOR_OUTPUT_DIR = "generator-output-dir"; + } +} diff --git a/src/main/java/io/vertx/starter/model/ArchiveFormat.java b/src/main/java/io/vertx/starter/model/ArchiveFormat.java new file mode 100644 index 00000000..72f7c222 --- /dev/null +++ b/src/main/java/io/vertx/starter/model/ArchiveFormat.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public enum ArchiveFormat { + + @JsonProperty("zip") + ZIP("zip", "application/zip"), + + @JsonProperty("tgz") + TGZ("tar.gz", "application/zip"); + + private final String fileExtension; + private final String contentType; + + ArchiveFormat(String fileExtension, String contentType) { + this.contentType = contentType; + this.fileExtension = fileExtension; + } + + public static ArchiveFormat fromFilename(String filename) { + if (filename.matches(".*\\.zip$")) { + return ArchiveFormat.ZIP; + } + if (filename.matches(".*(\\.tar\\.gz|\\.tgz)$")) { + return ArchiveFormat.TGZ; + } + return null; + } + + public String getFileExtension() { + return fileExtension; + } + + public String getContentType() { + return contentType; + } +} diff --git a/src/main/java/io/vertx/starter/model/BuildTool.java b/src/main/java/io/vertx/starter/model/BuildTool.java new file mode 100644 index 00000000..f604eab6 --- /dev/null +++ b/src/main/java/io/vertx/starter/model/BuildTool.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public enum BuildTool { + @JsonProperty("maven") + MAVEN, + @JsonProperty("gradle") + GRADLE +} diff --git a/src/main/java/io/vertx/starter/model/Language.java b/src/main/java/io/vertx/starter/model/Language.java new file mode 100644 index 00000000..829ce595 --- /dev/null +++ b/src/main/java/io/vertx/starter/model/Language.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public enum Language { + @JsonProperty("java") + JAVA("java", ".java"), + + @JsonProperty("kotlin") + KOTLIN("kotlin", ".kt"); + + private final String name; + private final String extension; + + Language(String name, String extension) { + this.name = name; + this.extension = extension; + } + + public String getName() { + return name; + } + + public String getExtension() { + return extension; + } +} diff --git a/src/main/java/io/vertx/starter/model/VertxProject.java b/src/main/java/io/vertx/starter/model/VertxProject.java new file mode 100644 index 00000000..c07a6226 --- /dev/null +++ b/src/main/java/io/vertx/starter/model/VertxProject.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.model; + +import java.util.Set; + +public class VertxProject { + + private String id; + private String type; + private String groupId; + private String artifactId; + private Language language; + private BuildTool buildTool; + private String vertxVersion; + private Set vertxDependencies; + private ArchiveFormat archiveFormat; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public Language getLanguage() { + return language; + } + + public void setLanguage(Language language) { + this.language = language; + } + + public BuildTool getBuildTool() { + return buildTool; + } + + public void setBuildTool(BuildTool buildTool) { + this.buildTool = buildTool; + } + + public String getVertxVersion() { + return vertxVersion; + } + + public void setVertxVersion(String vertxVersion) { + this.vertxVersion = vertxVersion; + } + + public Set getVertxDependencies() { + return vertxDependencies; + } + + public void setVertxDependencies(Set vertxDependencies) { + this.vertxDependencies = vertxDependencies; + } + + public ArchiveFormat getArchiveFormat() { + return archiveFormat; + } + + public void setArchiveFormat(ArchiveFormat archiveFormat) { + this.archiveFormat = archiveFormat; + } + + @Override + public String toString() { + return "Project{" + + "id='" + id + '\'' + + ", type='" + type + '\'' + + ", groupId='" + groupId + '\'' + + ", artifactId='" + artifactId + '\'' + + ", language=" + language + + ", buildTool=" + buildTool + + ", vertxVersion='" + vertxVersion + '\'' + + ", vertxDependencies=" + vertxDependencies + + ", archiveFormat=" + archiveFormat + + '}'; + } +} diff --git a/src/main/java/io/vertx/starter/service/AnalyticsService.java b/src/main/java/io/vertx/starter/service/AnalyticsService.java new file mode 100644 index 00000000..c8b4ce04 --- /dev/null +++ b/src/main/java/io/vertx/starter/service/AnalyticsService.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.service; + +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.mongo.MongoClient; + +public class AnalyticsService { + + private static final Logger log = LoggerFactory.getLogger(AnalyticsService.class); + + private static final String COLLECTION_NAME = "projects"; + + private final MongoClient mongoClient; + + public AnalyticsService(MongoClient mongoClient) { + this.mongoClient = mongoClient; + } + + public void onProjectCreated(Message message) { + log.debug("Building analytics with on new project created"); + JsonObject document = message.body(); + mongoClient.save(COLLECTION_NAME, document, res -> { + if (res.failed()) { + log.error("Failed to save project {}: {}", document, res.cause().getMessage()); + } else { + log.debug("Saved project: {}", document); + } + }); + } +} diff --git a/src/main/java/io/vertx/starter/service/GeneratorService.java b/src/main/java/io/vertx/starter/service/GeneratorService.java new file mode 100644 index 00000000..0409a3ee --- /dev/null +++ b/src/main/java/io/vertx/starter/service/GeneratorService.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.service; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.Vertx; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.starter.model.VertxProject; +import org.gradle.tooling.*; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +public class GeneratorService { + + private final Logger log = LoggerFactory.getLogger(GeneratorService.class); + + private final Vertx vertx; + private final String generatorDir; + private final String generatorOutputDir; + private final ProjectConnection connection; + + public GeneratorService(String generatorDir, String generatorOutputDir, Vertx vertx) { + this.vertx = vertx; + this.generatorDir = generatorDir; + this.generatorOutputDir = generatorOutputDir; + GradleConnector connector = GradleConnector.newConnector(); + connector.forProjectDirectory(new File(generatorDir)); + this.connection = connector.connect(); + log.info("Gradle connection with project directory: {}", generatorDir ); + } + + private Path projectBuildDir(VertxProject project) { + return Paths.get(generatorOutputDir, project.getId()).toAbsolutePath(); + } + + public void onProjectRequested(Message message) { + VertxProject project = message.body().mapTo(VertxProject.class); + log.debug("Generating project: {}", project); + generateProject(project, ar -> { + if (ar.succeeded()) { + log.info("Generation done fo VertxProject: {}", project); + message.reply(ar.result()); + } else { + log.error("Failed to generate project: {}: {}", project, ar.cause().getMessage()); + message.fail(500, ar.cause().getMessage()); + } + }); + } + + public void onProjectCreated(Message message) { + VertxProject project = message.body().mapTo(VertxProject.class); + Path projectBuildDir = projectBuildDir(project); + log.debug("Cleaning project: {}", project); + vertx.fileSystem().deleteRecursive(projectBuildDir.toString(), true, ar -> { + if (ar.succeeded()) { + log.debug("Cleaning done for VertxProject build dir: {}", projectBuildDir); + } else { + log.error("Impossible to clean {}", projectBuildDir); + } + }); + } + + public void generateProject(VertxProject project, Handler> handler) { + log.info("Generating Project: {}", project); + this.vertx.executeBlocking(blockingBuildFuture -> { + // Configure the build + Path projectBuildDir = projectBuildDir(project); + BuildLauncher launcher = connection.newBuild(); + List args = Arrays.asList( + "-Dorg.gradle.project.buildDir=" + projectBuildDir.toString(), + "-Ptype=" + project.getType(), + "-PgroupId=" + project.getGroupId(), + "-PartifactId=" + project.getArtifactId(), + "-Planguage=" + project.getLanguage(), + "-PbuildTool=" + project.getBuildTool(), + "-PvertxVersion=" + project.getVertxVersion(), + "-PvertxDependencies=" + String.join(",", project.getVertxDependencies()), + "-ParchiveFormat=" + project.getArchiveFormat().getFileExtension() + ); + launcher.withArguments(args); + launcher.setStandardOutput(System.out); + launcher.setStandardError(System.err); + // Run the build + log.info("Running {}/gradlew {}", this.generatorDir, this.generatorDir, String.join(" ", args)); + launcher.run(new ResultHandler() { + @Override + public void onComplete(Void aVoid) { + String archivePath = projectBuildDir.resolve(project.getArtifactId() + "." + project.getArchiveFormat().getFileExtension()).toAbsolutePath().toString(); + blockingBuildFuture.complete(archivePath); + } + + @Override + public void onFailure(GradleConnectionException e) { + blockingBuildFuture.fail(e); + } + }); + }, (AsyncResult res) -> { + if (res.succeeded()) { + handler.handle(Future.succeededFuture(res.result())); + } else { + log.error("Failed to generate VertxProject {}", res.cause().getMessage()); + handler.handle(Future.failedFuture(res.cause())); + } + }); + } +} diff --git a/src/main/java/io/vertx/starter/service/StarterMetadataService.java b/src/main/java/io/vertx/starter/service/StarterMetadataService.java new file mode 100644 index 00000000..c8a63952 --- /dev/null +++ b/src/main/java/io/vertx/starter/service/StarterMetadataService.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.service; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.Vertx; +import io.vertx.core.file.FileSystem; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.web.client.WebClient; + +public class StarterMetadataService { + + private static final Logger log = LoggerFactory.getLogger(StarterMetadataService.class); + + private static final String DEPENDENCIES_PATH = "dependencies.json"; + public static final String VERSION_PROVIDER_API_URL = "https://api.bintray.com/packages/bintray/jcenter/io.vertx:vertx-core"; + public static final JsonArray DEFAULT_VERSIONS = new JsonArray() + .add("3.5.3") + .add("3.5.2") + .add("3.5.1") + .add("3.5.0") + .add("3.4.2") + .add("3.4.1") + .add("3.4.0"); + + private final WebClient webClient; + private JsonArray dependencies; + + public StarterMetadataService(Vertx vertx) { + loadDependencies(vertx.fileSystem()); + this.webClient = WebClient.create(vertx); + } + + private void loadDependencies(FileSystem fileSystem) { + log.debug("Loading dependencies from {}", DEPENDENCIES_PATH); + fileSystem.readFile(DEPENDENCIES_PATH, ar -> { + if (ar.succeeded()) { + String raw = ar.result().toString(); + this.dependencies = new JsonObject(raw).getJsonArray("content"); + log.info("Vert.x dependencies loaded"); + } else { + log.error("Impossible to load dependencies {}: {}", DEPENDENCIES_PATH, ar.cause().getMessage()); + } + }); + } + + public void getAllVertxVersions(Handler> reply) { + //TODO cache result + log.debug("Finding Vert.x version via Bintray"); + webClient.getAbs(VERSION_PROVIDER_API_URL).send(ar -> { + if (ar.succeeded()) { + JsonObject data = new JsonObject(ar.result().body()); + reply.handle(Future.succeededFuture(data.getJsonArray("versions"))); + } else { + log.error("Providing default versions because: {}", ar.cause()); + reply.handle(Future.succeededFuture(DEFAULT_VERSIONS)); + } + }); + } + + public void getAllVertxDependencies(Handler> reply) { + //TODO cache result + log.debug("Finding Vert.x dependencies"); + reply.handle(Future.succeededFuture(this.dependencies)); + } + +} diff --git a/src/main/java/io/vertx/starter/web/rest/StarterResource.java b/src/main/java/io/vertx/starter/web/rest/StarterResource.java new file mode 100644 index 00000000..8f7017e3 --- /dev/null +++ b/src/main/java/io/vertx/starter/web/rest/StarterResource.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.web.rest; + +import io.vertx.core.MultiMap; +import io.vertx.core.eventbus.EventBus; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.web.RoutingContext; +import io.vertx.starter.model.ArchiveFormat; +import io.vertx.starter.model.BuildTool; +import io.vertx.starter.model.Language; +import io.vertx.starter.model.VertxProject; +import io.vertx.starter.service.StarterMetadataService; +import io.vertx.starter.web.util.RestUtil; + +import java.io.File; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +import static io.vertx.starter.config.ProjectConstants.*; +import static io.vertx.starter.config.Topics.PROJECT_CREATED; +import static io.vertx.starter.config.Topics.PROJECT_REQUESTED; +import static java.net.HttpURLConnection.HTTP_OK; +import static java.util.Arrays.asList; + +public class StarterResource { + + private static final Logger log = LoggerFactory.getLogger(StarterResource.class); + + private final EventBus eventBus; + private final StarterMetadataService starterMetadataService; + private final JsonObject defaults; + + public StarterResource(EventBus eventBus, StarterMetadataService starterMetadataService, JsonObject defaults) { + this.eventBus = eventBus; + this.starterMetadataService = starterMetadataService; + this.defaults = defaults; + } + + private VertxProject createProjectWithDefaultValues() { + return defaults.mapTo(VertxProject.class); + } + + public void getStarterMetadata(RoutingContext rc) { + log.debug("REST request to get starter metdata"); + JsonObject details = new JsonObject(); + details.put("defaults", defaults); + details.put("buildTools", asList("maven", "gradle")); + details.put("languages", asList("java", "kotlin")); + starterMetadataService.getAllVertxDependencies(dependencies -> { + if (dependencies.succeeded()) { + details.put("vertxDependencies", dependencies.result()); + starterMetadataService.getAllVertxVersions(versions -> { + if (versions.succeeded()) { + details.put("vertxVersions", versions.result()); + RestUtil.respondJson(rc, details); + } else { + RestUtil.error(rc, versions.cause()); + } + }); + } else { + RestUtil.error(rc, dependencies.cause()); + } + }); + } + + public void generateProject(RoutingContext rc) { + VertxProject project = buildProject(rc.request()); + log.debug("REST request to generate project: {}", project); + this.eventBus.send(PROJECT_REQUESTED, JsonObject.mapFrom(project), reply -> { + if (reply.succeeded()) { + String archivePath = (String) reply.result().body(); + File archive = new File(archivePath); + String filename = project.getArtifactId() + "." + project.getArchiveFormat().getFileExtension(); + log.debug("Sending archive: " + archive.getAbsolutePath()); + rc.response() + .setStatusCode(HTTP_OK) + .putHeader("Content-Type", project.getArchiveFormat().getContentType()) + .putHeader("Content-Disposition", "attachment; filename=" + filename) + .sendFile(archive.getAbsolutePath(), onFileSent -> { + if (onFileSent.succeeded()) { + log.debug("Notifying project created"); + this.eventBus.publish(PROJECT_CREATED, JsonObject.mapFrom(project)); + } else { + log.error("Generated archive {} could not be found", archive); + RestUtil.error(rc, "Generated archive could not be found"); + + } + }); + } else { + String errorMessage = reply.cause().getMessage(); + log.error("Failed to create project: {}", project.getId()); + RestUtil.error(rc, "Failed to create project: " + project.getId()); + } + }); + } + + private VertxProject buildProject(HttpServerRequest request) { + VertxProject project = createProjectWithDefaultValues(); + String projectId = UUID.randomUUID().toString(); + project.setId(projectId); + + MultiMap params = request.params(); + if (isNotBlank(params.get(TYPE))) { + project.setType(params.get(TYPE)); + } + if (isNotBlank(params.get(GROUP_ID))) { + project.setGroupId(params.get(GROUP_ID)); + } + if (isNotBlank(params.get(ARTIFACT_ID))) { + project.setArtifactId(params.get(ARTIFACT_ID)); + } + if (isNotBlank(params.get(LANGUAGE))) { + project.setLanguage(Language.valueOf(params.get(LANGUAGE).toUpperCase())); + } + if (isNotBlank(params.get(BUILD_TOOL))) { + project.setBuildTool(BuildTool.valueOf(params.get(BUILD_TOOL).toUpperCase())); + } + if (isNotBlank(params.get(VERTX_VERSION))) { + project.setVertxVersion(params.get(VERTX_VERSION)); + } + Set vertxDependencies = new HashSet<>(project.getVertxDependencies()); + if (isNotBlank(params.get(VERTX_DEPENDENCIES))) { + for (String dependency : params.get(VERTX_DEPENDENCIES).split(",")) { + vertxDependencies.add(dependency.toLowerCase()); + } + project.setVertxDependencies(vertxDependencies); + } + ArchiveFormat archiveFormat = Optional + .ofNullable(ArchiveFormat.fromFilename(request.path())) + .orElse(ArchiveFormat.valueOf(defaults.getString(ARCHIVE_FORMAT).toUpperCase())); + project.setArchiveFormat(archiveFormat); + return project; + } + + private boolean isNotBlank(String value) { + return value != null && value.length() > 0; + } + +} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/util/RestUtil.java b/src/main/java/io/vertx/starter/web/util/RestUtil.java similarity index 53% rename from vertx-starter-web/src/main/java/io/vertx/starter/web/util/RestUtil.java rename to src/main/java/io/vertx/starter/web/util/RestUtil.java index 10a6d12c..d8bfb4a9 100644 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/util/RestUtil.java +++ b/src/main/java/io/vertx/starter/web/util/RestUtil.java @@ -1,18 +1,19 @@ /* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. + * Copyright (c) 2017-2018 Daniel Petisme * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html + * Licensed 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 * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php + * http://www.apache.org/licenses/LICENSE-2.0 * - * You may elect to redistribute this code under either of these licenses. + * 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. */ + package io.vertx.starter.web.util; import io.vertx.core.json.JsonArray; @@ -25,7 +26,11 @@ public final class RestUtil { public static void error(RoutingContext rc, Throwable cause) { - rc.response().setStatusCode(HTTP_INTERNAL_ERROR).end(new JsonObject().put("status", HTTP_INTERNAL_ERROR).put("message", cause.getMessage()).toString()); + error(rc, cause.getCause().getMessage()); + } + + public static void error(RoutingContext rc, String message) { + rc.response().setStatusCode(HTTP_INTERNAL_ERROR).end(new JsonObject().put("status", HTTP_INTERNAL_ERROR).put("message", message).toString()); } private static void respond(RoutingContext rc, String contentType, String chunk) { diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf new file mode 100644 index 00000000..6e7aa8a7 --- /dev/null +++ b/src/main/resources/application.conf @@ -0,0 +1,37 @@ +vertx-boot { + verticles { + web { + name = "io.vertx.starter.WebVerticle" + configuration { + http-port = 8080 + project-defaults { + type = "core" + groupId = "io.vertx", + artifactId = "starter", + language = "java", + buildTool = "maven", + vertxVersion = "3.5.3", + vertxDependencies = [] + archiveFormat = "zip", + } + } + } + analytics { + name = "io.vertx.starter.AnalyticsVerticle" + worker = true + configuration { + mongo-host = "localhost" + mongo-port = "27017" + mongo-db_name = "vertx-starter-analytics" + } + } + worker { + name = "io.vertx.starter.GeneratorVerticle" + worker = true + configuration { + generator-dir = "/Users/daniel/workspace/vertx-project-generator" + generator-output-dir = "/tmp/vertx" + } + } + } +} diff --git a/dependencies.json b/src/main/resources/dependencies.json similarity index 87% rename from dependencies.json rename to src/main/resources/dependencies.json index d081d5dd..5aea3614 100644 --- a/dependencies.json +++ b/src/main/resources/dependencies.json @@ -70,7 +70,7 @@ "description": "Vert.x provides an implementation of the STOMP protocol." }, { - "artifactId": "none", + "artifactId": "vertx-jca", "name": "JCA Adaptor", "description": "Vert.x provides a Java Connector Architecture (JCA) adaptor which allows it to interoperate with any JavaEE application server." }, @@ -148,7 +148,7 @@ "description": "Auth implementation for OAuth2" }, { - "artifactId": "", + "artifactId": "vertx-auth-htdigest", "name": ".htdigest Auth", "description": ".htdigest file to query user information" } @@ -159,8 +159,13 @@ "description": "Vert.x provides a couple of components to make your applications more reactive.", "items": [ { - "artifactId": "", - "name": "Vert.x Rx", + "artifactId": "vertx-rx-java", + "name": "Vert.x RxJava v1", + "description": "Don't like callback-style APIs? Vert.x provides Rx-ified (using RxJava) versions for most of its APIs so you can use those if you prefer. RxJava is a great choice when you want to perform complex operations on multiple asynchronous streams of data." + }, + { + "artifactId": "vertx-rx-java2", + "name": "Vert.x RxJava v2", "description": "Don't like callback-style APIs? Vert.x provides Rx-ified (using RxJava) versions for most of its APIs so you can use those if you prefer. RxJava is a great choice when you want to perform complex operations on multiple asynchronous streams of data." }, { @@ -169,7 +174,7 @@ "description": "Vert.x supports reactive streams so your applications can interoperate with other reactive systems such as Akka or Project Reactor." }, { - "artifactId": "", + "artifactId": "vertx-sync", "name": "Vert.x Sync", "description": "Vertx-sync allows you to deploy verticles that run using fibers. Fibers are very lightweight threads that can be blocked without blocking a kernel thread. This enables you to write your verticle code in a familiar synchronous style." } @@ -200,9 +205,9 @@ "category": "IoT", "items": [ { - "artifactId": "", - "name": "MQTT Server", - "description": "Vert.x MQTT Server is able to handle connections, communication and messages exchange with remote MQTT clients. Its API provides a bunch of events related to protocol messages received by clients and exposes allow to send messages to them.", + "artifactId": "vertx-mqtt", + "name": "MQTT", + "description": "Vert.x MQTT (client and server) is able to handle connections, communication and messages exchange with remote MQTT clients. Its API provides a bunch of events related to protocol messages received by clients and exposes allow to send messages to them.", "flag": "Technical Preview" } ] @@ -227,7 +232,7 @@ "description": "This component provides a simple way to expose health checks." }, { - "artifactId": "", + "artifactId": "vertx-shell", "name": "Shell", "description": "This component lets you interact with your Vert.x application using a CLI interface." }, @@ -250,6 +255,10 @@ { "name": "Vert.x Unit", "artifactId": "vertx-unit" + }, + { + "name": "Vert.x JUnit5", + "artifactId": "vertx-junit5" } ] }, @@ -259,19 +268,23 @@ "items": [ { "name": "Hazelcast", + "artifactId": "vertx-hazelcast", "description": "Cluster manager implementation that uses Hazelcast. This is the default." }, { "name": "Infinispan", + "artifactId": "vertx-infinispan", "description": "Cluster manager implementation that uses Infinispan.", "flag": "Technical Preview" }, { "name": "Apache Ignite", + "artifactId": "vertx-ignite", "description": "Cluster manager implementation that uses Apache Ignite." }, { "name": "Apache Zookeper", + "artifactId": "vertx-zookeeper", "description": "Cluster manager implementation that uses Apache Zookeeper.", "flag": "Technical Preview" } @@ -283,26 +296,32 @@ "items": [ { "name": "Service Proxies", + "artifactId": "vertx-service-proxy", "description": "Proxies allow remote event bus services to be called as if they were local." }, { "name": "SockJS Service Proxies", + "artifactId": "vertx-sockjs-service-proxy", "description": "Allow event bus services to be called from JavaScript (browser or Node.js)." }, { "name": "gRPC", + "artifactId": "vertx-grpc", "description": "Implement gRPC Clients and Servers for Vert.x." }, { "name": "Service Factories", + "artifactId": "vertx-service-factory", "description": "How to package and deploy Vert.x independent services." }, { "name": "Maven Service Factory", + "artifactId": "vertx-maven-service-factory", "description": "This lets you dynamically install and deploy services from Maven at run-time." }, { "name": "HTTP Service Factory", + "artifactId": "vertx-http-service-factory", "description": "This lets you dynamically install and deploy services from an HTTP server (for example Bintray at run-time." } ] diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 00000000..4a84f874 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,33 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + diff --git a/vertx-starter-web/src/main/resources/webroot/index.html b/src/main/resources/webroot/index.html similarity index 79% rename from vertx-starter-web/src/main/resources/webroot/index.html rename to src/main/resources/webroot/index.html index 6bf13111..22b26f80 100644 --- a/vertx-starter-web/src/main/resources/webroot/index.html +++ b/src/main/resources/webroot/index.html @@ -1,19 +1,20 @@ - + + Eclipse Vert.x @@ -57,6 +58,10 @@ + + @@ -138,38 +182,38 @@

Generate a Vert.x project

- +
- +
-
-
@@ -178,7 +222,7 @@

Generate a Vert.x project

@@ -186,14 +230,14 @@

Generate a Vert.x project

-
+

-
+
{{ dependency.name }} -
@@ -201,6 +245,13 @@

Generate a Vert.x project

+
+ {{alert}} +

+ Report + the problem. +

+

+
+

+ +

+
@@ -288,7 +344,10 @@

Generate a Vert.x project

integrity="sha256-UzSbSKd9UMo8E8MPnTx9OTfXYin6xmVHCnmOOUDYn68=" crossorigin="anonymous"> + @@ -296,12 +355,17 @@

Generate a Vert.x project

integrity="sha256-6vbKDGwy9JmzGKxxeypGzCjyOmACDtgheaOQT6ZVafA=" crossorigin="anonymous"> + + + + diff --git a/src/main/resources/webroot/main.js b/src/main/resources/webroot/main.js new file mode 100644 index 00000000..d49bbb12 --- /dev/null +++ b/src/main/resources/webroot/main.js @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +angular + .module('app', ['ngResource', 'ui.bootstrap', 'cfp.hotkeys']) + .value('bowser', bowser) + .factory('Starter', ['$http', function ($http) { + var service = { + 'generate': function(vertxProject) { + return $http.get('/starter.' + vertxProject.archiveFormat, { + responseType: 'blob', + params: { + type: vertxProject.type, + groupId: vertxProject.groupId, + artifactId: vertxProject.artifactId, + language: vertxProject.language, + buildTool: vertxProject.buildTool, + vertxVersion: vertxProject.vertxVersion, + vertxDependencies: vertxProject.vertxDependencies + } + }); + }, + 'metadata': function() { + return $http.get('/metadata'); + } + }; + + return service; + }]) + .factory('httpErrorInterceptor', ['$q', function($q) { + return { + 'responseError': function(rejection) { + if (rejection.status === 500) { + var errorData = rejection.data; + var decoder = new TextDecoder("utf-8"); + rejection.data = JSON.parse(decoder.decode(errorData.data)); + } + return $q.reject(rejection); + } + } + }]) + .filter('capitalize', function() { + return function(input) { + return (!!input) ? input.charAt(0).toUpperCase() + input.slice(1).toLowerCase() : ''; + } + }) + .config(['$httpProvider', 'hotkeysProvider', function ($httpProvider, hotkeysProvider) { + hotkeysProvider.includeCheatSheet = false; + $httpProvider.interceptors.push('httpErrorInterceptor'); + }]) + .controller('VertxStarterController', ['$document', '$window', 'hotkeys', 'Starter', + function VertxStarterController($document, $window, hotkeys, Starter) { + var vm = this; + vm.isGenerating = false + vm.vertxVersions = []; + vm.vertxDependencies = []; + vm.languages = []; + vm.buildTools = []; + + vm.vertxProject = {}; + vm.selectedDependency = null; + vm.alerts = []; + vm.onDependencySelected = onDependencySelected; + vm.removeDependency = removeDependency; + vm.generate = generate; + vm.addAlert = addAlert; + vm.closeAlert = closeAlert; + + loadAll(); + + hotkeys.add({ + combo: ['command+enter', 'alt+enter'], + callback: function (event, hotkey) { + event.preventDefault(); + generate(); + } + }); + vm.hotkey = (bowser.mac) ? '\u2318 + \u23CE' : 'alt + \u23CE'; + + try { + vm.isFileSaverSupported = !!new Blob; + } catch (e) { + } + + function loadAll() { + Starter.metadata() + .then(function(response) { + var data = response.data; + vm.vertxVersions = data.vertxVersions.slice(0, 10); + vm.vertxDependencies = data.vertxDependencies + .map(function (category) { + return category.items; + }).reduce(function (a, b) { + return a.concat(b); + }); + vm.buildTools = data.buildTools; + vm.languages = data.languages; + initProjectWithDefaults(data.defaults); + }) + .catch(function(error) { + console.error('Impossible to load starter metadata: ' + JSON.stringify(error)); + }); + } + + function initProjectWithDefaults(defaults) { + vm.vertxProject.type = defaults.type; + vm.vertxProject.model = defaults.model; + vm.vertxProject.groupId = defaults.groupId; + vm.vertxProject.artifactId = defaults.artifactId; + vm.vertxProject.language = defaults.language; + vm.vertxProject.buildTool = defaults.buildTool; + vm.vertxProject.vertxVersion = defaults.vertxVersion; + vm.vertxProject.archiveFormat = defaults.archiveFormat; + vm.vertxProject.vertxDependencies = []; + } + + function onDependencySelected($item, $model, $label, $event) { + addDependency($model); + vm.selectedDependency = null; + } + + function indexOfDependency(predicate) { + for (var i = 0; i < vm.vertxProject.vertxDependencies.length; i++) { + if (predicate(vm.vertxProject.vertxDependencies[i])) { + return i; + } + } + return -1; + } + + function addDependency(dependency) { + var index = indexOfDependency(function (it) { + return it.name === dependency.name; + }); + if (index == -1) { + vm.vertxProject.vertxDependencies.push(dependency); + } + } + + function removeDependency(dependency) { + vm.vertxProject.vertxDependencies = vm.vertxProject.vertxDependencies.filter(function (it) { + return it.name !== dependency.name; + }); + } + + function save(data, contentType) { + if (vm.isFileSaverSupported) { + var archive = new Blob([data], {type: contentType}); + console.log(archive.size); + saveAs(archive, vm.vertxProject.artifactId + '.' + vm.vertxProject.archiveFormat); + } + } + + + function vertxProjectRequest() { + var vertxProject = {}; + angular.copy(vm.vertxProject, vertxProject); + var artifacts = vm.vertxProject.vertxDependencies.map(function (dependency) { + return dependency.artifactId; + }); + vertxProject.vertxDependencies = artifacts.join(); + console.log(JSON.stringify(vertxProject)); + return vertxProject; + } + + function generate() { + vm.isGenerating = true + Starter + .generate(vertxProjectRequest()) + .then(function (response) { + vm.isGenerating = false + var headers = response.headers() + save(response.data, headers['Content-Type']); + }) + .catch(function(error) { + vm.isGenerating = false + addAlert(error.data.message); + }); + }; + + function addAlert(message) { + vm.alerts.push(message); + }; + + function closeAlert(index) { + vm.alerts.splice(index, 1); + }; + + }]); diff --git a/src/test/java/io/vertx/starter/service/GeneratorServiceTest.java b/src/test/java/io/vertx/starter/service/GeneratorServiceTest.java new file mode 100644 index 00000000..a504ae78 --- /dev/null +++ b/src/test/java/io/vertx/starter/service/GeneratorServiceTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.service; + +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTestContext; +import io.vertx.starter.model.ArchiveFormat; +import io.vertx.starter.model.BuildTool; +import io.vertx.starter.model.Language; +import io.vertx.starter.model.VertxProject; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.UUID; + +import static io.vertx.starter.config.ProjectConstants.*; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(VertxExtension.class) +public class GeneratorServiceTest { + + public static final String BASE_GENERATOR_DIR = "src/test/resources/generator"; + public static final String GENERATOR_OUTPUT_DIR = "build"; + private static final Logger log = LoggerFactory.getLogger(GeneratorServiceTest.class); + + private static VertxProject initProject() { + VertxProject project = new VertxProject(); + project.setId(UUID.randomUUID().toString()); + project.setType("AAAAA"); + project.setGroupId("AA.BB.CC"); + project.setArtifactId("DD"); + project.setLanguage(Language.JAVA); + project.setBuildTool(BuildTool.MAVEN); + project.setVertxVersion("0.0.0"); + project.setVertxDependencies(new HashSet<>(asList("EE", "FF"))); + project.setArchiveFormat(ArchiveFormat.ZIP); + return project; + } + + @Test + @DisplayName("should return archive filename when Gradle is done") + public void should(Vertx vertx, VertxTestContext testContext) { + VertxProject project = initProject(); + String generatorDir = Paths.get(BASE_GENERATOR_DIR, "no-op").toString(); + String generatorOutputDir = Paths.get(generatorDir, "/build").toString(); + GeneratorService generatorService = new GeneratorService(generatorDir, generatorOutputDir, vertx); + generatorService.generateProject(project, testContext.succeeding(generatedArchive -> testContext.verify(() -> { + String expectedArchiveName = Paths.get(generatorOutputDir, project.getId(), project.getArtifactId() + "." + project.getArchiveFormat().getFileExtension()).toAbsolutePath().toString(); + assertThat(generatedArchive).isEqualTo(expectedArchiveName); + testContext.completeNow(); + }))); + } + + @Test + @DisplayName("should passed project properties to Gradle") + public void shouldTriggerGradleGeneration(Vertx vertx, VertxTestContext testContext) { + VertxProject project = initProject(); + String generatorDir = Paths.get(BASE_GENERATOR_DIR, "passing-properties").toString(); + GeneratorService generatorService = new GeneratorService(generatorDir, GENERATOR_OUTPUT_DIR, vertx); + + generatorService.generateProject(project, testContext.succeeding(generatedArchive -> testContext.verify(() -> { + String filename = Paths.get(GENERATOR_OUTPUT_DIR, project.getId(), "project.json").toString(); + vertx.fileSystem().readFile(filename, testContext.succeeding(buffer -> testContext.verify(() -> { + JsonObject generatedProject = new JsonObject(buffer); + assertThat(generatedProject.getString(TYPE)).isEqualTo(project.getType()); + assertThat(generatedProject.getString(GROUP_ID)).isEqualTo(project.getGroupId()); + assertThat(generatedProject.getString(ARTIFACT_ID)).isEqualTo(project.getArtifactId()); + assertThat(generatedProject.getString(LANGUAGE)).isEqualTo(project.getLanguage().toString()); + assertThat(generatedProject.getString(BUILD_TOOL)).isEqualTo(project.getBuildTool().toString()); + assertThat(generatedProject.getString(VERTX_VERSION)).isEqualTo(project.getVertxVersion()); +// Should be parsed as JsonArray and not String +// assertThat(generatedProject.getString(VERTX_DEPENDENCIES)).containsAll(project.getVertxDependencies()); + assertThat(generatedProject.getString(ARCHIVE_FORMAT)).isEqualTo(project.getArchiveFormat().getFileExtension()); + testContext.completeNow(); + }))); + }))); + } + +} diff --git a/src/test/java/io/vertx/starter/web/rest/StarterResourceTest.java b/src/test/java/io/vertx/starter/web/rest/StarterResourceTest.java new file mode 100644 index 00000000..a4be1c6c --- /dev/null +++ b/src/test/java/io/vertx/starter/web/rest/StarterResourceTest.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +package io.vertx.starter.web.rest; + +import io.vertx.core.DeploymentOptions; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; +import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTestContext; +import io.vertx.starter.WebVerticle; +import io.vertx.starter.config.Topics; +import io.vertx.starter.config.VerticleConfigurationConstants; +import io.vertx.starter.model.ArchiveFormat; +import io.vertx.starter.model.BuildTool; +import io.vertx.starter.model.Language; +import io.vertx.starter.model.VertxProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.HashSet; + +import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR; +import static java.net.HttpURLConnection.HTTP_OK; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(VertxExtension.class) +public class StarterResourceTest { + + private static final Logger log = LoggerFactory.getLogger(StarterResourceTest.class); + + private static final int HTTP_PORT = 9000; + private WebClient webClient; + private JsonObject config; + + private static VertxProject defaultProject() { + VertxProject defaultProject = new VertxProject(); + defaultProject.setType("AAAAA"); + defaultProject.setGroupId("AA.BB.CC"); + defaultProject.setArtifactId("DD"); + defaultProject.setLanguage(Language.JAVA); + defaultProject.setBuildTool(BuildTool.MAVEN); + defaultProject.setVertxVersion("0.0.0"); + defaultProject.setVertxDependencies(new HashSet<>(asList("EE", "FF"))); + defaultProject.setArchiveFormat(ArchiveFormat.ZIP); + return defaultProject; + } + + private static JsonObject testConfig() { + JsonObject config = new JsonObject(); + config.put(VerticleConfigurationConstants.Web.HTTP_PORT, HTTP_PORT); + config.put(VerticleConfigurationConstants.Web.PROJECT_DEFAULTS, JsonObject.mapFrom(defaultProject())); + return config; + } + + @BeforeEach + public void beforeEach(Vertx vertx, VertxTestContext testContext) { + this.config = testConfig(); + vertx.deployVerticle( + new WebVerticle(), + new DeploymentOptions().setConfig(config), + testContext.succeeding(id -> { + vertx.eventBus().consumer(Topics.PROJECT_REQUESTED).unregister(); + this.webClient = WebClient.create(vertx, new WebClientOptions().setDefaultPort(HTTP_PORT)); + testContext.completeNow(); + }) + ); + } + + @Test + @DisplayName("should create project with default values when details not provided") + public void shouldCreateProjectWithDefaultValuesWhenDetailsNotProvided(Vertx vertx, VertxTestContext testContext) { + vertx.eventBus().consumer(Topics.PROJECT_REQUESTED).handler(message -> { + VertxProject project = message.body().mapTo(VertxProject.class); + assertThat(project).isEqualToIgnoringGivenFields(defaultProject(), "id"); + message.reply("src/test/resources/web/starter.zip"); + }); + webClient.get("/starter.dummy") + .send(testContext.succeeding(response -> testContext.verify(() -> { + assertThat(response.statusCode()).isEqualTo(HTTP_OK); + testContext.completeNow(); + }))); + } + + @Test + @DisplayName("should return HTTP 500 when the generated archive is invalid") + public void shouldReturnFailureWhenGeneratedArchiveIsInvalid(Vertx vertx, VertxTestContext testContext) { + vertx.eventBus().consumer(Topics.PROJECT_REQUESTED).handler(message -> { + VertxProject project = message.body().mapTo(VertxProject.class); + assertThat(project).isEqualToIgnoringGivenFields(defaultProject(), "id"); + message.reply("/not/exist.zip"); + }); + webClient.get("/starter.zip") + .send(testContext.succeeding(response -> testContext.verify(() -> { + assertThat(response.statusCode()).isEqualTo(HTTP_INTERNAL_ERROR); + testContext.completeNow(); + }))); + } + + @Test + @DisplayName("should return Starter metadata") + public void shouldReturnStarterMetadata(Vertx vertx, VertxTestContext testContext) { + webClient.get("/metadata") + .send(testContext.succeeding(response -> testContext.verify(() -> { + assertThat(response.statusCode()).isEqualTo(HTTP_OK); + JsonObject metadata = response.bodyAsJsonObject(); + assertThat(metadata.getJsonArray("languages")).contains("java", "kotlin"); + assertThat(metadata.getJsonArray("buildTools")).contains("maven", "gradle"); + assertThat(metadata.getJsonObject("defaults")).isEqualTo(this.config.getJsonObject("project-defaults")); + testContext.completeNow(); + }))); + } + +} diff --git a/src/test/resources/generator/no-op/build.gradle b/src/test/resources/generator/no-op/build.gradle new file mode 100644 index 00000000..70a535c7 --- /dev/null +++ b/src/test/resources/generator/no-op/build.gradle @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +defaultTasks 'noop' + +task noop { + doLast { + println "Vert.x rocks!" + } +} diff --git a/src/test/resources/generator/passing-properties/build.gradle b/src/test/resources/generator/passing-properties/build.gradle new file mode 100644 index 00000000..f9c9f187 --- /dev/null +++ b/src/test/resources/generator/passing-properties/build.gradle @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017-2018 Daniel Petisme + * + * Licensed 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. + */ + +defaultTasks 'printPropertiesToJson' + + +task printPropertiesToJson { + doLast { + def flatten = [:] + project.properties.each { k, v -> flatten.put(k.toString(), v.toString()) } + delete "$buildDir" + mkdir "$buildDir" + new File("$buildDir/project.json").text = groovy.json.JsonOutput.toJson(flatten) + } +} diff --git a/vertx-starter-web/src/test/resources/starter.zip b/src/test/resources/web/starter.zip similarity index 100% rename from vertx-starter-web/src/test/resources/starter.zip rename to src/test/resources/web/starter.zip diff --git a/vertx-starter-analytics/pom.xml b/vertx-starter-analytics/pom.xml deleted file mode 100644 index a776ce8a..00000000 --- a/vertx-starter-analytics/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - vertx-starter-analytics - - - io.vertx - vertx-starter - ../pom.xml - 1.0.0-SNAPSHOT - - - - 1.11 - 4.0.6 - 3.5.0 - - - - - io.vertx - vertx-core - ${vertx.version} - - - io.vertx - vertx-mongo-client - ${vertx.version} - - - org.slf4j - slf4j-simple - - - - diff --git a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/AnalyticsVerticle.java b/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/AnalyticsVerticle.java deleted file mode 100644 index 6bde19f9..00000000 --- a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/AnalyticsVerticle.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.vertx.starter.analytics; - -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.mongo.MongoClient; -import io.vertx.starter.analytics.repository.ProjectRepository; -import io.vertx.starter.analytics.service.ProjectService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AnalyticsVerticle extends AbstractVerticle { - - private final Logger log = LoggerFactory.getLogger(AnalyticsVerticle.class); - - private MongoClient mongoClient() { - return MongoClient.createShared(vertx, config()); - } - - private ProjectService projectService() { - return new ProjectService(vertx, new ProjectRepository(mongoClient())); - } - - @Override - public void start(Future startFuture) throws Exception { - ProjectService projectService = projectService(); - vertx.eventBus().consumer("project.created").handler(projectService::onProjectCreated); - - log.info("\n----------------------------------------------------------\n\t" + - "{} is running!\n" + - "----------------------------------------------------------", - AnalyticsVerticle.class.getSimpleName()); - startFuture.complete(); - } -} diff --git a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/repository/ProjectRepository.java b/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/repository/ProjectRepository.java deleted file mode 100644 index 46a28eb5..00000000 --- a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/repository/ProjectRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.vertx.starter.analytics.repository; - -import io.vertx.core.AsyncResult; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.mongo.MongoClient; - -import java.util.List; - -public class ProjectRepository { - - private static final String COLLECTION_NAME = "projects"; - - private final Logger log = LoggerFactory.getLogger(ProjectRepository.class); - - private final MongoClient mongoClient; - - public ProjectRepository(MongoClient mongoClient) { - this.mongoClient = mongoClient; - } - - public void save(JsonObject project) { - mongoClient.save(COLLECTION_NAME, project, res -> { - if (res.failed()) { - log.error("Failed to save project {}: {}", project, res.cause().getMessage()); - } else { - log.debug("Saved project: {}", project); - } - }); - } - - public void findAll(Handler>> handler) { - mongoClient.find(COLLECTION_NAME, new JsonObject(), handler); - } - - -} diff --git a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/service/ProjectService.java b/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/service/ProjectService.java deleted file mode 100644 index 41bfb655..00000000 --- a/vertx-starter-analytics/src/main/java/io/vertx/starter/analytics/service/ProjectService.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.vertx.starter.analytics.service; - -import io.vertx.core.Vertx; -import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.starter.analytics.repository.ProjectRepository; - -import java.time.Instant; -import java.util.Objects; - -public class ProjectService { - - private final Logger log = LoggerFactory.getLogger(ProjectService.class); - - private final Vertx vertx; - private final ProjectRepository projectRepository; - - - public ProjectService(Vertx vertx, ProjectRepository projectRepository) { - this.vertx = vertx; - this.projectRepository = projectRepository; - } - - public void onProjectCreated(Message message) { - Objects.requireNonNull(message.body(), "Project can't be null"); - projectRepository.save(toProject(message.body())); - } - - private JsonObject toProject(JsonObject projectRequest) { - return new JsonObject() - .put("version", projectRequest.getString("version")) - .put("language", projectRequest.getString("language")) - .put("build", projectRequest.getString("build")) - .put("groupId", projectRequest.getString("groupId")) - .put("artifactId", projectRequest.getString("artifactId")) - .put("dependencies", projectRequest.getJsonArray("dependencies")) - .put("format", projectRequest.getString("format")) - .put("creationDate", Instant.now()); - } - -} diff --git a/vertx-starter-generator/pom.xml b/vertx-starter-generator/pom.xml deleted file mode 100644 index b75068d1..00000000 --- a/vertx-starter-generator/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - 4.0.0 - - vertx-starter-generator - - - io.vertx - vertx-starter - ../pom.xml - 1.0.0-SNAPSHOT - - - - 1.11 - 4.0.6 - 3.5.0 - - - - - io.vertx - vertx-core - ${vertx.version} - - - io.vertx - vertx-unit - - - org.slf4j - slf4j-simple - - - junit - junit - - - org.zeroturnaround - zt-zip - ${zt-zip.version} - - - com.github.jknack - handlebars - ${handlebars.version} - - - - - diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/GeneratorVerticle.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/GeneratorVerticle.java deleted file mode 100644 index c9f3bc88..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/GeneratorVerticle.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.generator; - -import com.github.jknack.handlebars.io.ClassPathTemplateLoader; -import com.github.jknack.handlebars.io.TemplateLoader; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.starter.generator.service.ArchiveService; -import io.vertx.starter.generator.service.ProjectGeneratorService; -import io.vertx.starter.generator.service.StarterService; -import io.vertx.starter.generator.service.TemplateService; - -public class GeneratorVerticle extends AbstractVerticle { - - public static final String TEMPLATE_DIR = "/templates"; - private final Logger log = LoggerFactory.getLogger(GeneratorVerticle.class); - - String tempDir() { - return config().getString("temp.dir", System.getProperty("java.io.tmpdir")); - } - - @Override - public void start(Future startFuture) throws Exception { - TemplateLoader loader = new ClassPathTemplateLoader(TEMPLATE_DIR); - StarterService starter = new StarterService(vertx, tempDir()); - ProjectGeneratorService generator = new ProjectGeneratorService(vertx, new TemplateService(vertx, loader)); - ArchiveService archive = new ArchiveService(vertx); - - vertx.eventBus().consumer("project.requested").handler(starter::starter); - vertx.eventBus().consumer("generate").handler(generator::generate); - vertx.eventBus().consumer("archive").handler(archive::archive); - vertx.eventBus().consumer("project.created").handler(starter::clean); - - log.info("\n----------------------------------------------------------\n\t" + - "{} is running!\n" + - "----------------------------------------------------------", - GeneratorVerticle.class.getSimpleName()); - startFuture.complete(); - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ArchiveService.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ArchiveService.java deleted file mode 100644 index f07173c9..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ArchiveService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.generator.service; - -import io.vertx.core.Vertx; -import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import org.zeroturnaround.zip.ZipUtil; - -import java.io.File; - -public class ArchiveService { - - private final Logger log = LoggerFactory.getLogger(ArchiveService.class); - - private Vertx vertx; - - public ArchiveService(Vertx vertx) { - this.vertx = vertx; - } - - public void archive(Message message) { - JsonObject metadata = message.body(); - String baseDir = metadata.getString("baseDir"); - String rootDir = metadata.getString("rootDir"); - String archive = rootDir + "/archive.zip"; - vertx.fileSystem().createFile(archive, ar -> { - if (ar.failed()) { - log.error("Impossible to create file {}: {}", archive, ar.cause().getMessage()); - message.fail(500, ar.cause().getMessage()); - } else { - ZipUtil.pack(new File(baseDir), new File(archive), true); - message.reply(archive); - } - }); - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/BasicProject.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/BasicProject.java deleted file mode 100644 index e778c2b0..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/BasicProject.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; - -public class BasicProject extends ProjectGenerator { - - public BasicProject(TemplateService templateService, JsonObject project) { - super(templateService, project); - } - - @Override - public void generate() { - render("gitignore", ".gitignore"); - copy("editorconfig", ".editorconfig"); - } - -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleBuildProject.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleBuildProject.java deleted file mode 100644 index 246df821..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleBuildProject.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; - -public class GradleBuildProject extends ProjectGenerator { - - public GradleBuildProject(TemplateService templateService, JsonObject project) { - super(templateService, project); - } - - @Override - public void generate() { - render("build.gradle", "build.gradle"); - render("settings.gradle", "settings.gradle"); - copy("gradlew", "gradlew"); - copy("gradlew.bat", "gradlew.bat"); - copy("gradle/wrapper/gradle-wrapper.jar", "gradle/wrapper/gradle-wrapper.jar"); - copy("gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties"); - } - -} - diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleJavaProject.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleJavaProject.java deleted file mode 100644 index ae832875..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/GradleJavaProject.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; - -public class GradleJavaProject extends BasicProject { - - public static final String SRC_MAIN_SOURCES_DIR = "src/main/java/"; - public static final String SRC_MAIN_RESOURCES_DIR = "src/main/resources/"; - public static final String SRC_TEST_SOURCES_DIR = "src/test/java/"; - public static final String SRC_TEST_RESOURCES_DIR = "src/test/resources/"; - - private GradleBuildProject gradleBuildProject; - - public GradleJavaProject(TemplateService templateService, JsonObject project) { - super(templateService, project); - gradleBuildProject = new GradleBuildProject(templateService, project); - } - - private String packageDir() { - return String.format("%s/%s/", SRC_MAIN_SOURCES_DIR, ProjectUtils.packageDir(groupId(), artifactId())); - } - - @Override - public void generate() { - super.generate(); - gradleBuildProject.generate(); - render(SRC_MAIN_SOURCES_DIR + "package/MainVerticle.java", packageDir() + "MainVerticle.java"); - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenBuildProject.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenBuildProject.java deleted file mode 100644 index 0b461ee9..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenBuildProject.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; - - -public class MavenBuildProject extends ProjectGenerator { - - public MavenBuildProject(TemplateService templateService, JsonObject project) { - super(templateService, project); - } - - @Override - public void generate() { - render("pom.xml", "pom.xml"); - copy("mvnw", "mvnw"); - copy("mvnw.bat", "mvnw.bat"); - copy("maven/wrapper/maven-wrapper.jar", "maven/wrapper/maven-wrapper.jar"); - copy("maven/wrapper/maven-wrapper.properties", "maven/wrapper/maven-wrapper.properties"); - } - -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenJavaProject.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenJavaProject.java deleted file mode 100644 index 2f2f83dc..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/MavenJavaProject.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; - -public class MavenJavaProject extends BasicProject { - - public static final String SRC_MAIN_SOURCES_DIR = "src/main/java/"; - public static final String SRC_MAIN_RESOURCES_DIR = "src/main/resources/"; - public static final String SRC_TEST_SOURCES_DIR = "src/test/java/"; - public static final String SRC_TEST_RESOURCES_DIR = "src/test/resources/"; - - private MavenBuildProject mavenBuildProject; - - public MavenJavaProject(TemplateService templateService, JsonObject project) { - super(templateService, project); - mavenBuildProject = new MavenBuildProject(templateService, project); - } - - private String packageDir() { - return String.format("%s/%s/", SRC_MAIN_SOURCES_DIR, ProjectUtils.packageDir(groupId(), artifactId())); - } - - @Override - public void generate() { - super.generate(); - mavenBuildProject.generate(); - render(SRC_MAIN_SOURCES_DIR + "package/MainVerticle.java", packageDir() + "MainVerticle.java"); - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGenerator.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGenerator.java deleted file mode 100644 index 14fb122f..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGenerator.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.AsyncResult; -import io.vertx.core.CompositeFuture; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -import static java.lang.String.format; - -public abstract class ProjectGenerator { - - private final Logger log = LoggerFactory.getLogger(ProjectGenerator.class); - - private final TemplateService templateService; - private final JsonObject project; - - private List futures = new ArrayList<>(); - - public ProjectGenerator(TemplateService templateService, JsonObject project) { - this.templateService = templateService; - this.project = project; - } - - protected String groupId() { - return project.getString("groupId"); - } - - protected String artifactId() { - return project.getString("artifactId"); - } - - protected String buildTool() { - return project.getString("build"); - } - - protected String language() { - return project.getString("language"); - } - - protected String baseDir() { - return project.getString("baseDir"); - } - - public void render(String template, String destination) { - futures.add(templateService.render(template, format("%s/%s", baseDir(), destination), project)); - } - - public void copy(String source, String destination) { - futures.add(templateService.copy(source, format("%s/%s", baseDir(), destination))); - } - - public abstract void generate(); - - public void run(Handler>> handler) { - generate(); - CompositeFuture.all(futures).setHandler(ar -> { - if (ar.succeeded()) { - handler.handle(Future.succeededFuture(ar.result().list())); - } else { - handler.handle(Future.failedFuture(ar.cause())); - } - }); - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGeneratorService.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGeneratorService.java deleted file mode 100644 index cedd9d23..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectGeneratorService.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.generator.service; - -import io.vertx.core.Vertx; -import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; - -public class ProjectGeneratorService { - - private final Logger log = LoggerFactory.getLogger(ProjectGeneratorService.class); - - private Vertx vertx; - private TemplateService templateService; - - public ProjectGeneratorService(Vertx vertx, TemplateService templateService) { - this.vertx = vertx; - this.templateService = templateService; - } - - public void generate(Message message) { - getGenerator(message.body()).run(onGenerationDone -> { - if (onGenerationDone.failed()) { - message.fail(500, onGenerationDone.cause().getMessage()); - } else { - message.reply(null); - } - }); - } - - private ProjectGenerator getGenerator(JsonObject project) { - String build = project.getString("build"); - String language = project.getString("language"); - ProjectGenerator projectGenerator = null; - if (build.equalsIgnoreCase("maven") && language.equalsIgnoreCase("java")) { - projectGenerator = new MavenJavaProject(templateService, project); - } - if (build.equalsIgnoreCase("gradle") && language.equalsIgnoreCase("java")) { - projectGenerator = new GradleJavaProject(templateService, project); - } - return projectGenerator; - } - -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectUtils.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectUtils.java deleted file mode 100644 index c9db4073..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/ProjectUtils.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.vertx.starter.generator.service; - -import static java.lang.String.format; - -public class ProjectUtils { - - public static String packageDir(String groupId, String artifactId) { - return format("%s/%s/", groupId.replaceAll("\\.", "/"), artifactId); - } - -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/StarterService.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/StarterService.java deleted file mode 100644 index aff3bb8f..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/StarterService.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.generator.service; - -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.UUID; - -public class StarterService { - - private final Logger log = LoggerFactory.getLogger(StarterService.class); - - private Vertx vertx; - private String tempDir; - - public StarterService(Vertx vertx, String tempDir) { - this.vertx = vertx; - this.tempDir = tempDir; - } - - JsonObject buildMetadata(JsonObject projectRequest) { - Path rootDir = Paths.get(tempDir, "vertx-starter", UUID.randomUUID().toString()); - Path baseDir = rootDir.resolve(projectRequest.getString("artifactId", "project")); - projectRequest.put("rootDir", rootDir.toString()); - projectRequest.put("baseDir", baseDir.toString()); - return projectRequest; - } - - public void starter(Message request) { - JsonObject metadata = buildMetadata(request.body()); - log.info("Forging project with request: {}", metadata); - createTempDir(metadata) - .compose(v -> generate(metadata)) - .compose(v -> archive(metadata)) - .setHandler(ar -> { - if (ar.failed()) { - log.error("Impossible to create project {}: {}", metadata, ar.cause().getMessage()); - request.fail(-1, "Impossible to createProject"); - } else { - String archivePath = ar.result(); - log.debug("Archive starterd: {}", archivePath); - metadata.put("archivePath", archivePath); - vertx.eventBus().publish("starter:created", metadata); - request.reply(metadata); - } - }); - } - - private Future generate(JsonObject metadata) { - Future future = Future.future(); - vertx.eventBus().send("generate", metadata, ar -> { - if (ar.failed()) { - log.error(ar.cause().getMessage()); - } else { - future.complete(); - } - }); - return future; - } - - private Future archive(JsonObject metadata) { - Future future = Future.future(); - vertx.eventBus().send("archive", metadata, ar -> { - if (ar.failed()) { - log.error(ar.cause().getMessage()); - } else { - future.complete(ar.result().body()); - } - }); - return future; - } - - private Future createTempDir(JsonObject metadata) { - Future future = Future.future(); - String dir = metadata.getString("baseDir"); - vertx.fileSystem().mkdirs(dir, ar -> { - if (ar.failed()) { - log.error("Impossible to create temp directory {}: {}", dir, ar.cause().getMessage()); - future.fail(ar.cause()); - } else { - future.complete(); - } - }); - return future; - } - - - public void clean(Message message) { - JsonObject metadata = message.body(); - String rootDir = metadata.getString("rootDir"); - vertx.fileSystem().deleteRecursive(rootDir, true, ar -> { - if (ar.failed()) { - log.error("Impossible to delete temp directory {}: {}", rootDir, ar.cause().getMessage()); - } else { - log.debug("Temp directory {} deleted", rootDir); - } - }); - - } -} diff --git a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/TemplateService.java b/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/TemplateService.java deleted file mode 100644 index 09d11574..00000000 --- a/vertx-starter-generator/src/main/java/io/vertx/starter/generator/service/TemplateService.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.generator.service; - -import com.github.jknack.handlebars.Context; -import com.github.jknack.handlebars.Handlebars; -import com.github.jknack.handlebars.context.MapValueResolver; -import com.github.jknack.handlebars.io.TemplateLoader; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.nio.file.*; -import java.util.HashMap; - -import static java.util.Objects.requireNonNull; - -public class TemplateService { - - private final Logger log = LoggerFactory.getLogger(TemplateService.class); - - private Vertx vertx; - private TemplateLoader loader; - private Handlebars handlebars; - - public TemplateService(Vertx vertx, TemplateLoader loader) { - this.vertx = vertx; - this.loader = loader; - this.handlebars = new Handlebars(loader); - } - - public Future render(String template, String destination, JsonObject object) { - Context context = Context.newBuilder(object.getMap()).resolver(MapValueResolver.INSTANCE).build(); - log.debug("Rendering template {} with object {}", object); - Future future = Future.future(); - try { - future.complete(writeFile(destination, handlebars.compile(template).apply(context))); - } catch (IOException e) { - log.error("Impossible to render template {}: ", template, e); - future.fail(e.getCause()); - } - return future; - } - - private Future writeFile(String filename, String content) { - requireNonNull(filename); - requireNonNull(content); - Future future = Future.future(); - String parent = Paths.get(filename).getParent().toAbsolutePath().toString(); - boolean exists = vertx.fileSystem().existsBlocking(parent); - if (!exists) { - vertx.fileSystem().mkdirsBlocking(parent); - } - vertx.fileSystem().writeFile(filename, Buffer.buffer(content), onFileWritten -> { - if (onFileWritten.failed()) { - log.error("Impossible to write file {} : {}", filename, onFileWritten.cause().getMessage()); - future.fail(onFileWritten.cause()); - } else { - log.debug("File {} written", filename); - future.complete(filename); - } - }); - return future; - } - - private Path getPathInJar(String filename) throws IOException { - URL url = getClass().getResource(filename); - String jarPath = url.toString().split("!")[0]; - try (FileSystem jarfs = FileSystems.newFileSystem(URI.create(jarPath), new HashMap<>());) { - log.debug("Getting file from jar: {}", filename); - return jarfs.getPath(filename); - } catch (IOException e) { - log.error(e.getMessage()); - throw e; - } - } - - private Future getPath(String filename) { - Future future = Future.future(); - URL url = getClass().getResource(filename); - if (url.getProtocol().startsWith("jar")) { - try { - Path path = getPathInJar(filename); - future.complete(path); - } catch (IOException e) { - e.printStackTrace(); - future.fail(e); - } - } else { - future.complete(Paths.get(filename)); - } - return future; - } - - public Future mkdirs(String path) { - Future future = Future.future(); - Path p = Paths.get(path); - if (!p.toFile().isDirectory()) { - p = p.getParent(); - } - String dir = p.toString(); - vertx.fileSystem().exists(dir, onExistenceTested -> { - if (onExistenceTested.succeeded()) { - if (!onExistenceTested.result()) { - vertx.fileSystem().mkdirs(dir, onDirectoryCreated -> { - if (onDirectoryCreated.succeeded()) { - future.complete(dir); - } else { - future.fail(onDirectoryCreated.cause()); - } - }); - } else { - log.debug("Directory {} already exists", dir); - future.complete(dir); - } - } else { - future.fail(onExistenceTested.cause()); - } - }); - return future; - } - - private Future copyFileFromJar(String jarPath, String filename, String destination) { - log.debug("Copying {} from jar {} to {}", filename, jarPath, destination); - Future future = Future.future(); - try (FileSystem jarfs = FileSystems.newFileSystem(URI.create(jarPath), new HashMap<>())) { - Files.copy(jarfs.getPath(filename), Paths.get(destination)); - future.complete(filename); - } catch (IOException e) { - log.error("Impossible to copy file {} from jar {} to {}: {}", filename, jarPath, destination, e.getMessage()); - future.fail(e); - } - return future; - } - - private Future copyRegularFile(String filename, String destination) { - log.debug("Copying {} to {}", Paths.get(filename), destination); - Future future = Future.future(); - try { - Files.copy(Paths.get(filename), Paths.get(destination)); - future.complete(filename); - } catch (IOException e) { - log.error("Impossible to copy file {} to {}: {}", filename, destination, e); - future.fail(e); - } - return future; - } - - private Future copyInternal(String source, String destination) { - URL url = getClass().getResource(source); - if (url != null && url.getProtocol().startsWith("jar")) { - String jarPath = url.toString().split("!")[0]; - return copyFileFromJar(jarPath, source, destination); - } - return copyRegularFile(source, destination); - } - - public Future copy(String source, String destination) { - requireNonNull(source); - requireNonNull(destination); - log.debug("Copying {} to {}", source, destination); - return mkdirs(destination) - .compose((noop) -> copyInternal(loader.getPrefix() + source, destination)); - } - -} diff --git a/vertx-starter-generator/src/main/resources/templates/build.gradle.hbs b/vertx-starter-generator/src/main/resources/templates/build.gradle.hbs deleted file mode 100644 index 9b2240c6..00000000 --- a/vertx-starter-generator/src/main/resources/templates/build.gradle.hbs +++ /dev/null @@ -1,41 +0,0 @@ -plugins { - id 'java' - id 'application' - id 'com.github.johnrengelman.shadow' version '2.0.1' -} - -ext { - vertxVersion = '{{version}}' -} - -repositories { - mavenLocal() - jcenter() - maven { url "https://plugins.gradle.org/m2/" } -} - -version = '1.0.0-SNAPSHOT' -sourceCompatibility = '1.8' - -dependencies { -{{#each dependencies as |dependency|}} - compile "io.vertx:{{dependency}}:$vertxVersion" -{{/each}} -} - -mainClassName = '{{groupId}}.{{artifactId}}.MainVerticle' - -shadowJar { - classifier = 'fat' - mergeServiceFiles { - include 'META-INF/services/io.vertx.core.spi.VerticleFactory' - } -} - -run { - args = ['run', mainClassName, "--launcher-class=io.vertx.core.Launcher"] -} - -task wrapper(type: Wrapper) { - gradleVersion = '4.0' -} diff --git a/vertx-starter-generator/src/main/resources/templates/editorconfig b/vertx-starter-generator/src/main/resources/templates/editorconfig deleted file mode 100644 index a03599dd..00000000 --- a/vertx-starter-generator/src/main/resources/templates/editorconfig +++ /dev/null @@ -1,24 +0,0 @@ -# EditorConfig helps developers define and maintain consistent -# coding styles between different editors and IDEs -# editorconfig.org - -root = true - -[*] - -# Change these settings to your own preference -indent_style = space -indent_size = 4 - -# We recommend you to keep these unchanged -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false - -[{package,bower}.json] -indent_style = space -indent_size = 2 diff --git a/vertx-starter-generator/src/main/resources/templates/gitignore.hbs b/vertx-starter-generator/src/main/resources/templates/gitignore.hbs deleted file mode 100644 index e8ceb166..00000000 --- a/vertx-starter-generator/src/main/resources/templates/gitignore.hbs +++ /dev/null @@ -1,194 +0,0 @@ - -# Based on by https://www.gitignore.io/api/macos,maven,gradle,eclipse,netbeans,intellij+iml,visualstudiocode - -### Vert.x ### -.vertx/ - -### Eclipse ### - -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Intellij+iml ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -### Intellij+iml Patch ### -# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 - -*.iml -modules.xml -.idea/misc.xml -*.ipr - -### macOS ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -{{#if maven}} -### Maven ### -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties - -# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) -!/.mvn/wrapper/maven-wrapper.jar -{{/if}} - -{{#if gradle}} -### Gradle ### -.gradle -/build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties -{{/if}} - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -# End of https://www.gitignore.io/api/macos,maven,eclipse,netbeans,intellij+iml,visualstudiocode diff --git a/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.jar b/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 736fb7d3..00000000 Binary files a/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.properties b/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 74bb7784..00000000 --- a/vertx-starter-generator/src/main/resources/templates/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip diff --git a/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.jar b/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.jar deleted file mode 100644 index 593b7af7..00000000 Binary files a/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.properties b/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.properties deleted file mode 100644 index c7d83b77..00000000 --- a/vertx-starter-generator/src/main/resources/templates/maven/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.2.3/apache-maven-3.2.3-bin.zip \ No newline at end of file diff --git a/vertx-starter-generator/src/main/resources/templates/mvnw b/vertx-starter-generator/src/main/resources/templates/mvnw deleted file mode 100755 index c03152e1..00000000 --- a/vertx-starter-generator/src/main/resources/templates/mvnw +++ /dev/null @@ -1,170 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# 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. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - if [ -z "$JAVA_VERSION" ] ; then - JAVA_VERSION="CurrentJDK" - fi - if [ -z "$JAVA_HOME" ] ; then - JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Migwn, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - javaExecutable="`readlink -f \"$javaExecutable\"`" - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." - echo " We cannot execute $JAVACMD" - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` -fi - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "./maven/wrapper/maven-wrapper.jar" \ - ${WRAPPER_LAUNCHER} "$@" diff --git a/vertx-starter-generator/src/main/resources/templates/mvnw.bat b/vertx-starter-generator/src/main/resources/templates/mvnw.bat deleted file mode 100644 index ab2822dd..00000000 --- a/vertx-starter-generator/src/main/resources/templates/mvnw.bat +++ /dev/null @@ -1,189 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -:skipRcPre - -set ERROR_CODE=0 - -@REM set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" @setlocal -if "%OS%"=="WINNT" @setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo ERROR: JAVA_HOME not found in your environment. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory. -echo JAVA_HOME = "%JAVA_HOME%" -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation -echo. -goto error - -:chkMHome -if not "%M2_HOME%"=="" goto valMHome - -if "%OS%"=="Windows_NT" SET "M2_HOME=%~dp0.." -if "%OS%"=="WINNT" SET "M2_HOME=%~dp0.." -if not "%M2_HOME%"=="" goto valMHome - -echo. -echo ERROR: M2_HOME not found in your environment. -echo Please set the M2_HOME variable in your environment to match the -echo location of the Maven installation -echo. -goto error - -:valMHome - -:stripMHome -if not "_%M2_HOME:~-1%"=="_\" goto checkMBat -set "M2_HOME=%M2_HOME:~0,-1%" -goto stripMHome - -:checkMBat -if exist "%M2_HOME%\bin\mvn.bat" goto init - -echo. -echo ERROR: M2_HOME is set to an invalid directory. -echo M2_HOME = "%M2_HOME%" -echo Please set the M2_HOME variable in your environment to match the -echo location of the Maven installation -echo. -goto error -@REM ==== END VALIDATION ==== - -:init -@REM Decide how to startup depending on the version of windows - -@REM -- Windows NT with Novell Login -if "%OS%"=="WINNT" goto WinNTNovell - -@REM -- Win98ME -if NOT "%OS%"=="Windows_NT" goto Win9xArg - -:WinNTNovell - -@REM -- 4NT shell -if "%@eval[2+2]" == "4" goto 4NTArgs - -@REM -- Regular WinNT shell -set MAVEN_CMD_LINE_ARGS=%* -goto endInit - -@REM The 4NT Shell from jp software -:4NTArgs -set MAVEN_CMD_LINE_ARGS=%$ -goto endInit - -:Win9xArg -@REM Slurp the command line arguments. This loop allows for an unlimited number -@REM of agruments (up to the command line limit, anyway). -set MAVEN_CMD_LINE_ARGS= -:Win9xApp -if %1a==a goto endInit -set MAVEN_CMD_LINE_ARGS=%MAVEN_CMD_LINE_ARGS% %1 -shift -goto Win9xApp - -@REM Reaching here means variables are defined and arguments have been captured -:endInit -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - -@REM -- Regular WinNT shell -set WRAPPER_JAR="".\maven\wrapper\maven-wrapper.jar"" -goto runm2 - -@REM Start MAVEN2 -:runm2 -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %WRAPPER_JAR% %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -if "%OS%"=="Windows_NT" @endlocal -if "%OS%"=="WINNT" @endlocal -set ERROR_CODE=1 - -:end -@REM set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" goto endNT -if "%OS%"=="WINNT" goto endNT - -@REM For old DOS remove the set variables from ENV - we assume they were not set -@REM before we started - at least we don't leave any baggage around -set MAVEN_JAVA_EXE= -set MAVEN_CMD_LINE_ARGS= -goto postExec - -:endNT -@endlocal & set ERROR_CODE=%ERROR_CODE% - -:postExec - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -:skipRcPost - -@REM pause the batch file if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% - - diff --git a/vertx-starter-generator/src/main/resources/templates/pom.xml.hbs b/vertx-starter-generator/src/main/resources/templates/pom.xml.hbs deleted file mode 100644 index 881078e3..00000000 --- a/vertx-starter-generator/src/main/resources/templates/pom.xml.hbs +++ /dev/null @@ -1,85 +0,0 @@ - - - 4.0.0 - - {{groupId}} - {{artifactId}} - 1.0.0-SNAPSHOT - - - 1.8 - {{version}} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - ${java.version} - ${java.version} - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - package - - shade - - - - - - io.vertx.core.Launcher - {{groupId}}.{{artifactId}}.MainVerticle - - - - META-INF/services/io.vertx.core.spi.VerticleFactory - META-INF/services/io.vertx.core.spi.launcher.CommandFactory - - - - - ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.5.0 - - io.vertx.core.Launcher - - run - {{groupId}}.{{artifactId}}.MainVerticle - - - - - - - - - {{#each dependencies as |dependency|}} - - io.vertx - {{dependency}} - ${vertx.version} - - {{/each}} - - - diff --git a/vertx-starter-generator/src/main/resources/templates/settings.gradle.hbs b/vertx-starter-generator/src/main/resources/templates/settings.gradle.hbs deleted file mode 100644 index cc08101c..00000000 --- a/vertx-starter-generator/src/main/resources/templates/settings.gradle.hbs +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = '{{artifactId}}' diff --git a/vertx-starter-generator/src/main/resources/templates/src/main/java/package/MainVerticle.java.hbs b/vertx-starter-generator/src/main/resources/templates/src/main/java/package/MainVerticle.java.hbs deleted file mode 100644 index 8f5d639a..00000000 --- a/vertx-starter-generator/src/main/resources/templates/src/main/java/package/MainVerticle.java.hbs +++ /dev/null @@ -1,16 +0,0 @@ -package {{groupId}}.{{artifactId}}; - -import io.vertx.core.AbstractVerticle; - -public class MainVerticle extends AbstractVerticle { - - @Override - public void start() throws Exception { - vertx.createHttpServer().requestHandler(req -> { - req.response() - .putHeader("content-type", "text/plain") - .end("Hello from Vert.x!"); - }).listen(8080); - System.out.println("HTTP server started on port 8080"); - } -} diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/BaseProjectTest.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/BaseProjectTest.java deleted file mode 100644 index 28073993..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/BaseProjectTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.vertx.starter.generator.service; - -import com.github.jknack.handlebars.io.FileTemplateLoader; -import io.vertx.core.Vertx; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import io.vertx.starter.generator.utils.TestProjectBuilder; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; - -@RunWith(VertxUnitRunner.class) -public abstract class BaseProjectTest { - - protected static final String DEFAULT_GROUP_ID = "com.example"; - protected static final String DEFAULT_ARTIFACT_ID = "demo"; - protected static final String DEFAULT_VERSION = "1.0.0"; - - protected static String TEST_ROOT_DIR = "target/test-vertx-starter/"; - protected static String TEST_BASE_DIR = "target/test-vertx-starter/" + DEFAULT_ARTIFACT_ID + "/"; - - protected TemplateService templateService; - - protected Vertx vertx; - - public static TestProjectBuilder basicTestProject() { - return new TestProjectBuilder(TEST_BASE_DIR) - .groupId(DEFAULT_GROUP_ID) - .artifactId(DEFAULT_ARTIFACT_ID) - .version(DEFAULT_VERSION); - } - - @Before - public void beforeEach(TestContext context) { - vertx = Vertx.vertx(); - templateService = new TemplateService(vertx, new FileTemplateLoader("src/main/resources/templates")); - } - - @After - public void afterEach(TestContext context) { - vertx.fileSystem().deleteRecursiveBlocking(TEST_ROOT_DIR, true); - vertx.close(context.asyncAssertSuccess()); - } - - public void assertFileExists(TestContext context, String prefix, String... others) { - assertFileExists(context, prefix + "/" + String.join("/", others)); - } - - public void assertFileExists(TestContext context, String filename) { - vertx.fileSystem().exists(TEST_BASE_DIR + filename, it -> { - if (it.succeeded()) { - context.assertTrue(it.result()); - } else { - context.fail(it.cause()); - } - }); - } -} diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleBuildProjectTest.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleBuildProjectTest.java deleted file mode 100644 index 8c2dc471..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleBuildProjectTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import org.junit.Test; - -public class GradleBuildProjectTest extends BaseProjectTest { - - private JsonObject GRADLE_PROJECT = basicTestProject().gradle().java().build(); - - @Test - public void shouldGenerateMavenBuildProjectFiles(TestContext context) { - final Async async = context.async(); - GradleBuildProject gradleBuildProject = new GradleBuildProject(templateService, GRADLE_PROJECT); - - gradleBuildProject.run(onTestDone -> { - assertFileExists(context, "build.gradle"); - assertFileExists(context, "settings.gradle"); - assertFileExists(context, "gradlew"); - assertFileExists(context, "gradlew.bat"); - assertFileExists(context, "gradle/wrapper/gradle-wrapper.jar"); - assertFileExists(context, "gradle/wrapper/gradle-wrapper.properties"); - async.complete(); - }); - } - -} diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleJavaProjectTest.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleJavaProjectTest.java deleted file mode 100644 index c88267ea..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/GradleJavaProjectTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import org.junit.Test; - -import static io.vertx.starter.generator.service.MavenJavaProject.SRC_MAIN_SOURCES_DIR; -import static io.vertx.starter.generator.service.ProjectUtils.packageDir; - -public class GradleJavaProjectTest extends BaseProjectTest { - - private JsonObject GRADLE_PROJECT = basicTestProject().gradle().java().build(); - - private String javaDir() { - return SRC_MAIN_SOURCES_DIR + packageDir(DEFAULT_GROUP_ID, DEFAULT_ARTIFACT_ID); - } - - @Test - public void shouldGenerateGradleJavaProjectFiles(TestContext context) { - final Async async = context.async(); - GradleJavaProject gradleJavaProject = new GradleJavaProject(templateService, GRADLE_PROJECT); - - gradleJavaProject.run(onTestDone -> { - assertFileExists(context, javaDir(), "MainVerticle.java"); - async.complete(); - }); - } - -} - diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenBuildProjectTest.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenBuildProjectTest.java deleted file mode 100644 index 5d02b8d9..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenBuildProjectTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(VertxUnitRunner.class) -public class MavenBuildProjectTest extends BaseProjectTest { - - private JsonObject MAVEN_PROJECT = basicTestProject().maven().java().build(); - - @Test - public void shouldGenerateMavenBuildProjectFiles(TestContext context) { - final Async async = context.async(); - MavenBuildProject mavenBuildProject = new MavenBuildProject(templateService, MAVEN_PROJECT); - - mavenBuildProject.run(onTestDone -> { - assertFileExists(context, "pom.xml"); - assertFileExists(context, "mvnw"); - assertFileExists(context, "mvnw.bat"); - assertFileExists(context, "maven/wrapper/maven-wrapper.jar"); - assertFileExists(context, "maven/wrapper/maven-wrapper.properties"); - async.complete(); - }); - } - -} diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenJavaProjectTest.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenJavaProjectTest.java deleted file mode 100644 index a90982d8..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/service/MavenJavaProjectTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.vertx.starter.generator.service; - -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static io.vertx.starter.generator.service.MavenJavaProject.SRC_MAIN_SOURCES_DIR; -import static io.vertx.starter.generator.service.ProjectUtils.packageDir; - -@RunWith(VertxUnitRunner.class) -public class MavenJavaProjectTest extends BaseProjectTest { - - private JsonObject MAVEN_PROJECT = basicTestProject().maven().java().build(); - - private String javaDir() { - return SRC_MAIN_SOURCES_DIR + packageDir(DEFAULT_GROUP_ID, DEFAULT_ARTIFACT_ID); - } - - @Test - public void shouldGenerateMavenJavaProjectFiles(TestContext context) { - final Async async = context.async(); - MavenJavaProject mavenJavaProject = new MavenJavaProject(templateService, MAVEN_PROJECT); - - mavenJavaProject.run(onTestDone -> { - assertFileExists(context, javaDir(), "MainVerticle.java"); - async.complete(); - }); - } - -} diff --git a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/utils/TestProjectBuilder.java b/vertx-starter-generator/src/test/java/io/vertx/starter/generator/utils/TestProjectBuilder.java deleted file mode 100644 index 410c99c8..00000000 --- a/vertx-starter-generator/src/test/java/io/vertx/starter/generator/utils/TestProjectBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.vertx.starter.generator.utils; - -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; - -import static java.util.Arrays.asList; - -public class TestProjectBuilder { - - private final String baseDir; - private String language; - private String buildTool; - private String version; - private String groupId; - private String artifactId; - private Set dependencies = new HashSet<>(); - - public TestProjectBuilder(String baseDir) { - this.baseDir = baseDir; - } - - public TestProjectBuilder language(String language) { - this.language = language; - return this; - } - - public TestProjectBuilder java() { - return language("java"); - } - - public TestProjectBuilder buildTool(String buildTool) { - this.buildTool = buildTool; - return this; - } - - public TestProjectBuilder maven() { - return buildTool("maven"); - } - - public TestProjectBuilder gradle() { - return buildTool("gradle"); - } - - public TestProjectBuilder version(String version) { - this.version = version; - return this; - } - - public TestProjectBuilder groupId(String groupId) { - this.groupId = groupId; - return this; - } - - public TestProjectBuilder artifactId(String artifactId) { - this.artifactId = artifactId; - return this; - } - - public TestProjectBuilder dependency(String dependency) { - this.dependencies.add(dependency); - return this; - } - - public TestProjectBuilder dependencies(String... dependencies) { - this.dependencies.addAll(asList(dependencies)); - return this; - } - - public JsonObject build() { - return new JsonObject() - .put("baseDir", baseDir) - .put("language", language) - .put("buildTool", buildTool) - .put("version", version) - .put("groupId", groupId) - .put("artifactId", artifactId) - .put("dependencies", new JsonArray(new ArrayList(dependencies))); - } -} diff --git a/vertx-starter-main/conf/default-conf.json b/vertx-starter-main/conf/default-conf.json deleted file mode 100644 index 866bb11f..00000000 --- a/vertx-starter-main/conf/default-conf.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "web": { - "http.port": 7070, - "project.request": { - "version": "3.5.0", - "format": "zip", - "language": "java", - "build": "maven", - "groupId": "io.vertx", - "artifactId": "sample", - "dependencies": [ - "vertx-core", - "vertx-unit" - ] - }, - "dependencies.path": "./dependencies.json" - }, - "generator": { - "temp.dir": "." - }, - "analytics": { - "host": "localhost", - "port": 27017, - "db_name": "vertx-starter-analytics" - } -} diff --git a/vertx-starter-main/pom.xml b/vertx-starter-main/pom.xml deleted file mode 100644 index ce613c91..00000000 --- a/vertx-starter-main/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - io.vertx - vertx-starter - ../pom.xml - 1.0.0-SNAPSHOT - - - 4.0.0 - - vertx-starter-main - - - 2.3 - 3.5.0 - - - - - io.vertx - vertx-core - ${vertx.version} - - - org.slf4j - slf4j-simple - - - io.vertx - vertx-starter-web - ${project.version} - - - io.vertx - vertx-starter-generator - ${project.version} - - - io.vertx - vertx-starter-analytics - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - package - - shade - - - - - - io.vertx.core.Launcher - io.vertx.starter.MainVerticle - - - - - ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar - - - - - - - - - diff --git a/vertx-starter-main/src/main/java/io/vertx/starter/MainVerticle.java b/vertx-starter-main/src/main/java/io/vertx/starter/MainVerticle.java deleted file mode 100644 index fd61f876..00000000 --- a/vertx-starter-main/src/main/java/io/vertx/starter/MainVerticle.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter; - -import io.vertx.core.AbstractVerticle; -import io.vertx.core.CompositeFuture; -import io.vertx.core.DeploymentOptions; -import io.vertx.core.Future; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.starter.analytics.AnalyticsVerticle; -import io.vertx.starter.generator.GeneratorVerticle; -import io.vertx.starter.web.WebVerticle; - -import static io.vertx.core.Future.future; -import static java.util.Arrays.asList; - -public class MainVerticle extends AbstractVerticle { - - private final Logger log = LoggerFactory.getLogger(MainVerticle.class); - - @Override - public void start(Future startFuture) throws Exception { - Future generatorFuture = future(); - vertx.deployVerticle( - GeneratorVerticle.class.getName(), - new DeploymentOptions().setConfig(config().getJsonObject("generator")), - generatorFuture - ); - Future analyticsFuture = future(); - vertx.deployVerticle( - AnalyticsVerticle.class.getName(), - new DeploymentOptions().setConfig(config().getJsonObject("analytics")), - analyticsFuture - ); - Future webFuture = future(); - vertx.deployVerticle( - WebVerticle.class.getName(), - new DeploymentOptions().setConfig(config().getJsonObject("web")), - webFuture - ); - - CompositeFuture.all(asList(generatorFuture, analyticsFuture, webFuture)).setHandler(ar -> { - if (ar.failed()) { - log.error("Vertx starter failed to start: {}", ar.cause().getMessage()); - ar.cause().printStackTrace(); - } else { - log.info("\n----------------------------------------------------------\n\t" + - "{} is running!\n" + - "----------------------------------------------------------", - MainVerticle.class.getSimpleName()); - startFuture.complete(); - } - }); - } -} diff --git a/vertx-starter-web/pom.xml b/vertx-starter-web/pom.xml deleted file mode 100644 index c92937e7..00000000 --- a/vertx-starter-web/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - vertx-starter-web - - - io.vertx - vertx-starter - ../pom.xml - 1.0.0-SNAPSHOT - - - - - 1.11 - 4.0.6 - 3.5.0 - 4.12 - - - - - org.slf4j - slf4j-simple - - - io.vertx - vertx-core - ${vertx.version} - - - io.vertx - vertx-web - ${vertx.version} - - - io.vertx - vertx-unit - ${vertx.version} - test - - - junit - junit - ${junit.version} - test - - - io.vertx - vertx-web-client - ${vertx.version} - test - - - - - diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/WebVerticle.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/WebVerticle.java deleted file mode 100644 index 32d71545..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/WebVerticle.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web; - -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.http.HttpMethod; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.CorsHandler; -import io.vertx.ext.web.handler.StaticHandler; -import io.vertx.starter.web.rest.DependencyResource; -import io.vertx.starter.web.rest.ProjectResource; -import io.vertx.starter.web.rest.VersionResource; -import io.vertx.starter.web.service.DependencyService; -import io.vertx.starter.web.service.ProjectService; -import io.vertx.starter.web.service.VersionService; - -public class WebVerticle extends AbstractVerticle { - - public static final int DEFAULT_HTTP_PORT = 8080; - private final Logger log = LoggerFactory.getLogger(WebVerticle.class); - - private VersionResource versionResource; - private DependencyResource dependencyResource; - private ProjectResource projectResource; - - @Override - public void start(Future startFuture) throws Exception { - versionResource = new VersionResource(new VersionService()); - dependencyResource = new DependencyResource(new DependencyService(config().getString("dependencies.path"))); - projectResource = new ProjectResource(config().getJsonObject("project.request"), new ProjectService(vertx.eventBus())); - - Router router = Router.router(vertx); - cors(router); - router - .mountSubRouter("/api", starterRouter()) - .mountSubRouter("/api", versionsRouter()) - .mountSubRouter("/api", dependenciesRouter()) - .mountSubRouter("/api", versionsRouter()); - router.route().handler(StaticHandler.create()); - - int port = config().getInteger("http.port", DEFAULT_HTTP_PORT); - vertx - .createHttpServer() - .requestHandler(router::accept) - .listen(port, ar -> { - if (ar.failed()) { - log.error("Fail to start {}: {}", WebVerticle.class.getSimpleName(), ar.cause().getMessage()); - startFuture.fail(ar.cause()); - } else { - log.info("\n----------------------------------------------------------\n\t" + - "{} is running! Access URLs:\n\t" + - "Local: \t\thttp://localhost:{}\n" + - "----------------------------------------------------------", - WebVerticle.class.getSimpleName(), port); - startFuture.complete(); - } - }); - } - - private void cors(Router router) { - router.route().handler(CorsHandler.create("*") - .allowedMethod(HttpMethod.GET) - .allowedMethod(HttpMethod.POST) - .allowedHeader("Content-Type") - .allowedHeader("Accept") - ); - } - - private Router dependenciesRouter() { - Router router = Router.router(vertx); - router.get("/dependencies").handler(dependencyResource::findAll); - return router; - } - - private Router versionsRouter() { - Router router = Router.router(vertx); - router.get("/versions").handler(versionResource::findAll); - return router; - } - - private Router starterRouter() { - Router router = Router.router(vertx); - router.get("/starter*").handler(projectResource::create); - return router; - } - -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/DependencyResource.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/DependencyResource.java deleted file mode 100644 index 5252b804..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/DependencyResource.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web.rest; - -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.web.RoutingContext; -import io.vertx.starter.web.service.DependencyService; - -import static io.vertx.starter.web.util.RestUtil.error; -import static io.vertx.starter.web.util.RestUtil.respondJson; - -public class DependencyResource { - - private static final Logger log = LoggerFactory.getLogger(DependencyResource.class); - - private final DependencyService dependencyService; - - public DependencyResource(DependencyService dependencyService) { - this.dependencyService = dependencyService; - } - - public void findAll(RoutingContext rc) { - log.debug("REST request to get all Versions"); - dependencyService.findAll(reply -> { - if (reply.succeeded()) { - respondJson(rc, reply.result()); - } else { - error(rc, reply.cause()); - } - }); - } -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/ProjectResource.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/ProjectResource.java deleted file mode 100644 index 2b3a485f..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/ProjectResource.java +++ /dev/null @@ -1,112 +0,0 @@ -package io.vertx.starter.web.rest; - -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.web.RoutingContext; -import io.vertx.starter.web.service.ProjectService; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static io.vertx.starter.web.util.RestUtil.error; -import static java.net.HttpURLConnection.HTTP_OK; -import static java.util.Arrays.asList; - -public class ProjectResource { - - private static final Logger log = LoggerFactory.getLogger(ProjectResource.class); - - private static final List DEFAULT_DEPENDENCIES = asList("vertx-core", "vertx-unit"); - - private static final JsonObject DEFAULT_PROJECT_REQUEST = new JsonObject() - .put("format", "zip") - .put("language", "java") - .put("build", "maven") - .put("groupId", "io.vertx") - .put("artifactId", "sample") - .put("dependencies", new JsonArray(DEFAULT_DEPENDENCIES)); - - private final ProjectService projectService; - private final JsonObject defaults; - - public ProjectResource(JsonObject defaults, ProjectService projectService) { - this.defaults = DEFAULT_PROJECT_REQUEST.mergeIn(defaults); - this.projectService = projectService; - } - - public void create(RoutingContext rc) { - JsonObject projectRequest = buildProjectRequest(rc.request()); - projectService.create(projectRequest, reply -> { - if (reply.succeeded()) { - String archivePath = reply.result(); - File archive = new File(archivePath); - String archiveName = projectRequest.getString("artifactId"); - rc.response() - .setStatusCode(HTTP_OK) - .putHeader("Content-Type", "application/zip") - .putHeader("Content-Disposition", "attachment; filename=" + archiveName + ".zip") - .sendFile(archive.getAbsolutePath(), onFileSent -> { - if (onFileSent.failed()) { - log.error("Error: {}", onFileSent.cause().getMessage()); - } - }); - } else { - log.error("Failed to create project: {}" + reply.cause().getMessage()); - error(rc, reply.cause()); - } - }); - } - - private JsonObject buildProjectRequest(HttpServerRequest request) { - JsonObject userRequest = new JsonObject(); - String format = getArchiveFormat(request.path()); - if (format != null) { - userRequest.put("format", format); - } - MultiMap params = request.params(); - if (isNotBlank(params.get("version"))) { - userRequest.put("version", params.get("version")); - } - if (isNotBlank(params.get("language"))) { - userRequest.put("language", params.get("language").toLowerCase()); - } - if (isNotBlank(params.get("build"))) { - userRequest.put("build", params.get("build").toLowerCase()); - } - if (isNotBlank(params.get("groupId"))) { - userRequest.put("groupId", params.get("groupId")); - } - if (isNotBlank(params.get("artifactId"))) { - userRequest.put("artifactId", params.get("artifactId")); - } - if (isNotBlank(params.get("dependencies"))) { - Set dependencies = new HashSet<>(DEFAULT_DEPENDENCIES); - for (String dependency : params.get("dependencies").split(",")) { - dependencies.add(dependency.toLowerCase()); - } - userRequest.put("dependencies", new JsonArray(new ArrayList(dependencies))); - } - return this.defaults.copy().mergeIn(userRequest); - } - - private String getArchiveFormat(String path) { - if (path.matches(".*\\.zip$")) { - return "zip"; - } - if (path.matches(".*(\\.tar\\.gz|\\.tgz)$")) { - return "tgz"; - } - return null; - } - - private boolean isNotBlank(String value) { - return value != null && value.length() > 0; - } -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/Resource.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/Resource.java deleted file mode 100644 index cb2e54b2..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/Resource.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web.rest; - -import io.vertx.ext.web.Router; - -public interface Resource { - - Router registerRoutes(Router router); -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/VersionResource.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/VersionResource.java deleted file mode 100644 index 9f0652ea..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/rest/VersionResource.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web.rest; - -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.web.RoutingContext; -import io.vertx.starter.web.service.VersionService; - -import static io.vertx.starter.web.util.RestUtil.error; -import static io.vertx.starter.web.util.RestUtil.respondJson; - -public class VersionResource { - - private final Logger log = LoggerFactory.getLogger(VersionResource.class); - - private final VersionService versionService; - - public VersionResource(VersionService versionService) { - this.versionService = versionService; - } - - public void findAll(RoutingContext rc) { - log.debug("REST request to get all Versions"); - versionService.findAll(reply -> { - if (reply.succeeded()) { - respondJson(rc, reply.result()); - } else { - error(rc, reply.cause()); - } - }); - } -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/DependencyService.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/service/DependencyService.java deleted file mode 100644 index 7eb2beed..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/DependencyService.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web.service; - -import io.vertx.core.AsyncResult; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; - -import static java.util.Objects.requireNonNull; - -public class DependencyService { - - private static final Logger log = LoggerFactory.getLogger(DependencyService.class); - - private JsonArray dependencies; - - public DependencyService(String dependenciesPath) { - requireNonNull(dependenciesPath); - try { - String raw = new String( - Files.readAllBytes(new File(dependenciesPath).toPath()) - ); - dependencies = new JsonObject(raw).getJsonArray("content"); - } catch (IOException e) { - log.error("Impossible to load dependencies at path {}: {}", dependenciesPath, e.getMessage()); - } - } - - public void findAll(Handler> reply) { - if (dependencies != null) { - reply.handle(Future.succeededFuture(dependencies)); - } else { - reply.handle(Future.failedFuture("Impossible to retrieve dependencies")); - } - } - -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/ProjectService.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/service/ProjectService.java deleted file mode 100644 index f8c88387..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/ProjectService.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.vertx.starter.web.service; - -import io.vertx.core.AsyncResult; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.eventbus.EventBus; -import io.vertx.core.json.JsonObject; - -public class ProjectService { - - private final EventBus eventBus; - - public ProjectService(EventBus eventBus) { - this.eventBus = eventBus; - } - - public void create(JsonObject request, Handler> reply) { - eventBus.send("project.requested", request, ar -> { - if (ar.succeeded()) { - JsonObject project = (JsonObject) ar.result().body(); - eventBus.publish("project.created", project); - reply.handle(Future.succeededFuture(project.getString("archivePath"))); - } else { - reply.handle(Future.failedFuture(ar.cause())); - } - - }); - } - -} diff --git a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/VersionService.java b/vertx-starter-web/src/main/java/io/vertx/starter/web/service/VersionService.java deleted file mode 100644 index c21849ff..00000000 --- a/vertx-starter-web/src/main/java/io/vertx/starter/web/service/VersionService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.vertx.starter.web.service; - -import io.vertx.core.AsyncResult; -import io.vertx.core.Future; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonArray; - -public class VersionService { - - public static final JsonArray VERSIONS = new JsonArray() - .add("3.5.0") - .add("3.4.2") - .add("3.4.1") - .add("3.4.0"); - - public void findAll(Handler> reply) { - reply.handle(Future.succeededFuture(VERSIONS)); - } -} diff --git a/vertx-starter-web/src/main/resources/webroot/main.js b/vertx-starter-web/src/main/resources/webroot/main.js deleted file mode 100644 index 4b25e413..00000000 --- a/vertx-starter-web/src/main/resources/webroot/main.js +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2017 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -angular - .module('app', ['ngResource', 'ui.bootstrap', 'cfp.hotkeys']) - .value('bowser', bowser) - .config(['hotkeysProvider', function (hotkeysProvider) { - hotkeysProvider.includeCheatSheet = false; - }]) - .factory('Version', ['$resource', function ($resource) { - var service = $resource('/api/versions/:version', {}, { - 'query': {method: 'GET', isArray: true}, - 'get': { - method: 'GET', - transformResponse: function (data) { - data = angular.fromJson(data); - return data; - } - } - }); - - return service; - }]) - .factory('Dependency', ['$resource', function ($resource) { - var service = $resource('/api/dependencies/:dependency', {}, { - 'query': {method: 'GET', isArray: true}, - 'get': { - method: 'GET', - transformResponse: function (data) { - data = angular.fromJson(data); - return data; - } - } - }); - - return service; - }]) - .factory('Starter', ['$resource', function ($resource) { - var service = $resource('/api/starter.zip', {}, { - 'starter': { - method: 'GET', - responseType: 'arraybuffer', - cache: false, - transformResponse: function (data, headers) { - //https://github.com/eligrey/FileSaver.js/issues/156#issuecomment-250858896 - var response = {}; - response.data = data; - return response; - } - } - }); - - return service; - }]) - .controller('VertxStarterController', ['$document', '$window', 'hotkeys', 'Version', 'Dependency', 'Starter', - function VertxStarterController($document, $window, hotkeys, Version, Dependency, Starter) { - var vm = this; - - vm.versions = []; - vm.dependencies = []; -// Not used right now -// vm.languages = ['Java','Javascript','Groovy','Ruby','Ceylon','Kotlin','Scala']; -// vm.buildTools = ['Maven','Gradle']; - vm.languages = ['Java']; - vm.buildTools = ['Maven', 'Gradle']; - - vm.project = { - version: null, - language: 'Java', - build: 'Maven', - groupId: 'com.example', - artifactId: 'demo', - dependencies: [] - }; - vm.selectedDependency = null; - vm.onDependencySelected = onDependencySelected; - vm.removeDependency = removeDependency; - vm.generate = generate; - - loadAll(); - - hotkeys.add({ - combo: ['command+enter', 'alt+enter'], - callback: function (event, hotkey) { - event.preventDefault(); - generate(); - } - }); - vm.hotkey = (bowser.mac) ? '\u2318 + \u23CE' : 'alt + \u23CE'; - - try { - vm.isFileSaverSupported = !!new Blob; - } catch (e) { - } - - function loadAll() { - getVersions(); - getDependencies(); - } - - function getVersions() { - Version.query({}, function (versions) { - vm.versions = versions; - vm.project.version = vm.versions[0]; - }, function (error) { - console.error('Impossible to load versions. ' + JSON.stringify(error)); - }); - } - - - function getDependencies() { - Dependency.query({}, function (dependencies) { - vm.dependencies = dependencies - .map(function (category) { - return category.items; - }).reduce(function (a, b) { - return a.concat(b); - }); - }, function (error) { - console.error('Impossible to load dependencies. ' + JSON.stringify(error)); - }); - } - - function onDependencySelected($item, $model, $label, $event) { - addDependency($model); - vm.selectedDependency = null; - } - - function indexOfDependency(predicate) { - for (var i = 0; i < vm.project.dependencies.length; i++) { - if (predicate(vm.project.dependencies[i])) { - return i; - } - } - return -1; - } - - function addDependency(dependency) { - var index = indexOfDependency(function (it) { - return it.name === dependency.name; - }); - if (index == -1) { - vm.project.dependencies.push(dependency); - } - } - - function removeDependency(dependency) { - vm.project.dependencies = vm.project.dependencies.filter(function (it) { - return it.name !== dependency.name; - }); - } - - function save(data) { - if (vm.isFileSaverSupported) { - var archive = new Blob([data], {type: 'application/octet-stream'}); - saveAs(archive, vm.project.artifactId + '.zip'); - } - } - - - function projectRequest() { - var project = {}; - angular.copy(vm.project, project); - var artifacts = vm.project.dependencies.map(function (dependency) { - return dependency.artifactId; - }); - project.dependencies = artifacts.join(); - return project; - } - - function generate() { - Starter - .starter(projectRequest(), function (response) { - save(response.data); - }, function (error) { - console.error('Impossible to create project. ' + JSON.stringify(error)); - }); - }; - - }]); diff --git a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/AbstractResourceIntTest.java b/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/AbstractResourceIntTest.java deleted file mode 100644 index 16fda105..00000000 --- a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/AbstractResourceIntTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.vertx.starter.web.rest; - -import io.vertx.core.DeploymentOptions; -import io.vertx.core.Vertx; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.web.client.WebClient; -import io.vertx.ext.web.client.WebClientOptions; -import io.vertx.starter.web.WebVerticle; -import org.junit.After; -import org.junit.Before; - -public class AbstractResourceIntTest { - - protected Vertx vertx; - protected WebClient webClient; - - @Before - public void beforeEach(TestContext context) { - vertx = Vertx.vertx(); - int httpPort = 8000; - JsonObject config = new JsonObject() - .put("dependencies.path", "src/test/resources/dependencies.json") - .put("project.request", new JsonObject()) - .put("http.port", httpPort); - vertx.deployVerticle(new WebVerticle(), new DeploymentOptions().setConfig(config), context.asyncAssertSuccess()); - webClient = WebClient.create(vertx, new WebClientOptions().setDefaultPort(httpPort)); - } - - @After - public void afterEach(TestContext context) { - vertx.close(context.asyncAssertSuccess()); - } -} diff --git a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/DependencyResourceIntTest.java b/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/DependencyResourceIntTest.java deleted file mode 100644 index 18fea722..00000000 --- a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/DependencyResourceIntTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.vertx.starter.web.rest; - -import io.vertx.core.json.JsonArray; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import io.vertx.ext.web.codec.BodyCodec; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(VertxUnitRunner.class) -public class DependencyResourceIntTest extends AbstractResourceIntTest { - - @Test - public void shouldFindAll(TestContext context) { - Async async = context.async(); - webClient.get("/api/dependencies").as(BodyCodec.jsonArray()).send(response -> { - if (response.succeeded()) { - assertThat(response.result().statusCode(), is(200)); - JsonArray payload = response.result().body(); - assertThat(payload.size(), is(2)); - async.complete(); - } else { - context.fail(response.cause()); - async.complete(); - } - }); - } -} diff --git a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/ProjectResourceIntTest.java b/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/ProjectResourceIntTest.java deleted file mode 100644 index 4917bd80..00000000 --- a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/ProjectResourceIntTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.vertx.starter.web.rest; - -import io.vertx.core.json.JsonObject; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(VertxUnitRunner.class) -public class ProjectResourceIntTest extends AbstractResourceIntTest { - - @Test - public void shouldUseDefaultValuesWhenAParameterIsNotSet(TestContext context) { - Async async = context.async(); - vertx.eventBus().consumer("project.requested").handler(message -> { - message.reply(new JsonObject().put("archivePath", "src/test/resources/starter.zip")); - }); - - webClient.get("/api/starter.zip").sendJson(new JsonObject(), response -> { - if (response.succeeded()) { - assertThat(response.result().statusCode(), is(200)); - async.complete(); - } else { - context.fail(response.cause()); - async.complete(); - } - }); - } -} diff --git a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/VersionResourceIntTest.java b/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/VersionResourceIntTest.java deleted file mode 100644 index c51d34c8..00000000 --- a/vertx-starter-web/src/test/java/io/vertx/starter/web/rest/VersionResourceIntTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.vertx.starter.web.rest; - -import io.vertx.core.json.JsonArray; -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import io.vertx.ext.web.codec.BodyCodec; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(VertxUnitRunner.class) -public class VersionResourceIntTest extends AbstractResourceIntTest { - - @Test - public void shouldFindAll(TestContext context) { - Async async = context.async(); - webClient.get("/api/versions").as(BodyCodec.jsonArray()).send(response -> { - if (response.succeeded()) { - assertThat(response.result().statusCode(), is(200)); - JsonArray payload = response.result().body(); - assertThat(payload.size(), is(4)); - async.complete(); - } else { - context.fail(response.cause()); - async.complete(); - } - }); - } -} diff --git a/vertx-starter-web/src/test/resources/dependencies.json b/vertx-starter-web/src/test/resources/dependencies.json deleted file mode 100644 index 4f718aba..00000000 --- a/vertx-starter-web/src/test/resources/dependencies.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "content": [ - { - "category": "Category1", - "description": "Description1", - "items": [ - { - "artifactId": "artifact11", - "name": "Artifact11" - }, - { - "artifactId": "artifact12", - "name": "Artifact12" - } - ] - }, - { - "category": "Category2", - "description": "Description2", - "items": [ - { - "artifactId": "artifact21", - "name": "artifact21" - } - ] - } - ] -}