jjg@106: /* jjg@839: * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. jjg@106: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@106: * jjg@106: * This code is free software; you can redistribute it and/or modify it jjg@106: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this jjg@106: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. jjg@106: * jjg@106: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@106: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@106: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@106: * version 2 for more details (a copy is included in the LICENSE file that jjg@106: * accompanied this code). jjg@106: * jjg@106: * You should have received a copy of the GNU General Public License version jjg@106: * 2 along with this work; if not, write to the Free Software Foundation, jjg@106: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@106: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@106: */ jjg@106: jjg@106: package com.sun.tools.javac.file; jjg@106: jjg@106: import java.io.File; jjg@106: import java.io.IOException; jjg@106: import java.util.List; jjg@839: import java.util.Map; jjg@839: import java.util.concurrent.ConcurrentHashMap; jjg@106: jjg@106: import com.sun.tools.javac.util.Context; jjg@106: jjg@106: /** jjg@333: * Caching implementation of FSInfo. jjg@333: * jjg@581: *

This is NOT part of any supported API. 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@106: */ jjg@106: public class CacheFSInfo extends FSInfo { jjg@106: jjg@106: /** jjg@893: * Register a Context.Factory to create a CacheFSInfo. jjg@106: */ jjg@893: public static void preRegister(Context context) { jjg@106: context.put(FSInfo.class, new Context.Factory() { jjg@893: public FSInfo make(Context c) { jjg@872: FSInfo instance = new CacheFSInfo(); jjg@893: c.put(FSInfo.class, instance); jjg@872: return instance; jjg@106: } jjg@106: }); jjg@106: } jjg@106: jjg@106: public void clearCache() { jjg@106: cache.clear(); jjg@106: } jjg@106: jjg@106: @Override jjg@106: public File getCanonicalFile(File file) { jjg@106: Entry e = getEntry(file); jjg@106: return e.canonicalFile; jjg@106: } jjg@106: jjg@106: @Override jjg@106: public boolean exists(File file) { jjg@106: Entry e = getEntry(file); jjg@106: return e.exists; jjg@106: } jjg@106: jjg@106: @Override jjg@106: public boolean isDirectory(File file) { jjg@106: Entry e = getEntry(file); jjg@106: return e.isDirectory; jjg@106: } jjg@106: jjg@106: @Override jjg@106: public boolean isFile(File file) { jjg@106: Entry e = getEntry(file); jjg@106: return e.isFile; jjg@106: } jjg@106: jjg@106: @Override jjg@106: public List getJarClassPath(File file) throws IOException { jjg@106: // don't bother to lock the cache, because it is thread-safe, and jjg@106: // because the worst that can happen would be to create two identical jjg@106: // jar class paths together and have one overwrite the other. jjg@106: Entry e = getEntry(file); jjg@106: if (e.jarClassPath == null) jjg@106: e.jarClassPath = super.getJarClassPath(file); jjg@106: return e.jarClassPath; jjg@106: } jjg@106: jjg@106: private Entry getEntry(File file) { jjg@106: // don't bother to lock the cache, because it is thread-safe, and jjg@106: // because the worst that can happen would be to create two identical jjg@106: // entries together and have one overwrite the other. jjg@106: Entry e = cache.get(file); jjg@106: if (e == null) { jjg@106: e = new Entry(); jjg@106: e.canonicalFile = super.getCanonicalFile(file); jjg@106: e.exists = super.exists(file); jjg@106: e.isDirectory = super.isDirectory(file); jjg@106: e.isFile = super.isFile(file); jjg@106: cache.put(file, e); jjg@106: } jjg@106: return e; jjg@106: } jjg@106: jjg@106: // could also be a Map> ? jjg@106: private Map cache = new ConcurrentHashMap(); jjg@106: jjg@106: private static class Entry { jjg@106: File canonicalFile; jjg@106: boolean exists; jjg@106: boolean isFile; jjg@106: boolean isDirectory; jjg@106: List jarClassPath; jjg@106: } jjg@106: }