1 /*
   2  * Copyright (c) 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 8195795
  27  * @summary test the use of module directories in output, 
  28  *          and the --no-module-directories option
  29  * @modules jdk.javadoc/jdk.javadoc.internal.api
  30  *          jdk.javadoc/jdk.javadoc.internal.tool
  31  *          jdk.compiler/com.sun.tools.javac.api
  32  *          jdk.compiler/com.sun.tools.javac.main
  33  * @library ../lib /tools/lib
  34  * @build toolbox.ToolBox toolbox.ModuleBuilder JavadocTester
  35  * @run main TestModuleDirs
  36  */
  37 
  38 import java.io.IOException;
  39 import java.nio.file.Path;
  40 import java.nio.file.Paths;
  41 
  42 import toolbox.ModuleBuilder;
  43 import toolbox.ToolBox;
  44 
  45 public class TestModuleDirs extends JavadocTester {
  46 
  47     public final ToolBox tb;
  48     public static void main(String... args) throws Exception {
  49         TestModuleDirs tester = new TestModuleDirs();
  50         tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
  51     }
  52 
  53     public TestModuleDirs() {
  54         tb = new ToolBox();
  55     }
  56 
  57     @Test
  58     public void testNoModules(Path base) throws IOException {
  59         Path src = base.resolve("src");
  60         tb.writeJavaFiles(src, "package p; public class C { }");
  61 
  62         javadoc("-d", base.resolve("api").toString(),
  63                 "-sourcepath", src.toString(),
  64                 "-quiet",
  65                 "p");
  66 
  67         checkExit(Exit.OK);
  68         checkFiles(true, "p/package-summary.html");
  69     }
  70 
  71     @Test
  72     public void testNoModuleDirs(Path base) throws IOException {
  73         Path src = base.resolve("src");
  74         new ModuleBuilder(tb, "m")
  75                 .classes("package p; public class A {}")
  76                 .exports("p")
  77                 .write(src);
  78 
  79         javadoc("-d", base.resolve("api").toString(),
  80                 "-quiet",
  81                 "--module-source-path", src.toString(),
  82                 "--no-module-directories",
  83                 "--module", "m");
  84 
  85         checkExit(Exit.OK);
  86         checkFiles(true, 
  87                 "m-summary.html",
  88                 "p/package-summary.html");
  89         checkFiles(false, 
  90                 "m/module-summary.html",
  91                 "m/p/package-summary.html");
  92     }
  93 
  94     @Test
  95     public void testModuleDirs(Path base) throws IOException {
  96         Path src = base.resolve("src");
  97         new ModuleBuilder(tb, "m")
  98                 .classes("package p; public class A {}")
  99                 .exports("p")
 100                 .write(src);
 101 
 102         javadoc("-d", base.resolve("api").toString(),
 103                 "-quiet",
 104                 "--module-source-path", src.toString(),
 105                 "--module", "m");
 106 
 107         checkExit(Exit.OK);
 108         checkFiles(false, 
 109                 "m-summary.html",
 110                 "p/package-summary.html");
 111         checkFiles(true, 
 112                 "m/module-summary.html",
 113                 "m/p/package-summary.html");
 114     }
 115 }
 116