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).Modifier and Type | Class and Description |
---|---|
(package private) static interface |
FileRepo.Config |
RepositoryPlugin.DownloadListener, RepositoryPlugin.PutOptions, RepositoryPlugin.PutResult
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String |
abortPut |
(package private) java.lang.String |
action |
(package private) java.lang.String |
afterPut |
(package private) java.lang.String |
beforeGet |
(package private) java.lang.String |
beforePut |
(package private) boolean |
canWrite |
(package private) java.lang.String |
close |
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.
|
(package private) static JSONCodec |
codec |
(package private) boolean |
createLatest |
(package private) static RepositoryPlugin.PutOptions |
DEFAULTOPTIONS
Options used when the options are null
|
(package private) boolean |
dirty |
(package private) java.io.File[] |
EMPTY_FILES |
private boolean |
hasIndex |
(package private) PersistentMap<SearchableRepository.ResourceDescriptor> |
index |
static java.lang.String |
INDEX
Should this file repo have an index? Either true or false (absent)
|
(package private) java.lang.String |
init |
(package private) boolean |
inited |
static java.lang.String |
LATEST_OPTION
Property name for the latest option of the repository.
|
private static java.lang.String |
LATEST_POSTFIX |
private static java.util.SortedSet<Version> |
LATEST_SET |
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) . |
private static org.slf4j.Logger |
logger |
static int |
MAX_MAJOR |
(package private) java.lang.String |
name |
static java.lang.String |
NAME
Set the name of this repository (optional)
|
private static java.lang.String[] |
names |
(package private) java.lang.String |
open |
(package private) java.lang.String |
path |
static java.lang.String |
READONLY
Property name for the readonly state of the repository.
|
(package private) java.lang.String |
refresh |
(package private) Registry |
registry |
(package private) java.util.regex.Pattern |
REPO_FILE |
(package private) Reporter |
reporter |
protected java.io.File |
root |
(package private) java.lang.String |
shell |
(package private) boolean |
trace |
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) |
private SearchableRepository.ResourceDescriptor |
buildDescriptor(java.io.File f,
Jar jar,
byte[] digest,
java.lang.String bsn,
Version version) |
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
|
(package private) void |
exec(java.lang.String line,
java.lang.Object... args)
Execute a command.
|
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. |
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) |
private java.lang.Object |
readable(long length,
int n) |
(package private) void |
rebuildIndex() |
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(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.
|
private static final org.slf4j.Logger logger
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
static final RepositoryPlugin.PutOptions DEFAULTOPTIONS
public static final int MAX_MAJOR
private static final java.lang.String LATEST_POSTFIX
public static final Version LATEST_VERSION
private static final java.util.SortedSet<Version> LATEST_SET
static final JSONCodec codec
java.lang.String shell
java.lang.String path
java.lang.String init
java.lang.String open
java.lang.String refresh
java.lang.String beforePut
java.lang.String afterPut
java.lang.String abortPut
java.lang.String beforeGet
java.lang.String close
java.lang.String action
java.io.File[] EMPTY_FILES
protected java.io.File root
Registry registry
boolean createLatest
boolean canWrite
java.util.regex.Pattern REPO_FILE
Reporter reporter
boolean dirty
java.lang.String name
boolean inited
boolean trace
PersistentMap<SearchableRepository.ResourceDescriptor> index
private boolean hasIndex
private static java.lang.String[] names
public FileRepo()
public FileRepo(java.lang.String name, java.io.File location, boolean canWrite)
protected boolean init() throws java.lang.Exception
java.lang.Exception
public void setProperties(java.util.Map<java.lang.String,java.lang.String> map)
Plugin
setProperties
in interface Plugin
map
- attributes and directives for this plugin's clausePlugin.setProperties(java.util.Map)
public boolean canWrite()
canWrite
in interface RepositoryPlugin
protected java.io.File putArtifact(java.io.File tmpFile, byte[] digest) throws java.lang.Exception
tmpFile
- source filedigest
- java.lang.Exception
protected java.io.File putArtifact(java.io.File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) throws java.lang.Exception
java.lang.Exception
public RepositoryPlugin.PutResult put(java.io.InputStream stream, RepositoryPlugin.PutOptions options) throws java.lang.Exception
RepositoryPlugin
put
in interface RepositoryPlugin
stream
- 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.PutResult
java.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, or when another error has occurred.public void setLocation(java.lang.String string)
public void setReporter(Reporter reporter)
Plugin
setReporter
in interface Plugin
public java.util.List<java.lang.String> list(java.lang.String regex) throws java.lang.Exception
RepositoryPlugin
list
in interface RepositoryPlugin
regex
- A
null
.java.lang.Exception
public java.util.SortedSet<Version> versions(java.lang.String bsn) throws java.lang.Exception
RepositoryPlugin
versions
in interface RepositoryPlugin
java.lang.Exception
public java.lang.String toString()
toString
in class java.lang.Object
public java.io.File getRoot()
getRoot
in interface Refreshable
public boolean refresh() throws java.lang.Exception
Refreshable
refresh
in interface Refreshable
java.lang.Exception
public java.lang.String getName()
getName
in interface RepositoryPlugin
public 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
RepositoryPlugin
get
in interface RepositoryPlugin
bsn
- 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 RegistryPlugin
public java.lang.String getLocation()
RepositoryPlugin
getLocation
in interface RepositoryPlugin
public java.util.Map<java.lang.String,java.lang.Runnable> actions(java.lang.Object... target) throws java.lang.Exception
Actionable
actions
in interface Actionable
target
- the target object, null if commands for the encompassing
entity is sought (e.g. the repo itself).java.lang.Exception
protected void afterAction(java.io.File f, java.lang.String key)
public java.lang.String tooltip(java.lang.Object... target) throws java.lang.Exception
Actionable
tooltip
in interface Actionable
target
- the target, any number of parameters to identifyjava.lang.Exception
public java.lang.String title(java.lang.Object... target) throws java.lang.Exception
Actionable
title
in interface Actionable
target
- the target, any number of parameters to identifyjava.lang.Exception
protected 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)
private java.lang.Object readable(long length, int n)
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
protected 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) throws java.lang.Exception
java.lang.Exception
void exec(java.lang.String line, java.lang.Object... args)
line
- target
- public void setDir(java.io.File repoDir)
public void delete(java.lang.String bsn, Version version) throws java.lang.Exception
bsn
- version
- java.lang.Exception
public SearchableRepository.ResourceDescriptor getDescriptor(java.lang.String bsn, Version version) throws java.lang.Exception
java.lang.Exception
public java.util.SortedSet<SearchableRepository.ResourceDescriptor> getResources() throws java.lang.Exception
java.lang.Exception
public SearchableRepository.ResourceDescriptor getResource(byte[] sha) throws java.lang.Exception
java.lang.Exception
void rebuildIndex() throws java.lang.Exception
java.lang.Exception
private SearchableRepository.ResourceDescriptor buildDescriptor(java.io.File f, Jar jar, byte[] digest, java.lang.String bsn, Version version) throws java.security.NoSuchAlgorithmException, java.lang.Exception
java.security.NoSuchAlgorithmException
java.lang.Exception
public void setIndex(boolean b)