Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8242282: Test sun/tools/jps/TestJps.java fails after JDK-8237572
Browse files Browse the repository at this point in the history
Reviewed-by: dcubed, cjplummer
  • Loading branch information
Alex Menkov committed Apr 10, 2020
1 parent 8ace920 commit f11d462
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
30 changes: 21 additions & 9 deletions test/jdk/sun/tools/jps/LingeredAppForJps.java
Expand Up @@ -69,26 +69,38 @@ public void buildJar() throws IOException {
File jar = new File(className + ".jar");
String testClassPath = System.getProperty("test.class.path", "?");

// Classpath contains test class dir, libraries class dir(s), and
// may contains some additional dirs.
// We need to add to jar only classes from the test class directory.
// Main class (this class) should only be found in one directory
// from the classpath (test class dir), therefore only added once.
// Libraries class dir(s) and any additional classpath directories
// are written the jar manifest.

File manifestFile = new File(className + ".mf");
String nl = System.getProperty("line.separator");
try (BufferedWriter output = new BufferedWriter(new FileWriter(manifestFile))) {
output.write("Main-Class: " + className + nl);
}
String manifestClasspath = "";

List<String> jarArgs = new ArrayList<>();
jarArgs.add("-cfm");
jarArgs.add(jar.getAbsolutePath());
jarArgs.add(manifestFile.getAbsolutePath());

for (String path : testClassPath.split(File.pathSeparator)) {
String classFullName = path + File.separator + className + ".class";
File f = new File(classFullName);
if (f.exists()) {
jarArgs.add("-C");
jarArgs.add(path);
jarArgs.add(".");
System.out.println("INFO: scheduled to jar " + path);
break;
jarArgs.add("-C");
jarArgs.add(path);
jarArgs.add(".");
System.out.println("INFO: scheduled to jar " + path);
} else {
manifestClasspath += " " + new File(path).toURI();
}
}
try (BufferedWriter output = new BufferedWriter(new FileWriter(manifestFile))) {
output.write("Main-Class: " + className + nl);
if (!manifestClasspath.isEmpty()) {
output.write("Class-Path: " + manifestClasspath + nl);
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/jdk/sun/tools/jps/TestJps.java
Expand Up @@ -25,13 +25,17 @@
* @test
* @library /test/lib
* @modules jdk.jartool/sun.tools.jar
* @build jdk.test.lib.apps.LingeredApp
* @run main/othervm/timeout=360 TestJps
*/

/*
* Notes:
* @modules tag is ignored in driver mode, so need main/othervm
*
* LingeredApp is pre-built separately to have jdk.test.lib classes ready
* before the test is compiled (see JDK-8242282).
*
* Launching the process with relative path to an app jar file is not tested
*
* This test resides in default package, so correct appearance
Expand Down

0 comments on commit f11d462

Please sign in to comment.