1616import  org .gradle .process .ExecResult ;
1717
1818import  java .io .ByteArrayOutputStream ;
19- import  java .io .File ;
2019import  java .io .IOException ;
2120import  java .nio .charset .StandardCharsets ;
2221import  java .nio .file .Files ;
@@ -104,7 +103,7 @@ Map<String, TransportVersionDefinition> getNamedDefinitions() throws IOException
104103
105104    /** Get a named definition from main if it exists there, or null otherwise */ 
106105    TransportVersionDefinition  getNamedDefinitionFromMain (String  name ) {
107-         String  resourcePath  = getNamedDefinitionRelativePath (name ). toString ( );
106+         Path  resourcePath  = getNamedDefinitionRelativePath (name );
108107        return  getMainFile (resourcePath , TransportVersionDefinition ::fromString );
109108    }
110109
@@ -130,7 +129,7 @@ Map<String, TransportVersionDefinition> getUnreferencedDefinitions() throws IOEx
130129
131130    /** Get a named definition from main if it exists there, or null otherwise */ 
132131    TransportVersionDefinition  getUnreferencedDefinitionFromMain (String  name ) {
133-         String  resourcePath  = getUnreferencedDefinitionRelativePath (name ). toString ( );
132+         Path  resourcePath  = getUnreferencedDefinitionRelativePath (name );
134133        return  getMainFile (resourcePath , TransportVersionDefinition ::fromString );
135134    }
136135
@@ -145,7 +144,7 @@ Map<String, TransportVersionLatest> getLatestByReleaseBranch() throws IOExceptio
145144        try  (var  stream  = Files .list (transportResourcesDir .resolve (LATEST_DIR ))) {
146145            for  (var  latestFile  : stream .toList ()) {
147146                String  contents  = Files .readString (latestFile , StandardCharsets .UTF_8 ).strip ();
148-                 var  latest  = TransportVersionLatest .fromString (latestFile . getFileName (). toString () , contents );
147+                 var  latest  = TransportVersionLatest .fromString (latestFile , contents );
149148                latests .put (latest .name (), latest );
150149            }
151150        }
@@ -154,7 +153,7 @@ Map<String, TransportVersionLatest> getLatestByReleaseBranch() throws IOExceptio
154153
155154    /** Retrieve the latest transport version for the given release branch on main */ 
156155    TransportVersionLatest  getLatestFromMain (String  releaseBranch ) {
157-         String  resourcePath  = getLatestRelativePath (releaseBranch ). toString ( );
156+         Path  resourcePath  = getLatestRelativePath (releaseBranch );
158157        return  getMainFile (resourcePath , TransportVersionLatest ::fromString );
159158    }
160159
@@ -174,7 +173,7 @@ private Set<String> getMainResources() {
174173                String  output  = gitCommand ("ls-tree" , "--name-only" , "-r" , "main" , "." );
175174
176175                HashSet <String > resources  = new  HashSet <>();
177-                 Collections .addAll (resources , output .split (System . lineSeparator ())); 
176+                 Collections .addAll (resources , output .split (" \n " ));  // git always outputs LF 
178177                mainResources .set (resources );
179178            }
180179        }
@@ -188,20 +187,21 @@ private Set<String> getChangedResources() {
188187                String  output  = gitCommand ("diff" , "--name-only" , "main" , "." );
189188
190189                HashSet <String > resources  = new  HashSet <>();
191-                 Collections .addAll (resources , output .split (System . lineSeparator ())); 
190+                 Collections .addAll (resources , output .split (" \n " ));  // git always outputs LF 
192191                changedResources .set (resources );
193192            }
194193        }
195194        return  changedResources .get ();
196195    }
197196
198197    // Read a transport version resource from the main branch, or return null if it doesn't exist on main 
199-     private  <T > T  getMainFile (String  resourcePath , BiFunction <String , String , T > parser ) {
200-         if  (getMainResources ().contains (resourcePath ) == false ) {
198+     private  <T > T  getMainFile (Path  resourcePath , BiFunction <Path , String , T > parser ) {
199+         String  pathString  = resourcePath .toString ().replace ('\\' , '/' ); // normalize to forward slash that git uses 
200+         if  (getMainResources ().contains (pathString ) == false ) {
201201            return  null ;
202202        }
203203
204-         String  content  = gitCommand ("show" , "main:."  + File . separator  +  resourcePath ).strip ();
204+         String  content  = gitCommand ("show" , "main:./ "  + pathString ).strip ();
205205        return  parser .apply (resourcePath , content );
206206    }
207207
@@ -213,7 +213,7 @@ private static Map<String, TransportVersionDefinition> readDefinitions(Path dir)
213213        try  (var  definitionsStream  = Files .list (dir )) {
214214            for  (var  definitionFile  : definitionsStream .toList ()) {
215215                String  contents  = Files .readString (definitionFile , StandardCharsets .UTF_8 ).strip ();
216-                 var  definition  = TransportVersionDefinition .fromString (definitionFile . getFileName (). toString () , contents );
216+                 var  definition  = TransportVersionDefinition .fromString (definitionFile , contents );
217217                definitions .put (definition .name (), definition );
218218            }
219219        }
0 commit comments