2424 */
2525package jdk .jpackage .internal ;
2626
27- import jdk .jpackage .internal .model .WinExePackage ;
28- import jdk .jpackage .internal .model .WinLauncher ;
29- import jdk .jpackage .internal .model .WinApplication ;
30- import jdk .jpackage .internal .model .DottedVersion ;
3127import java .io .ByteArrayInputStream ;
3228import java .io .ByteArrayOutputStream ;
3329import java .io .IOException ;
3733import java .nio .charset .StandardCharsets ;
3834import java .nio .file .Files ;
3935import java .nio .file .Path ;
40- import java .text . MessageFormat ;
36+ import java .util . ArrayList ;
4137import java .util .HashMap ;
4238import java .util .List ;
4339import java .util .Map ;
40+ import java .util .Objects ;
4441import java .util .Optional ;
4542import java .util .Properties ;
46- import java .util .ResourceBundle ;
4743import java .util .function .Function ;
4844import java .util .stream .Stream ;
45+ import jdk .jpackage .internal .model .DottedVersion ;
46+ import jdk .jpackage .internal .model .WinApplication ;
47+ import jdk .jpackage .internal .model .WinExePackage ;
48+ import jdk .jpackage .internal .model .WinLauncher ;
4949
5050@ SuppressWarnings ("restricted" )
5151final class ExecutableRebrander {
@@ -62,15 +62,15 @@ final class ExecutableRebrander {
6262 Function <String , OverridableResource > resourceSupplier ,
6363 UpdateResourceAction ... extraActions ) {
6464 this (ExecutableProperties .create (app , launcher ), resourceSupplier .apply (
65- "WinLauncher.template" ).setPublicName (
66- launcher . executableName () + ".properties" ), extraActions );
65+ "WinLauncher.template" ).setPublicName (launcher . executableName () + ".properties" ),
66+ extraActions );
6767 }
6868
6969 private ExecutableRebrander (ExecutableProperties props ,
7070 OverridableResource propertiesFileResource ,
7171 UpdateResourceAction ... extraActions ) {
7272 this .extraActions = List .of (extraActions );
73- this .propertiesFileResource = propertiesFileResource ;
73+ this .propertiesFileResource = Objects . requireNonNull ( propertiesFileResource ) ;
7474
7575 this .props = new HashMap <>();
7676
@@ -90,8 +90,7 @@ void execute(BuildEnv env, Path target, Optional<Path> icon) {
9090
9191 UpdateResourceAction versionSwapper = resourceLock -> {
9292 if (versionSwap (resourceLock , propsArray ) != 0 ) {
93- throw new RuntimeException (MessageFormat .format (I18N .getString (
94- "error.version-swap" ), target ));
93+ throw I18N .buildException ().message ("error.version-swap" , target ).create (RuntimeException ::new );
9594 }
9695 };
9796
@@ -101,41 +100,38 @@ void execute(BuildEnv env, Path target, Optional<Path> icon) {
101100 .map (absIcon -> {
102101 return resourceLock -> {
103102 if (iconSwap (resourceLock , absIcon .toString ()) != 0 ) {
104- throw new RuntimeException (MessageFormat .format (
105- I18N .getString ("error.icon-swap" ), absIcon ));
103+ throw I18N .buildException ().message ("error.icon-swap" , absIcon ).create (RuntimeException ::new );
106104 }
107105 };
108106 });
109107
110108 try {
111- if ( updateIcon . isEmpty ()) {
112- rebrandExecutable ( env , target , versionSwapper );
113- } else {
114- rebrandExecutable ( env , target , versionSwapper , updateIcon . orElseThrow () );
115- }
109+ final List < UpdateResourceAction > actions = new ArrayList <>();
110+ actions . add ( versionSwapper );
111+ updateIcon . ifPresent ( actions :: add );
112+ actions . addAll ( extraActions );
113+ rebrandExecutable ( env , target , actions );
116114 } catch (IOException ex ) {
117115 throw new UncheckedIOException (ex );
118116 }
119117 }
120118
121- private static void rebrandExecutable (BuildEnv env ,
122- final Path target , UpdateResourceAction ... actions ) throws IOException {
119+ private static void rebrandExecutable (BuildEnv env , final Path target ,
120+ List <UpdateResourceAction > actions ) throws IOException {
121+ Objects .requireNonNull (actions );
122+ actions .forEach (Objects ::requireNonNull );
123123 try {
124124 String tempDirectory = env .buildRoot ().toAbsolutePath ().toString ();
125- if (WindowsDefender .isThereAPotentialWindowsDefenderIssue (
126- tempDirectory )) {
127- Log .verbose (MessageFormat .format (I18N .getString (
128- "message.potential.windows.defender.issue" ),
129- tempDirectory ));
125+ if (WindowsDefender .isThereAPotentialWindowsDefenderIssue (tempDirectory )) {
126+ Log .verbose (I18N .format ("message.potential.windows.defender.issue" , tempDirectory ));
130127 }
131128
132129 target .toFile ().setWritable (true , true );
133130
134131 var shortTargetPath = ShortPathUtils .toShortPath (target );
135132 long resourceLock = lockResource (shortTargetPath .orElse (target ).toString ());
136133 if (resourceLock == 0 ) {
137- throw new RuntimeException (MessageFormat .format (
138- I18N .getString ("error.lock-resource" ), shortTargetPath .orElse (target )));
134+ throw I18N .buildException ().message ("error.lock-resource" , shortTargetPath .orElse (target )).create (RuntimeException ::new );
139135 }
140136
141137 final boolean resourceUnlockedSuccess ;
@@ -160,8 +156,7 @@ private static void rebrandExecutable(BuildEnv env,
160156 }
161157
162158 if (!resourceUnlockedSuccess ) {
163- throw new RuntimeException (MessageFormat .format (I18N .getString (
164- "error.unlock-resource" ), target ));
159+ throw I18N .buildException ().message ("error.unlock-resource" , target ).create (RuntimeException ::new );
165160 }
166161 } finally {
167162 target .toFile ().setReadOnly ();
@@ -243,9 +238,6 @@ static ExecutableProperties create(WinExePackage pkg) {
243238 private final List <UpdateResourceAction > extraActions ;
244239 private final OverridableResource propertiesFileResource ;
245240
246- private static final ResourceBundle I18N = ResourceBundle .getBundle (
247- "jdk.jpackage.internal.resources.WinResources" );
248-
249241 static {
250242 System .loadLibrary ("jpackage" );
251243 }
0 commit comments