1 /*
   2  * Copyright (c) 2000, 2012, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javadoc;
  27 
  28 import java.io.PrintWriter;
  29 
  30 /**
  31  * Provides external entry points (tool and programmatic)
  32  * for the javadoc program.
  33  *
  34  *  <p><b>This is NOT part of any supported API.
  35  *  If you write code that depends on this, you do so at your own risk.
  36  *  This code and its internal interfaces are subject to change or
  37  *  deletion without notice.</b>
  38  *
  39  * @since 1.4
  40  */
  41 public class Main {
  42 
  43     /**
  44      * Constructor should never be called.
  45      */
  46     private Main() {
  47     }
  48 
  49     /**
  50      * Command line interface.
  51      * @param args   The command line parameters.
  52      */
  53     public static void main(String... args) {
  54         System.exit(execute(args));
  55     }
  56 
  57     /**
  58      * Programmatic interface.
  59      * @param args   The command line parameters.
  60      * @return The return code.
  61      */
  62     public static int execute(String... args) {
  63         Start jdoc = new Start();
  64         return jdoc.begin(args);
  65     }
  66 
  67     /**
  68      * Programmatic interface.
  69      * @param args   The command line parameters.
  70      * @param docletParentClassLoader The parent class loader used when
  71      *  creating the doclet classloader. If null, the class loader used
  72      *  to instantiate doclets will be created without specifying a parent
  73      *  class loader.
  74      * @return The return code.
  75      * @since 1.7
  76      */
  77     public static int execute(ClassLoader docletParentClassLoader, String... args) {
  78         Start jdoc = new Start(docletParentClassLoader);
  79         return jdoc.begin(args);
  80     }
  81 
  82     /**
  83      * Programmatic interface.
  84      * @param programName  Name of the program (for error messages).
  85      * @param args   The command line parameters.
  86      * @return The return code.
  87      */
  88     public static int execute(String programName, String... args) {
  89         Start jdoc = new Start(programName);
  90         return jdoc.begin(args);
  91     }
  92 
  93     /**
  94      * Programmatic interface.
  95      * @param programName  Name of the program (for error messages).
  96      * @param args   The command line parameters.
  97      * @param docletParentClassLoader The parent class loader used when
  98      *  creating the doclet classloader. If null, the class loader used
  99      *  to instantiate doclets will be created without specifying a parent
 100      *  class loader.
 101      * @return The return code.
 102      * @since 1.7
 103      */
 104     public static int execute(String programName, ClassLoader docletParentClassLoader, String... args) {
 105         Start jdoc = new Start(programName, docletParentClassLoader);
 106         return jdoc.begin(args);
 107     }
 108 
 109     /**
 110      * Programmatic interface.
 111      * @param programName  Name of the program (for error messages).
 112      * @param defaultDocletClassName  Fully qualified class name.
 113      * @param args   The command line parameters.
 114      * @return The return code.
 115      */
 116     public static int execute(String programName,
 117                               String defaultDocletClassName,
 118                               String... args) {
 119         Start jdoc = new Start(programName, defaultDocletClassName);
 120         return jdoc.begin(args);
 121     }
 122 
 123     /**
 124      * Programmatic interface.
 125      * @param programName  Name of the program (for error messages).
 126      * @param defaultDocletClassName  Fully qualified class name.
 127      * @param docletParentClassLoader The parent class loader used when
 128      *  creating the doclet classloader. If null, the class loader used
 129      *  to instantiate doclets will be created without specifying a parent
 130      *  class loader.
 131      * @param args   The command line parameters.
 132      * @return The return code.
 133      * @since 1.7
 134      */
 135     public static int execute(String programName,
 136                               String defaultDocletClassName,
 137                               ClassLoader docletParentClassLoader,
 138                               String... args) {
 139         Start jdoc = new Start(programName, defaultDocletClassName, docletParentClassLoader);
 140         return jdoc.begin(args);
 141     }
 142 
 143     /**
 144      * Programmatic interface.
 145      * @param programName  Name of the program (for error messages).
 146      * @param errWriter    PrintWriter to receive error messages.
 147      * @param warnWriter    PrintWriter to receive error messages.
 148      * @param noticeWriter    PrintWriter to receive error messages.
 149      * @param defaultDocletClassName  Fully qualified class name.
 150      * @param args   The command line parameters.
 151      * @return The return code.
 152      */
 153     public static int execute(String programName,
 154                               PrintWriter errWriter,
 155                               PrintWriter warnWriter,
 156                               PrintWriter noticeWriter,
 157                               String defaultDocletClassName,
 158                               String... args) {
 159         Start jdoc = new Start(programName,
 160                                errWriter, warnWriter, noticeWriter,
 161                                defaultDocletClassName);
 162         return jdoc.begin(args);
 163     }
 164 
 165     /**
 166      * Programmatic interface.
 167      * @param programName  Name of the program (for error messages).
 168      * @param errWriter    PrintWriter to receive error messages.
 169      * @param warnWriter    PrintWriter to receive error messages.
 170      * @param noticeWriter    PrintWriter to receive error messages.
 171      * @param defaultDocletClassName  Fully qualified class name.
 172      * @param docletParentClassLoader The parent class loader used when
 173      *  creating the doclet classloader. If null, the class loader used
 174      *  to instantiate doclets will be created without specifying a parent
 175      *  class loader.
 176      * @param args   The command line parameters.
 177      * @return The return code.
 178      * @since 1.7
 179      */
 180     public static int execute(String programName,
 181                               PrintWriter errWriter,
 182                               PrintWriter warnWriter,
 183                               PrintWriter noticeWriter,
 184                               String defaultDocletClassName,
 185                               ClassLoader docletParentClassLoader,
 186                               String... args) {
 187         Start jdoc = new Start(programName,
 188                                errWriter, warnWriter, noticeWriter,
 189                                defaultDocletClassName,
 190                                docletParentClassLoader);
 191         return jdoc.begin(args);
 192     }
 193 }