< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java

Print this page


  25 /*
  26  * @test
  27  * @summary Class-Path: attribute in MANIFEST file
  28  * @requires vm.cds
  29  * @library /test/lib
  30  * @modules jdk.jartool/sun.tools.jar
  31  * @run driver ClassPathAttr
  32  */
  33 
  34 import jdk.test.lib.process.OutputAnalyzer;
  35 import java.io.File;
  36 import java.nio.file.Files;
  37 import java.nio.file.FileAlreadyExistsException;
  38 import java.nio.file.StandardCopyOption;
  39 import java.nio.file.Paths;
  40 
  41 
  42 public class ClassPathAttr {
  43 
  44   public static void main(String[] args) throws Exception {





  45     buildCpAttr("cpattr1", "cpattr1.mf", "CpAttr1", "CpAttr1");
  46     buildCpAttr("cpattr1_long", "cpattr1_long.mf", "CpAttr1", "CpAttr1");
  47     buildCpAttr("cpattr2", "cpattr2.mf", "CpAttr2", "CpAttr2");
  48     buildCpAttr("cpattr3", "cpattr3.mf", "CpAttr3", "CpAttr2", "CpAttr3");
  49     buildCpAttr("cpattr4", "cpattr4.mf", "CpAttr4",
  50         "CpAttr2", "CpAttr3", "CpAttr4", "CpAttr5");
  51     buildCpAttr("cpattr5_123456789_223456789_323456789_423456789_523456789_623456789", "cpattr5_extra_long.mf", "CpAttr5", "CpAttr5");
  52 
  53     for (int i=1; i<=2; i++) {
  54       String jar1 = TestCommon.getTestJar("cpattr1.jar");
  55       String jar4 = TestCommon.getTestJar("cpattr4.jar");
  56       if (i == 2) {
  57         // Test case #2 -- same as #1, except we use cpattr1_long.jar, which has a super-long
  58         // Class-Path: attribute.
  59         jar1 = TestCommon.getTestJar("cpattr1_long.jar");
  60       }
  61       String cp = jar1 + File.pathSeparator + jar4;
  62 
  63       TestCommon.testDump(cp, TestCommon.list("CpAttr1",
  64                                                           "CpAttr2",


  74       // Logging test for class+path.
  75       TestCommon.run(
  76           "-Xlog:class+path",
  77           "-cp", cp,
  78           "CpAttr1")
  79         .assertNormalExit(output -> {
  80             output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
  81             output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
  82           });
  83 
  84       //  Make sure aliased TraceClassPaths still works
  85       TestCommon.run(
  86           "-XX:+TraceClassPaths",
  87           "-cp", cp,
  88           "CpAttr1")
  89         .assertNormalExit(output -> {
  90             output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
  91             output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
  92           });
  93     }

































  94   }
  95 
  96   private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception {
  97     String jarClassesDir = System.getProperty("test.classes") + File.separator + jarName + "_classes";
  98     try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }
  99 
 100     JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator +
 101         "test-classes" + File.separator + enclosingClassName + ".java");
 102     JarBuilder.buildWithManifest(jarName, manifest, jarClassesDir, testClassNames);
 103   }
 104 }


  25 /*
  26  * @test
  27  * @summary Class-Path: attribute in MANIFEST file
  28  * @requires vm.cds
  29  * @library /test/lib
  30  * @modules jdk.jartool/sun.tools.jar
  31  * @run driver ClassPathAttr
  32  */
  33 
  34 import jdk.test.lib.process.OutputAnalyzer;
  35 import java.io.File;
  36 import java.nio.file.Files;
  37 import java.nio.file.FileAlreadyExistsException;
  38 import java.nio.file.StandardCopyOption;
  39 import java.nio.file.Paths;
  40 
  41 
  42 public class ClassPathAttr {
  43 
  44   public static void main(String[] args) throws Exception {
  45     testNormalOps();
  46     testNonExistentJars();
  47   }
  48 
  49   static void testNormalOps() throws Exception {
  50     buildCpAttr("cpattr1", "cpattr1.mf", "CpAttr1", "CpAttr1");
  51     buildCpAttr("cpattr1_long", "cpattr1_long.mf", "CpAttr1", "CpAttr1");
  52     buildCpAttr("cpattr2", "cpattr2.mf", "CpAttr2", "CpAttr2");
  53     buildCpAttr("cpattr3", "cpattr3.mf", "CpAttr3", "CpAttr2", "CpAttr3");
  54     buildCpAttr("cpattr4", "cpattr4.mf", "CpAttr4",
  55         "CpAttr2", "CpAttr3", "CpAttr4", "CpAttr5");
  56     buildCpAttr("cpattr5_123456789_223456789_323456789_423456789_523456789_623456789", "cpattr5_extra_long.mf", "CpAttr5", "CpAttr5");
  57 
  58     for (int i=1; i<=2; i++) {
  59       String jar1 = TestCommon.getTestJar("cpattr1.jar");
  60       String jar4 = TestCommon.getTestJar("cpattr4.jar");
  61       if (i == 2) {
  62         // Test case #2 -- same as #1, except we use cpattr1_long.jar, which has a super-long
  63         // Class-Path: attribute.
  64         jar1 = TestCommon.getTestJar("cpattr1_long.jar");
  65       }
  66       String cp = jar1 + File.pathSeparator + jar4;
  67 
  68       TestCommon.testDump(cp, TestCommon.list("CpAttr1",
  69                                                           "CpAttr2",


  79       // Logging test for class+path.
  80       TestCommon.run(
  81           "-Xlog:class+path",
  82           "-cp", cp,
  83           "CpAttr1")
  84         .assertNormalExit(output -> {
  85             output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
  86             output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
  87           });
  88 
  89       //  Make sure aliased TraceClassPaths still works
  90       TestCommon.run(
  91           "-XX:+TraceClassPaths",
  92           "-cp", cp,
  93           "CpAttr1")
  94         .assertNormalExit(output -> {
  95             output.shouldMatch("checking shared classpath entry: .*cpattr2.jar");
  96             output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
  97           });
  98     }
  99   }
 100 
 101   static void testNonExistentJars() throws Exception {
 102     buildCpAttr("cpattr6", "cpattr6.mf", "CpAttr6", "CpAttr6");
 103 
 104     String cp = TestCommon.getTestJar("cpattr6.jar");
 105     String nonExistPath = System.getProperty("test.classes") + File.separator + "cpattrX.jar";
 106     (new File(nonExistPath)).delete();
 107 
 108     TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
 109         "-Xlog:class+path");
 110 
 111     TestCommon.run(
 112         "-Xlog:class+path",
 113         "-cp", cp,
 114         "CpAttr6")
 115       .assertNormalExit(output -> {
 116           output.shouldMatch("should be non-existent: .*cpattrX.jar");
 117         });
 118 
 119     // Now make nonExistPath exist. CDS will fail to load.
 120     Files.copy(Paths.get(cp), Paths.get(nonExistPath),
 121                StandardCopyOption.REPLACE_EXISTING);
 122 
 123     TestCommon.run(
 124         "-Xlog:class+path",
 125         "-cp", cp,
 126         "CpAttr6")
 127       .assertAbnormalExit(output -> {
 128           output.shouldMatch("should be non-existent: .*cpattrX.jar");
 129           output.shouldMatch("file must not exist: *cpattrX.jar");
 130 
 131         });
 132   }
 133 
 134   private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception {
 135     String jarClassesDir = System.getProperty("test.classes") + File.separator + jarName + "_classes";
 136     try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }
 137 
 138     JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator +
 139         "test-classes" + File.separator + enclosingClassName + ".java");
 140     JarBuilder.buildWithManifest(jarName, manifest, jarClassesDir, testClassNames);
 141   }
 142 }
< prev index next >