SourceOnly.java revision 3233:b5d08bc0d224
11556Srgrimes/*
21556Srgrimes * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
31556Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41556Srgrimes *
51556Srgrimes * This code is free software; you can redistribute it and/or modify it
61556Srgrimes * under the terms of the GNU General Public License version 2 only, as
71556Srgrimes * published by the Free Software Foundation.
81556Srgrimes *
91556Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101556Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111556Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121556Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131556Srgrimes * accompanied this code).
141556Srgrimes *
151556Srgrimes * You should have received a copy of the GNU General Public License version
161556Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171556Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181556Srgrimes *
191556Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201556Srgrimes * or visit www.oracle.com if you need additional information or have any
211556Srgrimes * questions.
221556Srgrimes */
231556Srgrimes
241556Srgrimespackage p;
251556Srgrimes
261556Srgrimesimport java.util.Collections;
271556Srgrimesimport java.util.Set;
281556Srgrimes
291556Srgrimesimport javax.lang.model.SourceVersion;
301556Srgrimes
311556Srgrimesimport jdk.javadoc.doclet.Doclet;
321556Srgrimesimport jdk.javadoc.doclet.DocletEnvironment;
331556Srgrimes
341556Srgrimes/** Test that when running javadoc on a package, we only get
351556Srgrimes *  documentation for those classes for which source was provided.
361556Srgrimes */
371556Srgrimespublic class SourceOnly implements Doclet {
381556Srgrimes    public static void main(String[] args) {
391556Srgrimes        // run javadoc on package p
401556Srgrimes        int result = jdk.javadoc.internal.tool.Main.
411556Srgrimes            execute("javadoc", "p.SourceOnly", SourceOnly.class.getClassLoader(), new String[] {"p"});
421556Srgrimes        if (result != 0)
431556Srgrimes            throw new Error();
441556Srgrimes    }
451556Srgrimes
461556Srgrimes    public boolean start(DocletEnvironment root) {
471556Srgrimes        if (root.getIncludedClasses().size() != 1)
481556Srgrimes            throw new Error("wrong set of classes documented: " + java.util.Arrays.asList(root.getIncludedClasses()));
491556Srgrimes        return true;
501556Srgrimes    }
511556Srgrimes
521556Srgrimes    @Override
531556Srgrimes    public String getName() {
541556Srgrimes        return "Test";
551556Srgrimes    }
561556Srgrimes
571556Srgrimes    @Override
581556Srgrimes    public Set<Option> getSupportedOptions() {
591556Srgrimes        return Collections.emptySet();
601556Srgrimes    }
611556Srgrimes
621556Srgrimes    @Override
631556Srgrimes    public SourceVersion getSupportedSourceVersion() {
641556Srgrimes        return SourceVersion.latest();
651556Srgrimes    }
661556Srgrimes}
671556Srgrimes