public class FileRepo extends Object implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, 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 String |
CMD_ABORT_PUT
Property for commands.
|
static String |
CMD_AFTER_ACTION
Property for commands.
|
static String |
CMD_AFTER_PUT
Property for commands.
|
static String |
CMD_BEFORE_GET
Called before a before get.
|
static String |
CMD_BEFORE_PUT
Property for commands.
|
static String |
CMD_CLOSE
Property for commands.
|
static String |
CMD_INIT
Property for commands.
|
static String |
CMD_OPEN
Property for commands.
|
static String |
CMD_PATH
Path property for commands.
|
static String |
CMD_REFRESH
Property for commands.
|
static String |
CMD_SHELL
The name ( and path) of the shell to execute the commands.
|
static String |
INDEX
Should this file repo have an index? Either true or false (absent)
|
static String |
LATEST_OPTION
Property name for the latest option of the repository.
|
static Version |
LATEST_VERSION |
static 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 String |
NAME
Set the name of this repository (optional)
|
static String |
READONLY
Property name for the readonly state of the repository.
|
protected File |
root |
static String |
TRACE
If set, will trace to stdout.
|
| Constructor and Description |
|---|
FileRepo() |
FileRepo(String name,
File location,
boolean canWrite) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
abortPut(File tmpFile) |
Map<String,Runnable> |
actions(Object... target)
Return a map with command names (potentially localized) and a Runnable.
|
protected void |
afterAction(File f,
String key) |
protected void |
afterPut(File file,
String bsn,
Version version,
String sha) |
protected void |
beforeGet(String bsn,
Version version) |
protected void |
beforePut(File tmp) |
boolean |
canWrite()
Answer if this repository can write.
|
void |
close() |
void |
delete(String bsn,
Version version)
Delete an entry from the repository and cleanup the directory
|
protected void |
fireBundleAdded(File file) |
File |
get(String bsn,
Version version,
Map<String,String> properties,
RepositoryPlugin.DownloadListener... listeners)
Return a URL to a matching version of the given bundle.
|
SearchableRepository.ResourceDescriptor |
getDescriptor(String bsn,
Version version) |
protected File |
getLocal(String bsn,
Version version,
Map<String,String> properties) |
String |
getLocation()
Return a location identifier of this repository
|
String |
getName() |
SearchableRepository.ResourceDescriptor |
getResource(byte[] sha) |
SortedSet<SearchableRepository.ResourceDescriptor> |
getResources() |
File |
getRoot() |
protected boolean |
init()
Initialize the repository Subclasses should first call this method and
then if it returns true, do their own initialization
|
List<String> |
list(String regex)
Return a list of bsns that are present in the repository.
|
protected void |
open() |
RepositoryPlugin.PutResult |
put(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 File |
putArtifact(File tmpFile,
byte[] digest)
Local helper method that tries to insert a file in the repository.
|
protected File |
putArtifact(File tmpFile,
RepositoryPlugin.PutOptions options,
byte[] digest) |
boolean |
refresh()
Instructs a Refreshable to refresh itself
|
void |
setDir(File repoDir) |
void |
setIndex(boolean b) |
void |
setLocation(String string) |
void |
setProperties(Map<String,String> map)
Give the plugin the remaining properties.
|
void |
setRegistry(Registry registry) |
void |
setReporter(Reporter reporter)
Set the current reporter.
|
protected String |
status(String bsn,
Version version) |
String |
title(Object... target)
Provide a title for an element.
|
String |
tooltip(Object... target)
Return a tooltip for the given target or the encompassing entity if null
is passed.
|
String |
toString() |
SortedSet<Version> |
versions(String bsn)
Return a list of versions.
|
public static final String TRACE
public static final String LOCATION
IO.getFile(String).public static final String READONLY
Boolean.parseBoolean(String). Read only repositories will not
accept writes. Defaults to false.public static final String LATEST_OPTION
Boolean.parseBoolean(String)). Defaults to true.public static final String NAME
public static final String INDEX
public static final String CMD_PATH
public static final String CMD_SHELL
public static final String CMD_INIT
public static final String CMD_OPEN
public static final String CMD_AFTER_PUT
public static final String CMD_REFRESH
public static final String CMD_BEFORE_PUT
public static final String CMD_ABORT_PUT
public static final String CMD_CLOSE
public static final String CMD_AFTER_ACTION
public static final String CMD_BEFORE_GET
public static final int MAX_MAJOR
public static final Version LATEST_VERSION
protected File root
protected boolean init()
throws Exception
Exceptionpublic void setProperties(Map<String,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 File putArtifact(File tmpFile, byte[] digest) throws Exception
tmpFile - source filedigest - Exceptionprotected File putArtifact(File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) throws Exception
Exceptionpublic RepositoryPlugin.PutResult put(InputStream stream, RepositoryPlugin.PutOptions options) throws Exception
RepositoryPluginput 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.PutResultException - 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(String string)
public void setReporter(Reporter reporter)
PluginsetReporter in interface Pluginpublic List<String> list(String regex) throws Exception
RepositoryPluginlist in interface RepositoryPluginregex - A
null.Exceptionpublic SortedSet<Version> versions(String bsn) throws Exception
RepositoryPluginversions in interface RepositoryPluginExceptionpublic File getRoot()
getRoot in interface Refreshablepublic boolean refresh()
throws Exception
Refreshablerefresh in interface RefreshableExceptionpublic String getName()
getName in interface RepositoryPluginpublic File get(String bsn, Version version, Map<String,String> properties, RepositoryPlugin.DownloadListener... listeners) throws 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.Exception - when anything goes wrong, in this case no listeners
will be called back.public void setRegistry(Registry registry)
setRegistry in interface RegistryPluginpublic String getLocation()
RepositoryPlugingetLocation in interface RepositoryPluginpublic Map<String,Runnable> actions(Object... target) throws Exception
Actionableactions in interface Actionabletarget - the target object, null if commands for the encompassing
entity is sought (e.g. the repo itself).Exceptionpublic String tooltip(Object... target) throws Exception
Actionabletooltip in interface Actionabletarget - the target, any number of parameters to identifyExceptionpublic String title(Object... target) throws Exception
Actionabletitle in interface Actionabletarget - the target, any number of parameters to identifyExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected void open()
protected void beforePut(File tmp)
protected void abortPut(File tmpFile)
public void setDir(File repoDir)
public void delete(String bsn, Version version) throws Exception
bsn - version - Exceptionpublic SearchableRepository.ResourceDescriptor getDescriptor(String bsn, Version version) throws Exception
Exceptionpublic SortedSet<SearchableRepository.ResourceDescriptor> getResources() throws Exception
Exceptionpublic SearchableRepository.ResourceDescriptor getResource(byte[] sha) throws Exception
Exceptionpublic void setIndex(boolean b)
Copyright © 2019 aQute SARL. All rights reserved.