-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Gradle] Some tweaks to transport related build logic #133413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
3248d0c
86fc83b
9861447
066f879
8c06add
cd833dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.provider.ProviderFactory; | ||
import org.gradle.api.services.BuildService; | ||
import org.gradle.api.services.BuildServiceParameters; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
|
||
public abstract class ProjectSubscribeBuildService implements BuildService<BuildServiceParameters.None> { | ||
|
||
private final ProviderFactory providerFactory; | ||
|
||
/** | ||
* The filling of this map depends on the order of #registerProjectForTopic being called. | ||
* This is usually done during configuration phase, but we do not enforce yet the time of this method call. | ||
* The values are LinkedHashSet to preserve the order of registration mostly to provide a predicatable order | ||
* when running consecutive builds. | ||
* */ | ||
private Map<String, Collection<String>> versionsByTopic = new HashMap<>(); | ||
|
||
@Inject | ||
public ProjectSubscribeBuildService(ProviderFactory providerFactory) { | ||
this.providerFactory = providerFactory; | ||
} | ||
|
||
/** | ||
* Returning a provider so the evaluation of the map value is deferred to when the provider is queried. | ||
* */ | ||
public Provider<Collection<String>> getProjectsByTopic(String topic) { | ||
return providerFactory.provider(() -> versionsByTopic.computeIfAbsent(topic, k -> new java.util.LinkedHashSet<>())); | ||
} | ||
|
||
public void registerProjectForTopic(String topic, Project project) { | ||
versionsByTopic.computeIfAbsent(topic, k -> new java.util.LinkedHashSet<>()).add(project.getPath()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.provider.Provider; | ||
|
||
/** | ||
* This plugin registers a {@link ProjectSubscribeBuildService} to allow projects to | ||
* communicate with each other during the configuration phase. | ||
* | ||
* For example, a project can register itself as a publisher of a topic, and other | ||
* projects can resolve projects that have registered as publishers of that topic. | ||
* | ||
* The actual resolution of whatever data is usually done using dependency declarations. | ||
* Be aware the state of the list depends on the order of project configuration and | ||
* consuming on configuration phase before task graph calculation phase should be avoided. | ||
* | ||
* We want to avoid discouraged plugin api usage like project.allprojects or project.subprojects | ||
* in plugins to avoid unnecessary configuration of projects and not break project isolation and break | ||
* See https://docs.gradle.org/current/userguide/isolated_projects.html | ||
* */ | ||
public class ProjectSubscribeServicePlugin implements Plugin<Project> { | ||
|
||
private Provider<ProjectSubscribeBuildService> publishSubscribe; | ||
|
||
@Override | ||
public void apply(Project project) { | ||
publishSubscribe = project.getGradle().getSharedServices().registerIfAbsent("publishSubscribe", ProjectSubscribeBuildService.class); | ||
} | ||
|
||
public Provider<ProjectSubscribeBuildService> getService() { | ||
return publishSubscribe; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
import org.gradle.api.tasks.PathSensitive; | ||
import org.gradle.api.tasks.PathSensitivity; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.VerificationException; | ||
import org.gradle.api.tasks.VerificationTask; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
@@ -38,7 +40,7 @@ | |
* Validates that each defined transport version constant is referenced by at least one project. | ||
*/ | ||
@CacheableTask | ||
public abstract class ValidateTransportVersionResourcesTask extends DefaultTask { | ||
public abstract class ValidateTransportVersionResourcesTask extends DefaultTask implements VerificationTask { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we throwing error messages that align with this expecation? My understanding was that Develocity also requires the failure message to match a certain pattern. See https://docs.gradle.com/develocity/failure-classification/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! I was too naive here thinking using the task interface is enough. I'll have a quick look here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the throwing exceptions here |
||
|
||
@InputDirectory | ||
@Optional | ||
|
@@ -255,11 +257,11 @@ private void validateBase(int base, List<IdAndDefinition> ids) { | |
|
||
private void throwDefinitionFailure(TransportVersionDefinition definition, String message) { | ||
Path relativePath = getResources().get().getReferableDefinitionRepositoryPath(definition); | ||
throw new IllegalStateException("Transport version definition file [" + relativePath + "] " + message); | ||
throw new VerificationException("Transport version definition file [" + relativePath + "] " + message); | ||
} | ||
|
||
private void throwUpperBoundFailure(TransportVersionUpperBound upperBound, String message) { | ||
Path relativePath = getResources().get().getUpperBoundRepositoryPath(upperBound); | ||
throw new IllegalStateException("Transport version upper bound file [" + relativePath + "] " + message); | ||
throw new VerificationException("Transport version upper bound file [" + relativePath + "] " + message); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this can be final