diff --git a/maven/hello-world/.gitignore b/maven/.gitignore similarity index 65% rename from maven/hello-world/.gitignore rename to maven/.gitignore index c5078494ed..8ded6a27c2 100644 --- a/maven/hello-world/.gitignore +++ b/maven/.gitignore @@ -1,2 +1,4 @@ -target .idea +*.iml + +target diff --git a/maven/dagger-maven-example/pom.xml b/maven/dagger-example/pom.xml similarity index 56% rename from maven/dagger-maven-example/pom.xml rename to maven/dagger-example/pom.xml index c9b6638c30..41d8aebe4f 100644 --- a/maven/dagger-maven-example/pom.xml +++ b/maven/dagger-example/pom.xml @@ -1,37 +1,27 @@ - + 4.0.0 - org.jetbrains.kotlin.examples + + org.jetbrains.kotlin + kotlin-examples + 1.0-SNAPSHOT + + dagger-maven-example - 1.0-SNAPSHOT - 1.1-SNAPSHOT - 4.12 - coffee.CoffeeApp - UTF-8 + 2.29 com.google.dagger dagger - 2.9 - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - junit - junit - ${junit.version} - test + ${dagger.version} @@ -50,13 +40,12 @@ src/main/kotlin - src/main/java com.google.dagger dagger-compiler - 2.9 + ${dagger.version} @@ -69,7 +58,6 @@ src/main/kotlin - src/main/java @@ -81,13 +69,12 @@ src/test/kotlin - src/test/java com.google.dagger dagger-compiler - 2.9 + ${dagger.version} @@ -100,48 +87,16 @@ src/test/kotlin - src/test/java target/generated-sources/kapt/test + org.apache.maven.plugins maven-compiler-plugin - 3.5.1 - - none - 1.6 - 1.6 - - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - - compile - - - - java-test-compile - test-compile - - testCompile - - - diff --git a/maven/dagger-maven-example/src/main/kotlin/CoffeeMaker.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/CoffeeMaker.kt similarity index 92% rename from maven/dagger-maven-example/src/main/kotlin/CoffeeMaker.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/CoffeeMaker.kt index 58e9de6e83..35af380343 100755 --- a/maven/dagger-maven-example/src/main/kotlin/CoffeeMaker.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/CoffeeMaker.kt @@ -1,4 +1,4 @@ -package coffee +package examples.dagger import dagger.Lazy import javax.inject.Inject @@ -14,4 +14,5 @@ class CoffeeMaker @Inject constructor( println(" [_]P coffee! [_]P ") heater.get().off() } + } diff --git a/maven/dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/DripCoffeeModule.kt similarity index 64% rename from maven/dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/DripCoffeeModule.kt index a8c1dae207..8a24df658c 100755 --- a/maven/dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/DripCoffeeModule.kt @@ -1,13 +1,16 @@ -package coffee +package examples.dagger import dagger.Module import dagger.Provides import javax.inject.Singleton -@Module(includes = arrayOf(PumpModule::class)) +@Module(includes = [PumpModule::class]) class DripCoffeeModule { - @Provides @Singleton + + @Provides + @Singleton fun provideHeater(): Heater { return ElectricHeater() } + } diff --git a/maven/dagger-maven-example/src/main/kotlin/ElectricHeater.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/ElectricHeater.kt similarity index 90% rename from maven/dagger-maven-example/src/main/kotlin/ElectricHeater.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/ElectricHeater.kt index 6c1f1586a4..9dfd9ddd85 100755 --- a/maven/dagger-maven-example/src/main/kotlin/ElectricHeater.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/ElectricHeater.kt @@ -1,6 +1,7 @@ -package coffee +package examples.dagger open class ElectricHeater : Heater { + override var isHot: Boolean = false override fun on() { @@ -11,4 +12,5 @@ open class ElectricHeater : Heater { override fun off() { this.isHot = false } + } diff --git a/maven/dagger-maven-example/src/main/kotlin/Heater.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/Heater.kt similarity index 73% rename from maven/dagger-maven-example/src/main/kotlin/Heater.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/Heater.kt index f2ec5dabcc..76136d2454 100755 --- a/maven/dagger-maven-example/src/main/kotlin/Heater.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/Heater.kt @@ -1,7 +1,9 @@ -package coffee +package examples.dagger interface Heater { + fun on() fun off() val isHot: Boolean + } diff --git a/maven/dagger-maven-example/src/main/kotlin/Pump.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/Pump.kt similarity index 57% rename from maven/dagger-maven-example/src/main/kotlin/Pump.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/Pump.kt index 5c45453898..eedd32c249 100755 --- a/maven/dagger-maven-example/src/main/kotlin/Pump.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/Pump.kt @@ -1,5 +1,7 @@ -package coffee +package examples.dagger interface Pump { + fun pump() + } diff --git a/maven/dagger-maven-example/src/main/kotlin/PumpModule.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/PumpModule.kt similarity index 84% rename from maven/dagger-maven-example/src/main/kotlin/PumpModule.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/PumpModule.kt index a892e2b770..d6cab61448 100755 --- a/maven/dagger-maven-example/src/main/kotlin/PumpModule.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/PumpModule.kt @@ -1,10 +1,12 @@ -package coffee +package examples.dagger import dagger.Binds import dagger.Module @Module abstract class PumpModule { + @Binds abstract fun providePump(pump: Thermosiphon): Pump + } diff --git a/maven/dagger-maven-example/src/main/kotlin/Thermosiphon.kt b/maven/dagger-example/src/main/kotlin/examples/dagger/Thermosiphon.kt similarity index 56% rename from maven/dagger-maven-example/src/main/kotlin/Thermosiphon.kt rename to maven/dagger-example/src/main/kotlin/examples/dagger/Thermosiphon.kt index 09c84cff05..7cba4ce40f 100755 --- a/maven/dagger-maven-example/src/main/kotlin/Thermosiphon.kt +++ b/maven/dagger-example/src/main/kotlin/examples/dagger/Thermosiphon.kt @@ -1,12 +1,15 @@ -package coffee +package examples.dagger import javax.inject.Inject -class Thermosiphon @Inject -constructor(private val heater: Heater) : Pump { +class Thermosiphon @Inject constructor( + private val heater: Heater +) : Pump { + override fun pump() { if (heater.isHot) { println("=> => pumping => =>") } } + } diff --git a/maven/dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt b/maven/dagger-example/src/test/kotlin/examples/dagger/ExampleTest.kt similarity index 72% rename from maven/dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt rename to maven/dagger-example/src/test/kotlin/examples/dagger/ExampleTest.kt index 9b3f523e86..13168a7284 100644 --- a/maven/dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt +++ b/maven/dagger-example/src/test/kotlin/examples/dagger/ExampleTest.kt @@ -1,24 +1,26 @@ -package hello.tests +package examples.dagger -import coffee.* import dagger.Component import dagger.Module import dagger.Provides -import junit.framework.TestCase +import org.junit.Test import javax.inject.Singleton private var executed = false -class ExampleTest : TestCase() { +class ExampleTest { + @Singleton - @Component(modules = arrayOf(TestCoffeeModule::class)) + @Component(modules = [TestCoffeeModule::class]) interface Coffee { fun maker(): CoffeeMaker } - @Module(includes = arrayOf(PumpModule::class)) + @Module(includes = [PumpModule::class]) class TestCoffeeModule { - @Provides @Singleton + + @Provides + @Singleton fun provideHeater(): Heater { return object: ElectricHeater() { override fun on() { @@ -31,9 +33,11 @@ class ExampleTest : TestCase() { } } - fun testAssert() { + @Test + fun shouldBrewCoffee() { val coffee = DaggerExampleTest_Coffee.builder().build() coffee.maker().brew() assert(executed) } + } diff --git a/maven/dagger-maven-example/.gitignore b/maven/dagger-maven-example/.gitignore deleted file mode 100644 index 2a332e7de9..0000000000 --- a/maven/dagger-maven-example/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -target -.idea - -.settings/ -.classpath -.project diff --git a/maven/dagger-maven-example/src/main/kotlin/CoffeeApp.kt b/maven/dagger-maven-example/src/main/kotlin/CoffeeApp.kt deleted file mode 100755 index 9e1d910ef4..0000000000 --- a/maven/dagger-maven-example/src/main/kotlin/CoffeeApp.kt +++ /dev/null @@ -1,18 +0,0 @@ -package coffee - -import dagger.Component -import javax.inject.Singleton - -object CoffeeApp { - @Singleton - @Component(modules = arrayOf(DripCoffeeModule::class)) - interface Coffee { - fun maker(): CoffeeMaker - } - - @JvmStatic - fun main(args: Array) { - val coffee = DaggerCoffeeApp_Coffee.builder().build() - coffee.maker().brew() - } -} diff --git a/maven/dokka-maven-example/Module.md b/maven/dokka-example/MODULE.md similarity index 83% rename from maven/dokka-maven-example/Module.md rename to maven/dokka-example/MODULE.md index f490749a8d..50299325b0 100644 --- a/maven/dokka-maven-example/Module.md +++ b/maven/dokka-example/MODULE.md @@ -1,4 +1,4 @@ -# Module dokka-maven-example +# Module dokka-example This is an example of how you can write module documentation with Dokka. diff --git a/maven/dokka-maven-example/pom.xml b/maven/dokka-example/pom.xml similarity index 71% rename from maven/dokka-maven-example/pom.xml rename to maven/dokka-example/pom.xml index f5b64e757b..3249cb2b42 100644 --- a/maven/dokka-maven-example/pom.xml +++ b/maven/dokka-example/pom.xml @@ -2,24 +2,21 @@ + 4.0.0 - org.jetbrains.kotlin.examples - kotlin-maven-example - 1.0-SNAPSHOT + + org.jetbrains.kotlin + kotlin-examples + 1.0-SNAPSHOT + + + dokka-example + - 1.0.3 - 0.10.0 + 1.4.10 - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - ${project.basedir}/src/main/kotlin @@ -32,18 +29,14 @@ compile - compile compile - - - - test-compile - test-compile - - test-compile - + + + src/main/kotlin + + @@ -63,12 +56,12 @@ - Module.md + MODULE.md ${project.basedir} - https://github.com/JetBrains/kotlin-examples/blob/master/maven/dokka-maven-example + https://github.com/JetBrains/kotlin-examples/blob/master/maven/dokka-example #L diff --git a/maven/dokka-maven-example/src/main/kotlin/HelloWorld.kt b/maven/dokka-example/src/main/kotlin/examples/dokka/HelloWorld.kt similarity index 93% rename from maven/dokka-maven-example/src/main/kotlin/HelloWorld.kt rename to maven/dokka-example/src/main/kotlin/examples/dokka/HelloWorld.kt index 172e18f7cf..df2c9ba856 100644 --- a/maven/dokka-maven-example/src/main/kotlin/HelloWorld.kt +++ b/maven/dokka-example/src/main/kotlin/examples/dokka/HelloWorld.kt @@ -1,4 +1,4 @@ -package demo +package examples.dokka /** * This class supports greeting people by name. diff --git a/maven/hello-world/ReadMe.md b/maven/hello-world/README.md similarity index 79% rename from maven/hello-world/ReadMe.md rename to maven/hello-world/README.md index 0dc3e5ffd4..cddcb34162 100644 --- a/maven/hello-world/ReadMe.md +++ b/maven/hello-world/README.md @@ -12,8 +12,8 @@ If you have maven on your path, simple type: mvn test It will compile: - * src/main/kotlin/Hello.kt into target/classes/hello/HelloKt.class - * src/test/kotlin/HelloTest.kt into target/test-classes/hello/tests/HelloTest.class + * `src/main/kotlin/examples/helloworld/Hello.kt` into `target/classes/examples/helloworld/HelloKt.class` + * `src/test/kotlin/examples/helloworld/HelloTest.kt` into `target/test-classes/examples/helloworld/HelloTest.class` Then run tests, and finally run your main HelloKt class. diff --git a/maven/hello-world/pom.xml b/maven/hello-world/pom.xml index 4f575aed0c..0d489a9ee3 100644 --- a/maven/hello-world/pom.xml +++ b/maven/hello-world/pom.xml @@ -1,53 +1,24 @@ - + 4.0.0 - org.jetbrains.kotlin.examples - hello-world - 1.0-SNAPSHOT - - - 1.0.3 - 4.12 - hello.HelloKt - UTF-8 - + + org.jetbrains.kotlin + kotlin-examples + 1.0-SNAPSHOT + - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - - junit - junit - ${junit.version} - test - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - test - - + hello-world - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - kotlin-maven-plugin org.jetbrains.kotlin ${kotlin.version} - - compile @@ -65,35 +36,6 @@ - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - true - ${main.class} - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - test - - java - - - - - ${main.class} - - diff --git a/maven/hello-world/src/main/kotlin/Hello.kt b/maven/hello-world/src/main/kotlin/examples/helloworld/Hello.kt similarity index 66% rename from maven/hello-world/src/main/kotlin/Hello.kt rename to maven/hello-world/src/main/kotlin/examples/helloworld/Hello.kt index a31d8caf76..95add1f534 100644 --- a/maven/hello-world/src/main/kotlin/Hello.kt +++ b/maven/hello-world/src/main/kotlin/examples/helloworld/Hello.kt @@ -1,10 +1,9 @@ -package hello +package examples.helloworld fun getHelloString() : String { return "Hello, world!" } -fun main(args : Array) { +fun main() { println(getHelloString()) } - diff --git a/maven/hello-world/src/test/kotlin/HelloTest.kt b/maven/hello-world/src/test/kotlin/HelloTest.kt deleted file mode 100644 index ac4d52a9c6..0000000000 --- a/maven/hello-world/src/test/kotlin/HelloTest.kt +++ /dev/null @@ -1,11 +0,0 @@ -package hello.tests - -import hello.getHelloString -import kotlin.test.assertEquals -import org.junit.Test - -class HelloTest { - @Test fun testAssert() : Unit { - assertEquals("Hello, world!", getHelloString()) - } -} diff --git a/maven/hello-world/src/test/kotlin/examples/helloworld/HelloTest.kt b/maven/hello-world/src/test/kotlin/examples/helloworld/HelloTest.kt new file mode 100644 index 0000000000..b94e3bc6de --- /dev/null +++ b/maven/hello-world/src/test/kotlin/examples/helloworld/HelloTest.kt @@ -0,0 +1,13 @@ +package examples.helloworld + +import org.junit.Assert +import org.junit.Test + +class HelloTest { + + @Test + fun shouldReturnCorrectString() { + Assert.assertEquals("Hello, world!", getHelloString()) + } + +} diff --git a/maven/interop-example/pom.xml b/maven/interop-example/pom.xml new file mode 100644 index 0000000000..c762b13100 --- /dev/null +++ b/maven/interop-example/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-examples + 1.0-SNAPSHOT + + + interop-example + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + + compile + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/main/java + + + + + test-compile + + test-compile + + + + ${project.basedir}/src/test/kotlin + ${project.basedir}/src/test/java + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + diff --git a/maven/interop-example/src/main/java/examples/interop/JavaHello.java b/maven/interop-example/src/main/java/examples/interop/JavaHello.java new file mode 100644 index 0000000000..c4b5fd6c64 --- /dev/null +++ b/maven/interop-example/src/main/java/examples/interop/JavaHello.java @@ -0,0 +1,11 @@ +package examples.interop; + +public class JavaHello { + + public static String JavaHelloString = "Hello from Java!"; + + public static String getHelloStringFromKotlin() { + return KotlinHelloKt.getKotlinHelloString(); + } + +} diff --git a/maven/mixed-code-hello-world/src/main/kotlin/hello/KotlinHello.kt b/maven/interop-example/src/main/kotlin/examples/interop/KotlinHello.kt similarity index 84% rename from maven/mixed-code-hello-world/src/main/kotlin/hello/KotlinHello.kt rename to maven/interop-example/src/main/kotlin/examples/interop/KotlinHello.kt index e3b430b217..538603c1cc 100644 --- a/maven/mixed-code-hello-world/src/main/kotlin/hello/KotlinHello.kt +++ b/maven/interop-example/src/main/kotlin/examples/interop/KotlinHello.kt @@ -1,4 +1,4 @@ -package hello +package examples.interop val KotlinHelloString : String = "Hello from Kotlin!" diff --git a/maven/interop-example/src/test/java/examples/interop/tests/HelloTest.java b/maven/interop-example/src/test/java/examples/interop/tests/HelloTest.java new file mode 100644 index 0000000000..0be25c3a99 --- /dev/null +++ b/maven/interop-example/src/test/java/examples/interop/tests/HelloTest.java @@ -0,0 +1,16 @@ +package examples.interop.tests; + +import examples.interop.JavaHello; +import examples.interop.KotlinHelloKt; +import org.junit.Assert; +import org.junit.Test; + +public class HelloTest { + + @Test + public void shouldRetrieveCorrectStringsViaInterop() { + Assert.assertEquals("Hello from Kotlin!", JavaHello.getHelloStringFromKotlin()); + Assert.assertEquals("Hello from Java!", KotlinHelloKt.getHelloStringFromJava()); + } + +} diff --git a/maven/kotlin-querydsl/.gitignore b/maven/kotlin-querydsl/.gitignore deleted file mode 100755 index 4286515b69..0000000000 --- a/maven/kotlin-querydsl/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -.DS_Store - -generated -generated_tests - -.idea/ -*.iml -*.iws -*.ipr - -target/ \ No newline at end of file diff --git a/maven/kotlin-querydsl/pom.xml b/maven/kotlin-querydsl/pom.xml deleted file mode 100644 index 0caf752507..0000000000 --- a/maven/kotlin-querydsl/pom.xml +++ /dev/null @@ -1,187 +0,0 @@ - - - - 4.0.0 - - org.jetbrains.kotlin.examples - querydsl-maven-example - 1.0-SNAPSHOT - - - 1.2-SNAPSHOT - 4.12 - ru.trylogic.querydsl.example.Test - UTF-8 - - - - - com.mysema.querydsl - querydsl-jpa - 3.6.3 - - - com.h2database - h2 - 1.4.187 - - - org.hibernate - hibernate-entitymanager - 4.3.5.Final - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - junit - junit - ${junit.version} - test - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - - kapt - - kapt - - - - src/main/kotlin - - - - - com.mysema.querydsl - querydsl-apt - 3.6.3 - jpa - - - - - - compile - - compile - - - - src/main/kotlin - src/main/java - - - - - test-kapt - - test-kapt - - - - src/test/kotlin - src/test/java - - - - com.google.dagger - dagger-compiler - 2.9 - - - - - - test-compile - - test-compile - - - - src/test/kotlin - src/test/java - target/generated-sources/kapt/test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - none - 1.6 - 1.6 - - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - - compile - - - - java-test-compile - test-compile - testCompile - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - true - ${main.class} - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - test - - java - - - - - ${main.class} - - - - - diff --git a/maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/Test.kt b/maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/Test.kt deleted file mode 100755 index ad76dd52bf..0000000000 --- a/maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/Test.kt +++ /dev/null @@ -1,51 +0,0 @@ -package ru.trylogic.querydsl.example - -import com.mysema.query.jpa.impl.JPAQuery -import org.hibernate.Hibernate -import org.hibernate.SessionFactory -import org.hibernate.cfg.Configuration -import org.hibernate.cfg.Environment - -import javax.persistence.EntityManager -import javax.persistence.EntityManagerFactory -import javax.persistence.EntityTransaction -import javax.persistence.Persistence -import java.util.HashMap - -import ru.trylogic.querydsl.example.QUser.user - -object Test { - @JvmStatic - fun main(args: Array) = Persistence.createEntityManagerFactory("unit").use { emf -> - emf.createEntityManager().use { entityManager -> - val transaction = entityManager.transaction - transaction.begin() - - with (entityManager) { - persist(User("Smith")) - persist(User("Gates")) - persist(User("Orlov")) - persist(User("Smirnov")) - persist(User("Orlov")) - - flush() - } - - transaction.commit() - - val query = JPAQuery(entityManager) - - val uniqueUserNames = query.from(user) - .where(user.name.like("%ov")) - .groupBy(user.name) - .list(user.name) - - println("Unique names: ") - uniqueUserNames.forEach { println(it) } - } - } -} - -inline fun EntityManagerFactory.use(f: (EntityManagerFactory) -> T) = try { f(this) } finally { close() } - -inline fun EntityManager.use(f: (EntityManager) -> T) = try { f(this) } finally { close() } \ No newline at end of file diff --git a/maven/mixed-code-hello-world/.gitignore b/maven/mixed-code-hello-world/.gitignore deleted file mode 100644 index 2a332e7de9..0000000000 --- a/maven/mixed-code-hello-world/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -target -.idea - -.settings/ -.classpath -.project diff --git a/maven/mixed-code-hello-world/pom.xml b/maven/mixed-code-hello-world/pom.xml deleted file mode 100644 index 7ce35b4376..0000000000 --- a/maven/mixed-code-hello-world/pom.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - 4.0.0 - - org.jetbrains.kotlin.examples - mixed-code-hello-world - 1.0-SNAPSHOT - - - 1.0.1-2 - 4.12 - kotlin.KotlinHelloKt - UTF-8 - - - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - - junit - junit - ${junit.version} - test - - - org.jetbrains.kotlin - kotlin-test-junit - ${kotlin.version} - test - - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - compile - compile - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/java - - - - - test-compile - test-compile - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - compile - - - java-test-compile - test-compile - testCompile - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - true - ${main.class} - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.6 - - - make-assembly - package - single - - - - ${main.class} - - - - jar-with-dependencies - - - - - - - - diff --git a/maven/mixed-code-hello-world/src/main/java/hello/JavaHello.java b/maven/mixed-code-hello-world/src/main/java/hello/JavaHello.java deleted file mode 100644 index b41f759c02..0000000000 --- a/maven/mixed-code-hello-world/src/main/java/hello/JavaHello.java +++ /dev/null @@ -1,14 +0,0 @@ -package hello; - -public class JavaHello { - public static String JavaHelloString = "Hello from Java!"; - - public static String getHelloStringFromKotlin() { - return KotlinHelloKt.getKotlinHelloString(); - } - - public static void main(String[] args) { - System.out.println(getHelloStringFromKotlin()); - System.out.println(KotlinHelloKt.getHelloStringFromJava()); - } -} diff --git a/maven/mixed-code-hello-world/src/test/java/hello/tests/HelloTest.java b/maven/mixed-code-hello-world/src/test/java/hello/tests/HelloTest.java deleted file mode 100644 index b99e444fc0..0000000000 --- a/maven/mixed-code-hello-world/src/test/java/hello/tests/HelloTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package hello.tests; - -import hello.JavaHello; -import junit.framework.TestCase; - -public class HelloTest extends TestCase { - public void testAssert() { - assertEquals("Hello from Kotlin!", JavaHello.getHelloStringFromKotlin()); - assertEquals("Hello from Java!", hello.KotlinHelloKt.getHelloStringFromJava()); - - System.out.println(hello.KotlinHelloKt.getHelloStringFromJava()); - } -} diff --git a/maven/pom.xml b/maven/pom.xml index 26fc47e5b4..6ca4f89bd0 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -1,17 +1,84 @@ - + 4.0.0 org.jetbrains.kotlin kotlin-examples - 0.1-SNAPSHOT + 1.0-SNAPSHOT pom + + UTF-8 + 1.4.10 + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + junit + junit + 4.13 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + none + 1.8 + 1.8 + + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + + + dagger-example + dokka-example hello-world - mixed-code-hello-world + interop-example + querydsl-example + diff --git a/maven/kotlin-querydsl/LICENSE.txt b/maven/querydsl-example/LICENSE.txt similarity index 100% rename from maven/kotlin-querydsl/LICENSE.txt rename to maven/querydsl-example/LICENSE.txt diff --git a/maven/querydsl-example/pom.xml b/maven/querydsl-example/pom.xml new file mode 100644 index 0000000000..8f270a6b69 --- /dev/null +++ b/maven/querydsl-example/pom.xml @@ -0,0 +1,115 @@ + + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-examples + 1.0-SNAPSHOT + + + querydsl-example + + + 4.4.0 + + + + + com.querydsl + querydsl-jpa + ${querydsl.version} + + + com.h2database + h2 + 1.4.200 + + + org.hibernate + hibernate-entitymanager + 5.4.22.Final + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + kapt + + kapt + + + + src/main/kotlin + + + + com.querydsl + querydsl-apt + ${querydsl.version} + jpa + + + + + + compile + + compile + + + + src/main/kotlin + + + + + test-kapt + + test-kapt + + + + src/test/kotlin + + + + com.querydsl + querydsl-apt + ${querydsl.version} + jpa + + + + + + test-compile + + test-compile + + + + src/test/kotlin + target/generated-sources/kapt/test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + diff --git a/maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/User.kt b/maven/querydsl-example/src/main/kotlin/examples/querydsl/User.kt similarity index 83% rename from maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/User.kt rename to maven/querydsl-example/src/main/kotlin/examples/querydsl/User.kt index d5e0d7c30c..8bf1141a79 100755 --- a/maven/kotlin-querydsl/src/main/kotlin/ru/trylogic/querydsl/example/User.kt +++ b/maven/querydsl-example/src/main/kotlin/examples/querydsl/User.kt @@ -1,4 +1,4 @@ -package ru.trylogic.querydsl.example +package examples.querydsl import javax.persistence.Entity import javax.persistence.GeneratedValue @@ -8,4 +8,5 @@ import javax.persistence.Id @Entity class User( val name: String, - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Int = 0) \ No newline at end of file + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Int = 0 +) diff --git a/maven/kotlin-querydsl/src/main/resources/META-INF/persistence.xml b/maven/querydsl-example/src/main/resources/META-INF/persistence.xml similarity index 93% rename from maven/kotlin-querydsl/src/main/resources/META-INF/persistence.xml rename to maven/querydsl-example/src/main/resources/META-INF/persistence.xml index 7f37a360ca..bbfdfd70cd 100755 --- a/maven/kotlin-querydsl/src/main/resources/META-INF/persistence.xml +++ b/maven/querydsl-example/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,7 @@ org.hibernate.jpa.HibernatePersistenceProvider - ru.trylogic.querydsl.example.User + examples.querydsl.User diff --git a/maven/querydsl-example/src/test/kotlin/examples/querydsl/PersistenceTest.kt b/maven/querydsl-example/src/test/kotlin/examples/querydsl/PersistenceTest.kt new file mode 100755 index 0000000000..19119ce2b1 --- /dev/null +++ b/maven/querydsl-example/src/test/kotlin/examples/querydsl/PersistenceTest.kt @@ -0,0 +1,48 @@ +package examples.querydsl + +import com.querydsl.jpa.impl.JPAQuery + +import javax.persistence.EntityManager +import javax.persistence.EntityManagerFactory +import javax.persistence.Persistence + +import examples.querydsl.QUser.user +import org.junit.Assert +import org.junit.Test + +class PersistenceTest { + + @Test + fun shouldSaveAndRetrieveEntity() { + Persistence.createEntityManagerFactory("unit").use { emf -> + emf.createEntityManager().use { entityManager -> + val transaction = entityManager.transaction + transaction.begin() + + with(entityManager) { + persist(User("Smith")) + persist(User("Gates")) + persist(User("Orlov")) + persist(User("Smirnov")) + persist(User("Orlov")) + + flush() + } + + transaction.commit() + + val query = JPAQuery(entityManager) + + val uniqueUserNames = query.from(user) + .where(user.name.like("%ov")) + .groupBy(user.name) + .fetchCount() + + Assert.assertEquals(2, uniqueUserNames) + } + } + } +} + +inline fun EntityManagerFactory.use(f: (EntityManagerFactory) -> T) = try { f(this) } finally { close() } +inline fun EntityManager.use(f: (EntityManager) -> T) = try { f(this) } finally { close() }