Skip to content

Commit e2b9fbf

Browse files
committed
Apply code review feedback
1 parent cb0850c commit e2b9fbf

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

branches.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{
2-
"notice": "This file is not maintained outside of the main branch and should only be used for tooling.",
3-
"branches": [
2+
"notice" : "This file is not maintained outside of the main branch and should only be used for tooling.",
3+
"branches" : [
44
{
5-
"branch": "main",
6-
"version": "9.2.0"
5+
"branch" : "main",
6+
"version" : "9.2.0"
77
},
88
{
9-
"branch": "9.1",
10-
"version": "9.1.0"
9+
"branch" : "9.1",
10+
"version" : "9.1.0"
1111
},
1212
{
13-
"branch": "9.0",
14-
"version": "9.0.4"
13+
"branch" : "9.0",
14+
"version" : "9.0.4"
1515
},
1616
{
17-
"branch": "8.19",
18-
"version": "8.19.0"
17+
"branch" : "8.19",
18+
"version" : "8.19.0"
1919
},
2020
{
21-
"branch": "8.18",
22-
"version": "8.18.4"
21+
"branch" : "8.18",
22+
"version" : "8.18.4"
2323
},
2424
{
25-
"branch": "8.17",
26-
"version": "8.17.9"
25+
"branch" : "8.17",
26+
"version" : "8.17.9"
2727
},
2828
{
29-
"branch": "7.17",
30-
"version": "7.17.30"
29+
"branch" : "7.17",
30+
"version" : "7.17.30"
3131
}
3232
]
3333
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.gradle.Version;
1313

14+
import java.io.Serializable;
1415
import java.util.Objects;
1516

1617
/**
@@ -19,7 +20,7 @@
1920
* @param name Name of the development branch
2021
* @param version Elasticsearch version on the development branch
2122
*/
22-
public record DevelopmentBranch(String name, Version version) {
23+
public record DevelopmentBranch(String name, Version version) implements Serializable {
2324
public DevelopmentBranch {
2425
Objects.requireNonNull(name);
2526
Objects.requireNonNull(version);

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
import com.fasterxml.jackson.databind.node.ObjectNode;
1818

1919
import org.elasticsearch.gradle.Version;
20-
import org.elasticsearch.gradle.internal.conventions.util.Util;
2120
import org.elasticsearch.gradle.internal.info.BranchesFileParser;
2221
import org.elasticsearch.gradle.internal.info.DevelopmentBranch;
2322
import org.gradle.api.DefaultTask;
2423
import org.gradle.api.InvalidUserDataException;
25-
import org.gradle.api.Project;
24+
import org.gradle.api.file.ProjectLayout;
2625
import org.gradle.api.logging.Logger;
2726
import org.gradle.api.logging.Logging;
27+
import org.gradle.api.tasks.Input;
28+
import org.gradle.api.tasks.Optional;
29+
import org.gradle.api.tasks.OutputFile;
2830
import org.gradle.api.tasks.TaskAction;
2931
import org.gradle.api.tasks.options.Option;
3032

@@ -36,7 +38,6 @@
3638
import java.util.Comparator;
3739
import java.util.List;
3840

39-
import javax.annotation.Nullable;
4041
import javax.inject.Inject;
4142

4243
/**
@@ -46,22 +47,47 @@ public class UpdateBranchesJsonTask extends DefaultTask {
4647

4748
private static final Logger LOGGER = Logging.getLogger(UpdateBranchesJsonTask.class);
4849

49-
private final Project project;
5050
private final ObjectMapper objectMapper;
5151
private final BranchesFileParser branchesFileParser;
5252

53-
@Nullable
53+
@OutputFile
54+
private File branchesFile;
55+
56+
@Input
57+
@Optional
5458
private DevelopmentBranch addBranch;
55-
@Nullable
59+
@Input
60+
@Optional
5661
private String removeBranch;
57-
@Nullable
62+
@Input
63+
@Optional
5864
private DevelopmentBranch updateBranch;
5965

6066
@Inject
61-
public UpdateBranchesJsonTask(Project project) {
62-
this.project = project;
67+
public UpdateBranchesJsonTask(ProjectLayout projectLayout) {
6368
this.objectMapper = new ObjectMapper();
6469
this.branchesFileParser = new BranchesFileParser(objectMapper);
70+
this.branchesFile = projectLayout.getSettingsDirectory().file("branches.json").getAsFile();
71+
}
72+
73+
public File getBranchesFile() {
74+
return branchesFile;
75+
}
76+
77+
public void setBranchesFile(File branchesFile) {
78+
this.branchesFile = branchesFile;
79+
}
80+
81+
public DevelopmentBranch getAddBranch() {
82+
return addBranch;
83+
}
84+
85+
public String getRemoveBranch() {
86+
return removeBranch;
87+
}
88+
89+
public DevelopmentBranch getUpdateBranch() {
90+
return updateBranch;
6591
}
6692

6793
@Option(option = "add-branch", description = "Specifies the branch and corresponding version to add in format <branch>:<version>")
@@ -89,7 +115,6 @@ private DevelopmentBranch toDevelopmentBranch(String branchAndVersion) {
89115

90116
@TaskAction
91117
public void executeTask() throws IOException {
92-
File branchesFile = new File(Util.locateElasticsearchWorkspace(project.getGradle()), "branches.json");
93118
List<DevelopmentBranch> developmentBranches = readBranches(branchesFile);
94119

95120
if (addBranch == null && removeBranch == null && updateBranch == null) {
@@ -133,7 +158,6 @@ public void executeTask() throws IOException {
133158

134159
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
135160
prettyPrinter.indentArraysWith(new DefaultIndenter(" ", DefaultIndenter.SYS_LF));
136-
prettyPrinter.withoutSpacesInObjectEntries();
137161
objectMapper.writer(prettyPrinter).writeValue(branchesFile, jsonNode);
138162
}
139163

build-tools-internal/src/test/groovy/org/elasticsearch/gradle/internal/release/UpdateBranchesJsonTaskSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class UpdateBranchesJsonTaskSpec extends Specification {
3333
def setup() {
3434
Project project = ProjectBuilder.builder().withProjectDir(projectRoot).build()
3535
task = project.tasks.register("updateBranchesJson", UpdateBranchesJsonTask).get()
36+
task.branchesFile = new File(projectRoot, "branches.json")
3637
}
3738

3839
def "add new branch to branches.json (sorted by version) when --add-branch is specified"() {

0 commit comments

Comments
 (0)