@@ -123,6 +123,53 @@ public static TransportVersion fromInputStream(String path, boolean nameInFile,
123123 }
124124 }
125125
126+ public static Map <String , TransportVersion > fromInputStreams (
127+ String component ,
128+ Function <String , InputStream > nameToStream ,
129+ int latestId
130+ ) {
131+ String [] baseLocations = new String [] { "/transport/generated/" , "/transport/defined/" };
132+ Map <String , TransportVersion > transportVersions = new HashMap <>();
133+
134+ for (String baseLocation : baseLocations ) {
135+ String manifestLocation = baseLocation + "manifest.txt" ;
136+ List <String > versionFileNames = null ;
137+ try (InputStream inputStream = nameToStream .apply (baseLocation )) {
138+ if (inputStream != null ) {
139+ BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ));
140+ versionFileNames = reader .lines ().filter (line -> line .isBlank () == false ).toList ();
141+ }
142+ } catch (IOException ioe ) {
143+ throw new UncheckedIOException (
144+ "transport version manifest file not found at [" + component + ":" + manifestLocation + "]" ,
145+ ioe
146+ );
147+ }
148+
149+ if (versionFileNames != null ) {
150+ for (String versionFileName : versionFileNames ) {
151+ String versionLocation = baseLocation + versionFileName ;
152+ try (InputStream inputStream = nameToStream .apply (versionLocation )) {
153+ if (inputStream == null ) {
154+ throw new IllegalStateException ("transport version file not found [" + component + ":" + versionLocation + "]" );
155+ }
156+ TransportVersion transportVersion = TransportVersion .fromInputStream (versionLocation , false , inputStream , latestId );
157+ if (transportVersion != null ) {
158+ transportVersions .put (transportVersion .name (), transportVersion );
159+ }
160+ } catch (IOException ioe ) {
161+ throw new UncheckedIOException (
162+ "transport version file not found at [" + component + ":" + versionLocation + "]" ,
163+ ioe
164+ );
165+ }
166+ }
167+ }
168+ }
169+
170+ return transportVersions ;
171+ }
172+
126173 public static TransportVersion readVersion (StreamInput in ) throws IOException {
127174 return fromId (in .readVInt ());
128175 }
@@ -374,8 +421,6 @@ private static class VersionsHolder {
374421 }
375422
376423 private static Map <String , TransportVersion > loadTransportVersionsByName () {
377- Map <String , TransportVersion > transportVersions = new HashMap <>();
378-
379424 String latestLocation = "/transport/latest/" + Version .CURRENT .major + "." + Version .CURRENT .minor + ".csv" ;
380425 int latestId = -1 ;
381426 try (InputStream inputStream = TransportVersion .class .getResourceAsStream (latestLocation )) {
@@ -396,40 +441,10 @@ private static Map<String, TransportVersion> loadTransportVersionsByName() {
396441 latestId = latest .id ();
397442 }
398443 } catch (IOException ioe ) {
399- throw new UncheckedIOException ("latest transport version file not found at [" + latestLocation + "]" , ioe );
400- }
401-
402- String manifestLocation = "/transport/defined/manifest.txt" ;
403- List <String > versionFileNames = null ;
404- if (latestId > -1 ) {
405- try (InputStream inputStream = TransportVersion .class .getResourceAsStream (manifestLocation )) {
406- if (inputStream != null ) {
407- BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ));
408- versionFileNames = reader .lines ().filter (line -> line .isBlank () == false ).toList ();
409- }
410- } catch (IOException ioe ) {
411- throw new UncheckedIOException ("transport version manifest file not found at [" + manifestLocation + "]" , ioe );
412- }
413- }
414-
415- if (versionFileNames != null ) {
416- for (String name : versionFileNames ) {
417- String versionLocation = "/transport/defined/" + name ;
418- try (InputStream inputStream = TransportVersion .class .getResourceAsStream (versionLocation )) {
419- if (inputStream == null ) {
420- throw new IllegalStateException ("transport version file not found at [" + versionLocation + "]" );
421- }
422- TransportVersion transportVersion = TransportVersion .fromInputStream (versionLocation , false , inputStream , latestId );
423- if (transportVersion != null ) {
424- transportVersions .put (transportVersion .name (), transportVersion );
425- }
426- } catch (IOException ioe ) {
427- throw new UncheckedIOException ("transport version file not found at [ " + versionLocation + "]" , ioe );
428- }
429- }
444+ throw new UncheckedIOException ("latest transport version file not found at [<server>/" + latestLocation + "]" , ioe );
430445 }
431446
432- return transportVersions ;
447+ return TransportVersion . fromInputStreams ( "server" , TransportVersion . class :: getResourceAsStream , latestId ) ;
433448 }
434449
435450 private static List <TransportVersion > addTransportVersions (Collection <TransportVersion > addFrom , List <TransportVersion > addTo ) {
0 commit comments