private void whitelistOrBlacklistLibOrExtJars ( final boolean whitelist , final String ... jarLeafNames ) { if ( jarLeafNames . length == 0 ) { // If no jar leafnames are given, whitelist or blacklist all lib or ext jars for ( final String libOrExtJar : SystemJarFinder . getJreLibOrExtJars ( ) ) { whitelistOrBlacklistLibOrExtJars ( whitelist , JarUtils . leafName ( libOrExtJar ) ) ; } } else { for ( final String jarLeafName : jarLeafNames ) { final String leafName = JarUtils . leafName ( jarLeafName ) ; if ( ! leafName . equals ( jarLeafName ) ) { throw new IllegalArgumentException ( "Can only " + ( whitelist ? "whitelist" : "blacklist" ) + " jars by leafname: " + jarLeafName ) ; } if ( jarLeafName . contains ( "*" ) ) { // Compare wildcarded pattern against all jars in lib and ext dirs final Pattern pattern = WhiteBlackList . globToPattern ( jarLeafName ) ; boolean found = false ; for ( final String libOrExtJarPath : SystemJarFinder . getJreLibOrExtJars ( ) ) { final String libOrExtJarLeafName = JarUtils . leafName ( libOrExtJarPath ) ; if ( pattern . matcher ( libOrExtJarLeafName ) . matches ( ) ) { // Check for "*" in filename to prevent infinite recursion (shouldn't happen) if ( ! libOrExtJarLeafName . contains ( "*" ) ) { whitelistOrBlacklistLibOrExtJars ( whitelist , libOrExtJarLeafName ) ; } found = true ; } } if ( ! found && topLevelLog != null ) { topLevelLog . log ( "Could not find lib or ext jar matching wildcard: " + jarLeafName ) ; } } else { // No wildcards, just whitelist or blacklist the named jar, if present boolean found = false ; for ( final String libOrExtJarPath : SystemJarFinder . getJreLibOrExtJars ( ) ) { final String libOrExtJarLeafName = JarUtils . leafName ( libOrExtJarPath ) ; if ( jarLeafName . equals ( libOrExtJarLeafName ) ) { if ( whitelist ) { scanSpec . libOrExtJarWhiteBlackList . addToWhitelist ( jarLeafName ) ; } else { scanSpec . libOrExtJarWhiteBlackList . addToBlacklist ( jarLeafName ) ; } if ( topLevelLog != null ) { topLevelLog . log ( ( whitelist ? "Whitelisting" : "Blacklisting" ) + " lib or ext jar: " + libOrExtJarPath ) ; } found = true ; break ; } } if ( ! found && topLevelLog != null ) { topLevelLog . log ( "Could not find lib or ext jar: " + jarLeafName ) ; } } } } }
Add lib or ext jars to whitelist or blacklist .