langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java
changeset 44020 ef5f709f4fd8
parent 42828 cce89649f958
child 44189 dd311cfb920b
equal deleted inserted replaced
44019:284fa2ebd030 44020:ef5f709f4fd8
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   419             return (rc == 0) ? OK : ERROR;
   419             return (rc == 0) ? OK : ERROR;
   420         }
   420         }
   421 
   421 
   422         Result result = OK;
   422         Result result = OK;
   423         try {
   423         try {
   424             result = parseAndExecute(options, fileObjects)
   424             result = parseAndExecute(options, fileObjects);
   425                     ? OK
       
   426                     : ERROR;
       
   427         } catch (com.sun.tools.javac.main.Option.InvalidValueException e) {
   425         } catch (com.sun.tools.javac.main.Option.InvalidValueException e) {
   428             messager.printError(e.getMessage());
   426             messager.printError(e.getMessage());
   429             Throwable t = e.getCause();
   427             Throwable t = e.getCause();
   430             dumpStack(t == null ? e : t);
   428             dumpStack(t == null ? e : t);
   431             return ERROR;
   429             return ERROR;
   499 
   497 
   500     /**
   498     /**
   501      * Main program - internal
   499      * Main program - internal
   502      */
   500      */
   503     @SuppressWarnings("unchecked")
   501     @SuppressWarnings("unchecked")
   504     private boolean parseAndExecute(List<String> argList, Iterable<? extends JavaFileObject> fileObjects)
   502     private Result parseAndExecute(List<String> argList, Iterable<? extends JavaFileObject> fileObjects)
   505             throws ToolException, OptionException, com.sun.tools.javac.main.Option.InvalidValueException {
   503             throws ToolException, OptionException, com.sun.tools.javac.main.Option.InvalidValueException {
   506         long tm = System.currentTimeMillis();
   504         long tm = System.currentTimeMillis();
   507 
   505 
   508         List<String> javaNames = new ArrayList<>();
   506         List<String> javaNames = new ArrayList<>();
   509 
   507 
   519         parseArgs(argList, javaNames);
   517         parseArgs(argList, javaNames);
   520 
   518 
   521         Arguments arguments = Arguments.instance(context);
   519         Arguments arguments = Arguments.instance(context);
   522         arguments.init(ProgramName);
   520         arguments.init(ProgramName);
   523         arguments.allowEmpty();
   521         arguments.allowEmpty();
   524         arguments.validate();
   522         if (!arguments.validate()) {
       
   523             // Arguments does not always increase the error count in the
       
   524             // case of errors, so increment the error count only if it has
       
   525             // not been updated previously, preventing complaints by callers
       
   526             if (!messager.hasErrors() && !messager.hasWarnings())
       
   527                 messager.nerrors++;
       
   528             return CMDERR;
       
   529         }
   525 
   530 
   526         if (fileManager instanceof BaseFileManager) {
   531         if (fileManager instanceof BaseFileManager) {
   527             ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
   532             ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
   528         }
   533         }
   529 
   534 
   584                 }
   589                 }
   585             }
   590             }
   586         }
   591         }
   587 
   592 
   588         JavadocTool comp = JavadocTool.make0(context);
   593         JavadocTool comp = JavadocTool.make0(context);
   589         if (comp == null) return false;
   594         if (comp == null) return ABNORMAL;
   590 
   595 
   591         DocletEnvironment docEnv = comp.getEnvironment(jdtoolOpts,
   596         DocletEnvironment docEnv = comp.getEnvironment(jdtoolOpts,
   592                 javaNames,
   597                 javaNames,
   593                 fileObjects);
   598                 fileObjects);
   594 
   599 
   598         if (breakiterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
   603         if (breakiterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
   599             JavacTrees trees = JavacTrees.instance(context);
   604             JavacTrees trees = JavacTrees.instance(context);
   600             trees.setBreakIterator(BreakIterator.getSentenceInstance(locale));
   605             trees.setBreakIterator(BreakIterator.getSentenceInstance(locale));
   601         }
   606         }
   602         // pass off control to the doclet
   607         // pass off control to the doclet
   603         boolean ok = docEnv != null;
   608         Result returnStatus = docEnv != null && doclet.run(docEnv)
   604         if (ok) ok = doclet.run(docEnv);
   609                 ? OK
       
   610                 : ERROR;
   605 
   611 
   606         // We're done.
   612         // We're done.
   607         if (compOpts.get("-verbose") != null) {
   613         if (compOpts.get("-verbose") != null) {
   608             tm = System.currentTimeMillis() - tm;
   614             tm = System.currentTimeMillis() - tm;
   609             messager.notice("main.done_in", Long.toString(tm));
   615             messager.notice("main.done_in", Long.toString(tm));
   610         }
   616         }
   611 
   617 
   612         return ok;
   618         return returnStatus;
   613     }
   619     }
   614 
   620 
   615     boolean matches(List<String> names, String arg) {
   621     boolean matches(List<String> names, String arg) {
   616         for (String name : names) {
   622         for (String name : names) {
   617             if (StringUtils.toLowerCase(name).equals(StringUtils.toLowerCase(arg)))
   623             if (StringUtils.toLowerCase(name).equals(StringUtils.toLowerCase(arg)))