Skip to content

Commit

Permalink
Move public build api into included build (#72861)
Browse files Browse the repository at this point in the history
This moves the public build api and plugins into a separete included build called 'build-tools' 
and we removed the duplication of included buildSrc twice (2nd import as build-tools).

The elasticsearch internal build logic is kept in build-tools-internal as included build which allows us better handling of this project that its just being an buildSrc project (e.g. we can reference tasks directly from the root build etc.)

Convention logic applied to both projects will live in a new build-conventions project.
  • Loading branch information
breskeby committed Jun 1, 2021
1 parent 84def3c commit b2a183b
Show file tree
Hide file tree
Showing 477 changed files with 2,207 additions and 844 deletions.
53 changes: 53 additions & 0 deletions build-conventions/build.gradle
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

plugins {
id 'java-gradle-plugin'
id 'java-test-fixtures'
}

group = "org.elasticsearch"

def minRuntimeJava = JavaVersion.toVersion(file('../build-tools-internal/src/main/resources/minimumRuntimeVersion').text)
targetCompatibility = minRuntimeJava
sourceCompatibility = minRuntimeJava

gradlePlugin {
// We already configure publication and we don't need or want the one that comes
// with the java-gradle-plugin
automatedPublishing = false
plugins {
internalLicenseheaders {
id = 'elasticsearch.internal-licenseheaders'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin'
}
publish {
id = 'elasticsearch.publish'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.PublishPlugin'
}
licensing {
id = 'elasticsearch.licensing'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.LicensingPlugin'
}
basics {
id = 'elasticsearch.basic-build-tool-conventions'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.BasicBuildToolConventionsPlugin'
}
}
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
api 'org.apache.maven:maven-model:3.6.2'
api 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
api 'org.apache.rat:apache-rat:0.11'
}
8 changes: 8 additions & 0 deletions build-conventions/settings.gradle
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
rootProject.name = 'build-conventions'
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.conventions;

import org.elasticsearch.gradle.internal.conventions.info.ParallelDetector;
import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.testing.Test;

import java.io.File;

public class BasicBuildToolConventionsPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
int defaultParallel = ParallelDetector.findDefaultParallel(project);
project.getTasks().withType(Test.class).configureEach(test -> {
test.onlyIf((t) -> Util.getBooleanProperty("tests.fips.enabled", false) == false);
test.setMaxParallelForks(defaultParallel);
});
// we put all our distributable files under distributions
project.getTasks().withType(Jar.class).configureEach(j ->
j.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions"))
);
}
}
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.conventions;

import java.util.Locale;

public abstract class GUtils {

public static String capitalize(String s) {
return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1);
}
}
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.conventions;

import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
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 org.gradle.initialization.layout.BuildLayout;

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

class GitInfoPlugin implements Plugin<Project> {

private ProviderFactory factory;
private ObjectFactory objectFactory;

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

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

@Override
public void apply(Project project) {
File rootDir = (project.getGradle().getParent() == null) ?
project.getRootDir() :
project.getGradle().getParent().getRootProject().getRootDir();

gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
GitInfo.gitInfo(rootDir)
));
gitInfo.disallowChanges();
gitInfo.finalizeValueOnRead();

revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "master");
}

public Property<GitInfo> getGitInfo() {
return gitInfo;
}

public Provider<String> getRevision() {
return revision;
}
}
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.conventions;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

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

public class LicensingPlugin implements Plugin<Project> {
final static String ELASTIC_LICENSE_URL_PREFIX = "https://raw.githubusercontent.com/elastic/elasticsearch/";
final static String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";

private ProviderFactory providerFactory;

@Inject
public LicensingPlugin(ProviderFactory providerFactory) {
this.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().toString()
);

MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class);
Provider<String> projectLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
licenseCommit + 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", projectLicenseURL);

MapProperty<String, String> convention = licensesProperty.convention(
providerFactory.provider((Callable<Map<? extends String, ? extends String>>) () -> Map.of(
"Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
"Elastic License 2.0", projectLicenseURL.get())
)
);
// Default to the SSPL+Elastic dual license
project.getExtensions().getExtraProperties().set("licenseCommit", licenseCommitProvider);
project.getExtensions().getExtraProperties().set("projectLicenses", convention);
}

private boolean isSnapshotVersion(Project project) {
return project.getVersion().toString().endsWith("-SNAPSHOT");
}

}

0 comments on commit b2a183b

Please sign in to comment.