< prev index next >

test/langtools/tools/jdeps/DotFileTest.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562
  27  * @summary Basic tests for jdeps -dotoutput option
  28  * @modules java.management
  29  *          jdk.jdeps/com.sun.tools.jdeps
  30  * @build Test p.Foo p.Bar

  31  * @run main DotFileTest
  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.DirectoryStream;
  39 import java.nio.file.Files;
  40 import java.nio.file.Path;
  41 import java.nio.file.Paths;
  42 import java.util.*;
  43 import java.util.regex.*;
  44 import java.util.stream.Collectors;
  45 


  46 public class DotFileTest {
  47     public static void main(String... args) throws Exception {
  48         int errors = 0;
  49         errors += new DotFileTest().run();
  50         if (errors > 0)
  51             throw new Exception(errors + " errors found");
  52     }
  53 

  54     final Path dir;
  55     final Path dotoutput;
  56     DotFileTest() {

  57         this.dir = Paths.get(System.getProperty("test.classes", "."));
  58         this.dotoutput = dir.resolve("dots");
  59     }
  60 
  61     int run() throws IOException {
  62         File testDir = dir.toFile();
  63         // test a .class file
  64         test(new File(testDir, "Test.class"),
  65              new String[] {"java.lang", "p"},
  66              new String[] {"compact1", "not found"});
  67         // test a directory
  68         test(new File(testDir, "p"),
  69              new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"},
  70              new String[] {"compact1", "compact1", "compact3", "compact1"},
  71              new String[] {"-classpath", testDir.getPath()});
  72         // test class-level dependency output
  73         test(new File(testDir, "Test.class"),
  74              new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
  75              new String[] {"compact1", "compact1", "not found", "not found"},
  76              new String[] {"-verbose:class"});


 152         args.add("-dotoutput");
 153         args.add(dotoutput.toString());
 154         if (file != null) {
 155             args.add(file.getPath());
 156         }
 157 
 158         Map<String,String> result = jdeps(args, dotfile);
 159         checkResult("dependencies", expect, result.keySet());
 160 
 161         // with -P option
 162         List<String> argsWithDashP = new ArrayList<>();
 163         argsWithDashP.add("-P");
 164         argsWithDashP.addAll(args);
 165 
 166         result = jdeps(argsWithDashP, dotfile);
 167         checkResult("profiles", expect, profiles, result);
 168     }
 169 
 170     Map<String,String> jdeps(List<String> args, Path dotfile) throws IOException {
 171         if (Files.exists(dotoutput)) {
 172             try (DirectoryStream<Path> stream = Files.newDirectoryStream(dotoutput)) {
 173                 for (Path p : stream) {
 174                     Files.delete(p);
 175                 }
 176             }
 177             Files.delete(dotoutput);
 178         }
 179         // invoke jdeps
 180         StringWriter sw = new StringWriter();
 181         PrintWriter pw = new PrintWriter(sw);
 182         System.err.println("jdeps " + args.stream().collect(Collectors.joining(" ")));
 183         int rc = com.sun.tools.jdeps.Main.run(args.toArray(new String[0]), pw);
 184         pw.close();
 185         String out = sw.toString();
 186         if (!out.isEmpty())
 187             System.err.println(out);
 188         if (rc != 0)
 189             throw new Error("jdeps failed: rc=" + rc);
 190 
 191         // check output files
 192         if (Files.notExists(dotfile)) {
 193             throw new RuntimeException(dotfile + " doesn't exist");
 194         }
 195         return parse(dotfile);
 196     }
 197     private static Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562
  27  * @summary Basic tests for jdeps -dotoutput option
  28  * @modules java.management
  29  *          jdk.jdeps/com.sun.tools.jdeps
  30  * @library /tools/lib
  31  * @build toolbox.ToolBox Test p.Foo p.Bar
  32  * @run main DotFileTest
  33  */
  34 
  35 import java.io.File;
  36 import java.io.IOException;
  37 import java.io.PrintWriter;
  38 import java.io.StringWriter;
  39 import java.nio.file.DirectoryStream;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 import java.nio.file.Paths;
  43 import java.util.*;
  44 import java.util.regex.*;
  45 import java.util.stream.Collectors;
  46 
  47 import toolbox.ToolBox;
  48 
  49 public class DotFileTest {
  50     public static void main(String... args) throws Exception {
  51         int errors = 0;
  52         errors += new DotFileTest().run();
  53         if (errors > 0)
  54             throw new Exception(errors + " errors found");
  55     }
  56 
  57     final ToolBox toolBox;
  58     final Path dir;
  59     final Path dotoutput;
  60     DotFileTest() {
  61         this.toolBox = new ToolBox();
  62         this.dir = Paths.get(System.getProperty("test.classes", "."));
  63         this.dotoutput = dir.resolve("dots");
  64     }
  65 
  66     int run() throws IOException {
  67         File testDir = dir.toFile();
  68         // test a .class file
  69         test(new File(testDir, "Test.class"),
  70              new String[] {"java.lang", "p"},
  71              new String[] {"compact1", "not found"});
  72         // test a directory
  73         test(new File(testDir, "p"),
  74              new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"},
  75              new String[] {"compact1", "compact1", "compact3", "compact1"},
  76              new String[] {"-classpath", testDir.getPath()});
  77         // test class-level dependency output
  78         test(new File(testDir, "Test.class"),
  79              new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
  80              new String[] {"compact1", "compact1", "not found", "not found"},
  81              new String[] {"-verbose:class"});


 157         args.add("-dotoutput");
 158         args.add(dotoutput.toString());
 159         if (file != null) {
 160             args.add(file.getPath());
 161         }
 162 
 163         Map<String,String> result = jdeps(args, dotfile);
 164         checkResult("dependencies", expect, result.keySet());
 165 
 166         // with -P option
 167         List<String> argsWithDashP = new ArrayList<>();
 168         argsWithDashP.add("-P");
 169         argsWithDashP.addAll(args);
 170 
 171         result = jdeps(argsWithDashP, dotfile);
 172         checkResult("profiles", expect, profiles, result);
 173     }
 174 
 175     Map<String,String> jdeps(List<String> args, Path dotfile) throws IOException {
 176         if (Files.exists(dotoutput)) {
 177             // delete contents of directory, then directory,
 178             // waiting for confirmation on Windows
 179             toolBox.cleanDirectory(dotoutput);
 180             toolBox.deleteFiles(dotoutput);


 181         }
 182         // invoke jdeps
 183         StringWriter sw = new StringWriter();
 184         PrintWriter pw = new PrintWriter(sw);
 185         System.err.println("jdeps " + args.stream().collect(Collectors.joining(" ")));
 186         int rc = com.sun.tools.jdeps.Main.run(args.toArray(new String[0]), pw);
 187         pw.close();
 188         String out = sw.toString();
 189         if (!out.isEmpty())
 190             System.err.println(out);
 191         if (rc != 0)
 192             throw new Error("jdeps failed: rc=" + rc);
 193 
 194         // check output files
 195         if (Files.notExists(dotfile)) {
 196             throw new RuntimeException(dotfile + " doesn't exist");
 197         }
 198         return parse(dotfile);
 199     }
 200     private static Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");


< prev index next >