Path: blob/master/test/langtools/jdk/javadoc/tool/XWerror.java
40957 views
/*1* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 409952726* @summary javadoc tool: want flag to exit nonzero if there were warnings.27* @modules jdk.javadoc/jdk.javadoc.internal.tool28* @run main XWerror29*/3031import java.io.PrintWriter;32import java.io.StringWriter;33import java.util.Collections;34import java.util.Locale;35import java.util.Set;3637import javax.lang.model.SourceVersion;38import javax.tools.Diagnostic;3940import jdk.javadoc.doclet.Doclet;41import jdk.javadoc.doclet.Reporter;42import jdk.javadoc.doclet.DocletEnvironment;4344public class XWerror implements Doclet {4546private static final String message = "warning message";4748public static void main(String[] args) {49StringWriter sw = new StringWriter();50PrintWriter output = new PrintWriter(sw);5152String[] aargs = {53"-docletpath", System.getProperty("test.classes", "."),54"-doclet", "XWerror",55"-Xwerror",56System.getProperty("test.src", ".") + java.io.File.separatorChar57+ "XWerror.java"58};59if (jdk.javadoc.internal.tool.Main.execute(aargs, output) == 0) {60throw new Error("did not get non-zero exit code");61}62if (!sw.toString().contains(message)) {63throw new Error("expected message not found: " + message);64}65}66Reporter reporter;6768public boolean run(DocletEnvironment root) {69reporter.print(Diagnostic.Kind.WARNING , message);70return false;71}7273@Override74public String getName() {75return "Test";76}7778@Override79public Set<Option> getSupportedOptions() {80return Collections.emptySet();81}8283@Override84public SourceVersion getSupportedSourceVersion() {85return SourceVersion.latest();86}8788@Override89public void init(Locale locale, Reporter reporter) {90this.reporter = reporter;91return;92}93}949596