From 9707ae0c4e14d0c18b2c6bd930a6ffa9115d4d68 Mon Sep 17 00:00:00 2001 From: Dmitry Samersoff Date: Wed, 15 Jun 2016 11:24:12 +0300 Subject: [PATCH] 8153278: sun/tools/jps/TestJpsJar.java fails in hs nightly Refactor the test to take pwd right before the check Reviewed-by: dholmes --- jdk/test/sun/tools/jps/JpsBase.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/jdk/test/sun/tools/jps/JpsBase.java b/jdk/test/sun/tools/jps/JpsBase.java index f119f613951..d13a4053bd8 100644 --- a/jdk/test/sun/tools/jps/JpsBase.java +++ b/jdk/test/sun/tools/jps/JpsBase.java @@ -35,27 +35,28 @@ import jdk.testlibrary.ProcessTools; */ public final class JpsBase { - private static final String shortProcessName; - private static final String fullProcessName; - /** * The jps output should contain processes' names * (except when jps is started in quite mode). * The expected name of the test process is prepared here. */ - static { + + private static String getShortProcessName() { URL url = JpsBase.class.getResource("JpsBase.class"); boolean isJar = url.getProtocol().equals("jar"); + return (isJar) ? JpsBase.class.getSimpleName() + ".jar" : JpsBase.class.getSimpleName(); + } + private static String getFullProcessName() { + URL url = JpsBase.class.getResource("JpsBase.class"); + boolean isJar = url.getProtocol().equals("jar"); if (isJar) { - shortProcessName = JpsBase.class.getSimpleName() + ".jar"; String urlPath = url.getPath(); File jar = new File(urlPath.substring(urlPath.indexOf("file:") + 5, urlPath.indexOf("jar!") + 3)); - fullProcessName = jar.getAbsolutePath(); - } else { - shortProcessName = JpsBase.class.getSimpleName(); - fullProcessName = JpsBase.class.getName(); + return jar.getAbsolutePath(); } + + return JpsBase.class.getName(); } public static void main(String[] args) throws Exception { @@ -83,6 +84,7 @@ public final class JpsBase { // or the full path name to the application's JAR file: // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ... isFull = true; + String fullProcessName = getFullProcessName(); pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*"; output.shouldMatch(pattern); break; @@ -120,6 +122,7 @@ public final class JpsBase { // Output should only contain lines with pids after the first line with pid. JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*"); if (!isFull) { + String shortProcessName = getShortProcessName(); pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName); if (combination.isEmpty()) { // If no arguments are specified output should only contain