public class FileRepo extends java.lang.Object implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, java.io.Closeable
RepositoryPlugin, Refreshable, Actionable, and
Closeable. The FileRepo can be extended or used as is. When used as
is, it is possible to add shell commands to the life cycle of the FileRepo.
This life cycle is as follows:
CMD_INIT - Is only executed when the location did not existCMD_OPEN - Called (after init if necessary) to open it onceCMD_REFRESH - Called when refreshed.CMD_BEFORE_PUT - Before the file system is changedCMD_AFTER_PUT - After the file system has changed, and the put
CMD_BEFORE_GET - Before the file is gottenCMD_AFTER_ACTION - Before the file is gottenCMD_CLOSE - When the repo is closed and no more actions will
take placeCMD_ABORT_PUT - When the put is aborted.CMD_CLOSE - To close the repository.CMD_SHELL and the
CMD_PATH. Notice that you can use the ${global} macro to read global
(that is, machine local) settings from the ~/.bnd/settings.json file (can be
managed with bnd).RepositoryPlugin.DownloadListener, RepositoryPlugin.PutOptions, RepositoryPlugin.PutResult| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CMD_ABORT_PUT
Property for commands.
|
static java.lang.String |
CMD_AFTER_ACTION
Property for commands.
|
static java.lang.String |
CMD_AFTER_PUT
Property for commands.
|
static java.lang.String |
CMD_BEFORE_GET
Called before a before get.
|
static java.lang.String |
CMD_BEFORE_PUT
Property for commands.
|
static java.lang.String |
CMD_CLOSE
Property for commands.
|
static java.lang.String |
CMD_INIT
Property for commands.
|
static java.lang.String |
CMD_OPEN
Property for commands.
|
static java.lang.String |
CMD_PATH
Path property for commands.
|
static java.lang.String |
CMD_REFRESH
Property for commands.
|
static java.lang.String |
CMD_SHELL
The name ( and path) of the shell to execute the commands.
|
static java.lang.String |
INDEX
Should this file repo have an index? Either true or false (absent)
|
static java.lang.String |
LATEST_OPTION
Property name for the latest option of the repository.
|
static Version |
LATEST_VERSION |
static java.lang.String |
LOCATION
Property name for the location of the repo, must be a valid path name
using forward slashes (see
IO.getFile(String). |
static int |
MAX_MAJOR |
static java.lang.String |
NAME
Set the name of this repository (optional)
|
static java.lang.String |
READONLY
Property name for the readonly state of the repository.
|
protected java.io.File |
root |
static java.lang.String |
TRACE
If set, will trace to stdout.
|
| Constructor and Description |
|---|
FileRepo() |
FileRepo(java.lang.String name,
java.io.File location,
boolean canWrite) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
abortPut(java.io.File tmpFile) |
java.util.Map<java.lang.String,java.lang.Runnable> |
actions(java.lang.Object... target)
Return a map with command names (potentially localized) and a Runnable.
|
protected void |
afterAction(java.io.File f,
java.lang.String key) |
protected void |
afterPut(java.io.File file,
java.lang.String bsn,
Version version,
java.lang.String sha) |
protected void |
beforeGet(java.lang.String bsn,
Version version) |
protected void |
beforePut(java.io.File tmp) |
boolean |
canWrite()
Answer if this repository can write.
|
void |
close() |
void |
delete(java.lang.String bsn,
Version version)
Delete an entry from the repository and cleanup the directory
|
protected void |
fireBundleAdded(java.io.File file) |
java.io.File |
get(java.lang.String bsn,
Version version,
java.util.Map<java.lang.String,java.lang.String> properties,
RepositoryPlugin.DownloadListener... listeners)
Return a URL to a matching version of the given bundle.
|
SearchableRepository.ResourceDescriptor |
getDescriptor(java.lang.String bsn,
Version version) |
protected java.io.File |
getLocal(java.lang.String bsn,
Version version,
java.util.Map<java.lang.String,java.lang.String> properties) |
java.lang.String |
getLocation()
Return a location identifier of this repository
|
java.lang.String |
getName() |
SearchableRepository.ResourceDescriptor |
getResource(byte[] sha) |
java.util.SortedSet<SearchableRepository.ResourceDescriptor> |
getResources() |
java.io.File |
getRoot() |
protected boolean |
init()
Initialize the repository Subclasses should first call this method and
then if it returns true, do their own initialization
|
java.util.List<java.lang.String> |
list(java.lang.String regex)
Return a list of bsns that are present in the repository.
|
protected void |
open() |
RepositoryPlugin.PutResult |
put(java.io.InputStream stream,
RepositoryPlugin.PutOptions options)
Put an artifact (from the InputStream) into the repository.
There is NO guarantee that the artifact on the input stream has not been modified after it's been put in the repository since that is dependent on the implementation of the repository (see RepositoryPlugin.PutOptions#allowArtifactChange). |
protected java.io.File |
putArtifact(java.io.File tmpFile,
byte[] digest)
Local helper method that tries to insert a file in the repository.
|
protected java.io.File |
putArtifact(java.io.File tmpFile,
RepositoryPlugin.PutOptions options,
byte[] digest) |
boolean |
refresh()
Instructs a Refreshable to refresh itself
|
void |
setDir(java.io.File repoDir) |
void |
setIndex(boolean b) |
void |
setLocation(java.lang.String string) |
void |
setProperties(java.util.Map<java.lang.String,java.lang.String> map)
Give the plugin the remaining properties.
|
void |
setRegistry(Registry registry) |
void |
setReporter(aQute.service.reporter.Reporter reporter)
Set the current reporter.
|
protected java.lang.String |
status(java.lang.String bsn,
Version version) |
java.lang.String |
title(java.lang.Object... target)
Provide a title for an element.
|
java.lang.String |
tooltip(java.lang.Object... target)
Return a tooltip for the given target or the encompassing entity if null
is passed.
|
java.lang.String |
toString() |
java.util.SortedSet<Version> |
versions(java.lang.String bsn)
Return a list of versions.
|
public static final java.lang.String TRACE
public static final java.lang.String LOCATION
IO.getFile(String).public static final java.lang.String READONLY
Boolean.parseBoolean(String). Read only repositories will not
accept writes. Defaults to false.public static final java.lang.String LATEST_OPTION
Boolean.parseBoolean(String)). Defaults to true.public static final java.lang.String NAME
public static final java.lang.String INDEX
public static final java.lang.String CMD_PATH
public static final java.lang.String CMD_SHELL
public static final java.lang.String CMD_INIT
public static final java.lang.String CMD_OPEN
public static final java.lang.String CMD_AFTER_PUT
public static final java.lang.String CMD_REFRESH
public static final java.lang.String CMD_BEFORE_PUT
public static final java.lang.String CMD_ABORT_PUT
public static final java.lang.String CMD_CLOSE
public static final java.lang.String CMD_AFTER_ACTION
public static final java.lang.String CMD_BEFORE_GET
public static final int MAX_MAJOR
public static final Version LATEST_VERSION
protected java.io.File root
public FileRepo()
public FileRepo(java.lang.String name,
java.io.File location,
boolean canWrite)
protected boolean init()
throws java.lang.Exception
java.lang.Exceptionpublic void setProperties(java.util.Map<java.lang.String,java.lang.String> map)
PluginsetProperties in interface Pluginmap - attributes and directives for this plugin's clausePlugin.setProperties(java.util.Map)public boolean canWrite()
canWrite in interface RepositoryPluginprotected java.io.File putArtifact(java.io.File tmpFile,
byte[] digest)
throws java.lang.Exception
tmpFile - source filedigest - java.lang.Exceptionprotected java.io.File putArtifact(java.io.File tmpFile,
RepositoryPlugin.PutOptions options,
byte[] digest)
throws java.lang.Exception
java.lang.Exceptionpublic RepositoryPlugin.PutResult put(java.io.InputStream stream, RepositoryPlugin.PutOptions options) throws java.lang.Exception
RepositoryPluginRepositoryPlugin.PutOptions#allowArtifactChange).put in interface RepositoryPluginstream - The input stream with the artifactoptions - The put options. See RepositoryPlugin.PutOptions, can
be null, which will then take the default options like
new PutOptions().RepositoryPlugin.PutResultjava.lang.Exception - When the repository root directory doesn't exist, when the
repository is read-only, when the specified checksum doesn't
match the checksum of the fetched artifact (see
RepositoryPlugin.PutOptions.digest), when the
implementation wants to modify the artifact but isn't allowed
(see RepositoryPlugin.PutOptions#allowArtifactChange
), or when another error has occurred.public void setLocation(java.lang.String string)
public void setReporter(aQute.service.reporter.Reporter reporter)
PluginsetReporter in interface Pluginpublic java.util.List<java.lang.String> list(java.lang.String regex)
throws java.lang.Exception
RepositoryPluginlist in interface RepositoryPluginregex - A null.java.lang.Exceptionpublic java.util.SortedSet<Version> versions(java.lang.String bsn) throws java.lang.Exception
RepositoryPluginversions in interface RepositoryPluginjava.lang.Exceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.io.File getRoot()
getRoot in interface Refreshablepublic boolean refresh()
throws java.lang.Exception
Refreshablerefresh in interface Refreshablejava.lang.Exceptionpublic java.lang.String getName()
getName in interface RepositoryPluginpublic java.io.File get(java.lang.String bsn,
Version version,
java.util.Map<java.lang.String,java.lang.String> properties,
RepositoryPlugin.DownloadListener... listeners)
throws java.lang.Exception
RepositoryPluginget in interface RepositoryPluginbsn - Bundle-SymbolicName of the searched bundleversion - Version requestedlisteners - Zero or more download listener that will be notified of the
outcome.java.lang.Exception - when anything goes wrong, in this case no listeners will be
called back.public void setRegistry(Registry registry)
setRegistry in interface RegistryPluginpublic java.lang.String getLocation()
RepositoryPlugingetLocation in interface RepositoryPluginpublic java.util.Map<java.lang.String,java.lang.Runnable> actions(java.lang.Object... target)
throws java.lang.Exception
Actionableactions in interface Actionabletarget - the target object, null if commands for the encompassing
entity is sought (e.g. the repo itself).java.lang.Exceptionprotected void afterAction(java.io.File f,
java.lang.String key)
public java.lang.String tooltip(java.lang.Object... target)
throws java.lang.Exception
Actionabletooltip in interface Actionabletarget - the target, any number of parameters to identifyjava.lang.Exceptionpublic java.lang.String title(java.lang.Object... target)
throws java.lang.Exception
Actionabletitle in interface Actionabletarget - the target, any number of parameters to identifyjava.lang.Exceptionprotected java.io.File getLocal(java.lang.String bsn,
Version version,
java.util.Map<java.lang.String,java.lang.String> properties)
protected java.lang.String status(java.lang.String bsn,
Version version)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionprotected void open()
protected void beforePut(java.io.File tmp)
protected void afterPut(java.io.File file,
java.lang.String bsn,
Version version,
java.lang.String sha)
protected void abortPut(java.io.File tmpFile)
protected void beforeGet(java.lang.String bsn,
Version version)
protected void fireBundleAdded(java.io.File file)
public void setDir(java.io.File repoDir)
public void delete(java.lang.String bsn,
Version version)
throws java.lang.Exception
bsn - version - java.lang.Exceptionpublic SearchableRepository.ResourceDescriptor getDescriptor(java.lang.String bsn, Version version) throws java.lang.Exception
java.lang.Exceptionpublic java.util.SortedSet<SearchableRepository.ResourceDescriptor> getResources() throws java.lang.Exception
java.lang.Exceptionpublic SearchableRepository.ResourceDescriptor getResource(byte[] sha) throws java.lang.Exception
java.lang.Exceptionpublic void setIndex(boolean b)