Skip to content

Commit 038c36c

Browse files
committed
8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permissions for jtreg version 7 jar
Backport-of: aa5b71893307b9fe6137bc3541edccaab73735ac
1 parent d944ce4 commit 038c36c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPPolicyManager.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
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
@@ -23,7 +23,9 @@
2323
package jaxp.library;
2424

2525

26+
import java.net.URI;
2627
import java.net.URL;
28+
import java.nio.file.Path;
2729
import java.security.CodeSource;
2830
import java.security.Permission;
2931
import java.security.PermissionCollection;
@@ -161,7 +163,7 @@ void removeTmpPermission(int index) {
161163
*/
162164
class TestPolicy extends Policy {
163165
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");
165167
private final PermissionCollection permissions = new Permissions();
166168

167169
private ThreadLocal<Map<Integer, Permission>> transientPermissions = new ThreadLocal<>();
@@ -213,9 +215,10 @@ public PermissionCollection getPermissions(CodeSource codesource) {
213215
private boolean isTestMachineryDomain(ProtectionDomain domain) {
214216
CodeSource cs = (domain == null) ? null : domain.getCodeSource();
215217
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)
219222
.findAny()
220223
.isPresent();
221224
}

0 commit comments

Comments
 (0)