Skip to content

Commit d9ce8fe

Browse files
committed
Add more build logic
1 parent 281b587 commit d9ce8fe

16 files changed

+190
-16
lines changed

build-tools-internal/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ gradlePlugin {
236236
id = 'elasticsearch.validate-transport-versions'
237237
implementationClass = 'org.elasticsearch.gradle.internal.transport.ValidateTransportVersionsPlugin'
238238
}
239+
aggregateTransportVersionDeclarationsPlugin{
240+
id = 'elasticsearch.aggregate-transport-versionDeclarations-plugin'
241+
implementationClass = 'org.elasticsearch.gradle.internal.transport.AggregateTransportVersionDeclarationsPlugin'
242+
}
239243
}
240244
}
241245

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BaseInternalPluginBuildPlugin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.gradle.internal.info.BuildParameterExtension;
1616
import org.elasticsearch.gradle.internal.precommit.JarHellPrecommitPlugin;
1717
import org.elasticsearch.gradle.internal.test.ClusterFeaturesMetadataPlugin;
18+
import org.elasticsearch.gradle.internal.transport.LocateTransportVersionsPlugin;
1819
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
1920
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension;
2021
import org.elasticsearch.gradle.util.GradleUtils;
@@ -36,6 +37,16 @@ public void apply(Project project) {
3637
project.getPluginManager().apply(JarHellPrecommitPlugin.class);
3738
project.getPluginManager().apply(ElasticsearchJavaPlugin.class);
3839
project.getPluginManager().apply(ClusterFeaturesMetadataPlugin.class);
40+
// We need to wire this up
41+
/*
42+
Old way is to set up a config here, then depend on it in the other plugin.
43+
The new way is called variant aware artifacts or something
44+
Basically attach some attributes to the artifacts
45+
Then those attributes are how we are tying this together.
46+
Now instead of saying I want this specific config, we now say I want the artifact from this project that has these attributes
47+
48+
*/
49+
project.getPluginManager().apply(LocateTransportVersionsPlugin.class);
3950
boolean isCi = project.getRootProject().getExtensions().getByType(BuildParameterExtension.class).getCi();
4051
// Clear default dependencies added by public PluginBuildPlugin as we add our
4152
// own project dependencies for internal builds
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.transport;
11+
12+
import org.gradle.api.Plugin;
13+
import org.gradle.api.Project;
14+
15+
import java.util.Map;
16+
17+
public class AggregateTransportVersionDeclarationsPlugin implements Plugin<Project> {
18+
@Override
19+
public void apply(Project project) {
20+
// need to have this task depend on all the tasks with BaseInternalPluginBuildPlugin registered
21+
// need to get the output of all those tasks as input to this task
22+
System.out.println("Potato: AggregateTransportVersionDeclarationsPlugin");
23+
// First thing is to create a configuration (holder for dependency information. Configurations are how the dep graph is modeled).
24+
var configuration = project.getConfigurations().create("aggregateTransportVersionDeclarations");
25+
var deps = project.getDependencies();
26+
27+
project.getRootProject().getSubprojects().stream()
28+
.filter(p -> p.getParent().getPath().equals(":modules") || p.getParent().getPath().equals(":plugins") || p.getParent().getPath().equals(":x-pack:plugin"))
29+
.forEach(p -> {
30+
deps.add(configuration
31+
.getName(),
32+
deps.project(Map.of("path", p.getPath(), "configuration", "locateTransportVersionsConfig"))); // adding a dep to the config we created
33+
});
34+
35+
var aggregationTask = project.getTasks()
36+
.register("aggregateTransportVersionDeclarations", AggregateTransportVersionDeclarationsTask.class, t -> {
37+
t.dependsOn(configuration); // this task can only run after this config is resolved
38+
t.getTransportVersionNameDeclarationsFiles().setFrom(configuration);
39+
t.getOutputFile().set(project.getLayout().getBuildDirectory()
40+
.file("generated-transport-info/all-transport-version-names.txt"));
41+
});
42+
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.transport;
11+
12+
import org.gradle.api.DefaultTask;
13+
import org.gradle.api.file.ConfigurableFileCollection;
14+
import org.gradle.api.file.RegularFileProperty;
15+
import org.gradle.api.tasks.InputFiles;
16+
import org.gradle.api.tasks.OutputFile;
17+
import org.gradle.api.tasks.TaskAction;
18+
19+
import java.io.File;
20+
import java.io.FileWriter;
21+
import java.io.IOException;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
25+
public abstract class AggregateTransportVersionDeclarationsTask extends DefaultTask {
26+
27+
@InputFiles
28+
public abstract ConfigurableFileCollection getTransportVersionNameDeclarationsFiles();
29+
30+
@OutputFile
31+
public abstract RegularFileProperty getOutputFile();
32+
33+
@TaskAction
34+
public void aggregateTransportVersionDeclarations() {
35+
final var files = getTransportVersionNameDeclarationsFiles().getFiles();
36+
var allTVNames= files.stream().flatMap(file -> {
37+
try {
38+
return Files.lines(Path.of(file.getPath()));
39+
} catch (IOException e) {
40+
throw new RuntimeException("Cannot read Transport Versions name declarations file", e);
41+
}
42+
}).toList();
43+
44+
File file = new File(getOutputFile().get().getAsFile().getAbsolutePath());
45+
try (FileWriter writer = new FileWriter(file)) {
46+
for (String tvName : allTVNames) {
47+
writer.write(tvName + "\n");
48+
}
49+
} catch (IOException e) {
50+
throw new RuntimeException(e);
51+
}
52+
}
53+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/GenerateTransportVersionDataTask.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.gradle.internal.transport;
1111

1212
import com.google.common.collect.Streams;
13-
1413
import org.elasticsearch.gradle.Version;
1514
import org.elasticsearch.gradle.VersionProperties;
1615
import org.elasticsearch.gradle.internal.transport.TransportVersionUtils.TransportVersionSetData;
@@ -116,7 +115,9 @@ public void generateTransportVersionData() {
116115
}).toList();
117116
if (existingIDsForReleaseVersion.isEmpty() == false) {
118117
throw new GradleException(
119-
"A transport version could not be created because one already exists for this release:"
118+
"A transport version could not be created because a preexisting one was found for this name & release."
119+
+ " This could be due to another pre-existing TV with the same name, or a result of running this"
120+
+ " task twice:"
120121
+ " Release version: "
121122
+ tvReleaseVersion
122123
+ " TransportVersion Id: "
@@ -144,6 +145,7 @@ public void generateTransportVersionData() {
144145
);
145146
}
146147

148+
// TODO Do I need to remove the patch when updating the server portion? NO, but probably need some additional checks
147149
private static int bumpVersionNumber(
148150
int tvIDToBump,
149151
ReleaseVersion releaseVersion,
@@ -153,7 +155,7 @@ private static int bumpVersionNumber(
153155

154156
/* The TV format:
155157
*
156-
* M_NNN_S_PP
158+
* MM_NNN_S_PP
157159
*
158160
* M - The major version of Elasticsearch
159161
* NNN - The server version part
@@ -166,7 +168,9 @@ private static int bumpVersionNumber(
166168
return releaseVersion.major * 1_000_000; // TODO add check that this doesn't cause overflow out of server versions
167169
} else {
168170
// Bump the server version part if not a major bump.
169-
return tvIDToBump + 1000; // TODO add check that this doesn't cause overflow out of server versions
171+
// TODO add check that this doesn't cause overflow out of server versions
172+
// TODO Do we need to assert on the shape of the number? e.g. no patch version.
173+
return tvIDToBump + 1000;
170174
}
171175
} else {
172176
// bump the patch version part
@@ -175,8 +179,9 @@ private static int bumpVersionNumber(
175179
}
176180

177181
/**
182+
* TODO update this
178183
* Accepts a major.minor version string (e.g. "9.0") and returns the LATEST.json file of the
179-
* previous release string (e.g. "8.19-LATEST.json").
184+
* previous release string (e.g. "8.19").
180185
*/
181186
private static ReleaseVersion getPriorReleaseVersion(File tvDataDir, ReleaseVersion releaseVersion) {
182187
assert tvDataDir != null;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/GenerateTransportVersionManifestTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void generateTransportVersionManifest() {
3838
var manifestFile = getManifestFile();
3939
System.out.println("Potato: manifest file location: " + manifestFile.getAsFile().get().getAbsolutePath());
4040
try (FileWriter writer = new FileWriter(manifestFile.getAsFile().get())) {
41-
for (var file : dir.listFiles()) {
41+
for (var file : dir. listFiles()) {
4242
System.out.println("Potato GenerateTransportVersionManifestTask: " + file.getAbsolutePath());
4343
var fileName = file.getName();
4444
if (fileName.endsWith("-LATEST.json") == false) {

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/LocateTransportVersionsPlugin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@
99

1010
package org.elasticsearch.gradle.internal.transport;
1111

12+
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
1213
import org.elasticsearch.gradle.util.GradleUtils;
1314
import org.gradle.api.Plugin;
1415
import org.gradle.api.Project;
1516
import org.gradle.api.file.FileCollection;
17+
import org.gradle.api.plugins.JavaPlugin;
1618
import org.gradle.api.tasks.SourceSet;
1719

1820
public class LocateTransportVersionsPlugin implements Plugin<Project> {
1921
public static final String TRANSPORT_VERSION_NAMES_FILE = "generated-transport-info/transport-version-set-names.txt";
2022

2123
@Override
2224
public void apply(Project project) {
23-
// TODO figure out what the classpath needs to be to be able to scan the server classes
24-
// Does this need to be a lib (to limit scanning by making this a jar, to exclude gradle)? Ask Mark
25-
// "/Users/john.verwolf/code/elasticsearch/build-tools-internal/build/classes/java/main"
25+
var config = project.getConfigurations().create("locateTransportVersionsConfig");
2626

2727
final var checkTransportVersion = project.getTasks().register("locateTransportVersions", LocateTransportVersionsTask.class, t -> {
2828
SourceSet mainSourceSet = GradleUtils.getJavaSourceSets(project).findByName(SourceSet.MAIN_SOURCE_SET_NAME);
29+
FileCollection dependencyJars = project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
2930
FileCollection compiledPluginClasses = mainSourceSet.getOutput().getClassesDirs();
30-
t.getClassDirs().set(compiledPluginClasses);
31+
FileCollection clasDirs = dependencyJars.plus(compiledPluginClasses)
32+
.minus(project.getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME));
33+
t.getClassDirs().set(clasDirs);
3134

3235
t.getOutputFile().set(project.getLayout().getBuildDirectory().file(TRANSPORT_VERSION_NAMES_FILE));
3336
});
37+
38+
project.getArtifacts().add(config.getName(), checkTransportVersion);
3439
}
3540
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/LocateTransportVersionsTask.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636
import java.util.Set;
3737

3838
/**
39-
* This task locates all method invocations of org.elasticsearch.TransportVersionSetData#get(java.lang.String) in the
39+
* This task locates all method invocations of org.elasticsearch.TransportVersionSet#get(java.lang.String) in the
4040
* provided directory, and then records the value of string literals passed as arguments. It then records each
4141
* String on a newline in the provided output file.
4242
*/
4343
public abstract class LocateTransportVersionsTask extends DefaultTask {
44-
public static final String TRANSPORT_VERSION_SET_CLASS = "org/elasticsearch/TransportVersionSetData";
44+
public static final String TRANSPORT_VERSION_SET_CLASS = "org/elasticsearch/TransportVersionSet";
4545
public static final String TRANSPORT_VERSION_SET_METHOD_NAME = "get";
4646

4747
/**
48-
* The directory to scan for TransportVersionSetData#get invocations.
48+
* The directory to scan for TransportVersionSet#get invocations.
4949
*/
5050
@InputFiles
5151
public abstract Property<FileCollection> getClassDirs();
5252

5353
/**
54-
* The output file, with each newline containing the string literal argument of each TransportVersionSetData#get
54+
* The output file, with each newline containing the string literal argument of each TransportVersionSet#get
5555
* invocation.
5656
*/
5757
@OutputFile
@@ -94,7 +94,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String descri
9494
var abstractInstruction = this.instructions.getLast();
9595
if (abstractInstruction instanceof LdcInsnNode ldcInsnNode) {
9696
if (ldcInsnNode.cst instanceof String tvName && tvName.isEmpty() == false) {
97-
System.out.println("constant: " + tvName);
97+
System.out.println("Potato: constant: " + tvName);
9898
results.add(tvName);
9999
} else {
100100
System.out.println(

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import com.fasterxml.jackson.annotation.JsonProperty;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414

15+
import java.io.BufferedReader;
1516
import java.io.File;
17+
import java.io.FileReader;
18+
import java.io.IOException;
1619
import java.io.Serializable;
1720
import java.nio.file.Path;
1821
import java.util.List;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/ValidateTransportVersionsTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* TODO:
3131
* - make this depend on the LocateTransportVersions task/plugin
3232
* - make this both a local (per module/plugin) and global task
33+
* - Also validate that there are no duplicate tvs (ids, names?)
3334
*/
3435
public abstract class ValidateTransportVersionsTask extends DefaultTask {
3536

0 commit comments

Comments
 (0)