39
39
import java .security .SecureRandom ;
40
40
import java .util .ArrayList ;
41
41
import java .util .Collection ;
42
- import java .util .HashMap ;
43
42
import java .util .Iterator ;
44
43
import java .util .List ;
45
44
import java .util .ListIterator ;
@@ -668,15 +667,15 @@ public boolean isPackageUnpacked() {
668
667
}
669
668
670
669
public static void useToolProviderByDefault (ToolProvider jpackageToolProvider ) {
671
- defaultToolProvider = Optional .of (jpackageToolProvider );
670
+ defaultToolProvider . set ( Optional .of (jpackageToolProvider ) );
672
671
}
673
672
674
673
public static void useToolProviderByDefault () {
675
674
useToolProviderByDefault (JavaTool .JPACKAGE .asToolProvider ());
676
675
}
677
676
678
677
public static void useExecutableByDefault () {
679
- defaultToolProvider = Optional .empty ();
678
+ defaultToolProvider . set ( Optional .empty () );
680
679
}
681
680
682
681
public JPackageCommand useToolProvider (boolean v ) {
@@ -785,7 +784,9 @@ public JPackageCommand validateOutput(CannedFormattedString... str) {
785
784
}
786
785
787
786
public boolean isWithToolProvider () {
788
- return Optional .ofNullable (withToolProvider ).orElseGet (defaultToolProvider ::isPresent );
787
+ return Optional .ofNullable (withToolProvider ).orElseGet (() -> {
788
+ return defaultToolProvider .get ().isPresent ();
789
+ });
789
790
}
790
791
791
792
public JPackageCommand executePrerequisiteActions () {
@@ -801,7 +802,7 @@ private Executor createExecutor() {
801
802
.addArguments (args );
802
803
803
804
if (isWithToolProvider ()) {
804
- exec .setToolProvider (defaultToolProvider .orElseGet (JavaTool .JPACKAGE ::asToolProvider ));
805
+ exec .setToolProvider (defaultToolProvider .get (). orElseGet (JavaTool .JPACKAGE ::asToolProvider ));
805
806
} else {
806
807
exec .setExecutable (JavaTool .JPACKAGE );
807
808
if (TKit .isWindows ()) {
@@ -1233,10 +1234,7 @@ public void assertFileNotInAppImage(Path filename) {
1233
1234
1234
1235
private void assertFileInAppImage (Path filename , Path expectedPath ) {
1235
1236
if (expectedPath != null ) {
1236
- if (expectedPath .isAbsolute ()) {
1237
- throw new IllegalArgumentException ();
1238
- }
1239
- if (!expectedPath .getFileName ().equals (filename .getFileName ())) {
1237
+ if (expectedPath .isAbsolute () || !expectedPath .getFileName ().equals (filename .getFileName ())) {
1240
1238
throw new IllegalArgumentException ();
1241
1239
}
1242
1240
}
@@ -1322,7 +1320,7 @@ private JPackageCommand adjustArgumentsBeforeExecution() {
1322
1320
addArguments ("--runtime-image" , DEFAULT_RUNTIME_IMAGE );
1323
1321
}
1324
1322
1325
- if (!hasArgument ("--verbose" ) && TKit .VERBOSE_JPACKAGE && !ignoreDefaultVerbose ) {
1323
+ if (!hasArgument ("--verbose" ) && TKit .verboseJPackage () && !ignoreDefaultVerbose ) {
1326
1324
addArgument ("--verbose" );
1327
1325
}
1328
1326
@@ -1346,11 +1344,7 @@ public void verifyIsOfType(PackageType ... types) {
1346
1344
final var typesSet = Stream .of (types ).collect (Collectors .toSet ());
1347
1345
if (!hasArgument ("--type" )) {
1348
1346
if (!isImagePackageType ()) {
1349
- if (TKit .isLinux () && typesSet .equals (PackageType .LINUX )) {
1350
- return ;
1351
- }
1352
-
1353
- if (TKit .isWindows () && typesSet .equals (PackageType .WINDOWS )) {
1347
+ if ((TKit .isLinux () && typesSet .equals (PackageType .LINUX )) || (TKit .isWindows () && typesSet .equals (PackageType .WINDOWS ))) {
1354
1348
return ;
1355
1349
}
1356
1350
@@ -1500,29 +1494,16 @@ public void run() {
1500
1494
private Set <ReadOnlyPathAssert > readOnlyPathAsserts = Set .of (ReadOnlyPathAssert .values ());
1501
1495
private Set <AppLayoutAssert > appLayoutAsserts = Set .of (AppLayoutAssert .values ());
1502
1496
private List <Consumer <Iterator <String >>> outputValidators = new ArrayList <>();
1503
- private static Optional <ToolProvider > defaultToolProvider = Optional . empty ( );
1497
+ private static ThreadLocal < Optional <ToolProvider >> defaultToolProvider = InheritableThreadLocal . withInitial ( Optional :: empty );
1504
1498
1505
- private static final Map <String , PackageType > PACKAGE_TYPES = Functional .identity (
1506
- () -> {
1507
- Map <String , PackageType > reply = new HashMap <>();
1508
- for (PackageType type : PackageType .values ()) {
1509
- reply .put (type .getType (), type );
1510
- }
1511
- return reply ;
1512
- }).get ();
1513
-
1514
- public static final Path DEFAULT_RUNTIME_IMAGE = Functional .identity (() -> {
1515
- // Set the property to the path of run-time image to speed up
1516
- // building app images and platform bundles by avoiding running jlink
1517
- // The value of the property will be automativcally appended to
1518
- // jpackage command line if the command line doesn't have
1519
- // `--runtime-image` parameter set.
1520
- String val = TKit .getConfigProperty ("runtime-image" );
1521
- if (val != null ) {
1522
- return Path .of (val );
1523
- }
1524
- return null ;
1525
- }).get ();
1499
+ private static final Map <String , PackageType > PACKAGE_TYPES = Stream .of (PackageType .values ()).collect (toMap (PackageType ::getType , x -> x ));
1500
+
1501
+ // Set the property to the path of run-time image to speed up
1502
+ // building app images and platform bundles by avoiding running jlink.
1503
+ // The value of the property will be automatically appended to
1504
+ // jpackage command line if the command line doesn't have
1505
+ // `--runtime-image` parameter set.
1506
+ public static final Path DEFAULT_RUNTIME_IMAGE = Optional .ofNullable (TKit .getConfigProperty ("runtime-image" )).map (Path ::of ).orElse (null );
1526
1507
1527
1508
// [HH:mm:ss.SSS]
1528
1509
private static final Pattern TIMESTAMP_REGEXP = Pattern .compile (
0 commit comments