diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 7f6f337e8a906..8a07bb6f047cb 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -19,18 +19,14 @@ package org.elasticsearch.gradle.plugin import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin -import nebula.plugin.info.scm.ScmInfoPlugin +import groovy.xml.XmlUtil import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.NoticeTask import org.elasticsearch.gradle.test.RestIntegTestTask import org.elasticsearch.gradle.test.RunTask import org.gradle.api.InvalidUserDataException -import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.XmlProvider -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.bundling.Zip @@ -69,16 +65,16 @@ public class PluginBuildPlugin extends BuildPlugin { String name = project.pluginProperties.extension.name project.archivesBaseName = name + // while the jar isn't normally published, we still at least build a pom of deps + // in case it is published, for instance when other plugins extend this plugin + configureJarPom(project) + if (project.pluginProperties.extension.hasClientJar) { // for plugins which work with the transport client, we copy the jar // file to a new name, copy the nebula generated pom to the same name, // and generate a different pom for the zip - addClientJarPomGeneration(project) addClientJarTask(project) } - // while the jar isn't normally published, we still at least build a pom of deps - // in case it is published, for instance when other plugins extend this plugin - configureJarPom(project) project.integTestCluster.dependsOn(project.bundlePlugin) project.tasks.run.dependsOn(project.bundlePlugin) @@ -169,21 +165,42 @@ public class PluginBuildPlugin extends BuildPlugin { project.artifacts.add('zip', bundle) } + /** Find the reponame. */ + static String urlFromOrigin(String origin) { + if (origin == null) { + return null // best effort, the url doesnt really matter, it is just required by maven central + } + if (origin.startsWith('https')) { + return origin + } + Matcher matcher = GIT_PATTERN.matcher(origin) + if (matcher.matches()) { + return "https://${matcher.group(1)}/${matcher.group(2)}" + } else { + return origin // best effort, the url doesnt really matter, it is just required by maven central + } + } + + static final Pattern GIT_PATTERN = Pattern.compile(/git@([^:]+):([^\.]+)\.git/) + /** Adds a task to move jar and associated files to a "-client" name. */ protected static void addClientJarTask(Project project) { Task clientJar = project.tasks.create('clientJar') - clientJar.dependsOn(project.jar, project.tasks.generatePomFileForClientJarPublication, project.javadocJar, project.sourcesJar) + clientJar.dependsOn(project.jar, project.tasks.generatePomFileForNebulaPublication, project.javadocJar, project.sourcesJar) clientJar.doFirst { Path jarFile = project.jar.outputs.files.singleFile.toPath() String clientFileName = jarFile.fileName.toString().replace(project.version, "client-${project.version}") Files.copy(jarFile, jarFile.resolveSibling(clientFileName), StandardCopyOption.REPLACE_EXISTING) + // We need to change the artifact name in the nebula pom String clientPomFileName = clientFileName.replace('.jar', '.pom') - Files.copy( - project.tasks.generatePomFileForClientJarPublication.outputs.files.singleFile.toPath(), - jarFile.resolveSibling(clientPomFileName), - StandardCopyOption.REPLACE_EXISTING - ) + Node pom = new XmlParser() + .parse(project.tasks.generatePomFileForNebulaPublication.outputs.files.singleFile) + pom.artifactId[0].value = project.name + "-client" + jarFile.resolveSibling(clientPomFileName).toFile().text = XmlUtil.serialize(pom) + // Groovy has an odd way of formatting the XML, fix it up3 + .replaceAll(/\n\s*\n/, "\n") + .replace("\"UTF-8\"?>\n - Node root = xml.asNode() - root.appendNode('name', project.pluginProperties.extension.name) - root.appendNode('description', project.pluginProperties.extension.description) - root.appendNode('url', urlFromOrigin(project.scminfo.origin)) - Node scmNode = root.appendNode('scm') - scmNode.appendNode('url', project.scminfo.origin) - } - } - } - } - } - /** Configure the pom for the main jar of this plugin */ protected static void configureJarPom(Project project) { - project.plugins.apply(ScmInfoPlugin.class) - project.plugins.apply(MavenPublishPlugin.class) - - project.publishing { - publications { - nebula(MavenPublication) { - artifactId project.pluginProperties.extension.name - } - } - } + project.plugins.apply(nebula.plugin.publishing.maven.MavenScmPlugin.class) + // have the nebula plugin set the correct description + project.description = project.pluginProperties.extension.description } protected void addNoticeGeneration(Project project) { diff --git a/modules/transport-netty4/build.gradle b/modules/transport-netty4/build.gradle index 5d4bcd7c10a84..2a18815fde184 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -23,6 +23,7 @@ * fix the hack in the build framework that copies transport-netty4 into the integ test cluster * maybe figure out a way to run all tests from core with netty4/network? */ + esplugin { description 'Netty 4 based transport implementation' classname 'org.elasticsearch.transport.Netty4Plugin' diff --git a/x-pack/plugin/core/build.gradle b/x-pack/plugin/core/build.gradle index ca926fa0d54cc..5db149bc6774e 100644 --- a/x-pack/plugin/core/build.gradle +++ b/x-pack/plugin/core/build.gradle @@ -6,8 +6,6 @@ import java.nio.file.Paths import java.nio.file.StandardCopyOption apply plugin: 'elasticsearch.esplugin' -apply plugin: 'nebula.maven-base-publish' -apply plugin: 'nebula.maven-scm' archivesBaseName = 'x-pack-core'