|
1 | 1 | /* |
2 | | - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
23 | 23 | package jaxp.library; |
24 | 24 |
|
25 | 25 |
|
| 26 | +import java.net.URI; |
26 | 27 | import java.net.URL; |
| 28 | +import java.nio.file.Path; |
27 | 29 | import java.security.CodeSource; |
28 | 30 | import java.security.Permission; |
29 | 31 | import java.security.PermissionCollection; |
@@ -161,7 +163,7 @@ void removeTmpPermission(int index) { |
161 | 163 | */ |
162 | 164 | class TestPolicy extends Policy { |
163 | 165 | private final static Set<String> TEST_JARS = |
164 | | - Set.of("jtreg.jar", "javatest.jar", "testng.jar", "jcommander.jar"); |
| 166 | + Set.of("jtreg.*jar", "javatest.*jar", "testng.*jar", "jcommander.*jar"); |
165 | 167 | private final PermissionCollection permissions = new Permissions(); |
166 | 168 |
|
167 | 169 | private ThreadLocal<Map<Integer, Permission>> transientPermissions = new ThreadLocal<>(); |
@@ -213,9 +215,10 @@ public PermissionCollection getPermissions(CodeSource codesource) { |
213 | 215 | private boolean isTestMachineryDomain(ProtectionDomain domain) { |
214 | 216 | CodeSource cs = (domain == null) ? null : domain.getCodeSource(); |
215 | 217 | URL loc = (cs == null) ? null : cs.getLocation(); |
216 | | - String path = (loc == null) ? null : loc.getPath(); |
217 | | - return path != null && TEST_JARS.stream() |
218 | | - .filter(path::endsWith) |
| 218 | + URI uri = (loc == null) ? null : URI.create(loc.toString()); |
| 219 | + String name = (uri == null) ? null : Path.of(uri).getFileName().toString(); |
| 220 | + return name != null && TEST_JARS.stream() |
| 221 | + .filter(name::matches) |
219 | 222 | .findAny() |
220 | 223 | .isPresent(); |
221 | 224 | } |
|
0 commit comments