├── .travis ├── secring.gpg.enc └── deploy.sh ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── common.gradle └── publish.gradle ├── vertx-guice ├── src │ ├── test │ │ ├── java │ │ │ └── com │ │ │ │ └── intapp │ │ │ │ └── vertx │ │ │ │ └── guice │ │ │ │ ├── stubs │ │ │ │ ├── Dependency.java │ │ │ │ ├── DependencyImpl.java │ │ │ │ ├── DependencyAsSingletonModule.java │ │ │ │ ├── DependencyModule.java │ │ │ │ ├── Verticle2WithDependency.java │ │ │ │ ├── VerticleWithDependency.java │ │ │ │ └── VerticleWithVertxDependency.java │ │ │ │ ├── GuiceVertxLauncherTest.java │ │ │ │ ├── GuiceVertxDeploymentManagerTest.java │ │ │ │ └── GuiceVerticleFactoryTest.java │ │ └── resources │ │ │ └── UncompiledVerticleWithDependency.java │ └── main │ │ └── java │ │ └── com │ │ └── intapp │ │ └── vertx │ │ └── guice │ │ ├── VertxModule.java │ │ ├── GuiceVerticleFactory.java │ │ ├── GuiceVertxLauncher.java │ │ └── GuiceVertxDeploymentManager.java └── build.gradle ├── vertx-guice-examples ├── manual │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── intapp │ │ │ └── vertx │ │ │ └── guice │ │ │ └── examples │ │ │ └── manual │ │ │ ├── business │ │ │ ├── Dependency.java │ │ │ ├── DependencyImpl.java │ │ │ └── BusinessModule.java │ │ │ ├── MainVerticle.java │ │ │ └── ServiceLauncher.java │ └── build.gradle ├── launcher │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── intapp │ │ │ └── vertx │ │ │ └── guice │ │ │ └── examples │ │ │ └── launcher │ │ │ ├── business │ │ │ ├── Dependency.java │ │ │ ├── DependencyImpl.java │ │ │ └── BusinessModule.java │ │ │ ├── ServiceLauncher.java │ │ │ └── MainVerticle.java │ └── build.gradle └── service-proxy │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── intapp │ │ └── vertx │ │ └── guice │ │ └── examples │ │ └── serviceproxy │ │ ├── business │ │ ├── package-info.java │ │ ├── BusinessService.java │ │ ├── BusinessModule.java │ │ ├── BusinessServiceImpl.java │ │ └── BusinessServiceProvider.java │ │ ├── ServiceLauncher.java │ │ └── MainVerticle.java │ └── build.gradle ├── settings.gradle ├── .travis.yml ├── LICENSE ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /.travis/secring.gpg.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intappx/vertx-guice/HEAD/.travis/secring.gpg.enc -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intappx/vertx-guice/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/Dependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | /** 4 | * Interface to represent dependency. 5 | */ 6 | public interface Dependency { 7 | } 8 | -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/DependencyImpl.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | /** 4 | * Default dependency implementation. 5 | */ 6 | public class DependencyImpl implements Dependency { 7 | } 8 | -------------------------------------------------------------------------------- /vertx-guice-examples/manual/src/main/java/com/intapp/vertx/guice/examples/manual/business/Dependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.manual.business; 2 | 3 | public interface Dependency { 4 | String getGreetingMessage(); 5 | } 6 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/src/main/java/com/intapp/vertx/guice/examples/launcher/business/Dependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.launcher.business; 2 | 3 | public interface Dependency { 4 | String getGreetingMessage(); 5 | } 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 23 15:29:02 MSK 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip 7 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/business/package-info.java: -------------------------------------------------------------------------------- 1 | @ModuleGen(name = "BusinessService", groupPackage="com.intapp.vertx.guice.examples.serviceproxy.business") 2 | package com.intapp.vertx.guice.examples.serviceproxy.business; 3 | 4 | import io.vertx.codegen.annotations.ModuleGen; -------------------------------------------------------------------------------- /vertx-guice-examples/manual/src/main/java/com/intapp/vertx/guice/examples/manual/business/DependencyImpl.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.manual.business; 2 | 3 | class DependencyImpl implements Dependency { 4 | @Override 5 | public String getGreetingMessage() { 6 | return "Hi all from vertx-guice manual example."; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/src/main/java/com/intapp/vertx/guice/examples/launcher/business/DependencyImpl.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.launcher.business; 2 | 3 | class DependencyImpl implements Dependency { 4 | @Override 5 | public String getGreetingMessage() { 6 | return "Hi all from vertx-guice launcher example."; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/src/main/java/com/intapp/vertx/guice/examples/launcher/business/BusinessModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.launcher.business; 2 | 3 | import com.google.inject.AbstractModule; 4 | 5 | public class BusinessModule extends AbstractModule { 6 | protected void configure() { 7 | this.bind(Dependency.class).to(DependencyImpl.class); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vertx-guice-examples/manual/src/main/java/com/intapp/vertx/guice/examples/manual/business/BusinessModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.manual.business; 2 | 3 | 4 | import com.google.inject.AbstractModule; 5 | 6 | public class BusinessModule extends AbstractModule { 7 | protected void configure() { 8 | this.bind(Dependency.class).to(DependencyImpl.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='vertx-guice' 2 | 3 | include 'vertx-guice', \ 4 | 'vertx-guice-examples/launcher', \ 5 | 'vertx-guice-examples/manual', \ 6 | 'vertx-guice-examples/service-proxy' 7 | 8 | project(':vertx-guice-examples/launcher').name = 'launcher-example' 9 | project(':vertx-guice-examples/manual').name = 'manual-example' 10 | project(':vertx-guice-examples/service-proxy').name = 'service-proxy-example' -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/DependencyAsSingletonModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Singleton; 5 | 6 | public class DependencyAsSingletonModule extends AbstractModule { 7 | protected void configure() { 8 | this.bind(Dependency.class).to(DependencyImpl.class).in(Singleton.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/business/BusinessService.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.serviceproxy.business; 2 | 3 | import io.vertx.codegen.annotations.ProxyGen; 4 | import io.vertx.core.AsyncResult; 5 | import io.vertx.core.Handler; 6 | 7 | @ProxyGen 8 | public interface BusinessService { 9 | void getGreetingMessage(Handler> resultHandler); 10 | } 11 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/business/BusinessModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.serviceproxy.business; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Singleton; 5 | 6 | public class BusinessModule extends AbstractModule { 7 | protected void configure() { 8 | this.bind(BusinessService.class).toProvider(BusinessServiceProvider.class).in(Singleton.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/DependencyModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | import com.google.inject.AbstractModule; 4 | 5 | /** 6 | * Guice module which binds {@link Dependency} interface to its default {@link DependencyImpl} implementation. 7 | */ 8 | public class DependencyModule extends AbstractModule { 9 | @Override 10 | protected void configure() { 11 | this.bind(Dependency.class).to(DependencyImpl.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vertx-guice-examples/manual/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | } 5 | 6 | //noinspection GroovyUnusedAssignment 7 | sourceCompatibility = 1.8 8 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 9 | 10 | repositories { 11 | mavenCentral() 12 | } 13 | 14 | def vertxVersion = "3.2.1"; 15 | 16 | mainClassName = 'com.intapp.vertx.guice.examples.manual.ServiceLauncher' 17 | 18 | dependencies { 19 | compile 'com.google.inject:guice:4.0' 20 | compile "io.vertx:vertx-core:$vertxVersion" 21 | 22 | compile project(':vertx-guice') 23 | } -------------------------------------------------------------------------------- /vertx-guice/src/test/resources/UncompiledVerticleWithDependency.java: -------------------------------------------------------------------------------- 1 | import com.google.common.base.Preconditions; 2 | 3 | import io.vertx.core.AbstractVerticle; 4 | import io.vertx.core.Vertx; 5 | 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * Uncompiled version of the Verticle which uses constructor 10 | * injection to obtain reference to Vertx instance. 11 | */ 12 | public class UncompiledVerticleWithDependency extends AbstractVerticle { 13 | @Inject 14 | public UncompiledVerticleWithDependency(Vertx vertx) { 15 | Preconditions.checkNotNull(vertx); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | } 5 | 6 | //noinspection GroovyUnusedAssignment 7 | sourceCompatibility = 1.8 8 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 9 | 10 | repositories { 11 | mavenCentral() 12 | } 13 | 14 | def vertxVersion = "3.2.1"; 15 | 16 | mainClassName = 'com.intapp.vertx.guice.examples.launcher.ServiceLauncher' 17 | 18 | dependencies { 19 | compile 'com.google.inject:guice:4.0' 20 | compile "io.vertx:vertx-core:$vertxVersion" 21 | 22 | compile project(':vertx-guice') 23 | } 24 | 25 | run { 26 | args = ['run', "java-guice:com.intapp.vertx.guice.examples.launcher.MainVerticle", "--launcher-class=$mainClassName"] 27 | } -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/Verticle2WithDependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | import io.vertx.core.AbstractVerticle; 6 | 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * Verticle which uses constructor injection to define dependent classes. 11 | */ 12 | public class Verticle2WithDependency extends AbstractVerticle { 13 | private final Dependency dependency; 14 | 15 | @Inject 16 | public Verticle2WithDependency(Dependency dependency) { 17 | this.dependency = Preconditions.checkNotNull(dependency); 18 | } 19 | 20 | public Dependency getDependency() { 21 | return dependency; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/VerticleWithDependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | import io.vertx.core.AbstractVerticle; 6 | 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * Verticle which uses constructor injection to define dependent classes. 11 | */ 12 | public class VerticleWithDependency extends AbstractVerticle { 13 | private final Dependency dependency; 14 | 15 | @Inject 16 | public VerticleWithDependency(Dependency dependency) { 17 | this.dependency = Preconditions.checkNotNull(dependency); 18 | } 19 | 20 | public Dependency getDependency() { 21 | return dependency; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /vertx-guice/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'jacoco' 4 | } 5 | 6 | //noinspection GroovyUnusedAssignment 7 | sourceCompatibility = 1.8 8 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 9 | 10 | repositories { 11 | mavenCentral() 12 | } 13 | 14 | def vertxVersion = "3.2.1"; 15 | 16 | dependencies { 17 | compile "io.vertx:vertx-core:$vertxVersion" 18 | compile 'com.google.inject:guice:4.0' 19 | 20 | testCompile 'junit:junit:4.11' 21 | testCompile 'org.mockito:mockito-core:1.10.19' 22 | testCompile 'org.assertj:assertj-core-java8:1.0.0m1' 23 | 24 | testCompile "io.vertx:vertx-core:$vertxVersion:tests" 25 | testCompile "io.vertx:vertx-rx-java:$vertxVersion" 26 | } 27 | 28 | jacocoTestReport { 29 | reports { 30 | xml.enabled true 31 | } 32 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | 4 | jdk: 5 | - oraclejdk8 6 | 7 | before_install: 8 | - chmod +x gradlew 9 | - chmod +x .travis/deploy.sh 10 | 11 | script: 12 | - ./gradlew --info check 13 | 14 | after_success: 15 | - pip install --user codecov 16 | - ./gradlew jacocoTestReport 17 | - codecov 18 | 19 | before_deploy: 20 | - openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in .travis/secring.gpg.enc -out vertx-guice/local.secring.gpg -d 21 | 22 | deploy: 23 | - 24 | provider: script 25 | script: ".travis/deploy.sh" 26 | skip_cleanup: true 27 | on: 28 | repo: intappx/vertx-guice 29 | branch: master 30 | - 31 | provider: script 32 | script: .travis/deploy.sh 33 | skip_cleanup: true 34 | on: 35 | repo: intappx/vertx-guice 36 | tags: true 37 | -------------------------------------------------------------------------------- /gradle/common.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // This file is to be applied to every subproject. 3 | // 4 | 5 | apply plugin: 'java' 6 | apply plugin: 'maven' 7 | 8 | //noinspection GroovyUnusedAssignment 9 | sourceCompatibility = '1.8' 10 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 11 | 12 | repositories { 13 | mavenCentral(); 14 | } 15 | 16 | group = 'com.intapp' 17 | version = project.hasProperty('mavenVersion') ? project['mavenVersion'] : '1.0-SNAPSHOT' 18 | 19 | task createFolders(description: 'Creates the source folders if they do not exist.') doLast { 20 | sourceSets*.allSource*.srcDirs*.each { File srcDir -> 21 | if (!srcDir.isDirectory()) { 22 | println "Creating source folder: ${srcDir}" 23 | srcDir.mkdirs() 24 | } 25 | } 26 | } 27 | 28 | task getVersion << { 29 | println version 30 | } 31 | -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/stubs/VerticleWithVertxDependency.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.stubs; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | import io.vertx.core.AbstractVerticle; 6 | import io.vertx.core.Vertx; 7 | 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | import javax.inject.Inject; 11 | 12 | public class VerticleWithVertxDependency extends AbstractVerticle { 13 | public static AtomicInteger instanceCount = new AtomicInteger(); 14 | 15 | @Inject 16 | public VerticleWithVertxDependency(Vertx vertxInstanceDependency) { 17 | Preconditions.checkNotNull(vertxInstanceDependency); 18 | } 19 | 20 | @Override 21 | public void start() throws Exception { 22 | instanceCount.incrementAndGet(); 23 | } 24 | 25 | @Override 26 | public void stop() throws Exception { 27 | instanceCount.decrementAndGet(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/business/BusinessServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.serviceproxy.business; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.inject.Inject; 5 | 6 | import io.vertx.core.AsyncResult; 7 | import io.vertx.core.Future; 8 | import io.vertx.core.Handler; 9 | import io.vertx.core.Vertx; 10 | 11 | class BusinessServiceImpl implements BusinessService { 12 | private final Vertx vertx; 13 | 14 | @Inject 15 | public BusinessServiceImpl(final Vertx vertx) { 16 | // This is done for demonstration purpose only to show that service dependency can be resolved too. 17 | this.vertx = Preconditions.checkNotNull(vertx); 18 | } 19 | 20 | @Override 21 | public void getGreetingMessage(Handler> resultHandler) { 22 | resultHandler.handle(Future.succeededFuture("Hi all from vertx-guice from service.")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vertx-guice/src/main/java/com/intapp/vertx/guice/VertxModule.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.inject.AbstractModule; 5 | 6 | import io.vertx.core.Vertx; 7 | import io.vertx.core.eventbus.EventBus; 8 | import io.vertx.core.file.FileSystem; 9 | import io.vertx.core.shareddata.SharedData; 10 | 11 | /** 12 | * Guice {@link AbstractModule} for vertx and container injections. 13 | */ 14 | public class VertxModule extends AbstractModule { 15 | 16 | private final Vertx vertx; 17 | 18 | public VertxModule(Vertx vertx) { 19 | this.vertx = Preconditions.checkNotNull(vertx); 20 | } 21 | 22 | @Override 23 | protected void configure() { 24 | bind(Vertx.class).toInstance(this.vertx); 25 | bind(EventBus.class).toInstance(this.vertx.eventBus()); 26 | bind(FileSystem.class).toInstance(this.vertx.fileSystem()); 27 | bind(SharedData.class).toInstance(this.vertx.sharedData()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.travis/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | SUB_PROJECT=":vertx-guice:" 6 | 7 | if [ ! -z "$TRAVIS_TAG" ]; then 8 | # Release tags in github basically are named with 'v' prefix. Remove this prefix from version component. 9 | VERSION=${TRAVIS_TAG#v} 10 | 11 | echo "Deploying release version. Tag: ${TRAVIS_TAG}. Version: ${VERSION}" 12 | ./gradlew ${SUB_PROJECT}uploadArchives -PnexusUsername="${SONATYPE_USERNAME}" -PnexusPassword="${SONATYPE_PASSWORD}" -Psigning.keyId="${SIGNING_KEY_ID}" -Psigning.password="${SIGNING_PASSWORD}" -Psigning.secretKeyRingFile="local.secring.gpg" -PmavenVersion="${VERSION}" 13 | else 14 | 15 | SNAPSHOT_VERSION=$(./gradlew ${SUB_PROJECT}getVersion -q) 16 | echo "Deploying snapshot version. Version: ${SNAPSHOT_VERSION}" 17 | 18 | ./gradlew ${SUB_PROJECT}uploadArchives -PnexusUsername="${SONATYPE_USERNAME}" -PnexusPassword="${SONATYPE_PASSWORD}" -Psigning.keyId="${SIGNING_KEY_ID}" -Psigning.password="${SIGNING_PASSWORD}" -Psigning.secretKeyRingFile="local.secring.gpg" 19 | fi 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2015 Intapp, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/src/main/java/com/intapp/vertx/guice/examples/launcher/ServiceLauncher.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.launcher; 2 | 3 | import com.intapp.vertx.guice.GuiceVertxLauncher; 4 | import com.intapp.vertx.guice.examples.launcher.business.BusinessModule; 5 | 6 | import com.google.inject.Module; 7 | 8 | import io.vertx.core.Launcher; 9 | import io.vertx.core.Vertx; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Examples which shows the following: 15 | * 1) Usage of the Vertx Launcher and Gradle configuration 16 | * 2) Extending GuiceVertxLauncher to register application specific modules 17 | */ 18 | public class ServiceLauncher extends GuiceVertxLauncher { 19 | /** 20 | * Main entry point. 21 | * 22 | * @param args the user command line arguments. For supported command line arguments please see {@link Launcher}. 23 | */ 24 | public static void main(String[] args) { 25 | new ServiceLauncher().dispatch(args); 26 | } 27 | 28 | @Override 29 | protected List getModules(Vertx vertx) { 30 | List modules = super.getModules(vertx); 31 | modules.add(new BusinessModule()); 32 | return modules; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.bmuschko.nexus' 2 | 3 | modifyPom { 4 | project { 5 | name 'vertx-guice' 6 | description 'Enable Verticle dependency injection in Vert.x using Guice.' 7 | url 'https://github.com/intappx/vertx-guice' 8 | packaging 'jar' 9 | organization { 10 | name 'Intapp Inc.' 11 | url 'http://www.intapp.com' 12 | } 13 | licenses { 14 | license { 15 | name 'MIT License' 16 | url 'http://www.opensource.org/licenses/mit-license.php' 17 | distribution 'repo' 18 | } 19 | } 20 | scm { 21 | url 'https://github.com/intappx/vertx-guice' 22 | connection 'scm:git:https://github.com/intappx/vertx-guice.git' 23 | developerConnection 'scm:git@github.com:intappx/vertx-guice.git' 24 | } 25 | developers { 26 | developer { 27 | id 'maximkornilov' 28 | name 'Maxim Kornilov' 29 | } 30 | } 31 | } 32 | } 33 | 34 | extraArchive { 35 | sources = true 36 | tests = false 37 | javadoc = true 38 | } 39 | 40 | nexus { 41 | sign = true 42 | repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' 43 | snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots' 44 | } -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/GuiceVertxLauncherTest.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.intapp.vertx.guice.stubs.VerticleWithVertxDependency; 4 | 5 | import io.vertx.test.core.VertxTestBase; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | /** 11 | * Implements test to verify work of the {@link GuiceVertxLauncher} class. 12 | */ 13 | public class GuiceVertxLauncherTest extends VertxTestBase { 14 | 15 | @Override 16 | @Before 17 | public void setUp() throws Exception { 18 | super.setUp(); 19 | 20 | VerticleWithVertxDependency.instanceCount.set(0); 21 | } 22 | 23 | /** 24 | * Verifies that verticle with Vertx instance dependency in constructor can be deployed and run successfully. 25 | */ 26 | @Test 27 | public void testRun_VerticleWithDependency_VerticleRunSuccessfully() throws Exception { 28 | // Arrange 29 | String[] args = 30 | {"run", GuiceVerticleFactory.PREFIX + ":" + VerticleWithVertxDependency.class.getCanonicalName()}; 31 | 32 | GuiceVertxLauncher launcher = new GuiceVertxLauncher(); 33 | 34 | // Act 35 | launcher.dispatch(args); 36 | waitUntil(() -> VerticleWithVertxDependency.instanceCount.get() == 1); 37 | 38 | // Assert 39 | org.assertj.core.api.Assertions.assertThat( 40 | VerticleWithVertxDependency.instanceCount.get()).isGreaterThan(0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/business/BusinessServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created by IntelliJ IDEA. 3 | * User: Maxim 4 | * Date: 3/23/2016 5 | * Time: 10:30 PM 6 | */ 7 | package com.intapp.vertx.guice.examples.serviceproxy.business; 8 | 9 | import com.google.common.base.Preconditions; 10 | import com.google.inject.Inject; 11 | import com.google.inject.Provider; 12 | 13 | import io.vertx.core.Vertx; 14 | import io.vertx.serviceproxy.ProxyHelper; 15 | 16 | /** 17 | * Guice provider which return code generation proxy to {@link BusinessService} service. 18 | * It also registered real service implementation. This way all registration is hidden from consumer. 19 | */ 20 | class BusinessServiceProvider implements Provider { 21 | private final Vertx vertx; 22 | 23 | @Inject 24 | public BusinessServiceProvider(Vertx vertx) { 25 | this.vertx = Preconditions.checkNotNull(vertx); 26 | } 27 | 28 | public BusinessService get() { 29 | // Register service implementation 30 | BusinessService service = new BusinessServiceImpl(vertx); 31 | ProxyHelper.registerService( 32 | BusinessService.class, this.vertx, service, BusinessService.class.getCanonicalName()); 33 | 34 | // All other code should work via service proxy 35 | return ProxyHelper.createProxy(BusinessService.class, this.vertx, BusinessService.class.getCanonicalName()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vertx-guice-examples/manual/src/main/java/com/intapp/vertx/guice/examples/manual/MainVerticle.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.manual; 2 | 3 | import com.intapp.vertx.guice.examples.manual.business.Dependency; 4 | 5 | import com.google.common.base.Preconditions; 6 | import com.google.inject.Inject; 7 | 8 | import io.vertx.core.AbstractVerticle; 9 | import io.vertx.core.Vertx; 10 | 11 | /** 12 | * Implements verticle to show dependency injection in action. 13 | * The following dependencies are injected: 14 | * 1) Vertx instance which bindings are configured in {@link com.intapp.vertx.guice.VertxModule} 15 | * 2) Application specific dependency 16 | */ 17 | public class MainVerticle extends AbstractVerticle{ 18 | private final Dependency dependency; 19 | private final Vertx vertx; 20 | 21 | @Inject 22 | public MainVerticle(final Vertx vertx, final Dependency dependency) { 23 | this.dependency = Preconditions.checkNotNull(dependency); 24 | this.vertx = Preconditions.checkNotNull(vertx); 25 | } 26 | 27 | @Override 28 | public void start() throws Exception { 29 | super.start(); 30 | 31 | this.vertx.createHttpServer() 32 | .requestHandler(req -> req.response().end(this.dependency.getGreetingMessage())) 33 | .listen(8080, handler -> { 34 | if (handler.succeeded()) { 35 | System.out.println("http://localhost:8080/"); 36 | } else { 37 | System.err.println("Failed to listen on port 8080"); 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vertx-guice-examples/launcher/src/main/java/com/intapp/vertx/guice/examples/launcher/MainVerticle.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.launcher; 2 | 3 | import com.intapp.vertx.guice.examples.launcher.business.Dependency; 4 | 5 | import com.google.common.base.Preconditions; 6 | import com.google.inject.Inject; 7 | 8 | import io.vertx.core.AbstractVerticle; 9 | import io.vertx.core.Vertx; 10 | 11 | /** 12 | * Implements verticle to show dependency injection in action. 13 | * The following dependencies are injected: 14 | * 1) Vertx instance which bindings are configured in {@link com.intapp.vertx.guice.VertxModule} 15 | * 2) Application specific dependency 16 | */ 17 | public class MainVerticle extends AbstractVerticle{ 18 | private final Dependency dependency; 19 | private final Vertx vertx; 20 | 21 | @Inject 22 | public MainVerticle(final Vertx vertx, final Dependency dependency) { 23 | this.dependency = Preconditions.checkNotNull(dependency); 24 | this.vertx = Preconditions.checkNotNull(vertx); 25 | } 26 | 27 | @Override 28 | public void start() throws Exception { 29 | super.start(); 30 | 31 | this.vertx.createHttpServer() 32 | .requestHandler(req -> req.response().end(this.dependency.getGreetingMessage())) 33 | .listen(8080, handler -> { 34 | if (handler.succeeded()) { 35 | System.out.println("http://localhost:8080/"); 36 | } else { 37 | System.err.println("Failed to listen on port 8080"); 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | } 5 | 6 | //noinspection GroovyUnusedAssignment 7 | sourceCompatibility = 1.8 8 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 9 | 10 | repositories { 11 | mavenCentral() 12 | } 13 | 14 | def vertxVersion = "3.2.1"; 15 | 16 | mainClassName = 'com.intapp.vertx.guice.examples.serviceproxy.ServiceLauncher' 17 | 18 | dependencies { 19 | compile 'com.google.inject:guice:4.0' 20 | compile "io.vertx:vertx-core:$vertxVersion" 21 | compile "io.vertx:vertx-codegen:$vertxVersion" 22 | compile "io.vertx:vertx-service-proxy:$vertxVersion" 23 | 24 | compile project(':vertx-guice') 25 | } 26 | 27 | ///////////////////////////////////////////////// 28 | // Code Gen support for service-proxy 29 | 30 | sourceSets { 31 | generated { 32 | java { 33 | srcDirs = ['src/main/generated'] 34 | } 35 | } 36 | } 37 | 38 | task generateServiceProxy(type: JavaCompile, description: 'Generates EBServiceProxies') { 39 | source = sourceSets.main.java 40 | classpath = configurations.compile 41 | destinationDir = sourceSets.generated.java.srcDirs.iterator().next() 42 | options.compilerArgs = [ 43 | "-proc:only", 44 | "-processor", "io.vertx.codegen.CodeGenProcessor", 45 | "-AoutputDirectory=$destinationDir" 46 | ] 47 | } 48 | 49 | compileJava { 50 | source sourceSets.main.java + sourceSets.generated.java 51 | } 52 | compileJava.dependsOn generateServiceProxy 53 | 54 | clean { 55 | delete += sourceSets.generated.java.srcDirs 56 | } -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/ServiceLauncher.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.serviceproxy; 2 | 3 | import com.intapp.vertx.guice.GuiceVerticleFactory; 4 | import com.intapp.vertx.guice.GuiceVertxDeploymentManager; 5 | import com.intapp.vertx.guice.VertxModule; 6 | import com.intapp.vertx.guice.examples.serviceproxy.business.BusinessModule; 7 | 8 | import com.google.inject.Guice; 9 | import com.google.inject.Injector; 10 | 11 | import io.vertx.core.Launcher; 12 | import io.vertx.core.Vertx; 13 | import io.vertx.core.VertxOptions; 14 | 15 | /** 16 | * Example which shows the following: 17 | * 1) Particullar the same stuff from manual example with addition that Vertx service concept is used. 18 | * 2) Dependency injection in services 19 | * 3) Dependency inejction of the proxy to services. 20 | */ 21 | public class ServiceLauncher { 22 | /** 23 | * Main entry point. 24 | * 25 | * @param args the user command line arguments. For supported command line arguments please see {@link Launcher}. 26 | */ 27 | public static void main(String[] args) { 28 | new ServiceLauncher().launch(); 29 | } 30 | 31 | public void launch() { 32 | Vertx vertx = Vertx.vertx(new VertxOptions()); 33 | 34 | Injector injector = Guice.createInjector( 35 | new VertxModule(vertx), 36 | new BusinessModule()); 37 | 38 | GuiceVerticleFactory guiceVerticleFactory = new GuiceVerticleFactory(injector); 39 | vertx.registerVerticleFactory(guiceVerticleFactory); 40 | 41 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(vertx); 42 | deploymentManager.deployVerticle(MainVerticle.class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vertx-guice-examples/service-proxy/src/main/java/com/intapp/vertx/guice/examples/serviceproxy/MainVerticle.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.serviceproxy; 2 | 3 | import com.intapp.vertx.guice.examples.serviceproxy.business.BusinessService; 4 | 5 | import com.google.common.base.Preconditions; 6 | import com.google.inject.Inject; 7 | 8 | import io.vertx.core.AbstractVerticle; 9 | import io.vertx.core.Vertx; 10 | 11 | /** 12 | * Implements verticle to show dependency injection in action. 13 | * The following dependencies are injected: 14 | * 1) Vertx instance which bindings are configured in {@link com.intapp.vertx.guice.VertxModule} 15 | * 2) Application specific dependency which is proxy to {@link BusinessService} class. 16 | */ 17 | public class MainVerticle extends AbstractVerticle{ 18 | private final BusinessService businessService; 19 | private final Vertx vertx; 20 | 21 | @Inject 22 | public MainVerticle(final Vertx vertx, final BusinessService businessService) { 23 | this.businessService = Preconditions.checkNotNull(businessService); 24 | this.vertx = Preconditions.checkNotNull(vertx); 25 | } 26 | 27 | @Override 28 | public void start() throws Exception { 29 | super.start(); 30 | 31 | this.vertx.createHttpServer() 32 | .requestHandler(requestHandler -> 33 | this.businessService.getGreetingMessage(handler -> 34 | requestHandler.response().end(handler.result()))) 35 | .listen(8080, handler -> { 36 | if (handler.succeeded()) { 37 | System.out.println("http://localhost:8080/"); 38 | } else { 39 | System.err.println("Failed to listen on port 8080"); 40 | } 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vertx-guice-examples/manual/src/main/java/com/intapp/vertx/guice/examples/manual/ServiceLauncher.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice.examples.manual; 2 | 3 | import com.intapp.vertx.guice.GuiceVerticleFactory; 4 | import com.intapp.vertx.guice.GuiceVertxDeploymentManager; 5 | import com.intapp.vertx.guice.VertxModule; 6 | import com.intapp.vertx.guice.examples.manual.business.BusinessModule; 7 | 8 | import com.google.inject.Guice; 9 | import com.google.inject.Injector; 10 | 11 | import io.vertx.core.Launcher; 12 | import io.vertx.core.Vertx; 13 | import io.vertx.core.VertxOptions; 14 | 15 | /** 16 | * Example which shows the following: 17 | * 1) Creating vertx manually in application main entry point 18 | * 2) Creating single injector with Vertx and application specific modules 19 | * 3) Registering GuiceVerticleFactory. 20 | * 4) Deploying verticle programmatically which uses GuiceVerticleFactory 21 | */ 22 | public class ServiceLauncher { 23 | /** 24 | * Main entry point. 25 | * 26 | * @param args the user command line arguments. For supported command line arguments please see {@link Launcher}. 27 | */ 28 | public static void main(String[] args) { 29 | new ServiceLauncher().launch(); 30 | } 31 | 32 | public void launch() { 33 | Vertx vertx = Vertx.vertx(new VertxOptions()); 34 | 35 | Injector injector = Guice.createInjector( 36 | new VertxModule(vertx), 37 | new BusinessModule()); 38 | 39 | GuiceVerticleFactory guiceVerticleFactory = new GuiceVerticleFactory(injector); 40 | vertx.registerVerticleFactory(guiceVerticleFactory); 41 | 42 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(vertx); 43 | deploymentManager.deployVerticle(MainVerticle.class); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vertx-guice/src/main/java/com/intapp/vertx/guice/GuiceVerticleFactory.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.inject.Injector; 5 | 6 | import io.vertx.core.Verticle; 7 | import io.vertx.core.impl.verticle.CompilingClassLoader; 8 | import io.vertx.core.spi.VerticleFactory; 9 | 10 | /** 11 | * Represents verticle factory which uses Guice for verticle creation. 12 | * To make vertx to use this factory for verticle creation the following criteria should be accomplished: 13 | * 1) This factory should be registered in Vertx. One of the way to achieve this is to use {@link GuiceVertxLauncher} 14 | * as Vertx main launcher. 15 | * 2) Verticle should be deployed with the factory prefix {@link #PREFIX}. 16 | */ 17 | public class GuiceVerticleFactory implements VerticleFactory { 18 | public static final String PREFIX = "java-guice"; 19 | private final Injector injector; 20 | 21 | public GuiceVerticleFactory(Injector injector) { 22 | this.injector = Preconditions.checkNotNull(injector); 23 | } 24 | 25 | @Override 26 | public String prefix() { 27 | return PREFIX; 28 | } 29 | 30 | @Override 31 | public Verticle createVerticle(String verticleName, ClassLoader classLoader) throws Exception { 32 | verticleName = VerticleFactory.removePrefix(verticleName); 33 | 34 | Class clazz; 35 | if (verticleName.endsWith(".java")) { 36 | CompilingClassLoader compilingLoader = new CompilingClassLoader(classLoader, verticleName); 37 | String className = compilingLoader.resolveMainClassName(); 38 | clazz = compilingLoader.loadClass(className); 39 | } else { 40 | clazz = classLoader.loadClass(verticleName); 41 | } 42 | 43 | return (Verticle) this.injector.getInstance(clazz); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ############################################################ 2 | # JAVA ignore defaults (https://github.com/github/gitignore/blob/master/Java.gitignore). 3 | ############################################################ 4 | 5 | *.class 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | 18 | # Eclipse 19 | .classpath 20 | .project 21 | .settings/ 22 | 23 | # Maven 24 | log/ 25 | target/ 26 | 27 | ############################################################ 28 | # Gradle ignore defaults (https://github.com/github/gitignore/blob/master/Gradle.gitignore) 29 | ############################################################ 30 | .gradle 31 | build/ 32 | 33 | # Ignore Gradle GUI config 34 | gradle-app.setting 35 | 36 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 37 | !gradle-wrapper.jar 38 | 39 | # Cache of project 40 | .gradletasknamecache 41 | 42 | # NetBeans IDE 43 | .nb-gradle 44 | 45 | ############################################################ 46 | # JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 47 | ############################################################ 48 | 49 | *.iml 50 | 51 | ## Directory-based project format: 52 | .idea/ 53 | # if you remove the above rule, at least ignore the following: 54 | 55 | # User-specific stuff: 56 | # .idea/workspace.xml 57 | # .idea/tasks.xml 58 | # .idea/dictionaries 59 | 60 | # Sensitive or high-churn files: 61 | # .idea/dataSources.ids 62 | # .idea/dataSources.xml 63 | # .idea/sqlDataSources.xml 64 | # .idea/dynamic.xml 65 | # .idea/uiDesigner.xml 66 | 67 | # Gradle: 68 | # .idea/gradle.xml 69 | # .idea/libraries 70 | 71 | # Mongo Explorer plugin: 72 | # .idea/mongoSettings.xml 73 | 74 | ## File-based project format: 75 | *.ipr 76 | *.iws 77 | 78 | ## Plugin-specific files: 79 | 80 | # IntelliJ 81 | /out/ 82 | 83 | # mpeltonen/sbt-idea plugin 84 | .idea_modules/ 85 | 86 | # JIRA plugin 87 | atlassian-ide-plugin.xml 88 | 89 | # Crashlytics plugin (for Android Studio and IntelliJ) 90 | com_crashlytics_export_strings.xml 91 | crashlytics.properties 92 | crashlytics-build.properties 93 | 94 | ############################################################ 95 | # Application specific 96 | ############################################################ 97 | vertx-guice-examples/service-proxy/src/main/generated/ 98 | 99 | // Local environment files. 100 | local.* 101 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /vertx-guice/src/main/java/com/intapp/vertx/guice/GuiceVertxLauncher.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.Module; 6 | 7 | import io.vertx.core.Launcher; 8 | import io.vertx.core.Vertx; 9 | 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | /** 14 | * Extends {@link Launcher} to use {@link GuiceVerticleFactory} verticle factory which uses Guice for verticle 15 | * creation. 16 | * 17 | *

Note: Verticle should be deployed with the factory prefix {@link GuiceVerticleFactory#PREFIX} to make vertx 18 | * to use registered factory for verticle creation and dependency injection.

19 | */ 20 | public class GuiceVertxLauncher extends Launcher { 21 | 22 | /** 23 | * Main entry point. 24 | * 25 | * @param args the user command line arguments. For supported command line arguments please see {@link Launcher}. 26 | */ 27 | public static void main(String[] args) { 28 | new GuiceVertxLauncher().dispatch(args); 29 | } 30 | 31 | @Override 32 | public void afterStartingVertx(Vertx vertx) { 33 | super.afterStartingVertx(vertx); 34 | 35 | GuiceVerticleFactory guiceVerticleFactory = 36 | new GuiceVerticleFactory(this.createInjector(vertx)); 37 | vertx.registerVerticleFactory(guiceVerticleFactory); 38 | } 39 | 40 | /** 41 | * Creates injector to be used for verticle creation. 42 | * This injector instance will be shared by all Verticles. 43 | * 44 | *

Override this method if you want to customize logic of the injector creation. 45 | * To add application specific modules to be used by injector, {@link #getModules} method should 46 | * be overridden instead.

47 | * 48 | * @param vertx Vert.x instance for which injetor will be created. 49 | * @return Guice inejector instantiated with modules provided by {@link #getModules} method. 50 | */ 51 | protected Injector createInjector(Vertx vertx) { 52 | return Guice.createInjector(this.getModules(vertx)); 53 | } 54 | 55 | /** 56 | * Gets the collection of the Guice modules to be registered in Guice injector. 57 | * Override this method to add application specific modules. 58 | * 59 | *

By default returned collection contains only {@link VertxModule} module.

60 | * 61 | * @param vertx Vert.x instance to load modules into. 62 | * @return Collection of the modules to register in injector. 63 | */ 64 | protected List getModules(Vertx vertx) { 65 | List modules = new LinkedList<>(); 66 | modules.add(new VertxModule(vertx)); 67 | return modules; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vertx-guice 2 | Enable Verticle dependency injection in Vert.x using Guice. 3 | 4 | [![Build Status](https://travis-ci.org/intappx/vertx-guice.svg?branch=master)](https://travis-ci.org/intappx/vertx-guice) 5 | [![Code Coverage](https://img.shields.io/codecov/c/github/intappx/vertx-guice.svg)](https://codecov.io/github/intappx/vertx-guice) 6 | [![Maven Central](https://img.shields.io/maven-central/v/com.intapp/vertx-guice.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.intapp%22%20AND%20a%3A%22vertx-guice%22) 7 | 8 | It is designed to use single injector per Vert.x instance. 9 | It means that `Singleton' scope is supported and works as expected. This was the main reason to implement this library instead of using [vertx-guice](https://github.com/englishtown/vertx-guice) library from English Town. 10 | 11 | ### What does it provide 12 | * `GuiceVerticleFactory` which uses Guice for verticle creation. To be used, it should be registered in Vertx and verticle should be deployed with `java-guice:` prefix. 13 | * `GuiceVertxLauncher` which extends default [vert.x launcher](http://vertx.io/docs/vertx-core/java/#_the_vert_x_launcher). It performs all necessary work related to the creating single injector per Vert.x instance, registering `GuiceVerticleFactory`. 14 | To register application specific dependencies, you can also create a sub-class of `GuiceVertxLauncher` and use it to start your application. 15 | * `GuiceVertxDeploymentManager` which implements convenient methods to deploy verticles programmatically by specified class using `GuiceVerticleFactory` factory. 16 | * `VertxModule` which contains binding for vertx itself and it's cached objects like EventBus, FileSystem, SharedData. 17 | 18 | ### How to use 19 | Several examples were added which covers main scenarios of the adding dependency injection support. 20 | 21 | ###### [Vert.x Launcher](vertx-guice-examples/launcher) 22 | Shows the way to use `GuiceVertxLauncher` to run application with registering application specific modules and deploying verticle with injecting dependencies. 23 | 24 | Basically it covers the following: 25 | 26 | * Extending `GuiceVertxLauncher` to register application specific modules 27 | * Customized `run` gradle task which deploys verticle with constructor dependency injection. 28 | 29 | *Note* some of the useful information about Vert.x launcher and gradle configuration can be found in [vertx 3.0 examples](https://github.com/vert-x3/vertx-examples/tree/master/gradle-redeploy). 30 | 31 | ##### [Creating and running Vert.x manually](vertx-guice-examples/manual) 32 | Example which shows the following: 33 | 34 | * Creating vertx manually in application main entry point 35 | * Creating single injector with Vertx and application specific modules 36 | * Registering 'GuiceVerticleFactory'. 37 | * Deploying verticle programmatically which uses 'GuiceVerticleFactory' 38 | 39 | ##### [Using dependency injection with Vert.x services](vertx-guice-examples/service-proxy) 40 | There is an [Vert.x Service Proxy](http://vertx.io/docs/vertx-service-proxy/java/) library which allows to develop less verbosity code for asynchronous verticles (which works over event bus). 41 | This example shows the following: 42 | 43 | * Particular the same stuff from manual example with addition that Vertx service concept is used. 44 | * Dependency injection in service itself 45 | * Hiding service registration and proxy creation by using Guice Provider concept 46 | * Using of the service via injected generated proxy in verticle 47 | * Gradle configuration 48 | 49 | ### TO-DO 50 | * Request Scope Support (if there will be a real use case for this) 51 | -------------------------------------------------------------------------------- /vertx-guice/src/main/java/com/intapp/vertx/guice/GuiceVertxDeploymentManager.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | import io.vertx.core.AsyncResult; 6 | import io.vertx.core.DeploymentOptions; 7 | import io.vertx.core.Handler; 8 | import io.vertx.core.Vertx; 9 | 10 | /** 11 | * Implements convenient methods to deploy verticles programmatically by specified class using @{@link GuiceVerticleFactory} factory. 12 | */ 13 | public class GuiceVertxDeploymentManager { 14 | private final Vertx vertx; 15 | 16 | public GuiceVertxDeploymentManager(final Vertx vertx) { 17 | this.vertx = Preconditions.checkNotNull(vertx); 18 | } 19 | 20 | /** 21 | * Deploy a verticle instance given a class of the verticle using default deployment options 22 | * and {@link GuiceVerticleFactory} factory. 23 | * 24 | * @param verticleClazz the class of the verticle to deploy. 25 | */ 26 | public void deployVerticle(final Class verticleClazz) { 27 | Preconditions.checkNotNull(verticleClazz); 28 | 29 | deployVerticle(verticleClazz, new DeploymentOptions()); 30 | } 31 | 32 | /** 33 | * Like {@link #deployVerticle(Class)} but {@link io.vertx.core.DeploymentOptions} are provided to configure the 34 | * deployment. 35 | * 36 | * @param verticleClazz the class of the verticle to deploy. 37 | * @param options the deployment options. 38 | */ 39 | public void deployVerticle (final Class verticleClazz, final DeploymentOptions options) { 40 | Preconditions.checkNotNull(verticleClazz); 41 | Preconditions.checkNotNull(options); 42 | 43 | this.vertx.deployVerticle(getFullVerticleName(verticleClazz), options); 44 | } 45 | 46 | 47 | /** 48 | * Like {@link #deployVerticle(Class)} but handler can be provided 49 | * which will be notified when the deployment is complete. 50 | * 51 | * @param verticleClazz the class of the verticle to deploy. 52 | * @param completionHandler a handler which will be notified when the deployment is complete. 53 | */ 54 | public void deployVerticle( final Class verticleClazz, Handler> completionHandler) { 55 | Preconditions.checkNotNull(verticleClazz); 56 | Preconditions.checkNotNull(completionHandler); 57 | 58 | this.vertx.deployVerticle(getFullVerticleName(verticleClazz), completionHandler); 59 | } 60 | 61 | /** 62 | * Like {@link #deployVerticle(Class, DeploymentOptions)} but handler can be provided 63 | * which will be notified when the deployment is complete. 64 | * 65 | * @param verticleClazz the class of the verticle to deploy. 66 | * @param options the deployment options. 67 | * @param completionHandler a handler which will be notified when the deployment is complete. 68 | */ 69 | public void deployVerticle( final Class verticleClazz, final DeploymentOptions options, Handler> completionHandler) { 70 | Preconditions.checkNotNull(verticleClazz); 71 | Preconditions.checkNotNull(options); 72 | Preconditions.checkNotNull(completionHandler); 73 | 74 | this.vertx.deployVerticle(getFullVerticleName(verticleClazz), options, completionHandler); 75 | } 76 | 77 | /** 78 | * Gets the name of the verticle with adding prefix required to notify vertx to use 79 | * @{@link GuiceVerticleFactory} factory for verticle creation. 80 | * 81 | * @param verticleClazz the class of the verticle to deploy. 82 | * @return Name of the verticle which can be used for deployment to vertx. 83 | */ 84 | private static String getFullVerticleName(final Class verticleClazz) { 85 | return GuiceVerticleFactory.PREFIX + ":" + verticleClazz.getCanonicalName(); 86 | } 87 | } -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/GuiceVertxDeploymentManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import com.intapp.vertx.guice.stubs.VerticleWithVertxDependency; 4 | 5 | import com.google.inject.Guice; 6 | import com.google.inject.Injector; 7 | 8 | import io.vertx.core.DeploymentOptions; 9 | import io.vertx.rx.java.ObservableFuture; 10 | import io.vertx.rx.java.RxHelper; 11 | import io.vertx.test.core.VertxTestBase; 12 | 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | /** 17 | * Implements tests to veriry logic of the {@see GuiceVertxDeploymentManager} class. 18 | */ 19 | public class GuiceVertxDeploymentManagerTest extends VertxTestBase { 20 | 21 | @Override 22 | @Before 23 | public void setUp() throws Exception { 24 | super.setUp(); 25 | 26 | Injector injector = Guice.createInjector(new VertxModule(this.vertx)); 27 | 28 | GuiceVerticleFactory guiceVerticleFactory = new GuiceVerticleFactory(injector); 29 | vertx.registerVerticleFactory(guiceVerticleFactory); 30 | 31 | VerticleWithVertxDependency.instanceCount.set(0); 32 | } 33 | 34 | /** 35 | * Verifies that verticle with dependency can be deployed successfully. 36 | * @throws Exception 37 | */ 38 | @Test 39 | public void testDeployVerticle() throws Exception { 40 | // Act 41 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(this.vertx); 42 | deploymentManager.deployVerticle(VerticleWithVertxDependency.class); 43 | waitUntil(() -> VerticleWithVertxDependency.instanceCount.get() == 1); 44 | 45 | // Assert 46 | org.assertj.core.api.Assertions.assertThat( 47 | VerticleWithVertxDependency.instanceCount.get()).isGreaterThan(0); 48 | } 49 | 50 | /** 51 | * Verifies that verticle with dependency can be deployed successfully with specific deployment options. 52 | * @throws Exception 53 | */ 54 | @Test 55 | public void testDeployVerticleWithOptions() throws Exception { 56 | // Act` 57 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(this.vertx); 58 | deploymentManager.deployVerticle( 59 | VerticleWithVertxDependency.class, 60 | new DeploymentOptions().setWorker(true)); 61 | 62 | waitUntil(() -> VerticleWithVertxDependency.instanceCount.get() == 1); 63 | 64 | // Assert 65 | org.assertj.core.api.Assertions.assertThat( 66 | VerticleWithVertxDependency.instanceCount.get()).isGreaterThan(0); 67 | } 68 | 69 | /** 70 | * Verifies that verticle with dependency can be deployed successfully and result of the deployment can be received 71 | * via providing completion handler. 72 | * 73 | * @throws Exception 74 | */ 75 | @Test 76 | public void testDeployVerticleWithCompletionHandler() throws Exception { 77 | // Act` 78 | ObservableFuture deplymentResult = RxHelper.observableFuture(); 79 | 80 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(this.vertx); 81 | deploymentManager.deployVerticle( 82 | VerticleWithVertxDependency.class, 83 | deplymentResult.toHandler()); 84 | 85 | String deploymentId = deplymentResult.toBlocking().single(); 86 | 87 | // Assert 88 | org.assertj.core.api.Assertions.assertThat(deploymentId).isNotEmpty(); 89 | } 90 | 91 | /** 92 | * Verifies that verticle with dependency can be deployed successfully and result of the deployment can be received 93 | * via providing completion handler. 94 | * 95 | * @throws Exception 96 | */ 97 | @Test 98 | public void testDeployVerticleWithOptionsAndCompletionHandler() throws Exception { 99 | // Act` 100 | ObservableFuture deplymentResult = RxHelper.observableFuture(); 101 | 102 | GuiceVertxDeploymentManager deploymentManager = new GuiceVertxDeploymentManager(this.vertx); 103 | deploymentManager.deployVerticle( 104 | VerticleWithVertxDependency.class, 105 | new DeploymentOptions(), 106 | deplymentResult.toHandler()); 107 | 108 | String deploymentId = deplymentResult.toBlocking().single(); 109 | 110 | // Assert 111 | org.assertj.core.api.Assertions.assertThat(deploymentId).isNotEmpty(); 112 | } 113 | 114 | 115 | } -------------------------------------------------------------------------------- /vertx-guice/src/test/java/com/intapp/vertx/guice/GuiceVerticleFactoryTest.java: -------------------------------------------------------------------------------- 1 | package com.intapp.vertx.guice; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.mockito.Mockito.when; 5 | 6 | import com.intapp.vertx.guice.stubs.DependencyAsSingletonModule; 7 | import com.intapp.vertx.guice.stubs.DependencyImpl; 8 | import com.intapp.vertx.guice.stubs.DependencyModule; 9 | import com.intapp.vertx.guice.stubs.Verticle2WithDependency; 10 | import com.intapp.vertx.guice.stubs.VerticleWithDependency; 11 | 12 | import com.google.inject.Guice; 13 | import com.google.inject.Injector; 14 | 15 | import io.vertx.core.Verticle; 16 | import io.vertx.core.Vertx; 17 | import io.vertx.core.eventbus.EventBus; 18 | import io.vertx.core.file.FileSystem; 19 | import io.vertx.core.shareddata.SharedData; 20 | 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.mockito.Mock; 25 | import org.mockito.runners.MockitoJUnitRunner; 26 | 27 | /** 28 | * Unit tests for {@link GuiceVerticleFactory} class. 29 | */ 30 | @RunWith(MockitoJUnitRunner.class) 31 | public class GuiceVerticleFactoryTest { 32 | @Mock Vertx vertx; 33 | @Mock EventBus eventBus; 34 | @Mock FileSystem fileSystem; 35 | @Mock SharedData sharedData; 36 | 37 | private Injector injector; 38 | private GuiceVerticleFactory factory; 39 | 40 | @Before 41 | public void setUp() throws Exception { 42 | this.injector = Guice.createInjector(new DependencyModule()); 43 | this.factory = new GuiceVerticleFactory(this.injector); 44 | this.factory.init(vertx); 45 | 46 | when(this.vertx.eventBus()).thenReturn(this.eventBus); 47 | when(this.vertx.fileSystem()).thenReturn(this.fileSystem); 48 | when(this.vertx.sharedData()).thenReturn(this.sharedData); 49 | } 50 | 51 | @Test 52 | public void testPrefix() { 53 | // Assert 54 | assertThat(factory.prefix()).isEqualTo("java-guice"); 55 | } 56 | 57 | /** 58 | * This test verifies that Verticle which uses constructor injection for dependency management 59 | * can be instantiated successfully. 60 | */ 61 | @Test 62 | public void testCreateVerticle_VerticleWithDependencyInConstructor_VerticleIsCreated() throws Exception { 63 | // Arrange 64 | String identifier = GuiceVerticleFactory.PREFIX + ":" + VerticleWithDependency.class.getName(); 65 | 66 | // Act 67 | Verticle verticle = factory.createVerticle(identifier, this.getClass().getClassLoader()); 68 | 69 | // Assert 70 | assertThat(verticle).isExactlyInstanceOf(VerticleWithDependency.class); 71 | assertThat(((VerticleWithDependency) verticle).getDependency()).isExactlyInstanceOf(DependencyImpl.class); 72 | } 73 | 74 | /** 75 | * This test verifies that {@link GuiceVertxLauncher} can be used to instantiate and inject dependency for 76 | * Uncompiled verticle (the same way as {@link io.vertx.core.impl.JavaVerticleFactory} works. 77 | */ 78 | @Test 79 | public void testCreateVerticle_UncompiledVerticleWithDependencyInConstructor_VerticleIsCreated() throws Exception { 80 | // Arrange 81 | this.injector = Guice.createInjector(new VertxModule(this.vertx)); 82 | this.factory = new GuiceVerticleFactory(this.injector); 83 | this.factory.init(vertx); 84 | 85 | String identifier = GuiceVerticleFactory.PREFIX + ":UncompiledVerticleWithDependency.java"; 86 | 87 | // Act 88 | Verticle verticle = factory.createVerticle(identifier, this.getClass().getClassLoader()); 89 | 90 | // Assert 91 | assertThat(verticle).isNotNull(); 92 | } 93 | 94 | /** 95 | * This test verifies that when dependency is injected using Singleton scope, 96 | * than the single instance of this dependency is used by all verticles. 97 | */ 98 | @Test 99 | public void testCreateVerticle_DependencyBindedInSingletonScope_SameInstanceIsUsedByAllVerticles() 100 | throws Exception { 101 | // Arrange 102 | this.injector = Guice.createInjector(new DependencyAsSingletonModule()); 103 | this.factory = new GuiceVerticleFactory(this.injector); 104 | this.factory.init(vertx); 105 | 106 | String identifier = GuiceVerticleFactory.PREFIX + ":" + VerticleWithDependency.class.getName(); 107 | String identifier2 = GuiceVerticleFactory.PREFIX + ":" + Verticle2WithDependency.class.getName(); 108 | 109 | // Act 110 | VerticleWithDependency verticle = 111 | (VerticleWithDependency) factory.createVerticle(identifier, this.getClass().getClassLoader()); 112 | Verticle2WithDependency verticle2 = 113 | (Verticle2WithDependency) factory.createVerticle(identifier2, this.getClass().getClassLoader()); 114 | 115 | // Assert 116 | assertThat(verticle.getDependency()).isSameAs(verticle2.getDependency()); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | --------------------------------------------------------------------------------