24
24
*/
25
25
package jdk .jpackage .internal ;
26
26
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 ;
31
27
import java .io .ByteArrayInputStream ;
32
28
import java .io .ByteArrayOutputStream ;
33
29
import java .io .IOException ;
37
33
import java .nio .charset .StandardCharsets ;
38
34
import java .nio .file .Files ;
39
35
import java .nio .file .Path ;
40
- import java .text . MessageFormat ;
36
+ import java .util . ArrayList ;
41
37
import java .util .HashMap ;
42
38
import java .util .List ;
43
39
import java .util .Map ;
40
+ import java .util .Objects ;
44
41
import java .util .Optional ;
45
42
import java .util .Properties ;
46
- import java .util .ResourceBundle ;
47
43
import java .util .function .Function ;
48
44
import 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 ;
49
49
50
50
@ SuppressWarnings ("restricted" )
51
51
final class ExecutableRebrander {
@@ -62,15 +62,15 @@ final class ExecutableRebrander {
62
62
Function <String , OverridableResource > resourceSupplier ,
63
63
UpdateResourceAction ... extraActions ) {
64
64
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 );
67
67
}
68
68
69
69
private ExecutableRebrander (ExecutableProperties props ,
70
70
OverridableResource propertiesFileResource ,
71
71
UpdateResourceAction ... extraActions ) {
72
72
this .extraActions = List .of (extraActions );
73
- this .propertiesFileResource = propertiesFileResource ;
73
+ this .propertiesFileResource = Objects . requireNonNull ( propertiesFileResource ) ;
74
74
75
75
this .props = new HashMap <>();
76
76
@@ -90,8 +90,7 @@ void execute(BuildEnv env, Path target, Optional<Path> icon) {
90
90
91
91
UpdateResourceAction versionSwapper = resourceLock -> {
92
92
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 );
95
94
}
96
95
};
97
96
@@ -101,41 +100,38 @@ void execute(BuildEnv env, Path target, Optional<Path> icon) {
101
100
.map (absIcon -> {
102
101
return resourceLock -> {
103
102
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 );
106
104
}
107
105
};
108
106
});
109
107
110
108
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 );
116
114
} catch (IOException ex ) {
117
115
throw new UncheckedIOException (ex );
118
116
}
119
117
}
120
118
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 );
123
123
try {
124
124
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 ));
130
127
}
131
128
132
129
target .toFile ().setWritable (true , true );
133
130
134
131
var shortTargetPath = ShortPathUtils .toShortPath (target );
135
132
long resourceLock = lockResource (shortTargetPath .orElse (target ).toString ());
136
133
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 );
139
135
}
140
136
141
137
final boolean resourceUnlockedSuccess ;
@@ -160,8 +156,7 @@ private static void rebrandExecutable(BuildEnv env,
160
156
}
161
157
162
158
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 );
165
160
}
166
161
} finally {
167
162
target .toFile ().setReadOnly ();
@@ -243,9 +238,6 @@ static ExecutableProperties create(WinExePackage pkg) {
243
238
private final List <UpdateResourceAction > extraActions ;
244
239
private final OverridableResource propertiesFileResource ;
245
240
246
- private static final ResourceBundle I18N = ResourceBundle .getBundle (
247
- "jdk.jpackage.internal.resources.WinResources" );
248
-
249
241
static {
250
242
System .loadLibrary ("jpackage" );
251
243
}
0 commit comments