test/langtools/tools/javadoc/6176978/T6176978.java
changeset 47216 71c04702a3d5
parent 30730 d3ce7619db2c
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2008, 2015, 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 6176978
       
    27  * @summary current Javadoc's invocation and extension (Doclet) mechanisms are problematic
       
    28  * @modules jdk.javadoc
       
    29  * @build T6176978
       
    30  * @run main T6176978
       
    31  */
       
    32 
       
    33 import java.io.*;
       
    34 import java.net.*;
       
    35 
       
    36 public class T6176978
       
    37 {
       
    38     public static void main(String[] args) throws Exception {
       
    39         // create and use a temp dir that will not be on jtreg's
       
    40         // default class path
       
    41         File tmpDir = new File("tmp");
       
    42         tmpDir.mkdirs();
       
    43 
       
    44         File testSrc = new File(System.getProperty("test.src", "."));
       
    45         String[] javac_args = {
       
    46             "-d",
       
    47             "tmp",
       
    48             new File(testSrc, "X.java").getPath()
       
    49         };
       
    50 
       
    51         int rc = com.sun.tools.javac.Main.compile(javac_args);
       
    52         if (rc != 0)
       
    53             throw new Error("javac exit code: " + rc);
       
    54 
       
    55         String[] jdoc_args = {
       
    56             "-doclet",
       
    57             "X",
       
    58             new File(testSrc, "T6176978.java").getPath()
       
    59         };
       
    60 
       
    61         rc = com.sun.tools.javadoc.Main.execute(jdoc_args);
       
    62         if (rc == 0)
       
    63             throw new Error("javadoc unexpectedly succeeded");
       
    64 
       
    65 
       
    66 
       
    67         Thread currThread = Thread.currentThread();
       
    68         ClassLoader saveClassLoader = currThread.getContextClassLoader();
       
    69         URLClassLoader urlCL = new URLClassLoader(new URL[] { tmpDir.toURL() });
       
    70         currThread.setContextClassLoader(urlCL);
       
    71 
       
    72         try {
       
    73             rc = com.sun.tools.javadoc.Main.execute(jdoc_args);
       
    74             if (rc != 0)
       
    75                 throw new Error("javadoc exit: " + rc);
       
    76         }
       
    77         finally {
       
    78             currThread.setContextClassLoader(saveClassLoader);
       
    79         }
       
    80     }
       
    81 }