From 32490124f56b1297e7a20fa7122890794c324f7a Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Thu, 19 Jul 2018 15:55:36 +0300 Subject: [PATCH 1/3] Auto add nebula plugin, keep a single publication Versions of Gradle before 4.9 don't support project that depend on other projects which have multiple jar publications, see gradle/gradle#1061. It just so happens that we upgraded master and 6.x to 4.9 recently, but 6.3 is still on Gradle 4.5 so the multi publications will break there. This change removes the client jar publication, since now the artifactId is the only one that differes, and adds the nebula configuration to the plugin so we don't rely on it's presence in the build scipt to generate a correct pom. Without the plugin applied, the generated dependencies would be empty. --- .../gradle/plugin/PluginBuildPlugin.groovy | 85 ++++--------------- modules/transport-netty4/build.gradle | 4 + x-pack/plugin/core/build.gradle | 2 - 3 files changed, 21 insertions(+), 70 deletions(-) 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..3960dc21ebf0d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -19,27 +19,20 @@ 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 import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption -import java.util.regex.Matcher -import java.util.regex.Pattern - /** * Encapsulates build configuration for an Elasticsearch plugin. */ @@ -69,16 +62,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) @@ -172,18 +165,21 @@ public class PluginBuildPlugin extends BuildPlugin { /** 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..b8c9292806db6 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -23,6 +23,10 @@ * 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? */ + +//apply plugin: 'nebula.maven-base-publish' +//apply plugin: 'nebula.maven-scm' + 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' From b416c992b5d4e8a05401690a3c248c554d8e7c19 Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Thu, 19 Jul 2018 16:14:05 +0300 Subject: [PATCH 2/3] Keep method, used elsewhere --- .../gradle/plugin/PluginBuildPlugin.groovy | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 3960dc21ebf0d..8a07bb6f047cb 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -33,6 +33,9 @@ import org.gradle.api.tasks.bundling.Zip import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption +import java.util.regex.Matcher +import java.util.regex.Pattern + /** * Encapsulates build configuration for an Elasticsearch plugin. */ @@ -162,6 +165,24 @@ 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') @@ -177,7 +198,7 @@ public class PluginBuildPlugin extends BuildPlugin { .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 + // Groovy has an odd way of formatting the XML, fix it up3 .replaceAll(/\n\s*\n/, "\n") .replace("\"UTF-8\"?>\n Date: Thu, 19 Jul 2018 16:19:19 +0300 Subject: [PATCH 3/3] remove commented code --- modules/transport-netty4/build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/transport-netty4/build.gradle b/modules/transport-netty4/build.gradle index b8c9292806db6..2a18815fde184 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -24,9 +24,6 @@ * maybe figure out a way to run all tests from core with netty4/network? */ -//apply plugin: 'nebula.maven-base-publish' -//apply plugin: 'nebula.maven-scm' - esplugin { description 'Netty 4 based transport implementation' classname 'org.elasticsearch.transport.Netty4Plugin'