public abstract class CachedJarsPackageManager extends PackageManager
Modifier and Type | Class and Description |
---|---|
static class |
CachedJarsPackageManager.JarXEntry
Class of object used to represent a cache file and last modification time, internally and to
outCreateCacheFile(org.python.core.packagecache.CachedJarsPackageManager.JarXEntry, boolean) . |
Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
logger |
topLevelPackage
Constructor and Description |
---|
CachedJarsPackageManager() |
Modifier and Type | Method and Description |
---|---|
void |
addJarToPackages(java.io.File jarfile)
Gathers classes info from jar specified by File jarfile.
|
void |
addJarToPackages(java.io.File jarfile,
boolean cache)
Gathers package and class lists from a jar specified by a
File . |
void |
addJarToPackages(java.net.URL jarurl)
Gathers classes info from jar specified by a URL.
|
void |
addJarToPackages(java.net.URL jarurl,
boolean cache)
Gathers classes info from jar specified by URL.
|
protected void |
addModuleToPackages(java.nio.file.Path modulePath)
Scan a Java module, creating package objects.
|
protected void |
comment(java.lang.String msg,
java.lang.Object... params)
Comment log method - hook.
|
protected void |
debug(java.lang.String msg,
java.lang.Object... params)
Debug log method - hook.
|
protected void |
deleteCacheFile(java.lang.String cachefile)
Delete (invalidated) cache file from persistent storage - hook.
|
protected boolean |
filterByAccess(java.lang.String name,
int acc)
Filter class by access perms helper method - hook.
|
protected boolean |
filterByName(java.lang.String name,
boolean pkg)
Filter class/pkg by name helper method - hook.
|
protected void |
initCache()
Initialise the cache by reading the index from storage, through
inOpenIndex() , or by
creating a new empty one. |
protected java.io.DataInputStream |
inOpenCacheFile(java.lang.String cachefile)
Open a particular cache file for reading from persistent storage.
|
protected java.io.DataInputStream |
inOpenIndex()
Open cache index for reading from persistent storage – hook.
|
protected void |
message(java.lang.String msg,
java.lang.Object... params)
Message log method - hook.
|
protected java.io.DataOutputStream |
outCreateCacheFile(CachedJarsPackageManager.JarXEntry entry,
boolean create)
Create/open cache file for rewriting back to persistent storage – hook.
|
protected java.io.DataOutputStream |
outOpenIndex()
Open cache index for writing back to persistent storage – hook.
|
void |
saveCache()
Write back cache index.
|
protected static java.lang.String[] |
splitString(java.lang.String str,
int maxLength)
Split up a string into several chunks based on a certain size
The writeCacheFile method will use the writeUTF method on a DataOutputStream which only
allows writing 64k chunks, so use this utility method to split it up
|
protected boolean |
useCacheDir(java.io.File cachedir)
Initialize off-the-shelf (default) local file-system cache implementation.
|
protected void |
warning(java.lang.String msg,
java.lang.Object... params)
Warning log method - hook.
|
addDirectory, addJar, addJarDir, basicDoDir, checkAccess, doDir, findClass, findClass, lookupName, makeJavaPackage, merge, notifyPackageImport, packageExists, split, split
protected void message(java.lang.String msg, java.lang.Object... params)
msg
- message template (see java.text.MessageFormat)params
- parameters to insertprotected void warning(java.lang.String msg, java.lang.Object... params)
msg
- message template (see java.text.MessageFormat)params
- parameters to insertprotected void comment(java.lang.String msg, java.lang.Object... params)
msg
- message template (see java.text.MessageFormat)params
- parameters to insertprotected void debug(java.lang.String msg, java.lang.Object... params)
msg
- message template (see java.text.MessageFormat)params
- parameters to insertprotected boolean filterByName(java.lang.String name, boolean pkg)
addJarToPackages(java.net.URL)
in order to filter out classes whose name contains '$' (e.g. inner
classes). Should be used or overridden by derived classes too. Also to be used in
PackageManager.doDir(org.python.core.PyJavaPackage, boolean, boolean)
.name
- class/pkg namepkg
- if true, name refers to a pkgtrue
if name should be filtered outprotected boolean filterByAccess(java.lang.String name, int acc)
addJarToPackages(java.net.URL)
in order to filter out non-public classes. Should be used or
overridden by derived classes too. Also to be used in PackageManager.doDir(org.python.core.PyJavaPackage, boolean, boolean)
. Access permissions can
be read with PackageManager.checkAccess(java.io.InputStream)
.name
- class nameacc
- class access permissions as inttrue
if name should be filtered outpublic void addJarToPackages(java.net.URL jarurl)
public void addJarToPackages(java.net.URL jarurl, boolean cache)
public void addJarToPackages(java.io.File jarfile)
public void addJarToPackages(java.io.File jarfile, boolean cache)
File
. Eventually just using
previously cached info. Eventually updated info is (re-)cached if param cache is true.
Persistent cache storage access goes through inOpenCacheFile() and outCreateCacheFile().protected void addModuleToPackages(java.nio.file.Path modulePath)
protected static java.lang.String[] splitString(java.lang.String str, int maxLength)
str
- - The string to split up into chunksmaxLength
- - The max size a string should beprotected void initCache()
inOpenIndex()
, or by
creating a new empty one.public void saveCache()
protected java.io.DataInputStream inOpenIndex() throws java.io.IOException
java.io.IOException
protected java.io.DataOutputStream outOpenIndex() throws java.io.IOException
java.io.IOException
protected java.io.DataInputStream inOpenCacheFile(java.lang.String cachefile) throws java.io.IOException
java.io.IOException
protected void deleteCacheFile(java.lang.String cachefile)
protected java.io.DataOutputStream outCreateCacheFile(CachedJarsPackageManager.JarXEntry entry, boolean create) throws java.io.IOException
create
is false
, the cache file is supposed to exist at
entry.cachefile
and will be opened for rewriting. If create
is true
,
entry.cachefile
is the base name (e.g. JAR or module name) for a cache to be created,
and the full name will be put in entry.cachefile
on exit. This default implementation
is part of the off-the-shelf local file-system cache implementation. It may be overridden to
provide a different cache medium and use of entry.cachefile
.entry
- cache file descriptioncreate
- new or use existing file named in entry.cachefile
java.io.IOException
protected boolean useCacheDir(java.io.File cachedir)
initCache()
. cachedir is the cache repository directory, this is eventually
created. Returns true if dir works.