16
16
import org .gradle .process .ExecResult ;
17
17
18
18
import java .io .ByteArrayOutputStream ;
19
- import java .io .File ;
20
19
import java .io .IOException ;
21
20
import java .nio .charset .StandardCharsets ;
22
21
import java .nio .file .Files ;
@@ -104,7 +103,7 @@ Map<String, TransportVersionDefinition> getNamedDefinitions() throws IOException
104
103
105
104
/** Get a named definition from main if it exists there, or null otherwise */
106
105
TransportVersionDefinition getNamedDefinitionFromMain (String name ) {
107
- String resourcePath = getNamedDefinitionRelativePath (name ). toString ( );
106
+ Path resourcePath = getNamedDefinitionRelativePath (name );
108
107
return getMainFile (resourcePath , TransportVersionDefinition ::fromString );
109
108
}
110
109
@@ -130,7 +129,7 @@ Map<String, TransportVersionDefinition> getUnreferencedDefinitions() throws IOEx
130
129
131
130
/** Get a named definition from main if it exists there, or null otherwise */
132
131
TransportVersionDefinition getUnreferencedDefinitionFromMain (String name ) {
133
- String resourcePath = getUnreferencedDefinitionRelativePath (name ). toString ( );
132
+ Path resourcePath = getUnreferencedDefinitionRelativePath (name );
134
133
return getMainFile (resourcePath , TransportVersionDefinition ::fromString );
135
134
}
136
135
@@ -145,7 +144,7 @@ Map<String, TransportVersionLatest> getLatestByReleaseBranch() throws IOExceptio
145
144
try (var stream = Files .list (transportResourcesDir .resolve (LATEST_DIR ))) {
146
145
for (var latestFile : stream .toList ()) {
147
146
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 );
149
148
latests .put (latest .name (), latest );
150
149
}
151
150
}
@@ -154,7 +153,7 @@ Map<String, TransportVersionLatest> getLatestByReleaseBranch() throws IOExceptio
154
153
155
154
/** Retrieve the latest transport version for the given release branch on main */
156
155
TransportVersionLatest getLatestFromMain (String releaseBranch ) {
157
- String resourcePath = getLatestRelativePath (releaseBranch ). toString ( );
156
+ Path resourcePath = getLatestRelativePath (releaseBranch );
158
157
return getMainFile (resourcePath , TransportVersionLatest ::fromString );
159
158
}
160
159
@@ -174,7 +173,7 @@ private Set<String> getMainResources() {
174
173
String output = gitCommand ("ls-tree" , "--name-only" , "-r" , "main" , "." );
175
174
176
175
HashSet <String > resources = new HashSet <>();
177
- Collections .addAll (resources , output .split (System . lineSeparator ()));
176
+ Collections .addAll (resources , output .split (" \n " )); // git always outputs LF
178
177
mainResources .set (resources );
179
178
}
180
179
}
@@ -188,20 +187,21 @@ private Set<String> getChangedResources() {
188
187
String output = gitCommand ("diff" , "--name-only" , "main" , "." );
189
188
190
189
HashSet <String > resources = new HashSet <>();
191
- Collections .addAll (resources , output .split (System . lineSeparator ()));
190
+ Collections .addAll (resources , output .split (" \n " )); // git always outputs LF
192
191
changedResources .set (resources );
193
192
}
194
193
}
195
194
return changedResources .get ();
196
195
}
197
196
198
197
// 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 ) {
201
201
return null ;
202
202
}
203
203
204
- String content = gitCommand ("show" , "main:." + File . separator + resourcePath ).strip ();
204
+ String content = gitCommand ("show" , "main:./ " + pathString ).strip ();
205
205
return parser .apply (resourcePath , content );
206
206
}
207
207
@@ -213,7 +213,7 @@ private static Map<String, TransportVersionDefinition> readDefinitions(Path dir)
213
213
try (var definitionsStream = Files .list (dir )) {
214
214
for (var definitionFile : definitionsStream .toList ()) {
215
215
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 );
217
217
definitions .put (definition .name (), definition );
218
218
}
219
219
}
0 commit comments