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 (see RepositoryPlugin.PutOptions#allowArtifactChange ). |
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 |
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
Exception
public void setProperties(Map<String,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 File putArtifact(File tmpFile, byte[] digest) throws Exception
tmpFile
- source filedigest
- Exception
protected File putArtifact(File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) throws Exception
Exception
public RepositoryPlugin.PutResult put(InputStream stream, RepositoryPlugin.PutOptions options) throws Exception
RepositoryPlugin
RepositoryPlugin.PutOptions#allowArtifactChange
).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
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(String string)
public void setReporter(Reporter reporter)
Plugin
setReporter
in interface Plugin
public List<String> list(String regex) throws Exception
RepositoryPlugin
list
in interface RepositoryPlugin
regex
- A null
.Exception
public SortedSet<Version> versions(String bsn) throws Exception
RepositoryPlugin
versions
in interface RepositoryPlugin
Exception
public File getRoot()
getRoot
in interface Refreshable
public boolean refresh() throws Exception
Refreshable
refresh
in interface Refreshable
Exception
public String getName()
getName
in interface RepositoryPlugin
public File get(String bsn, Version version, Map<String,String> properties, RepositoryPlugin.DownloadListener... listeners) throws 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.Exception
- when anything goes wrong, in this case no listeners will be
called back.public void setRegistry(Registry registry)
setRegistry
in interface RegistryPlugin
public String getLocation()
RepositoryPlugin
getLocation
in interface RepositoryPlugin
public Map<String,Runnable> actions(Object... target) throws Exception
Actionable
actions
in interface Actionable
target
- the target object, null if commands for the encompassing
entity is sought (e.g. the repo itself).Exception
public String tooltip(Object... target) throws Exception
Actionable
tooltip
in interface Actionable
target
- the target, any number of parameters to identifyException
public String title(Object... target) throws Exception
Actionable
title
in interface Actionable
target
- the target, any number of parameters to identifyException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
protected void open()
protected void beforePut(File tmp)
protected void abortPut(File tmpFile)
protected void fireBundleAdded(File file)
public void setDir(File repoDir)
public void delete(String bsn, Version version) throws Exception
bsn
- version
- Exception
public SearchableRepository.ResourceDescriptor getDescriptor(String bsn, Version version) throws Exception
Exception
public SortedSet<SearchableRepository.ResourceDescriptor> getResources() throws Exception
Exception
public SearchableRepository.ResourceDescriptor getResource(byte[] sha) throws Exception
Exception
Copyright © 2015 aQute SARL. All rights reserved.