3939import  java .security .SecureRandom ;
4040import  java .util .ArrayList ;
4141import  java .util .Collection ;
42- import  java .util .HashMap ;
4342import  java .util .Iterator ;
4443import  java .util .List ;
4544import  java .util .ListIterator ;
@@ -691,15 +690,15 @@ public boolean isPackageUnpacked() {
691690    }
692691
693692    public  static  void  useToolProviderByDefault (ToolProvider  jpackageToolProvider ) {
694-         defaultToolProvider  =  Optional .of (jpackageToolProvider );
693+         defaultToolProvider . set ( Optional .of (jpackageToolProvider ) );
695694    }
696695
697696    public  static  void  useToolProviderByDefault () {
698697        useToolProviderByDefault (JavaTool .JPACKAGE .asToolProvider ());
699698    }
700699
701700    public  static  void  useExecutableByDefault () {
702-         defaultToolProvider  =  Optional .empty ();
701+         defaultToolProvider . set ( Optional .empty () );
703702    }
704703
705704    public  JPackageCommand  useToolProvider (boolean  v ) {
@@ -808,7 +807,9 @@ public JPackageCommand validateOutput(CannedFormattedString... str) {
808807    }
809808
810809    public  boolean  isWithToolProvider () {
811-         return  Optional .ofNullable (withToolProvider ).orElseGet (defaultToolProvider ::isPresent );
810+         return  Optional .ofNullable (withToolProvider ).orElseGet (() -> {
811+             return  defaultToolProvider .get ().isPresent ();
812+         });
812813    }
813814
814815    public  JPackageCommand  executePrerequisiteActions () {
@@ -824,7 +825,7 @@ private Executor createExecutor() {
824825                .addArguments (args );
825826
826827        if  (isWithToolProvider ()) {
827-             exec .setToolProvider (defaultToolProvider .orElseGet (JavaTool .JPACKAGE ::asToolProvider ));
828+             exec .setToolProvider (defaultToolProvider .get (). orElseGet (JavaTool .JPACKAGE ::asToolProvider ));
828829        } else  {
829830            exec .setExecutable (JavaTool .JPACKAGE );
830831            if  (TKit .isWindows ()) {
@@ -1256,10 +1257,7 @@ public void assertFileNotInAppImage(Path filename) {
12561257
12571258    private  void  assertFileInAppImage (Path  filename , Path  expectedPath ) {
12581259        if  (expectedPath  != null ) {
1259-             if  (expectedPath .isAbsolute ()) {
1260-                 throw  new  IllegalArgumentException ();
1261-             }
1262-             if  (!expectedPath .getFileName ().equals (filename .getFileName ())) {
1260+             if  (expectedPath .isAbsolute () || !expectedPath .getFileName ().equals (filename .getFileName ())) {
12631261                throw  new  IllegalArgumentException ();
12641262            }
12651263        }
@@ -1345,7 +1343,7 @@ private JPackageCommand adjustArgumentsBeforeExecution() {
13451343            addArguments ("--runtime-image" , DEFAULT_RUNTIME_IMAGE );
13461344        }
13471345
1348-         if  (!hasArgument ("--verbose" ) && TKit .VERBOSE_JPACKAGE  && !ignoreDefaultVerbose ) {
1346+         if  (!hasArgument ("--verbose" ) && TKit .verboseJPackage ()  && !ignoreDefaultVerbose ) {
13491347            addArgument ("--verbose" );
13501348        }
13511349
@@ -1369,11 +1367,7 @@ public void verifyIsOfType(PackageType ... types) {
13691367        final  var  typesSet  = Stream .of (types ).collect (Collectors .toSet ());
13701368        if  (!hasArgument ("--type" )) {
13711369            if  (!isImagePackageType ()) {
1372-                 if  (TKit .isLinux () && typesSet .equals (PackageType .LINUX )) {
1373-                     return ;
1374-                 }
1375- 
1376-                 if  (TKit .isWindows () && typesSet .equals (PackageType .WINDOWS )) {
1370+                 if  ((TKit .isLinux () && typesSet .equals (PackageType .LINUX )) || (TKit .isWindows () && typesSet .equals (PackageType .WINDOWS ))) {
13771371                    return ;
13781372                }
13791373
@@ -1523,29 +1517,21 @@ public void run() {
15231517    private  Set <ReadOnlyPathAssert > readOnlyPathAsserts  = Set .of (ReadOnlyPathAssert .values ());
15241518    private  Set <AppLayoutAssert > appLayoutAsserts  = Set .of (AppLayoutAssert .values ());
15251519    private  List <Consumer <Iterator <String >>> outputValidators  = new  ArrayList <>();
1526-     private  static  Optional <ToolProvider > defaultToolProvider  = Optional .empty ();
1527- 
1528-     private  static  final  Map <String , PackageType > PACKAGE_TYPES  = Functional .identity (
1529-             () -> {
1530-                 Map <String , PackageType > reply  = new  HashMap <>();
1531-                 for  (PackageType  type  : PackageType .values ()) {
1532-                     reply .put (type .getType (), type );
1533-                 }
1534-                 return  reply ;
1535-             }).get ();
1536- 
1537-     public  static  final  Path  DEFAULT_RUNTIME_IMAGE  = Functional .identity (() -> {
1538-         // Set the property to the path of run-time image to speed up 
1539-         // building app images and platform bundles by avoiding running jlink 
1540-         // The value of the property will be automativcally appended to 
1541-         // jpackage command line if the command line doesn't have 
1542-         // `--runtime-image` parameter set. 
1543-         String  val  = TKit .getConfigProperty ("runtime-image" );
1544-         if  (val  != null ) {
1545-             return  Path .of (val );
1520+     private  static  InheritableThreadLocal <Optional <ToolProvider >> defaultToolProvider  = new  InheritableThreadLocal <>() {
1521+         @ Override 
1522+         protected  Optional <ToolProvider > initialValue () {
1523+             return  Optional .empty ();
15461524        }
1547-         return  null ;
1548-     }).get ();
1525+     };
1526+ 
1527+     private  static  final  Map <String , PackageType > PACKAGE_TYPES  = Stream .of (PackageType .values ()).collect (toMap (PackageType ::getType , x  -> x ));
1528+ 
1529+     // Set the property to the path of run-time image to speed up 
1530+     // building app images and platform bundles by avoiding running jlink. 
1531+     // The value of the property will be automatically appended to 
1532+     // jpackage command line if the command line doesn't have 
1533+     // `--runtime-image` parameter set. 
1534+     public  static  final  Path  DEFAULT_RUNTIME_IMAGE  = Optional .ofNullable (TKit .getConfigProperty ("runtime-image" )).map (Path ::of ).orElse (null );
15491535
15501536    // [HH:mm:ss.SSS] 
15511537    private  static  final  Pattern  TIMESTAMP_REGEXP  = Pattern .compile (
0 commit comments