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

Thu, 10 Jun 2010 16:08:01 -0700

author
jjg
date
Thu, 10 Jun 2010 16:08:01 -0700
changeset 581
f2fdd52e4e87
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

6944312: Potential rebranding issues in openjdk/langtools repository sources
Reviewed-by: darcy

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

mercurial