Skip to content

Commit 0d5ea9d

Browse files
committedAug 26, 2022
8292688: Support Security properties in security.testlibrary.Proc
Reviewed-by: sgehwolf
1 parent 026a6c5 commit 0d5ea9d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed
 

‎jdk/test/java/security/testlibrary/Proc.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2019, 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
@@ -25,6 +25,9 @@
2525
import java.io.File;
2626
import java.io.IOException;
2727
import java.io.InputStreamReader;
28+
import java.io.OutputStream;
29+
import java.io.PrintStream;
30+
import java.io.UncheckedIOException;
2831
import java.net.URL;
2932
import java.net.URLClassLoader;
3033
import java.nio.file.Files;
@@ -107,6 +110,7 @@ public class Proc {
107110
private List<String> args = new ArrayList<>();
108111
private Map<String,String> env = new HashMap<>();
109112
private Map<String,String> prop = new HashMap();
113+
private Map<String,String> secprop = new HashMap();
110114
private boolean inheritIO = false;
111115
private boolean noDump = false;
112116

@@ -167,6 +171,11 @@ public Proc prop(String a, String b) {
167171
prop.put(a, b);
168172
return this;
169173
}
174+
// Specifies a security property. Can be called multiple times.
175+
public Proc secprop(String a, String b) {
176+
secprop.put(a, b);
177+
return this;
178+
}
170179
// Adds a perm to policy. Can be called multiple times. In order to make it
171180
// effective, please also call prop("java.security.manager", "").
172181
public Proc perm(Permission p) {
@@ -191,6 +200,17 @@ public Proc start() throws IOException {
191200
cp.append(url.getFile());
192201
}
193202
cmd.add(cp.toString());
203+
if (!secprop.isEmpty()) {
204+
Path p = Paths.get(getId("security"));
205+
try (OutputStream fos = Files.newOutputStream(p);
206+
PrintStream ps = new PrintStream(fos)) {
207+
secprop.forEach((k,v) -> ps.println(k + "=" + v));
208+
} catch (IOException e) {
209+
throw new UncheckedIOException(e);
210+
}
211+
prop.put("java.security.properties", p.toString());
212+
}
213+
194214
for (Entry<String,String> e: prop.entrySet()) {
195215
cmd.add("-D" + e.getKey() + "=" + e.getValue());
196216
}
@@ -289,6 +309,12 @@ public int waitFor() throws Exception {
289309
}
290310
return p.waitFor();
291311
}
312+
// Wait for process end with expected exit code
313+
public void waitFor(int expected) throws Exception {
314+
if (p.waitFor() != expected) {
315+
throw new RuntimeException("Exit code not " + expected);
316+
}
317+
}
292318

293319
// The following methods are used inside a proc
294320

0 commit comments

Comments
 (0)
Please sign in to comment.