< prev index next >

test/langtools/tools/jdeps/Basic.java

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562 8005428 8015912 8027481 8048063 8068937
  27  * @summary Basic tests for jdeps tool
  28  * @modules java.management
  29  *          jdk.jdeps/com.sun.tools.jdeps
  30  * @build Test p.Foo p.Bar p.C p.SubClass q.Gee
  31  * @run main Basic
  32  */
  33 
  34 import java.io.File;
  35 import java.io.IOException;
  36 import java.io.PrintWriter;
  37 import java.io.StringWriter;
  38 import java.nio.file.Files;
  39 import java.nio.file.Path;

  40 import java.util.*;
  41 import java.util.regex.*;
  42 import java.util.stream.Collectors;
  43 
  44 import static java.nio.file.StandardCopyOption.*;
  45 
  46 public class Basic {
  47     public static void main(String... args) throws Exception {
  48         int errors = 0;
  49         errors += new Basic().run();
  50         if (errors > 0)
  51             throw new Exception(errors + " errors found");
  52     }
  53 
  54     int run() throws IOException {
  55         File testDir = new File(System.getProperty("test.classes", "."));
  56         // test a .class file
  57         test(new File(testDir, "Test.class"),
  58              new String[] {"java.lang", "p"},
  59              new String[] {"compact1", "not found"});


 118         // split package p - move p/Foo.class to dir1 and p/Bar.class to dir2
 119         Path testClassPath = testDir.toPath();
 120         Path dirP = testClassPath.resolve("p");
 121         Path dir1 = testClassPath.resolve("dir1");
 122         Path subdir1P = dir1.resolve("p");
 123         Path dir2 = testClassPath.resolve("dir2");
 124         Path subdir2P = dir2.resolve("p");
 125         if (!Files.exists(subdir1P))
 126             Files.createDirectories(subdir1P);
 127         if (!Files.exists(subdir2P))
 128             Files.createDirectories(subdir2P);
 129         Files.move(dirP.resolve("Foo.class"), subdir1P.resolve("Foo.class"), REPLACE_EXISTING);
 130         Files.move(dirP.resolve("Bar.class"), subdir2P.resolve("Bar.class"), REPLACE_EXISTING);
 131         StringBuilder cpath = new StringBuilder(testDir.toString());
 132         cpath.append(File.pathSeparator).append(dir1.toString());
 133         cpath.append(File.pathSeparator).append(dir2.toString());
 134         test(new File(testDir, "Test.class"),
 135              new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
 136              new String[] {"compact1", "compact1", dir1.toFile().getName(), dir2.toFile().getName()},
 137              new String[] {"-v", "-classpath", cpath.toString(), "Test.class"});













 138         return errors;
 139     }
 140 
 141     void test(File file, String[] expect, String[] profiles) {
 142         test(file, expect, profiles, new String[0]);
 143     }
 144 
 145     void test(File file, String[] expect, String[] profiles, String[] options) {
 146         List<String> args = new ArrayList<>(Arrays.asList(options));
 147         if (file != null) {
 148             args.add(file.getPath());
 149         }
 150         List<String> argsWithDashP = new ArrayList<>();
 151         argsWithDashP.add("-P");
 152         argsWithDashP.addAll(args);
 153         // test without -P
 154         checkResult("dependencies", expect, jdeps(args.toArray(new String[0])).keySet());
 155         // test with -P
 156         checkResult("profiles", expect, profiles, jdeps(argsWithDashP.toArray(new String[0])));
 157     }




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562 8005428 8015912 8027481 8048063 8068937
  27  * @summary Basic tests for jdeps tool
  28  * @modules java.management
  29  *          jdk.jdeps/com.sun.tools.jdeps
  30  * @build Test p.Foo p.Bar p.C p.SubClass q.Gee
  31  * @run main Basic
  32  */
  33 
  34 import java.io.File;
  35 import java.io.IOException;
  36 import java.io.PrintWriter;
  37 import java.io.StringWriter;
  38 import java.nio.file.Files;
  39 import java.nio.file.Path;
  40 import java.nio.file.Paths;
  41 import java.util.*;
  42 import java.util.regex.*;
  43 import java.util.stream.Collectors;
  44 
  45 import static java.nio.file.StandardCopyOption.*;
  46 
  47 public class Basic {
  48     public static void main(String... args) throws Exception {
  49         int errors = 0;
  50         errors += new Basic().run();
  51         if (errors > 0)
  52             throw new Exception(errors + " errors found");
  53     }
  54 
  55     int run() throws IOException {
  56         File testDir = new File(System.getProperty("test.classes", "."));
  57         // test a .class file
  58         test(new File(testDir, "Test.class"),
  59              new String[] {"java.lang", "p"},
  60              new String[] {"compact1", "not found"});


 119         // split package p - move p/Foo.class to dir1 and p/Bar.class to dir2
 120         Path testClassPath = testDir.toPath();
 121         Path dirP = testClassPath.resolve("p");
 122         Path dir1 = testClassPath.resolve("dir1");
 123         Path subdir1P = dir1.resolve("p");
 124         Path dir2 = testClassPath.resolve("dir2");
 125         Path subdir2P = dir2.resolve("p");
 126         if (!Files.exists(subdir1P))
 127             Files.createDirectories(subdir1P);
 128         if (!Files.exists(subdir2P))
 129             Files.createDirectories(subdir2P);
 130         Files.move(dirP.resolve("Foo.class"), subdir1P.resolve("Foo.class"), REPLACE_EXISTING);
 131         Files.move(dirP.resolve("Bar.class"), subdir2P.resolve("Bar.class"), REPLACE_EXISTING);
 132         StringBuilder cpath = new StringBuilder(testDir.toString());
 133         cpath.append(File.pathSeparator).append(dir1.toString());
 134         cpath.append(File.pathSeparator).append(dir2.toString());
 135         test(new File(testDir, "Test.class"),
 136              new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
 137              new String[] {"compact1", "compact1", dir1.toFile().getName(), dir2.toFile().getName()},
 138              new String[] {"-v", "-classpath", cpath.toString(), "Test.class"});
 139 
 140         // tests --missing-deps option
 141         test(new File(testDir, "Test.class"),
 142              new String[] {"p.Foo", "p.Bar"},
 143              new String[] {"not found", "not found"},
 144              new String[] {"--missing-deps"});
 145 
 146         // no missing dependence
 147         test(new File(testDir, "Test.class"),
 148              new String[0],
 149              new String[0],
 150              new String[] {"--missing-deps", "-classpath", cpath.toString()});
 151 
 152         return errors;
 153     }
 154 
 155     void test(File file, String[] expect, String[] profiles) {
 156         test(file, expect, profiles, new String[0]);
 157     }
 158 
 159     void test(File file, String[] expect, String[] profiles, String[] options) {
 160         List<String> args = new ArrayList<>(Arrays.asList(options));
 161         if (file != null) {
 162             args.add(file.getPath());
 163         }
 164         List<String> argsWithDashP = new ArrayList<>();
 165         argsWithDashP.add("-P");
 166         argsWithDashP.addAll(args);
 167         // test without -P
 168         checkResult("dependencies", expect, jdeps(args.toArray(new String[0])).keySet());
 169         // test with -P
 170         checkResult("profiles", expect, profiles, jdeps(argsWithDashP.toArray(new String[0])));
 171     }


< prev index next >