Skip to content

Commit

Permalink
8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permis…
Browse files Browse the repository at this point in the history
…sions for jtreg version 7 jar

Backport-of: aa5b71893307b9fe6137bc3541edccaab73735ac
  • Loading branch information
shipilev committed Feb 27, 2024
1 parent 64269a3 commit d2d988a
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,9 @@
package jaxp.library;


import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
Expand Down Expand Up @@ -161,7 +163,7 @@ void removeTmpPermission(int index) {
*/
class TestPolicy extends Policy {
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 ThreadLocal<Map<Integer, Permission>> transientPermissions = new ThreadLocal<>();
Expand Down Expand Up @@ -213,9 +215,10 @@ public PermissionCollection getPermissions(CodeSource codesource) {
private boolean isTestMachineryDomain(ProtectionDomain domain) {
CodeSource cs = (domain == null) ? null : domain.getCodeSource();
URL loc = (cs == null) ? null : cs.getLocation();
String path = (loc == null) ? null : loc.getPath();
return path != null && TEST_JARS.stream()
.filter(path::endsWith)
URI uri = (loc == null) ? null : URI.create(loc.toString());
String name = (uri == null) ? null : Path.of(uri).getFileName().toString();
return name != null && TEST_JARS.stream()
.filter(name::matches)
.findAny()
.isPresent();
}
Expand Down

0 comments on commit d2d988a

Please sign in to comment.