Skip to content

Commit

Permalink
Inspect only *.properties entries under META-INF/gradle-plugins/
Browse files Browse the repository at this point in the history
  • Loading branch information
bamboo authored and eskatos committed Mar 26, 2019
1 parent d8b3d55 commit 376b6cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Expand Up @@ -348,13 +348,22 @@ class PrecompiledScriptPluginAccessorsTest : AbstractPrecompiledScriptPluginTest
val pluginJar = jarForPlugin(pluginId, "MyPlugin")

withPrecompiledScriptApplying(pluginId, pluginJar)
assertPrecompiledScriptPluginApplies(
pluginId,
"Plugin_gradle"
)
}

private
fun assertPrecompiledScriptPluginApplies(pluginId: String, precompiledScriptClassName: String) {

compileKotlin()

val (project, pluginManager) = projectAndPluginManagerMocks()

instantiatePrecompiledScriptOf(
project,
"Plugin_gradle"
precompiledScriptClassName
)

inOrder(pluginManager) {
Expand All @@ -363,6 +372,27 @@ class PrecompiledScriptPluginAccessorsTest : AbstractPrecompiledScriptPluginTest
}
}

@Test
fun `can use plugin specs with jruby-gradle-plugin`() {

withKotlinDslPlugin().appendText("""
dependencies {
compile("com.github.jruby-gradle:jruby-gradle-plugin:1.4.0")
}
""")

withPrecompiledKotlinScript("plugin.gradle.kts", """
plugins {
com.github.`jruby-gradle`.base
}
""")

assertPrecompiledScriptPluginApplies(
"com.github.jruby-gradle.base",
"Plugin_gradle"
)
}

@Test
fun `plugin application errors are reported but don't cause the build to fail`() {

Expand Down
Expand Up @@ -22,6 +22,7 @@ import org.gradle.plugin.use.PluginDependencySpec
import java.io.File

import java.util.Properties
import java.util.jar.JarEntry
import java.util.jar.JarFile


Expand Down Expand Up @@ -248,11 +249,17 @@ internal
fun pluginEntriesFrom(jar: File): List<PluginEntry> =
JarFile(jar).use { jarFile ->
jarFile.entries().asSequence().filter {
it.isFile && it.name.startsWith("META-INF/gradle-plugins/")
isGradlePluginPropertiesFile(it)
}.map { pluginEntry ->
val pluginProperties = jarFile.getInputStream(pluginEntry).use { Properties().apply { load(it) } }
val id = pluginEntry.name.substringAfterLast("/").substringBeforeLast(".properties")
val implementationClass = pluginProperties.getProperty("implementation-class")
PluginEntry(id, implementationClass)
}.toList()
}


private
fun isGradlePluginPropertiesFile(entry: JarEntry) = entry.run {
isFile && name.run { startsWith("META-INF/gradle-plugins/") && endsWith(".properties") }
}

0 comments on commit 376b6cb

Please sign in to comment.