8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permissions for jtreg version 7 jar

Reviewed-by: joehw, lancea, iris, naoto
This commit is contained in:
Christian Stein 2022-08-15 13:34:19 +00:00 committed by Lance Andersen
parent 695bb39391
commit aa5b718933

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,9 @@
package jaxp.library; package jaxp.library;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.file.Path;
import java.security.CodeSource; import java.security.CodeSource;
import java.security.Permission; import java.security.Permission;
import java.security.PermissionCollection; import java.security.PermissionCollection;
@ -161,7 +163,7 @@ public class JAXPPolicyManager {
*/ */
class TestPolicy extends Policy { class TestPolicy extends Policy {
private final static Set<String> TEST_JARS = private final static Set<String> TEST_JARS =
Set.of("jtreg.jar", "javatest.jar", "testng.jar", "jcommander.jar"); Set.of("jtreg.*jar", "javatest.*jar", "testng.*jar", "jcommander.*jar");
private final PermissionCollection permissions = new Permissions(); private final PermissionCollection permissions = new Permissions();
private ThreadLocal<Map<Integer, Permission>> transientPermissions = new ThreadLocal<>(); private ThreadLocal<Map<Integer, Permission>> transientPermissions = new ThreadLocal<>();
@ -213,9 +215,10 @@ class TestPolicy extends Policy {
private boolean isTestMachineryDomain(ProtectionDomain domain) { private boolean isTestMachineryDomain(ProtectionDomain domain) {
CodeSource cs = (domain == null) ? null : domain.getCodeSource(); CodeSource cs = (domain == null) ? null : domain.getCodeSource();
URL loc = (cs == null) ? null : cs.getLocation(); URL loc = (cs == null) ? null : cs.getLocation();
String path = (loc == null) ? null : loc.getPath(); URI uri = (loc == null) ? null : URI.create(loc.toString());
return path != null && TEST_JARS.stream() String name = (uri == null) ? null : Path.of(uri).getFileName().toString();
.filter(path::endsWith) return name != null && TEST_JARS.stream()
.filter(name::matches)
.findAny() .findAny()
.isPresent(); .isPresent();
} }