53
53
import java .util .ServiceConfigurationError ;
54
54
import java .util .ServiceLoader ;
55
55
import java .util .Set ;
56
+ import java .util .stream .Collectors ;
56
57
import java .util .stream .Stream ;
57
58
58
59
import jdk .test .lib .Platform ;
60
+ import jdk .test .lib .Utils ;
59
61
import jdk .test .lib .artifacts .Artifact ;
60
62
import jdk .test .lib .artifacts .ArtifactResolver ;
61
63
import jdk .test .lib .artifacts .ArtifactResolverException ;
@@ -481,14 +483,13 @@ public static String getNssConfig() throws Exception {
481
483
return null ;
482
484
}
483
485
484
- String base = getBase ();
485
-
486
+ String nssConfigDir = copyNssFiles ();
486
487
String libfile = libdir + System .mapLibraryName (nss_library );
487
488
488
489
String customDBdir = System .getProperty ("CUSTOM_DB_DIR" );
489
490
String dbdir = (customDBdir != null ) ?
490
491
customDBdir :
491
- base + SEP + "nss" + SEP + "db" ;
492
+ nssConfigDir + SEP + "db" ;
492
493
// NSS always wants forward slashes for the config path
493
494
dbdir = dbdir .replace ('\\' , '/' );
494
495
@@ -498,7 +499,7 @@ public static String getNssConfig() throws Exception {
498
499
System .setProperty ("pkcs11test.nss.db" , dbdir );
499
500
return (customConfig != null ) ?
500
501
customConfig :
501
- base + SEP + "nss" + SEP + customConfigName ;
502
+ nssConfigDir + SEP + customConfigName ;
502
503
}
503
504
504
505
// Generate a vector of supported elliptic curves of a given provider
@@ -725,6 +726,31 @@ private static Path findNSSLibrary(Path path, Path libraryName) throws IOExcepti
725
726
}
726
727
}
727
728
729
+ //Copy the nss config files to the current directory for tests. Returns the destination path
730
+ private static String copyNssFiles () throws Exception {
731
+ String nss = "nss" ;
732
+ String db = "db" ;
733
+ Path nssDirSource = Path .of (getBase ()).resolve (nss );
734
+ Path nssDirDestination = Path .of ("." ).resolve (nss );
735
+
736
+ // copy files from nss directory
737
+ copyFiles (nssDirSource , nssDirDestination );
738
+ // copy files from nss/db directory
739
+ copyFiles (nssDirSource .resolve (db ), nssDirDestination .resolve (db ));
740
+ return nssDirDestination .toString ();
741
+ }
742
+
743
+ private static void copyFiles (Path dirSource , Path dirDestination ) throws IOException {
744
+ List <Path > sourceFiles = Arrays
745
+ .stream (dirSource .toFile ().listFiles ())
746
+ .filter (File ::isFile )
747
+ .map (File ::toPath )
748
+ .collect (Collectors .toList ());
749
+ List <Path > destFiles = Utils .copyFiles (sourceFiles , dirDestination ,
750
+ StandardCopyOption .REPLACE_EXISTING );
751
+ destFiles .forEach ((Path file ) -> file .toFile ().setWritable (true ));
752
+ }
753
+
728
754
public abstract void main (Provider p ) throws Exception ;
729
755
730
756
protected boolean skipTest (Provider p ) {
0 commit comments