public class ExtensionsManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ExtensionsManager.JarFirstURIComparator
Compare URI:s so that 'jar:' scheme always are listed first.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.io.File> |
directories |
private java.util.Set<java.io.File> |
ignore |
private java.util.Map<ObjectKey<?>,ExtensionsFile> |
installedObjects |
private ProcessResults |
lastResults |
private static org.slf4j.Logger |
log |
private int |
numDeleted |
private int |
numModified |
private int |
numNew |
private int |
numUnmodified |
private Registry |
registry |
private Settings |
settings |
private java.util.Map<java.net.URI,ExtensionsFile> |
xtFiles |
Constructor and Description |
---|
ExtensionsManager(Registry registry,
java.io.File settingsFile)
Create a new extensions manager and use the given registry
to store extensions.
|
Modifier and Type | Method and Description |
---|---|
int |
addDirectory(java.io.File dir)
Add a directory to this manager.
|
private void |
addExtensionsFile(ExtensionsFile xtFile) |
ExtensionsFile |
addFile(java.io.File file)
Add a file to the manager that is supposed to contain extensions.
|
void |
addIgnore(java.io.File file)
Add a file to the ignore list.
|
ExtensionsFile |
addURI(java.net.URI uri)
Add an URI that points to an XML file containing definitions.
|
ExtensionsFile |
getFileByObjectKey(ObjectKey<?> key)
Find out which file the object with the given key was defined.
|
ExtensionsFile |
getFileByURI(java.lang.String uri)
Get the extension file that is located at the given URI.
|
java.util.List<ExtensionsFile> |
getFiles()
Get a list of all extension files managed by this manager.
|
ProcessResults |
getLastProcessResults()
Get the results of the last processing.
|
int |
getNumDeleted()
Get the number of deleted files that was found in the last
call to
scanForChanges() . |
int |
getNumModified()
Get the number of modified files that was found in the last
call to
scanForChanges() . |
int |
getNumNew()
Get the number of new files that was found in the last
call to
scanForChanges() . |
int |
getNumUnmodified()
Get the number of unmodified files that was found in the last
call to
scanForChanges() . |
Registry |
getRegistry()
Get the registry in which all extensions that are managed by this
manager are stored.
|
Settings |
getSettings()
Get the settings for the extension manager.
|
void |
processFiles(ExtensionsFileProcessor processor)
Process all know file with the given processer.
|
void |
processFiles(ExtensionsFileProcessor processor,
Filter<ExtensionsFile> filter)
Process all known extension files with the given processor.
|
(package private) void |
registerObject(ObjectKey<?> key,
ExtensionsFile xtFile)
Register an object as defined by the given extensions file.
|
(package private) void |
removeFile(java.io.File file)
Remove a file from the extensions manager.
|
void |
removeIgnore(java.io.File file)
Remove a file from the ignore list.
|
int |
scanForChanges()
Scan the managed directories for new, updated and deleted files.
|
private int |
scanForInstalledFiles(java.io.File dir,
Settings settings)
Scan the given directory and add files that are installed
according to the settings.
|
private int |
scanForNewFiles(java.io.File dir)
Scan the given directory and add files that are new.
|
void |
setLastProcessResults(ProcessResults results)
Save the last process results so that they can be used
later on.
|
(package private) void |
unregisterAllObjects(ExtensionsFile xtFile)
Unregister all objects know in the file.
|
(package private) void |
unregisterObject(ObjectKey<?> key,
ExtensionsFile xtFile)
Unregister an object.
|
private static final org.slf4j.Logger log
private final Registry registry
private final Settings settings
private final java.util.Set<java.io.File> ignore
private final java.util.Set<java.io.File> directories
private final java.util.Map<java.net.URI,ExtensionsFile> xtFiles
private final java.util.Map<ObjectKey<?>,ExtensionsFile> installedObjects
private ProcessResults lastResults
private int numNew
private int numModified
private int numUnmodified
private int numDeleted
public ExtensionsManager(Registry registry, java.io.File settingsFile)
registry
- The registry to usesettingsFile
- The file were settings are storedpublic Registry getRegistry()
public Settings getSettings()
public void setLastProcessResults(ProcessResults results)
results
- public ProcessResults getLastProcessResults()
public void addIgnore(java.io.File file)
file
- The file to addremoveIgnore(File)
public void removeIgnore(java.io.File file)
file
- The file to removeaddIgnore(File)
public int addDirectory(java.io.File dir)
Settings.isInstalledFile(File)
are loaded into manager.
This method call is ignored if the path is not pointing to an existing directory.
dir
- An existing directorypublic ExtensionsFile addFile(java.io.File file)
file
- An extensions file (null is not allowed)void removeFile(java.io.File file)
Note that if the file remains in a managed directory it will
reappear in the manager if scanForChanges()
is
called.
file
- The file to remove (if null this method is ignored)public ExtensionsFile addURI(java.net.URI uri)
This method can't be used for JAR files and if used for XML files it doesn't detect changes that are made after installation.
uri
- An URI pointing to an extensions file (null is not allowed)private void addExtensionsFile(ExtensionsFile xtFile)
public int scanForChanges()
processFiles(ExtensionsFileProcessor)
method must be called.
Note! The new or modified status of files are NOT reset as a result of calling this method. The status can only be changed as a result of some processing.
public int getNumNew()
scanForChanges()
.public int getNumModified()
scanForChanges()
.public int getNumUnmodified()
scanForChanges()
.public int getNumDeleted()
scanForChanges()
.private int scanForNewFiles(java.io.File dir)
dir
- The directory to scanprivate int scanForInstalledFiles(java.io.File dir, Settings settings)
dir
- The directory to scanpublic java.util.List<ExtensionsFile> getFiles()
public ExtensionsFile getFileByURI(java.lang.String uri)
addFile(File)
or
addDirectory(File)
.uri
- An URI that is pointing to an extensions filepublic ExtensionsFile getFileByObjectKey(ObjectKey<?> key)
ObjectKey
for various types
of objects to look for.key
- The object keyvoid registerObject(ObjectKey<?> key, ExtensionsFile xtFile)
key
- The object keyxtFile
- The extensions file the object is defined invoid unregisterObject(ObjectKey<?> key, ExtensionsFile xtFile)
key
- The object keyxtFile
- The extensions file the object is defined invoid unregisterAllObjects(ExtensionsFile xtFile)
public void processFiles(ExtensionsFileProcessor processor)
processor
- A processor implementation, null is not allowedpublic void processFiles(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter)
processor
- A processor implementation, null is not allowedfilter
- An optional filter implementation that can be used to
limit which files are sent to the processor