langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JRTIndex.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 34560 b6a567b677f7
child 36526 3b41f1c69604
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     1
/*
31753
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     4
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    10
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    15
 * accompanied this code).
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    16
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    20
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    23
 * questions.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 34560
diff changeset
    25
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    26
package com.sun.tools.javac.file;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    27
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    28
import java.io.IOException;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    29
import java.io.UncheckedIOException;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    30
import java.lang.ref.SoftReference;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    31
import java.net.URI;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    32
import java.nio.file.DirectoryStream;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    33
import java.nio.file.FileSystem;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    34
import java.nio.file.FileSystems;
27859
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    35
import java.nio.file.FileSystemNotFoundException;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    36
import java.nio.file.Files;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    37
import java.nio.file.Path;
27859
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    38
import java.nio.file.ProviderNotFoundException;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    39
import java.util.Collections;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    40
import java.util.HashMap;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    41
import java.util.LinkedHashMap;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    42
import java.util.LinkedHashSet;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    43
import java.util.Map;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    44
import java.util.MissingResourceException;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    45
import java.util.ResourceBundle;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    46
import java.util.Set;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    47
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    48
import javax.tools.FileObject;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    49
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    50
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    51
import com.sun.tools.javac.util.Context;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    52
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    53
/**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    54
 * A package-oriented index into the jrt: filesystem.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    55
 */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    56
