XWerror.java revision 3233:b5d08bc0d224
1/* 2 * Copyright (c) 2002, 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 4099527 27 * @summary javadoc tool: want flag to exit nonzero if there were warnings. 28 * @author gafter 29 * @modules jdk.javadoc 30 * @run main XWerror 31 */ 32 33import java.io.PrintWriter; 34import java.io.StringWriter; 35import java.util.Collections; 36import java.util.Locale; 37import java.util.Set; 38 39import javax.lang.model.SourceVersion; 40import javax.tools.Diagnostic; 41 42import jdk.javadoc.doclet.Doclet; 43import jdk.javadoc.doclet.Reporter; 44import jdk.javadoc.doclet.DocletEnvironment; 45 46public class XWerror implements Doclet { 47 48 private static final String message = "warning message"; 49 50 public static void main(String[] args) { 51 StringWriter sw = new StringWriter(); 52 PrintWriter output = new PrintWriter(sw); 53 54 String[] aargs = { 55 "-docletpath", System.getProperty("test.classes", "."), 56 "-doclet", "XWerror", 57 "-Xwerror", 58 System.getProperty("test.src", ".") + java.io.File.separatorChar 59 + "XWerror.java" 60 }; 61 if (jdk.javadoc.internal.tool.Main.execute(aargs, output) == 0) { 62 throw new Error("did not get non-zero exit code"); 63 } 64 if (!sw.toString().contains(message)) { 65 throw new Error("expected message not found: " + message); 66 } 67 } 68 Reporter reporter; 69 70 public boolean run(DocletEnvironment root) { 71 reporter.print(Diagnostic.Kind.WARNING , message); 72 return false; 73 } 74 75 @Override 76 public String getName() { 77 return "Test"; 78 } 79 80 @Override 81 public Set<Option> getSupportedOptions() { 82 return Collections.emptySet(); 83 } 84 85 @Override 86 public SourceVersion getSupportedSourceVersion() { 87 return SourceVersion.latest(); 88 } 89 90 @Override 91 public void init(Locale locale, Reporter reporter) { 92 this.reporter = reporter; 93 return; 94 } 95} 96