11/*
2- * Copyright (c) 2003, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2003, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
5656import java .util .ServiceConfigurationError ;
5757import java .util .ServiceLoader ;
5858import java .util .Set ;
59- import java .util .regex .Matcher ;
60- import java .util .regex .Pattern ;
61- import java .util .stream .Collectors ;
59+ import java .util .stream .Stream ;
6260
6361import jdk .test .lib .Platform ;
6462import jdk .test .lib .artifacts .Artifact ;
@@ -383,19 +381,13 @@ private static Path getNSSLibPath() throws Exception {
383381
384382 static Path getNSSLibPath (String library ) throws Exception {
385383 String osid = getOsId ();
386- String nssLibDir = fetchNssLib (osid );
387- if (nssLibDir == null ) {
384+ Path libraryName = Path .of (System .mapLibraryName (library ));
385+ Path nssLibPath = fetchNssLib (osid , libraryName );
386+ if (nssLibPath == null ) {
388387 throw new SkippedException ("Warning: unsupported OS: " + osid
389388 + ", please initialize NSS library location, skipping test" );
390389 }
391-
392- String libraryName = System .mapLibraryName (library );
393- Path libPath = Paths .get (nssLibDir ).resolve (libraryName );
394- if (!Files .exists (libPath )) {
395- throw new SkippedException ("NSS library \" " + libraryName + "\" was not found in " + nssLibDir );
396- }
397-
398- return libPath ;
390+ return nssLibPath ;
399391 }
400392
401393 private static String getOsId () {
@@ -834,42 +826,42 @@ static byte[] generateData(int length) {
834826 return data ;
835827 }
836828
837- private static String fetchNssLib (String osId ) {
829+ private static Path fetchNssLib (String osId , Path libraryName ) {
838830 switch (osId ) {
839831 case "Windows-amd64-64" :
840- return fetchNssLib (WINDOWS_X64 .class );
832+ return fetchNssLib (WINDOWS_X64 .class , libraryName );
841833
842834 case "MacOSX-x86_64-64" :
843- return fetchNssLib (MACOSX_X64 .class );
835+ return fetchNssLib (MACOSX_X64 .class , libraryName );
844836
845837 case "MacOSX-aarch64-64" :
846- return fetchNssLib (MACOSX_AARCH64 .class );
838+ return fetchNssLib (MACOSX_AARCH64 .class , libraryName );
847839
848840 case "Linux-amd64-64" :
849841 if (Platform .isOracleLinux7 ()) {
850842 throw new SkippedException ("Skipping Oracle Linux prior to v8" );
851843 } else {
852- return fetchNssLib (LINUX_X64 .class );
844+ return fetchNssLib (LINUX_X64 .class , libraryName );
853845 }
854846
855847 case "Linux-aarch64-64" :
856848 if (Platform .isOracleLinux7 ()) {
857849 throw new SkippedException ("Skipping Oracle Linux prior to v8" );
858850 } else {
859- return fetchNssLib (LINUX_AARCH64 .class );
851+ return fetchNssLib (LINUX_AARCH64 .class , libraryName );
860852 }
861853 default :
862854 return null ;
863855 }
864856 }
865857
866- private static String fetchNssLib (Class <?> clazz ) {
867- String path = null ;
858+ private static Path fetchNssLib (Class <?> clazz , Path libraryName ) {
859+ Path path = null ;
868860 try {
869- path = ArtifactResolver .resolve (clazz ).entrySet ().stream ()
870- .findAny ().get ().getValue () + File . separator + "nss"
871- + File . separator + "lib" + File . separator ;
872- } catch (ArtifactResolverException e ) {
861+ Path p = ArtifactResolver .resolve (clazz ).entrySet ().stream ()
862+ .findAny ().get ().getValue ();
863+ path = findNSSLibrary ( p , libraryName ) ;
864+ } catch (ArtifactResolverException | IOException e ) {
873865 Throwable cause = e .getCause ();
874866 if (cause == null ) {
875867 System .out .println ("Cannot resolve artifact, "
@@ -883,6 +875,16 @@ private static String fetchNssLib(Class<?> clazz) {
883875 return path ;
884876 }
885877
878+ private static Path findNSSLibrary (Path path , Path libraryName ) throws IOException {
879+ try (Stream <Path > files = Files .find (path , 10 ,
880+ (tp , attr ) -> tp .getFileName ().equals (libraryName ))) {
881+
882+ return files .findAny ()
883+ .orElseThrow (() -> new SkippedException (
884+ "NSS library \" " + libraryName + "\" was not found in " + path ));
885+ }
886+ }
887+
886888 public abstract void main (Provider p ) throws Exception ;
887889
888890 protected boolean skipTest (Provider p ) {
0 commit comments