src/share/classes/com/sun/tools/javac/file/SymbolArchive.java

Fri, 09 May 2014 20:33:21 -0700

author
mfang
date
Fri, 09 May 2014 20:33:21 -0700
changeset 2388
0add97444be9
parent 581
f2fdd52e4e87
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8041424: 8u20 l10n resource file translation update 1
Reviewed-by: naoto, yhuang

jjg@57 1 /*
ohair@554 2 * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
jjg@57 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@57 4 *
jjg@57 5 * This code is free software; you can redistribute it and/or modify it
jjg@57 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
jjg@57 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@57 10 *
jjg@57 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@57 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@57 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@57 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@57 15 * accompanied this code).
jjg@57 16 *
jjg@57 17 * You should have received a copy of the GNU General Public License version
jjg@57 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@57 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@57 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
jjg@57 24 */
jjg@57 25
jjg@57 26 package com.sun.tools.javac.file;
jjg@57 27
jjg@57 28 import java.io.File;
jjg@57 29 import java.io.IOException;
jjg@57 30 import java.util.zip.ZipEntry;
jjg@57 31 import java.util.zip.ZipFile;
jjg@57 32 import javax.tools.JavaFileObject;
jjg@57 33
jjg@103 34 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
jjg@103 35 import com.sun.tools.javac.file.RelativePath.RelativeFile;
jjg@103 36 import com.sun.tools.javac.util.List;
jjg@103 37
jjg@333 38 /**
jjg@581 39 * <p><b>This is NOT part of any supported API.
jjg@333 40 * If you write code that depends on this, you do so at your own risk.
jjg@333 41 * This code and its internal interfaces are subject to change or
jjg@333 42 * deletion without notice.</b>
jjg@333 43 */
jjg@57 44 public class SymbolArchive extends ZipArchive {
jjg@57 45
jjg@57 46 final File origFile;
jjg@103 47 final RelativeDirectory prefix;
jjg@57 48
jjg@103 49 public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException {
jjg@103 50 super(fileManager, zdir, false);
jjg@57 51 this.origFile = orig;
jjg@57 52 this.prefix = prefix;
jjg@103 53 initMap();
jjg@57 54 }
jjg@57 55
jjg@57 56 @Override
jjg@57 57 void addZipEntry(ZipEntry entry) {
jjg@57 58 String name = entry.getName();
jjg@103 59 if (!name.startsWith(prefix.path)) {
jjg@57 60 return;
jjg@57 61 }
jjg@103 62 name = name.substring(prefix.path.length());
jjg@57 63 int i = name.lastIndexOf('/');
jjg@103 64 RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
jjg@57 65 String basename = name.substring(i + 1);
jjg@57 66 if (basename.length() == 0) {
jjg@57 67 return;
jjg@57 68 }
jjg@57 69 List<String> list = map.get(dirname);
jjg@103 70 if (list == null)
jjg@57 71 list = List.nil();
jjg@57 72 list = list.prepend(basename);
jjg@57 73 map.put(dirname, list);
jjg@57 74 }
jjg@57 75
jjg@400 76 @Override
jjg@103 77 public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
jjg@103 78 RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path);
jjg@424 79 ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zfile);
jjg@103 80 return new SymbolFileObject(this, file, ze);
jjg@57 81 }
jjg@103 82
jjg@400 83 @Override
jjg@103 84 public String toString() {
jjg@424 85 return "SymbolArchive[" + zfile.getName() + "]";
jjg@103 86 }
jjg@103 87
jjg@103 88 /**
jjg@103 89 * A subclass of JavaFileObject representing zip entries in a symbol file.
jjg@103 90 */
jjg@103 91 public static class SymbolFileObject extends ZipFileObject {
jjg@103 92 protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) {
jjg@103 93 super(zarch, name, entry);
jjg@103 94 }
jjg@103 95
jjg@103 96 @Override
jjg@103 97 protected String inferBinaryName(Iterable<? extends File> path) {
jjg@415 98 String entryName = entry.getName();
jjg@103 99 String prefix = ((SymbolArchive) zarch).prefix.path;
jjg@103 100 if (entryName.startsWith(prefix))
jjg@103 101 entryName = entryName.substring(prefix.length());
jjg@103 102 return removeExtension(entryName).replace('/', '.');
jjg@103 103 }
jjg@103 104 }
jjg@103 105
jjg@103 106
jjg@57 107 }

mercurial