test/langtools/tools/javadoc/6942366/T6942366.java
branchniosocketimpl-branch
changeset 57208 7a45c67e73d0
parent 57207 30695f27d7ea
parent 53902 7a6fd71449e7
child 57210 a67ea4f53e56
equal deleted inserted replaced
57207:30695f27d7ea 57208:7a45c67e73d0
     1 /*
       
     2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    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 6942366
       
    27  * @summary javadoc no longer inherits doc from sourcepath
       
    28  * @modules jdk.javadoc
       
    29  * @library /tools/javadoc/lib
       
    30  * @build p.Base Test ToyDoclet
       
    31  * @run main T6942366
       
    32  */
       
    33 
       
    34 import java.io.*;
       
    35 import java.util.*;
       
    36 
       
    37 public class T6942366 {
       
    38     public static void main(String... args) throws Exception {
       
    39         new T6942366().run();
       
    40     }
       
    41 
       
    42     File testSrc;
       
    43     File testClasses;
       
    44     int count;
       
    45     int errors;
       
    46 
       
    47     void run() throws Exception {
       
    48         testSrc = new File(System.getProperty("test.src"));
       
    49         testClasses = new File(System.getProperty("test.classes"));
       
    50 
       
    51         test(true,  false);
       
    52         test(false, true);
       
    53         test(true,  true);
       
    54 
       
    55         if (errors > 0)
       
    56             throw new Exception(errors + " errors found");
       
    57     }
       
    58 
       
    59     void test(boolean useSourcePath, boolean useClassPath) throws Exception {
       
    60         System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);
       
    61         File testDir = new File("test" + count);
       
    62         testDir.mkdirs();
       
    63 
       
    64         List<String> args = new ArrayList<String>();
       
    65         args.add("-doclet");
       
    66         args.add("ToyDoclet");
       
    67         if (useSourcePath) {
       
    68             args.add("-sourcepath");
       
    69             args.add(testSrc.getPath());
       
    70         }
       
    71         if (useClassPath) {
       
    72             args.add("-classpath");
       
    73             args.add(testClasses.getPath());
       
    74         } else {
       
    75             // override classpath to avoid stuff jtreg might have put on papth
       
    76             args.add("-classpath");
       
    77             args.add(".");
       
    78         }
       
    79 
       
    80         args.add(new File(testSrc, "Test.java").getPath());
       
    81         System.out.println("ToyDoclet: " + args);
       
    82 
       
    83         StringWriter sw = new StringWriter();
       
    84         PrintWriter pw = new PrintWriter(sw);
       
    85 
       
    86         int rc = com.sun.tools.javadoc.Main.execute("ToyDoclet", pw, pw, pw,
       
    87                 "ToyDoclet", getClass().getClassLoader(),
       
    88                 args.toArray(new String[args.size()]));
       
    89 
       
    90         if (rc != 0)
       
    91             throw new Exception("unexpected exit from javadoc, rc=" + rc);
       
    92 
       
    93         if (useSourcePath && useClassPath) {
       
    94             long srcLastMod = new File(testSrc, "Test.java").lastModified();
       
    95             long classLastMod = new File(testClasses, "Test.class").lastModified();
       
    96             System.out.println("Test.java last modified:  " + new Date(srcLastMod));
       
    97             System.out.println("Test.class last modified: " + new Date(classLastMod));
       
    98             System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");
       
    99         }
       
   100 
       
   101         String s = "javadoc-for-Base.m";
       
   102         boolean expect = useSourcePath;
       
   103         boolean found = sw.toString().contains(s);
       
   104         if (found) {
       
   105             if (expect)
       
   106                 System.out.println("javadoc content \"" + s + "\" found, as expected");
       
   107             else
       
   108                 error("javadoc content \"" + s + "\" found unexpectedly");
       
   109         } else {
       
   110             if (expect)
       
   111                 error("javadoc content \"" + s + "\" not found");
       
   112             else
       
   113                 System.out.println("javadoc content \"" + s + "\" not found, as expected");
       
   114         }
       
   115 
       
   116         System.out.println();
       
   117     }
       
   118 
       
   119     boolean contains(File f, String s) throws Exception {
       
   120         byte[] buf = new byte[(int) f.length()];
       
   121         try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {
       
   122             in.readFully(buf);
       
   123         }
       
   124         return new String(buf).contains(s);
       
   125     }
       
   126 
       
   127     void error(String msg) {
       
   128         System.out.println("Error: " + msg);
       
   129         errors++;
       
   130     }
       
   131 
       
   132 }
       
   133