-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3248d0c
[Gradle] Some tweaks to transport related build logic
breskeby 86fc83b
Address some review feedback
breskeby 9861447
Rework mapping project path list to dependencies
breskeby 066f879
Some more review feedback
breskeby 8c06add
Minor tweak after review feedback
breskeby cd833dc
Merge branch 'main' into gradle-transport-polishing
breskeby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...nternal/src/main/java/org/elasticsearch/gradle/internal/ProjectSubscribeBuildService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 final 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()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ternal/src/main/java/org/elasticsearch/gradle/internal/ProjectSubscribeServicePlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the throwing exceptions here