Thu, 18 Sep 2008 18:39:44 -0700
6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel
duke@1 | 1 | /* |
xdono@54 | 2 | * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javadoc; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.tools.javac.code.Symbol.PackageSymbol; |
jjg@50 | 29 | import com.sun.tools.javac.file.JavacFileManager; |
jjg@57 | 30 | import com.sun.tools.javac.file.ZipArchive.ZipFileObject; |
jjg@50 | 31 | import com.sun.tools.javac.file.Old199; |
jjg@57 | 32 | import com.sun.tools.javac.file.ZipFileIndexArchive; |
duke@1 | 33 | import com.sun.tools.javac.jvm.ClassReader; |
duke@1 | 34 | import com.sun.tools.javac.util.Context; |
duke@1 | 35 | |
duke@1 | 36 | import java.io.File; |
duke@1 | 37 | import java.util.EnumSet; |
duke@1 | 38 | import javax.tools.JavaFileObject; |
duke@1 | 39 | |
duke@1 | 40 | /** Javadoc uses an extended class reader that records package.html entries |
duke@1 | 41 | * @author Neal Gafter |
duke@1 | 42 | */ |
duke@1 | 43 | class JavadocClassReader extends ClassReader { |
duke@1 | 44 | |
duke@1 | 45 | public static JavadocClassReader instance0(Context context) { |
duke@1 | 46 | ClassReader instance = context.get(classReaderKey); |
duke@1 | 47 | if (instance == null) |
duke@1 | 48 | instance = new JavadocClassReader(context); |
duke@1 | 49 | return (JavadocClassReader)instance; |
duke@1 | 50 | } |
duke@1 | 51 | |
duke@1 | 52 | public static void preRegister(final Context context) { |
duke@1 | 53 | context.put(classReaderKey, new Context.Factory<ClassReader>() { |
duke@1 | 54 | public ClassReader make() { |
duke@1 | 55 | return new JavadocClassReader(context); |
duke@1 | 56 | } |
duke@1 | 57 | }); |
duke@1 | 58 | } |
duke@1 | 59 | |
duke@1 | 60 | private DocEnv docenv; |
duke@1 | 61 | private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS, |
duke@1 | 62 | JavaFileObject.Kind.SOURCE, |
duke@1 | 63 | JavaFileObject.Kind.HTML); |
duke@1 | 64 | private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS, |
duke@1 | 65 | JavaFileObject.Kind.HTML); |
duke@1 | 66 | |
duke@1 | 67 | private JavadocClassReader(Context context) { |
duke@1 | 68 | super(context, true); |
duke@1 | 69 | docenv = DocEnv.instance(context); |
duke@1 | 70 | } |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Override getPackageFileKinds to include search for package.html |
duke@1 | 74 | */ |
duke@1 | 75 | @Override |
duke@1 | 76 | protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() { |
duke@1 | 77 | return docenv.docClasses ? noSource : all; |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | /** |
duke@1 | 81 | * Override extraFileActions to check for package documentation |
duke@1 | 82 | */ |
duke@1 | 83 | @Override |
duke@1 | 84 | protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) { |
duke@1 | 85 | CharSequence fileName = Old199.getName(fo); |
duke@1 | 86 | if (docenv != null && fileName.equals("package.html")) { |
jjg@57 | 87 | if (fo instanceof ZipFileObject) { |
jjg@57 | 88 | ZipFileObject zfo = (ZipFileObject) fo; |
duke@1 | 89 | String zipName = zfo.getZipName(); |
duke@1 | 90 | String entryName = zfo.getZipEntryName(); |
duke@1 | 91 | int lastSep = entryName.lastIndexOf("/"); |
duke@1 | 92 | String classPathName = entryName.substring(0, lastSep + 1); |
duke@1 | 93 | docenv.getPackageDoc(pack).setDocPath(zipName, classPathName); |
duke@1 | 94 | } |
jjg@57 | 95 | else if (fo instanceof ZipFileIndexArchive.ZipFileIndexFileObject) { |
jjg@57 | 96 | ZipFileIndexArchive.ZipFileIndexFileObject zfo = (ZipFileIndexArchive.ZipFileIndexFileObject) fo; |
duke@1 | 97 | String zipName = zfo.getZipName(); |
duke@1 | 98 | String entryName = zfo.getZipEntryName(); |
duke@1 | 99 | if (File.separatorChar != '/') { |
duke@1 | 100 | entryName = entryName.replace(File.separatorChar, '/'); |
duke@1 | 101 | } |
duke@1 | 102 | |
duke@1 | 103 | int lastSep = entryName.lastIndexOf("/"); |
duke@1 | 104 | String classPathName = entryName.substring(0, lastSep + 1); |
duke@1 | 105 | docenv.getPackageDoc(pack).setDocPath(zipName, classPathName); |
duke@1 | 106 | } |
duke@1 | 107 | else { |
duke@1 | 108 | File fileDir = new File(Old199.getPath(fo)).getParentFile(); |
duke@1 | 109 | docenv.getPackageDoc(pack).setDocPath(fileDir.getAbsolutePath()); |
duke@1 | 110 | } |
duke@1 | 111 | } |
duke@1 | 112 | } |
duke@1 | 113 | } |