2828
2929import java .io .BufferedInputStream ;
3030import java .io .File ;
31- import java .io .FileNotFoundException ;
3231import java .io .IOException ;
3332import java .io .InputStream ;
3433import java .io .PrintWriter ;
6059import java .util .Objects ;
6160import java .util .Optional ;
6261import java .util .Set ;
63- import java .util .TreeSet ;
6462import java .util .stream .Collectors ;
6563import java .util .stream .Stream ;
6664
@@ -202,16 +200,22 @@ public class JlinkTask {
202200 throw taskHelper .newBadArgs ("err.sha.overrides.multiple" );
203201 }
204202 Path file = Paths .get (arg .substring (1 ));
205- try {
206- Files .readAllLines (file ).stream ()
207- .forEach (task .options .shaOverrides ::add );
208- } catch (FileNotFoundException e ) {
209- throw taskHelper .newBadArgs ("err.sha.overrides.fnf" , file .toString ());
210- } catch (IOException e ) {
211- throw taskHelper .newBadArgs ("err.sha.overrides.freaderr" , file .toString ());
203+ // Ignore non-existing sha overrides file.
204+ //
205+ // This is to allow for custom builds needing to optionally
206+ // support run-time image links on (possibly) modified
207+ // binaries/debuginfo files done after the JDK build
208+ if (Files .exists (file )) {
209+ try {
210+ Files .readAllLines (file ).stream ()
211+ .forEach (task .options .shaOverrides ::add );
212+ } catch (IOException e ) {
213+ throw taskHelper .newBadArgs ("err.sha.overrides.freaderr" , file .toString ());
214+ }
212215 }
213216 } else {
214- // Comma separated values on CLI. Possible multiples.
217+ // Allow multiple values, separated by comma in addition to
218+ // multiple times the same option.
215219 Arrays .asList (arg .split ("," )).stream ()
216220 .forEach (task .options .shaOverrides ::add );
217221 }
@@ -486,7 +490,7 @@ private JlinkConfiguration initJlinkConfig() throws BadArgs {
486490
487491 LinkableRuntimeImage .Config linkableRuntimeConfig = new LinkableRuntimeImage .Config (
488492 options .ignoreModifiedRuntime ,
489- isLinkFromRuntime ? buildShaSumMap (finder , taskHelper , options .shaOverrides ) : Map . of () );
493+ isLinkFromRuntime ? buildShaSumMap (taskHelper , options .shaOverrides ) : null );
490494 return new JlinkConfiguration (options .output ,
491495 roots ,
492496 finder ,
@@ -495,15 +499,9 @@ private JlinkConfiguration initJlinkConfig() throws BadArgs {
495499 options .generateLinkableRuntime );
496500 }
497501
498- private Map <String , Map <String , Set <String >>> buildShaSumMap (ModuleFinder finder ,
499- TaskHelper taskHelper ,
502+ private Map <String , Map <String , Set <String >>> buildShaSumMap (TaskHelper taskHelper ,
500503 Set <String > shaOverrides ) throws BadArgs {
501- Set <String > modules = finder .findAll ().stream ()
502- .map (ModuleReference ::descriptor )
503- .map (ModuleDescriptor ::name )
504- .collect (Collectors .toSet ());
505504 Map <String , Map <String , Set <String >>> moduleToFiles = new HashMap <>();
506- modules .forEach (m -> { moduleToFiles .put (m , new HashMap <>());});
507505 for (String t : shaOverrides ) {
508506 String trimmed = t .trim ();
509507 if (trimmed .startsWith ("#" )) {
@@ -518,12 +516,8 @@ private Map<String, Map<String, Set<String>>> buildShaSumMap(ModuleFinder finder
518516 // <module-name>
519517 // <file-path>
520518 // <SHA-512-sum>
521- Map <String , Set <String >> perModuleMap = moduleToFiles .get (tokens [0 ]);
522- if (perModuleMap == null ) {
523- throw taskHelper .newBadArgs ("err.sha.overrides.bad.module" , tokens [0 ]);
524- }
525- // TreeSet to disallow null values
526- Set <String > shaSumsPerFile = perModuleMap .computeIfAbsent (tokens [1 ], k -> new TreeSet <>());
519+ Map <String , Set <String >> perModuleMap = moduleToFiles .computeIfAbsent (tokens [0 ], k -> new HashMap <>());
520+ Set <String > shaSumsPerFile = perModuleMap .computeIfAbsent (tokens [1 ], k -> new HashSet <>());
527521 shaSumsPerFile .add (tokens [2 ]);
528522 }
529523 return moduleToFiles ;
0 commit comments