EnsureNewOldDoclet.java revision 3294:9adfb22ff08f
12311Sjkh/* 22311Sjkh * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 32311Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42311Sjkh * 52311Sjkh * This code is free software; you can redistribute it and/or modify it 62311Sjkh * under the terms of the GNU General Public License version 2 only, as 72311Sjkh * published by the Free Software Foundation. 82311Sjkh * 92311Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT 102311Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112311Sjkh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 122311Sjkh * version 2 for more details (a copy is included in the LICENSE file that 132311Sjkh * accompanied this code). 142311Sjkh * 152311Sjkh * You should have received a copy of the GNU General Public License version 162311Sjkh * 2 along with this work; if not, write to the Free Software Foundation, 172311Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1850479Speter * 192311Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20208054Sbrueffer * or visit www.oracle.com if you need additional information or have any 2129452Scharnier * questions. 2229452Scharnier */ 2329452Scharnier 2429452Scharnier/* 2529452Scharnier * @test 2629452Scharnier * @bug 8035473 2768965Sru * @summary make sure the new doclet is invoked by default, and -Xold 2829452Scharnier */ 2929452Scharnier 3068965Sruimport java.io.*; 3129452Scharnierimport java.util.ArrayList; 3229452Scharnierimport java.util.List; 3329452Scharnierimport java.util.regex.Pattern; 3429452Scharnier 3529452Scharnier/** 3629452Scharnier * Dummy javadoc comment. 3729452Scharnier */ 3895127Scharnierpublic class EnsureNewOldDoclet { 3995127Scharnier 4095127Scharnier final File javadoc; 412311Sjkh final File testSrc; 4229452Scharnier final String thisClassName; 43126613Strhodes 44126613Strhodes final static Pattern Expected1 = Pattern.compile("^Standard Doclet \\(Next\\) version.*"); 4529452Scharnier final static Pattern Expected2 = Pattern.compile("^Standard Doclet version.*"); 4629452Scharnier 4729452Scharnier public EnsureNewOldDoclet() { 4829452Scharnier File javaHome = new File(System.getProperty("java.home")); 492311Sjkh if (javaHome.getName().endsWith("jre")) 5029452Scharnier javaHome = javaHome.getParentFile(); 512311Sjkh javadoc = new File(new File(javaHome, "bin"), "javadoc"); 52126613Strhodes testSrc = new File(System.getProperty("test.src")); 53126613Strhodes thisClassName = EnsureNewOldDoclet.class.getName(); 5429452Scharnier } 552311Sjkh 5629452Scharnier public static void main(String... args) throws Exception { 5729452Scharnier EnsureNewOldDoclet test = new EnsureNewOldDoclet(); 5829452Scharnier test.run1(); 5929452Scharnier test.run2(); 6029452Scharnier } 61126613Strhodes 62126613Strhodes // make sure new doclet is invoked by default 632311Sjkh void run1() throws Exception { 642311Sjkh List<String> output = doTest(javadoc.getPath(), 652311Sjkh "-classpath", ".", // insulates us from ambient classpath 6692501Sdwmalone "-Xdoclint:none", 6792501Sdwmalone "-package", 6892501Sdwmalone new File(testSrc, thisClassName + ".java").getPath()); 6992501Sdwmalone System.out.println(output); 7029452Scharnier for (String x : output) { 7129452Scharnier if (Expected1.matcher(x).matches()) { 72126613Strhodes return; 73130087Sru } 74126613Strhodes } 7529452Scharnier throw new Exception("run1: Expected string not found:"); 7629452Scharnier } 7729452Scharnier 7829452Scharnier // make sure the old doclet is invoked with -Xold 7929452Scharnier void run2() throws Exception { 80126613Strhodes List<String> output = doTest(javadoc.getPath(), 81126613Strhodes "-Xold", 8229452Scharnier "-classpath", ".", // insulates us from ambient classpath 83126613Strhodes "-Xdoclint:none", 84126613Strhodes "-package", 85126613Strhodes new File(testSrc, thisClassName + ".java").getPath()); 86126613Strhodes 87126613Strhodes for (String x : output) { 8849732Schris if (Expected2.matcher(x).matches()) { 892311Sjkh throw new Exception("run2: Expected string not found"); 9029452Scharnier } 912311Sjkh return; 9249732Schris } 932311Sjkh } 9429452Scharnier 952311Sjkh /** 9629452Scharnier * More dummy comments. 9729452Scharnier */ 9829452Scharnier List<String> doTest(String... args) throws Exception { 9929452Scharnier List<String> output = new ArrayList<>(); 10029452Scharnier // run javadoc in separate process to ensure doclet executed under 10129452Scharnier // normal user conditions w.r.t. classloader 10229452Scharnier Process p = new ProcessBuilder() 10329452Scharnier .command(args) 10429452Scharnier .redirectErrorStream(true) 10529452Scharnier .start(); 10668388Sdwmalone try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()))) { 10768388Sdwmalone String line = in.readLine(); 10868388Sdwmalone while (line != null) { 10968388Sdwmalone output.add(line.trim()); 11068388Sdwmalone line = in.readLine(); 11168388Sdwmalone } 1122311Sjkh } 11329452Scharnier int rc = p.waitFor(); 11429452Scharnier if (rc != 0) 11529452Scharnier throw new Exception("javadoc failed, rc:" + rc); 11629452Scharnier return output; 117208054Sbrueffer } 11829452Scharnier} 119208054Sbrueffer