< prev index next >

src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Start.java

Print this page




  28 import java.io.File;
  29 import java.io.FileNotFoundException;
  30 import java.io.IOException;
  31 import java.io.PrintWriter;
  32 import java.nio.file.Path;
  33 import java.util.ArrayList;
  34 import java.util.Collection;
  35 import java.util.Collections;
  36 import java.util.Objects;
  37 
  38 import javax.tools.JavaFileManager;
  39 import javax.tools.JavaFileObject;
  40 import javax.tools.StandardJavaFileManager;
  41 import javax.tools.StandardLocation;
  42 
  43 import com.sun.javadoc.*;
  44 import com.sun.tools.javac.file.JavacFileManager;
  45 import com.sun.tools.javac.main.CommandLine;
  46 import com.sun.tools.javac.main.Option;
  47 import com.sun.tools.javac.file.BaseFileManager;


  48 import com.sun.tools.javac.platform.PlatformDescription;
  49 import com.sun.tools.javac.platform.PlatformUtils;
  50 import com.sun.tools.javac.util.ClientCodeException;
  51 import com.sun.tools.javac.util.Context;
  52 import com.sun.tools.javac.util.List;
  53 import com.sun.tools.javac.util.ListBuffer;
  54 import com.sun.tools.javac.util.Log;
  55 import com.sun.tools.javac.util.Options;
  56 
  57 import static com.sun.tools.javac.code.Flags.*;
  58 
  59 /**
  60  * Main program of Javadoc.
  61  * Previously named "Main".
  62  *
  63  *  <p><b>This is NOT part of any supported API.
  64  *  If you write code that depends on this, you do so at your own risk.
  65  *  This code and its internal interfaces are subject to change or
  66  *  deletion without notice.</b>
  67  *


 156 
 157         Log log = context.get(Log.logKey);
 158         if (log instanceof Messager)
 159             messager = (Messager) log;
 160         else {
 161             PrintWriter out = context.get(Log.errKey);
 162             messager = (out == null) ? new Messager(context, javadocName)
 163                     : new Messager(context, javadocName, out, out, out);
 164         }
 165     }
 166 
 167     /**
 168      * Usage
 169      */
 170     @Override
 171     void usage() {
 172         usage(true);
 173     }
 174 
 175     void usage(boolean exit) {
 176         usage("main.usage", "-help", null, exit);
 177     }
 178 
 179     @Override
 180     void Xusage() {
 181         Xusage(true);
 182     }
 183 
 184     void Xusage(boolean exit) {
 185         usage("main.Xusage", "-X", "main.Xusage.foot", exit);
 186     }
 187 
 188     private void usage(String main, String doclet, String foot, boolean exit) {
 189         // RFE: it would be better to replace the following with code to
 190         // write a header, then help for each option, then a footer.
 191         messager.notice(main);
 192 
 193         // let doclet print usage information (does nothing on error)
 194         if (docletInvoker != null) {
 195             // RFE: this is a pretty bad way to get the doclet to show
 196             // help info. Moreover, the output appears on stdout,


 348                         args.append(argv[++i]);
 349                     }
 350                     setOption(arg, args.toList());
 351                 }
 352             } else {
 353                 javaNames.append(arg);
 354             }
 355         }
 356 
 357         if (fileManager == null) {
 358             JavacFileManager.preRegister(context);
 359             fileManager = context.get(JavaFileManager.class);
 360             if (fileManager instanceof BaseFileManager) {
 361                 ((BaseFileManager) fileManager).autoClose = true;
 362             }
 363         }
 364         if (fileManager instanceof BaseFileManager) {
 365             ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
 366         }
 367 
 368         String platformString = compOpts.get("-release");
 369 
 370         if (platformString != null) {
 371             if (compOpts.isSet("-source")) {
 372                 usageError("main.release.bootclasspath.conflict", "-source");
 373             }
 374             if (fileManagerOpts.containsKey(Option.BOOTCLASSPATH)) {
 375                 usageError("main.release.bootclasspath.conflict", Option.BOOTCLASSPATH.getText());
 376             }
 377 
 378             PlatformDescription platformDescription =
 379                     PlatformUtils.lookupPlatformDescription(platformString);
 380 
 381             if (platformDescription == null) {
 382                 usageError("main.unsupported.release.version", platformString);
 383             }
 384 
 385             compOpts.put(Option.SOURCE, platformDescription.getSourceVersion());
 386 
 387             context.put(PlatformDescription.class, platformDescription);
 388 
 389             Collection<Path> platformCP = platformDescription.getPlatformPath();
 390 
 391             if (platformCP != null) {
 392                 if (fileManager instanceof StandardJavaFileManager) {
 393                     StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
 394 
 395                     sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);


 538     /**
 539      * indicate an option with one argument was given.
 540      */
 541     private void setOption(String opt, String argument) {
 542         String[] option = { opt, argument };
 543         options.append(option);
 544     }
 545 
 546     /**
 547      * indicate an option with the specified list of arguments was given.
 548      */
 549     private void setOption(String opt, List<String> arguments) {
 550         String[] args = new String[arguments.length() + 1];
 551         int k = 0;
 552         args[k++] = opt;
 553         for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
 554             args[k++] = i.head;
 555         }
 556         options.append(args);
 557     }















 558 }


  28 import java.io.File;
  29 import java.io.FileNotFoundException;
  30 import java.io.IOException;
  31 import java.io.PrintWriter;
  32 import java.nio.file.Path;
  33 import java.util.ArrayList;
  34 import java.util.Collection;
  35 import java.util.Collections;
  36 import java.util.Objects;
  37 
  38 import javax.tools.JavaFileManager;
  39 import javax.tools.JavaFileObject;
  40 import javax.tools.StandardJavaFileManager;
  41 import javax.tools.StandardLocation;
  42 
  43 import com.sun.javadoc.*;
  44 import com.sun.tools.javac.file.JavacFileManager;
  45 import com.sun.tools.javac.main.CommandLine;
  46 import com.sun.tools.javac.main.Option;
  47 import com.sun.tools.javac.file.BaseFileManager;
  48 import com.sun.tools.javac.main.OptionHelper;
  49 import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
  50 import com.sun.tools.javac.platform.PlatformDescription;
  51 import com.sun.tools.javac.platform.PlatformUtils;
  52 import com.sun.tools.javac.util.ClientCodeException;
  53 import com.sun.tools.javac.util.Context;
  54 import com.sun.tools.javac.util.List;
  55 import com.sun.tools.javac.util.ListBuffer;
  56 import com.sun.tools.javac.util.Log;
  57 import com.sun.tools.javac.util.Options;
  58 
  59 import static com.sun.tools.javac.code.Flags.*;
  60 
  61 /**
  62  * Main program of Javadoc.
  63  * Previously named "Main".
  64  *
  65  *  <p><b>This is NOT part of any supported API.
  66  *  If you write code that depends on this, you do so at your own risk.
  67  *  This code and its internal interfaces are subject to change or
  68  *  deletion without notice.</b>
  69  *


 158 
 159         Log log = context.get(Log.logKey);
 160         if (log instanceof Messager)
 161             messager = (Messager) log;
 162         else {
 163             PrintWriter out = context.get(Log.errKey);
 164             messager = (out == null) ? new Messager(context, javadocName)
 165                     : new Messager(context, javadocName, out, out, out);
 166         }
 167     }
 168 
 169     /**
 170      * Usage
 171      */
 172     @Override
 173     void usage() {
 174         usage(true);
 175     }
 176 
 177     void usage(boolean exit) {
 178         usage("main.usage", "-help", "main.usage.foot", exit);
 179     }
 180 
 181     @Override
 182     void Xusage() {
 183         Xusage(true);
 184     }
 185 
 186     void Xusage(boolean exit) {
 187         usage("main.Xusage", "-X", "main.Xusage.foot", exit);
 188     }
 189 
 190     private void usage(String main, String doclet, String foot, boolean exit) {
 191         // RFE: it would be better to replace the following with code to
 192         // write a header, then help for each option, then a footer.
 193         messager.notice(main);
 194 
 195         // let doclet print usage information (does nothing on error)
 196         if (docletInvoker != null) {
 197             // RFE: this is a pretty bad way to get the doclet to show
 198             // help info. Moreover, the output appears on stdout,


 350                         args.append(argv[++i]);
 351                     }
 352                     setOption(arg, args.toList());
 353                 }
 354             } else {
 355                 javaNames.append(arg);
 356             }
 357         }
 358 
 359         if (fileManager == null) {
 360             JavacFileManager.preRegister(context);
 361             fileManager = context.get(JavaFileManager.class);
 362             if (fileManager instanceof BaseFileManager) {
 363                 ((BaseFileManager) fileManager).autoClose = true;
 364             }
 365         }
 366         if (fileManager instanceof BaseFileManager) {
 367             ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
 368         }
 369 
 370         String platformString = compOpts.get("--release");
 371 
 372         if (platformString != null) {
 373             if (compOpts.isSet("-source")) {
 374                 usageError("main.release.bootclasspath.conflict", "-source");
 375             }
 376             if (fileManagerOpts.containsKey(Option.BOOT_CLASS_PATH)) {
 377                 usageError("main.release.bootclasspath.conflict", Option.BOOT_CLASS_PATH.getPrimaryName());
 378             }
 379 
 380             PlatformDescription platformDescription =
 381                     PlatformUtils.lookupPlatformDescription(platformString);
 382 
 383             if (platformDescription == null) {
 384                 usageError("main.unsupported.release.version", platformString);
 385             }
 386 
 387             compOpts.put(Option.SOURCE, platformDescription.getSourceVersion());
 388 
 389             context.put(PlatformDescription.class, platformDescription);
 390 
 391             Collection<Path> platformCP = platformDescription.getPlatformPath();
 392 
 393             if (platformCP != null) {
 394                 if (fileManager instanceof StandardJavaFileManager) {
 395                     StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
 396 
 397                     sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);


 540     /**
 541      * indicate an option with one argument was given.
 542      */
 543     private void setOption(String opt, String argument) {
 544         String[] option = { opt, argument };
 545         options.append(option);
 546     }
 547 
 548     /**
 549      * indicate an option with the specified list of arguments was given.
 550      */
 551     private void setOption(String opt, List<String> arguments) {
 552         String[] args = new String[arguments.length() + 1];
 553         int k = 0;
 554         args[k++] = opt;
 555         for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
 556             args[k++] = i.head;
 557         }
 558         options.append(args);
 559     }
 560 
 561     @Override
 562     OptionHelper getOptionHelper() {
 563         return new GrumpyHelper(null) {
 564             @Override
 565             public String get(com.sun.tools.javac.main.Option option) {
 566                 return compOpts.get(option);
 567             }
 568 
 569             @Override
 570             public void put(String name, String value) {
 571                 compOpts.put(name, value);
 572             }
 573         };
 574     }
 575 }
< prev index next >