1010package  org .elasticsearch .gradle .internal .transport ;
1111
1212import  com .google .common .collect .Streams ;
13- 
1413import  org .elasticsearch .gradle .VersionProperties ;
1514import  org .gradle .api .DefaultTask ;
1615import  org .gradle .api .file .RegularFileProperty ;
16+ import  org .gradle .api .provider .ListProperty ;
1717import  org .gradle .api .provider .Property ;
1818import  org .gradle .api .tasks .Input ;
1919import  org .gradle .api .tasks .InputDirectory ;
20+ import  org .gradle .api .tasks .Optional ;
2021import  org .gradle .api .tasks .TaskAction ;
2122
2223import  java .io .IOException ;
2324import  java .nio .file .Path ;
2425import  java .util .List ;
2526import  java .util .Objects ;
27+ import  java .util .function .Function ;
2628import  java .util .stream .Stream ;
2729
30+ import  static  org .elasticsearch .gradle .internal .transport .TransportVersionUtils .IdIncrement ;
31+ import  static  org .elasticsearch .gradle .internal .transport .TransportVersionUtils .getDefinedFile ;
32+ import  static  org .elasticsearch .gradle .internal .transport .TransportVersionUtils .getLatestFile ;
2833import  static  org .elasticsearch .gradle .internal .transport .TransportVersionUtils .updateLatestFile ;
2934import  static  org .elasticsearch .gradle .internal .transport .TransportVersionUtils .writeDefinitionFile ;
3035
@@ -50,96 +55,60 @@ public abstract class GenerateTransportVersionDataTask extends DefaultTask {
5055     * 
5156     * @return 
5257     */ 
58+     @ Optional 
5359    @ InputDirectory 
5460    public  abstract  RegularFileProperty  getDataFileDirectory ();
5561
5662    /** 
5763     * Used to set the name of the TransportVersionSet for which a data file will be generated. 
5864     */ 
65+     @ Optional 
5966    @ Input 
6067    public  abstract  Property <String > getTVName ();
6168
6269    /** 
6370     * Used to set the `major.minor` release version for which the specific TransportVersion ID will be generated. 
6471     * E.g.: "9.2", "8.18", etc. 
6572     */ 
73+     @ Optional 
74+     @ Input 
75+     public  abstract  ListProperty <String > getMinorVersionsForTV ();
76+ 
77+     @ Optional 
6678    @ Input 
67-     public  abstract  Property <String > getMinorVersionForTV ();
79+     public  abstract  Property <Function <String , IdIncrement >> getIdIncrementSupplier ();
80+ 
6881
6982    @ TaskAction 
7083    public  void  generateTransportVersionData () throws  IOException  {
7184        final  Path  tvDataDir  = Objects .requireNonNull (getDataFileDirectory ().getAsFile ().get ()).toPath ();
7285        final  var  tvName  = Objects .requireNonNull (getTVName ().get ());
73-         final  var  forMinorVersion  = Objects .requireNonNull (getMinorVersionForTV ().get ());
86+         final  var  forMinorVersions  = Objects .requireNonNull (getMinorVersionsForTV ().get ());
7487
75-         // Get the latest transport version data for the specified minor version. 
76-         final  var  latestTV  = TransportVersionUtils .getLatestFile (tvDataDir , forMinorVersion );
88+         // TODO 
89+         //  - do we need to validate that the minorVersions don't contain duplicates? 
90+         //  - is there an order we need to apply? ( I don't think so) 
7791
78-         // Create the new version 
79-         final  var  mainReleaseVersion  = VersionProperties .getElasticsearchVersion ();
80-         final  var  areWeOnMain  = forMinorVersion .equals (mainReleaseVersion );
81-         int  newVersion  = bumpVersionNumber (latestTV .ids ().getFirst (), areWeOnMain  ? PartToBump .SERVER  : PartToBump .PATCH );
92+         for  (var  forMinorVersion  : forMinorVersions ) {
93+             // Get the latest transport version data for the specified minor version. 
94+             final  var  latestTV  = getLatestFile (tvDataDir , forMinorVersion );
8295
83-         // Load the tvSetData for the specified name, if it exists 
84-         final  var  tvSetDataFromFile  = TransportVersionUtils .getDefinedFile (tvDataDir , tvName );
85-         final  var  tvSetFileExists  = tvSetDataFromFile  != null ;
96+             // Create the new version 
8697
87-         // Write the definition file. 
88-         final  var  ids  = tvSetFileExists 
89-             ? Streams .concat (tvSetDataFromFile .ids ().stream (), Stream .of (newVersion )).sorted ().toList ().reversed ()
90-             : List .of (newVersion );
91-         writeDefinitionFile (tvDataDir , tvName , ids );
98+             // TODO 
9299
93-         // Update  the LATEST file.  
94-         updateLatestFile (tvDataDir , forMinorVersion ,  tvName ,  newVersion );
95-     } 
100+              // Load  the tvSetData for the specified name, if it exists  
101+              final   var   tvSetDataFromFile  =  getDefinedFile (tvDataDir , tvName );
102+              final   var   tvSetFileExists  =  tvSetDataFromFile  !=  null ; 
96103
97-     public   enum   PartToBump  { 
98-         SERVER , 
99-         SUBSIDIARY , 
100-         PATCH 
101-     } 
104+              // Write the definition file. 
105+              final   var   ids  =  tvSetFileExists 
106+                 ?  Streams . concat ( tvSetDataFromFile . ids (). stream (),  Stream . of ( newVersion )). sorted (). toList (). reversed () 
107+                 :  List . of ( newVersion ); 
108+              writeDefinitionFile ( tvDataDir ,  tvName ,  ids ); 
102109
103-     // TODO Do I need to remove the patch when updating the server portion? NO, but probably need some additional checks 
104-     private  static  int  bumpVersionNumber (int  tvIDToBump , PartToBump  partToBump ) {
105- 
106-         /* The TV format: 
107-          * 
108-          * MM_NNN_S_PP 
109-          * 
110-          * M - The major version of Elasticsearch 
111-          * NNN - The server version part 
112-          * S - The subsidiary version part. It should always be 0 here, it is only used in subsidiary repositories. 
113-          * PP - The patch version part 
114-          */ 
115-         return  switch  (partToBump ) {
116-             case  SERVER  -> {
117-                 var  newId  = tvIDToBump  + 1000 ;
118-                 if  ((newId  / 1000 ) % 100  == 0 ) {
119-                     throw  new  IllegalStateException (
120-                         "Insufficient server version section in TransportVersion: "  + tvIDToBump  + ", Cannot bump." 
121-                     );
122-                 }
123-                 yield tvIDToBump  + 1000 ;
124-             }
125-             case  SUBSIDIARY  -> {
126-                 var  newId  = tvIDToBump  + 100 ;
127-                 if  ((newId  / 100 ) == 0 ) {
128-                     throw  new  IllegalStateException (
129-                         "Insufficient subsidiary version section in TransportVersion: "  + tvIDToBump  + ", Cannot bump." 
130-                     );
131-                 }
132-                 yield newId ;
133-             }
134-             case  PATCH  -> {
135-                 var  newId  = tvIDToBump  + 1 ;
136-                 if  (newId  % 10  == 0 ) {
137-                     throw  new  IllegalStateException (
138-                         "Insufficient patch version section in TransportVersion: "  + tvIDToBump  + ", Cannot bump." 
139-                     );
140-                 }
141-                 yield newId ;
142-             }
143-         };
110+             // Update the LATEST file. 
111+             updateLatestFile (tvDataDir , forMinorVersion , tvName , newVersion );
112+         }
144113    }
145114}
0 commit comments