jjg@57: /* xdono@404: * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. jjg@57: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@57: * jjg@57: * This code is free software; you can redistribute it and/or modify it jjg@57: * under the terms of the GNU General Public License version 2 only, as jjg@57: * published by the Free Software Foundation. Sun designates this jjg@57: * particular file as subject to the "Classpath" exception as provided jjg@57: * by Sun in the LICENSE file that accompanied this code. jjg@57: * jjg@57: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@57: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@57: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@57: * version 2 for more details (a copy is included in the LICENSE file that jjg@57: * accompanied this code). jjg@57: * jjg@57: * You should have received a copy of the GNU General Public License version jjg@57: * 2 along with this work; if not, write to the Free Software Foundation, jjg@57: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@57: * jjg@57: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@57: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@57: * have any questions. jjg@57: */ jjg@57: jjg@57: package com.sun.tools.javac.file; jjg@57: jjg@57: import java.io.File; jjg@57: import java.io.IOException; jjg@57: import java.util.zip.ZipEntry; jjg@57: import java.util.zip.ZipFile; jjg@57: import javax.tools.JavaFileObject; jjg@57: jjg@103: import com.sun.tools.javac.file.RelativePath.RelativeDirectory; jjg@103: import com.sun.tools.javac.file.RelativePath.RelativeFile; jjg@103: import com.sun.tools.javac.util.List; jjg@103: jjg@333: /** jjg@333: *

This is NOT part of any API supported by Sun Microsystems. jjg@333: * If you write code that depends on this, you do so at your own risk. jjg@333: * This code and its internal interfaces are subject to change or jjg@333: * deletion without notice. jjg@333: */ jjg@57: public class SymbolArchive extends ZipArchive { jjg@57: jjg@57: final File origFile; jjg@103: final RelativeDirectory prefix; jjg@57: jjg@103: public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException { jjg@103: super(fileManager, zdir, false); jjg@57: this.origFile = orig; jjg@57: this.prefix = prefix; jjg@103: initMap(); jjg@57: } jjg@57: jjg@57: @Override jjg@57: void addZipEntry(ZipEntry entry) { jjg@57: String name = entry.getName(); jjg@103: if (!name.startsWith(prefix.path)) { jjg@57: return; jjg@57: } jjg@103: name = name.substring(prefix.path.length()); jjg@57: int i = name.lastIndexOf('/'); jjg@103: RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1)); jjg@57: String basename = name.substring(i + 1); jjg@57: if (basename.length() == 0) { jjg@57: return; jjg@57: } jjg@57: List list = map.get(dirname); jjg@103: if (list == null) jjg@57: list = List.nil(); jjg@57: list = list.prepend(basename); jjg@57: map.put(dirname, list); jjg@57: } jjg@57: jjg@400: @Override jjg@103: public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { jjg@103: RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path); jjg@424: ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zfile); jjg@103: return new SymbolFileObject(this, file, ze); jjg@57: } jjg@103: jjg@400: @Override jjg@103: public String toString() { jjg@424: return "SymbolArchive[" + zfile.getName() + "]"; jjg@103: } jjg@103: jjg@103: /** jjg@103: * A subclass of JavaFileObject representing zip entries in a symbol file. jjg@103: */ jjg@103: public static class SymbolFileObject extends ZipFileObject { jjg@103: protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) { jjg@103: super(zarch, name, entry); jjg@103: } jjg@103: jjg@103: @Override jjg@103: protected String inferBinaryName(Iterable path) { jjg@415: String entryName = entry.getName(); jjg@103: String prefix = ((SymbolArchive) zarch).prefix.path; jjg@103: if (entryName.startsWith(prefix)) jjg@103: entryName = entryName.substring(prefix.length()); jjg@103: return removeExtension(entryName).replace('/', '.'); jjg@103: } jjg@103: } jjg@103: jjg@103: jjg@57: }