Fri, 09 May 2014 20:33:21 -0700
8041424: 8u20 l10n resource file translation update 1
Reviewed-by: naoto, yhuang
jjg@1413 | 1 | /* |
jjg@1543 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1413 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1413 | 4 | * |
jjg@1413 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1413 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1413 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@1413 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@1413 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@1413 | 10 | * |
jjg@1413 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1413 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1413 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1413 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1413 | 15 | * accompanied this code). |
jjg@1413 | 16 | * |
jjg@1413 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@1413 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1413 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1413 | 20 | * |
jjg@1413 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1413 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@1413 | 23 | * questions. |
jjg@1413 | 24 | */ |
jjg@1413 | 25 | |
jjg@1413 | 26 | package com.sun.tools.javadoc.api; |
jjg@1413 | 27 | |
jjg@1413 | 28 | import java.io.InputStream; |
jjg@1413 | 29 | import java.io.OutputStream; |
jjg@1413 | 30 | import java.io.OutputStreamWriter; |
jjg@1413 | 31 | import java.io.PrintWriter; |
jjg@1413 | 32 | import java.io.Writer; |
jjg@1413 | 33 | import java.nio.charset.Charset; |
jjg@1413 | 34 | import java.util.Collections; |
jjg@1413 | 35 | import java.util.EnumSet; |
jjg@1413 | 36 | import java.util.Locale; |
jjg@1413 | 37 | import java.util.Set; |
jjg@1413 | 38 | |
jjg@1413 | 39 | import javax.lang.model.SourceVersion; |
jjg@1413 | 40 | import javax.tools.DiagnosticListener; |
jjg@1413 | 41 | import javax.tools.DocumentationTool; |
jjg@1413 | 42 | import javax.tools.JavaFileManager; |
jjg@1413 | 43 | import javax.tools.JavaFileObject; |
jjg@1413 | 44 | import javax.tools.StandardJavaFileManager; |
jjg@1413 | 45 | |
jjg@1413 | 46 | import com.sun.tools.javac.api.ClientCodeWrapper; |
jjg@1413 | 47 | import com.sun.tools.javac.file.JavacFileManager; |
jjg@1413 | 48 | import com.sun.tools.javac.util.ClientCodeException; |
jjg@1413 | 49 | import com.sun.tools.javac.util.Context; |
jjg@1413 | 50 | import com.sun.tools.javac.util.Log; |
jjg@1413 | 51 | import com.sun.tools.javadoc.ToolOption; |
jjg@1413 | 52 | |
jjg@1413 | 53 | /** |
jjg@1413 | 54 | * Provides access to functionality specific to the JDK documentation tool, |
jjg@1413 | 55 | * javadoc. |
jjg@1413 | 56 | * |
jjg@1413 | 57 | * <p><b>This is NOT part of any supported API. |
jjg@1413 | 58 | * If you write code that depends on this, you do so at your own |
jjg@1413 | 59 | * risk. This code and its internal interfaces are subject to change |
jjg@1413 | 60 | * or deletion without notice.</b></p> |
jjg@1413 | 61 | */ |
jjg@1413 | 62 | public class JavadocTool implements DocumentationTool { |
jjg@1413 | 63 | @Override |
jjg@1413 | 64 | public DocumentationTask getTask( |
jjg@1413 | 65 | Writer out, |
jjg@1413 | 66 | JavaFileManager fileManager, |
jjg@1413 | 67 | DiagnosticListener<? super JavaFileObject> diagnosticListener, |
jjg@1413 | 68 | Class<?> docletClass, |
jjg@1413 | 69 | Iterable<String> options, |
jjg@1413 | 70 | Iterable<? extends JavaFileObject> compilationUnits) { |
jjg@1413 | 71 | Context context = new Context(); |
jjg@1413 | 72 | return getTask(out, fileManager, diagnosticListener, |
jjg@1413 | 73 | docletClass, options, compilationUnits, context); |
jjg@1413 | 74 | } |
jjg@1413 | 75 | |
jjg@1413 | 76 | public DocumentationTask getTask( |
jjg@1413 | 77 | Writer out, |
jjg@1413 | 78 | JavaFileManager fileManager, |
jjg@1413 | 79 | DiagnosticListener<? super JavaFileObject> diagnosticListener, |
jjg@1413 | 80 | Class<?> docletClass, |
jjg@1413 | 81 | Iterable<String> options, |
jjg@1413 | 82 | Iterable<? extends JavaFileObject> compilationUnits, |
jjg@1413 | 83 | Context context) { |
jjg@1413 | 84 | try { |
jjg@1413 | 85 | ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); |
jjg@1413 | 86 | |
jjg@1413 | 87 | if (options != null) { |
jjg@1413 | 88 | for (String option : options) |
jjg@1413 | 89 | option.getClass(); // null check |
jjg@1413 | 90 | } |
jjg@1413 | 91 | |
jjg@1413 | 92 | if (compilationUnits != null) { |
jjg@1413 | 93 | compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check |
jjg@1413 | 94 | for (JavaFileObject cu : compilationUnits) { |
jjg@1413 | 95 | if (cu.getKind() != JavaFileObject.Kind.SOURCE) { |
jjg@1413 | 96 | final String kindMsg = "All compilation units must be of SOURCE kind"; |
jjg@1413 | 97 | throw new IllegalArgumentException(kindMsg); |
jjg@1413 | 98 | } |
jjg@1413 | 99 | } |
jjg@1413 | 100 | } |
jjg@1413 | 101 | |
jjg@1413 | 102 | if (diagnosticListener != null) |
jjg@1413 | 103 | context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener)); |
jjg@1413 | 104 | |
jjg@1413 | 105 | if (out == null) |
jjg@1413 | 106 | context.put(Log.outKey, new PrintWriter(System.err, true)); |
jjg@1413 | 107 | else if (out instanceof PrintWriter) |
jjg@1413 | 108 | context.put(Log.outKey, ((PrintWriter) out)); |
jjg@1413 | 109 | else |
jjg@1413 | 110 | context.put(Log.outKey, new PrintWriter(out, true)); |
jjg@1413 | 111 | |
jjg@1413 | 112 | if (fileManager == null) |
jjg@1413 | 113 | fileManager = getStandardFileManager(diagnosticListener, null, null); |
jjg@1413 | 114 | fileManager = ccw.wrap(fileManager); |
jjg@1413 | 115 | context.put(JavaFileManager.class, fileManager); |
jjg@1413 | 116 | |
jjg@1413 | 117 | return new JavadocTaskImpl(context, docletClass, options, compilationUnits); |
jjg@1413 | 118 | } catch (ClientCodeException ex) { |
jjg@1413 | 119 | throw new RuntimeException(ex.getCause()); |
jjg@1413 | 120 | } |
jjg@1413 | 121 | } |
jjg@1413 | 122 | |
jjg@1413 | 123 | // TODO: used shared static method in JavacFileManager |
jjg@1413 | 124 | @Override |
jjg@1413 | 125 | public StandardJavaFileManager getStandardFileManager( |
jjg@1413 | 126 | DiagnosticListener<? super JavaFileObject> diagnosticListener, |
jjg@1413 | 127 | Locale locale, |
jjg@1413 | 128 | Charset charset) { |
jjg@1413 | 129 | Context context = new Context(); |
jjg@1413 | 130 | context.put(Locale.class, locale); |
jjg@1413 | 131 | if (diagnosticListener != null) |
jjg@1413 | 132 | context.put(DiagnosticListener.class, diagnosticListener); |
jjg@1413 | 133 | PrintWriter pw = (charset == null) |
jjg@1413 | 134 | ? new PrintWriter(System.err, true) |
jjg@1413 | 135 | : new PrintWriter(new OutputStreamWriter(System.err, charset), true); |
jjg@1413 | 136 | context.put(Log.outKey, pw); |
jjg@1413 | 137 | return new JavacFileManager(context, true, charset); |
jjg@1413 | 138 | } |
jjg@1413 | 139 | |
jjg@1413 | 140 | @Override |
jjg@1413 | 141 | public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { |
jjg@1543 | 142 | PrintWriter err_pw = new PrintWriter(err == null ? System.err : err, true); |
jjg@1543 | 143 | PrintWriter out_pw = new PrintWriter(out == null ? System.out : out); |
jjg@1413 | 144 | try { |
jjg@1413 | 145 | String standardDocletName = "com.sun.tools.doclets.standard.Standard"; |
jjg@1544 | 146 | ClassLoader cl = getClass().getClassLoader(); |
jjg@1413 | 147 | return com.sun.tools.javadoc.Main.execute( |
jjg@1544 | 148 | "javadoc", err_pw, err_pw, out_pw, standardDocletName, cl, arguments); |
jjg@1413 | 149 | } finally { |
jjg@1413 | 150 | err_pw.flush(); |
jjg@1413 | 151 | out_pw.flush(); |
jjg@1413 | 152 | } |
jjg@1413 | 153 | } |
jjg@1413 | 154 | |
jjg@1413 | 155 | @Override |
jjg@1413 | 156 | public Set<SourceVersion> getSourceVersions() { |
jjg@1413 | 157 | return Collections.unmodifiableSet( |
jjg@1413 | 158 | EnumSet.range(SourceVersion.RELEASE_3, SourceVersion.latest())); |
jjg@1413 | 159 | } |
jjg@1413 | 160 | |
jjg@1413 | 161 | @Override |
jjg@1413 | 162 | public int isSupportedOption(String option) { |
jjg@1413 | 163 | if (option == null) |
jjg@1413 | 164 | throw new NullPointerException(); |
jjg@1413 | 165 | for (ToolOption o: ToolOption.values()) { |
jjg@1413 | 166 | if (o.opt.equals(option)) |
jjg@1413 | 167 | return o.hasArg ? 1 : 0; |
jjg@1413 | 168 | } |
jjg@1413 | 169 | return -1; |
jjg@1413 | 170 | } |
jjg@1413 | 171 | |
jjg@1413 | 172 | } |