Merge pull request #20 from cgruber/fix_coffee_example
Update the dagger coffee example to use kt_jvm_library
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/Meta.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/Meta.kt
index ad2e772..fd76c8f 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/Meta.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/Meta.kt
@@ -54,12 +54,9 @@
}
}
-abstract class MandatoryMeta<T: Any>(override val defaultValue: T? = null): Meta<T> {
+open class MandatoryMeta<T: Any>(
+ override val id: String,
+ override val defaultValue: T? = null
+): Meta<T> {
override fun get(ctx: Context): T = checkNotNull(super.get(ctx)) { "ctx missing mandatory meta ${this.id}" }
-
- companion object {
- operator fun <T : Any> invoke(id: String): Meta<T> = object : MandatoryMeta<T>() {
- override val id: String = id
- }
- }
}
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
index b48b65e..21a677a 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
@@ -25,8 +25,8 @@
import io.bazel.ruleskotlin.workers.model.CompilePluginConfig
import io.bazel.ruleskotlin.workers.model.Flags
import io.bazel.ruleskotlin.workers.model.Metas
+import io.bazel.ruleskotlin.workers.utils.addAll
import io.bazel.ruleskotlin.workers.utils.annotationProcessingGeneratedJavaSources
-import java.util.*
// The Kotlin compiler is not suited for javac compilation as of 1.2.21. The errors are not conveyed directly and would need to be preprocessed, also javac
// invocations Configured via Kotlin use eager analysis in some corner cases this can result in classpath exceptions from the Java Compiler..
@@ -57,8 +57,10 @@
args.add(field.kotlinFlag!!); args.add(arg)
}
-// Collections.addAll(args, "-kotlin-home", KotlinToolchain.KOTLIN_HOME.toString())
- Collections.addAll(args, "-d", compileDirectories.classes.toString())
+ args
+ .addAll("-module-name", Metas.TARGET[ctx])
+ .addAll("-d", compileDirectories.classes.toString())
+
return args
}
@@ -68,7 +70,7 @@
val pluginStatus = CompilePluginConfig[ctx]
// run a kapt generation phase if needed.
- if(pluginStatus.hasAnnotationProcessors) {
+ if (pluginStatus.hasAnnotationProcessors) {
invokeCompilePhase(
args = mutableListOf(*commonArgs.toTypedArray()).let {
it.addAll(pluginStatus.args)
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/CompileState.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/CompileState.kt
index 88b29d1..05078ae 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/CompileState.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/CompileState.kt
@@ -47,12 +47,12 @@
}
}
- companion object: MandatoryMeta<CompileDirectories>()
+ companion object: MandatoryMeta<CompileDirectories>("compile_directories")
}
class CompilePluginConfig(
val hasAnnotationProcessors: Boolean = false,
val args: Array<String> = emptyArray()
): CompileState() {
- companion object: MandatoryMeta<CompilePluginConfig>(defaultValue = CompilePluginConfig())
+ companion object: MandatoryMeta<CompilePluginConfig>("plugin_config", defaultValue = CompilePluginConfig())
}
\ No newline at end of file
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Metas.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Metas.kt
index 0951c39..5c59ecd 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Metas.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Metas.kt
@@ -16,16 +16,15 @@
package io.bazel.ruleskotlin.workers.model
import io.bazel.ruleskotlin.workers.MandatoryMeta
-import io.bazel.ruleskotlin.workers.Meta
/**
* Listin of Meta keys that don't make sense as companion objects.
*/
object Metas {
// mandatory: the package part of the label.
- val PKG = Meta<String>("package")
+ val PKG = MandatoryMeta<String>("package")
// mandatory: The target part of the label.
- val TARGET = Meta<String>("target")
+ val TARGET = MandatoryMeta<String>("target")
// mandatory: If this is non empty then it is a mixed mode operation.
val JAVA_SOURCES = MandatoryMeta<List<String>>("java_sources")
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/utils/MiscUtils.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/utils/MiscUtils.kt
new file mode 100644
index 0000000..5ec7d8d
--- /dev/null
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/utils/MiscUtils.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2018 The Bazel Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.bazel.ruleskotlin.workers.utils
+
+fun <T, C: MutableCollection<T>> C.addAll(vararg entries: T): C = this.also { addAll(entries) }
\ No newline at end of file
diff --git a/tests/smoke/basic_tests.py b/tests/smoke/basic_tests.py
index c54dede..47589c3 100644
--- a/tests/smoke/basic_tests.py
+++ b/tests/smoke/basic_tests.py
@@ -38,6 +38,11 @@
def test_bin_targets_launch_correctly_with_data(self):
self.buildLaunchExpectingSuccess("helloworld")
+ def test_uses_target_name_as_default_module_name(self):
+ """tests that the target name is used as the default module name."""
+ jar = self.buildJarGetZipFile("helloworld", "jar")
+ self.assertJarContains(jar, "META-INF/helloworld.kotlin_module")
+
def test_conventional_strip_resources(self):
jar = self.buildJarGetZipFile("conventional_strip_resources", "jar")
self.assertJarContains(jar, "main.txt", "test.txt")