1717import com .fasterxml .jackson .databind .node .ObjectNode ;
1818
1919import org .elasticsearch .gradle .Version ;
20- import org .elasticsearch .gradle .internal .conventions .util .Util ;
2120import org .elasticsearch .gradle .internal .info .BranchesFileParser ;
2221import org .elasticsearch .gradle .internal .info .DevelopmentBranch ;
2322import org .gradle .api .DefaultTask ;
2423import org .gradle .api .InvalidUserDataException ;
25- import org .gradle .api .Project ;
24+ import org .gradle .api .file . ProjectLayout ;
2625import org .gradle .api .logging .Logger ;
2726import 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 ;
2830import org .gradle .api .tasks .TaskAction ;
2931import org .gradle .api .tasks .options .Option ;
3032
3638import java .util .Comparator ;
3739import java .util .List ;
3840
39- import javax .annotation .Nullable ;
4041import 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
0 commit comments