56N/A/*
553N/A * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
56N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56N/A *
56N/A * This code is free software; you can redistribute it and/or modify it
56N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
56N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
56N/A *
56N/A * This code is distributed in the hope that it will be useful, but WITHOUT
56N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56N/A * version 2 for more details (a copy is included in the LICENSE file that
56N/A * accompanied this code).
56N/A *
56N/A * You should have received a copy of the GNU General Public License version
56N/A * 2 along with this work; if not, write to the Free Software Foundation,
56N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
56N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
56N/A */
56N/A
56N/Apackage com.sun.tools.javac.file;
56N/A
56N/Aimport java.io.File;
56N/Aimport java.io.IOException;
56N/Aimport java.util.zip.ZipEntry;
56N/Aimport java.util.zip.ZipFile;
56N/Aimport javax.tools.JavaFileObject;
56N/A
102N/Aimport com.sun.tools.javac.file.RelativePath.RelativeDirectory;
102N/Aimport com.sun.tools.javac.file.RelativePath.RelativeFile;
102N/Aimport com.sun.tools.javac.util.List;
102N/A
332N/A/**
580N/A * <p><b>This is NOT part of any supported API.
332N/A * If you write code that depends on this, you do so at your own risk.
332N/A * This code and its internal interfaces are subject to change or
332N/A * deletion without notice.</b>
332N/A*/
56N/Apublic class SymbolArchive extends ZipArchive {
56N/A
56N/A final File origFile;
102N/A final RelativeDirectory prefix;
56N/A
102N/A public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException {
102N/A super(fileManager, zdir, false);
56N/A this.origFile = orig;
56N/A this.prefix = prefix;
102N/A initMap();
56N/A }
56N/A
56N/A @Override
56N/A void addZipEntry(ZipEntry entry) {
56N/A String name = entry.getName();
102N/A if (!name.startsWith(prefix.path)) {
56N/A return;
56N/A }
102N/A name = name.substring(prefix.path.length());
56N/A int i = name.lastIndexOf('/');
102N/A RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
56N/A String basename = name.substring(i + 1);
56N/A if (basename.length() == 0) {
56N/A return;
56N/A }
56N/A List<String> list = map.get(dirname);
102N/A if (list == null)
56N/A list = List.nil();
56N/A list = list.prepend(basename);
56N/A map.put(dirname, list);
56N/A }
56N/A
399N/A @Override
102N/A public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
102N/A RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path);
423N/A ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zfile);
102N/A return new SymbolFileObject(this, file, ze);
102N/A }
102N/A
399N/A @Override
102N/A public String toString() {
423N/A return "SymbolArchive[" + zfile.getName() + "]";
56N/A }
102N/A
102N/A /**
102N/A * A subclass of JavaFileObject representing zip entries in a symbol file.
102N/A */
102N/A public static class SymbolFileObject extends ZipFileObject {
102N/A protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) {
102N/A super(zarch, name, entry);
102N/A }
102N/A
102N/A @Override
102N/A protected String inferBinaryName(Iterable<? extends File> path) {
414N/A String entryName = entry.getName();
102N/A String prefix = ((SymbolArchive) zarch).prefix.path;
102N/A if (entryName.startsWith(prefix))
102N/A entryName = entryName.substring(prefix.length());
102N/A return removeExtension(entryName).replace('/', '.');
102N/A }
102N/A }
102N/A
102N/A
56N/A}