public class JRTIndex {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    57
    /** Get a shared instance of the cache. */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    58
    private static JRTIndex sharedInstance;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    59
    public synchronized static JRTIndex getSharedInstance() {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    60
        if (sharedInstance == null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    61
            try {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    62
                sharedInstance = new JRTIndex();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    63
            } catch (IOException e) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    64
                throw new UncheckedIOException(e);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    65
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    66
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    67
        return sharedInstance;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    68
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    69
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    70
    /** Get a context-specific instance of a cache. */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    71
    public static JRTIndex instance(Context context) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    72
        try {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    73
            JRTIndex instance = context.get(JRTIndex.class);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    74
            if (instance == null)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    75
                context.put(JRTIndex.class, instance = new JRTIndex());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    76
            return instance;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    77
        } catch (IOException e) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    78
            throw new UncheckedIOException(e);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    79
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    80
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    81
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    82
    public static boolean isAvailable() {
27859
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    83
        try {
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    84
            FileSystems.getFileSystem(URI.create("jrt:/"));
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    85
            return true;
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    86
        } catch (ProviderNotFoundException | FileSystemNotFoundException e) {
f5bd37460a09 8066731: javac does not work on exploded image
jjg
parents: 27579
diff changeset
    87
            return false;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    88
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    89
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    90
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    91
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    92
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    93
     * The jrt: file system.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    94
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    95
    private final FileSystem jrtfs;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    96
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    97
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    98
     * A lazily evaluated set of entries about the contents of the jrt: file system.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    99
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   100
    private final Map<RelativeDirectory, SoftReference<Entry>> entries;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   101
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   102
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   103
     * An entry provides cached info about a specific package directory within jrt:.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   104
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   105
    class Entry {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   106
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   107
         * The regular files for this package.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   108
         * For now, assume just one instance of each file across all modules.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   109
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   110
        final Map<String, Path> files;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   111
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   112
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   113
         * The set of subdirectories in jrt: for this package.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   114
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   115
        final Set<RelativeDirectory> subdirs;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   116
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   117
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   118
         * The info that used to be in ct.sym for classes in this package.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   119
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   120
        final CtSym ctSym;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   121
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   122
        private Entry(Map<String, Path> files, Set<RelativeDirectory> subdirs, CtSym ctSym) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   123
            this.files = files;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   124
            this.subdirs = subdirs;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   125
            this.ctSym = ctSym;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   126
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   127
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   128
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   129
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   130
     * The info that used to be in ct.sym for classes in a package.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   131
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   132
    public static class CtSym {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   133
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   134
         * The classes in this package are internal and not visible.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   135
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   136
        public final boolean hidden;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   137
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   138
         * The classes in this package are proprietary and will generate a warning.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   139
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   140
        public final boolean proprietary;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   141
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   142
         * The minimum profile in which classes in this package are available.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   143
         */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   144
        public final String minProfile;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   145
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   146
        CtSym(boolean hidden, boolean proprietary, String minProfile) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   147
            this.hidden = hidden;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   148
            this.proprietary = proprietary;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   149
            this.minProfile = minProfile;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   150
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   151
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   152
        @Override
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   153
        public String toString() {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   154
            StringBuilder sb = new StringBuilder("CtSym[");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   155
            boolean needSep = false;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   156
            if (hidden) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   157
                sb.append("hidden");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   158
                needSep = true;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   159
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   160
            if (proprietary) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   161
                if (needSep) sb.append(",");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   162
                sb.append("proprietary");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   163
                needSep = true;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   164
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   165
            if (minProfile != null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   166
                if (needSep) sb.append(",");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   167
                sb.append(minProfile);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   168
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   169
            sb.append("]");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   170
            return sb.toString();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   171
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   172
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   173
        static final CtSym EMPTY = new CtSym(false, false, null);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   174
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   175
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   176
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   177
     * Create and initialize the index.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   178
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   179
    private JRTIndex() throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   180
        jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   181
        entries = new HashMap<>();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   182
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   183
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   184
    public CtSym getCtSym(CharSequence packageName) throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   185
        return getEntry(RelativeDirectory.forPackage(packageName)).ctSym;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   186
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   187
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   188
    synchronized Entry getEntry(RelativeDirectory rd) throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   189
        SoftReference<Entry> ref = entries.get(rd);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   190
        Entry e = (ref == null) ? null : ref.get();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   191
        if (e == null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   192
            Map<String, Path> files = new LinkedHashMap<>();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   193
            Set<RelativeDirectory> subdirs = new LinkedHashSet<>();
31753
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   194
            Path dir;
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   195
            if (rd.path.isEmpty()) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   196
                dir = jrtfs.getPath("/modules");
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   197
            } else {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   198
                Path pkgs = jrtfs.getPath("/packages");
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   199
                dir = pkgs.resolve(rd.getPath().replaceAll("/$", "").replace("/", "."));
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   200
            }
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   201
            if (Files.exists(dir)) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   202
                try (DirectoryStream<Path> modules = Files.newDirectoryStream(dir)) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   203
                    for (Path module: modules) {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 31753
diff changeset
   204
                        Path p = rd.resolveAgainst(module);
31753
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   205
                        if (!Files.exists(p))
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   206
                            continue;
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   207
                        try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   208
                            for (Path entry: stream) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   209
                                String name = entry.getFileName().toString();
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   210
                                if (Files.isRegularFile(entry)) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   211
                                    // TODO: consider issue of files with same name in different modules
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   212
                                    files.put(name, entry);
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   213
                                } else if (Files.isDirectory(entry)) {
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   214
                                    subdirs.add(new RelativeDirectory(rd, name));
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   215
                                }
72417309a675 8080511: Refresh of jimage support
jfdenise
parents: 29780
diff changeset
   216
                            }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   217
                        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   218
                    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   219
                }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   220
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   221
            e = new Entry(Collections.unmodifiableMap(files),
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   222
                    Collections.unmodifiableSet(subdirs),
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   223
                    getCtInfo(rd));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   224
            entries.put(rd, new SoftReference<>(e));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   225
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   226
        return e;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   227
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   228
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   229
    public boolean isInJRT(FileObject fo) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   230
        if (fo instanceof PathFileObject) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   231
            Path path = ((PathFileObject) fo).getPath();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   232
            return (path.getFileSystem() == jrtfs);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   233
        } else {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   234
            return false;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   235
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   236
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   237
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   238
    private CtSym getCtInfo(RelativeDirectory dir) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   239
        if (dir.path.isEmpty())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   240
            return CtSym.EMPTY;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   241
        // It's a side-effect of the default build rules that ct.properties
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   242
        // ends up as a resource bundle.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   243
        if (ctBundle == null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   244
            final String bundleName = "com.sun.tools.javac.resources.ct";
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   245
            ctBundle = ResourceBundle.getBundle(bundleName);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   246
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   247
        try {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   248
            String attrs = ctBundle.getString(dir.path.replace('/', '.') + '*');
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   249
            boolean hidden = false;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   250
            boolean proprietary = false;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   251
            String minProfile = null;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   252
            for (String attr: attrs.split(" +", 0)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   253
                switch (attr) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   254
                    case "hidden":
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   255
                        hidden = true;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   256
                        break;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   257
                    case "proprietary":
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   258
                        proprietary = true;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   259
                        break;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   260
                    default:
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   261
                        minProfile = attr;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   262
                }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   263
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   264
            return new CtSym(hidden, proprietary, minProfile);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   265
        } catch (MissingResourceException e) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   266
            return CtSym.EMPTY;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   267
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   268
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   269
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   270
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   271
    private ResourceBundle ctBundle;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   272
}