Package aQute.lib.deployer
Class FileRepo
java.lang.Object
aQute.lib.deployer.FileRepo
- All Implemented Interfaces:
Actionable
,Plugin
,Refreshable
,RegistryPlugin
,RepositoryPlugin
,Closeable
,AutoCloseable
- Direct Known Subclasses:
InfoFileRepo
,Workspace.CachedFileRepo
public class FileRepo
extends Object
implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, Closeable
A FileRepo is the primary and example implementation of a repository based on
a file system. It maintains its files in a bsn/bsn-version.jar style from a
given location. It implements all the functions of the
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 putCMD_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 place was a success
CMD_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).-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface aQute.bnd.service.RepositoryPlugin
RepositoryPlugin.DownloadListener, RepositoryPlugin.PutOptions, RepositoryPlugin.PutResult
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String
(package private) String
(package private) String
(package private) String
(package private) String
(package private) boolean
(package private) String
static final String
Property for commands.static final String
Property for commands.static final String
Property for commands.static final String
Called before a before get.static final String
Property for commands.static final String
Property for commands.static final String
Property for commands.static final String
Property for commands.static final String
Path property for commands.static final String
Property for commands.static final String
The name ( and path) of the shell to execute the commands.(package private) static final JSONCodec
(package private) boolean
(package private) static final RepositoryPlugin.PutOptions
Options used when the options are null(package private) boolean
(package private) File[]
private boolean
(package private) PersistentMap<SearchableRepository.ResourceDescriptor>
static final String
Should this file repo have an index? Either true or false (absent)(package private) String
(package private) boolean
static final String
Property name for the latest option of the repository.private static final String
static final Version
static final String
Property name for the location of the repo, must be a valid path name using forward slashes (seeIO.getFile(String)
.private static final org.slf4j.Logger
static final int
(package private) String
static final String
Set the name of this repository (optional)private static String[]
(package private) String
(package private) String
static final String
Property name for the readonly state of the repository.(package private) String
(package private) Registry
private static final Pattern
(package private) Reporter
protected File
(package private) String
(package private) boolean
static final String
If set, will trace to stdout. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Return a map with command names (potentially localized) and a Runnable.protected void
afterAction
(File f, String key) protected void
protected void
protected void
buildDescriptor
(File f, Jar jar, byte[] digest, String bsn, Version version) boolean
canWrite()
Answer if this repository can write.void
close()
void
Delete an entry from the repository and cleanup the directory(package private) void
Execute a command.protected void
fireBundleAdded
(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.getDescriptor
(String bsn, Version version) protected File
Return a location identifier of this repositorygetName()
getResource
(byte[] sha) getRoot()
protected boolean
init()
Initialize the repository Subclasses should first call this method and then if it returns true, do their own initializationReturn a list of bsns that are present in the repository.protected void
open()
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) private Object
readable
(long length, int n) (package private) void
boolean
refresh()
Instructs a Refreshable to refresh itselfvoid
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
Provide a title for an element.Return a tooltip for the given target or the encompassing entity if null is passed.toString()
Return a list of versions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface aQute.bnd.service.RepositoryPlugin
getIcon, getStatus, isOk, isRemote
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
TRACE
If set, will trace to stdout. Works only if no reporter is set.- See Also:
-
LOCATION
Property name for the location of the repo, must be a valid path name using forward slashes (seeIO.getFile(String)
.- See Also:
-
READONLY
Property name for the readonly state of the repository. If no, will read/write, otherwise it must be a boolean value read byBoolean.parseBoolean(String)
. Read only repositories will not accept writes. Defaults to false.- See Also:
-
LATEST_OPTION
Property name for the latest option of the repository. If true, will copy the put jar to a 'latest' file (option must be a boolean value read byBoolean.parseBoolean(String)
). Defaults to true.- See Also:
-
NAME
Set the name of this repository (optional)- See Also:
-
INDEX
Should this file repo have an index? Either true or false (absent)- See Also:
-
CMD_PATH
Path property for commands. A comma separated path for directories to be searched for command. May contain $ @} which will be replaced by the system path. If this property is not set, the system path is assumed.- See Also:
-
CMD_SHELL
The name ( and path) of the shell to execute the commands. By default this is sh and searched in the path.- See Also:
-
CMD_INIT
Property for commands. The command only runs when the location does not exist.- See Also:
-
CMD_OPEN
Property for commands. Command is run before the repo is first used.- See Also:
-
CMD_AFTER_PUT
Property for commands. The command runs after a put operation.- See Also:
-
CMD_REFRESH
Property for commands. The command runs when the repository is refreshed.- See Also:
-
CMD_BEFORE_PUT
Property for commands. The command runs after the file is put.- See Also:
-
CMD_ABORT_PUT
Property for commands. The command runs when a put is aborted after file changes were made.- See Also:
-
CMD_CLOSE
Property for commands. The command runs after the file is put.- See Also:
-
CMD_AFTER_ACTION
Property for commands. Will be run after an action has been executed.- See Also:
-
CMD_BEFORE_GET
Called before a before get.- See Also:
-
DEFAULTOPTIONS
Options used when the options are null -
MAX_MAJOR
public static final int MAX_MAJOR- See Also:
-
LATEST_POSTFIX
- See Also:
-
LATEST_VERSION
-
LATEST_SET
-
codec
-
shell
String shell -
path
String path -
init
String init -
open
String open -
refresh
String refresh -
beforePut
String beforePut -
afterPut
String afterPut -
abortPut
String abortPut -
beforeGet
String beforeGet -
close
String close -
action
String action -
EMPTY_FILES
File[] EMPTY_FILES -
root
-
registry
Registry registry -
createLatest
boolean createLatest -
canWrite
boolean canWrite -
REPO_FILE
-
reporter
Reporter reporter -
dirty
boolean dirty -
name
String name -
inited
boolean inited -
trace
boolean trace -
index
-
hasIndex
private boolean hasIndex -
names
-
-
Constructor Details
-
FileRepo
public FileRepo() -
FileRepo
-
-
Method Details
-
init
Initialize the repository Subclasses should first call this method and then if it returns true, do their own initialization- Returns:
- true if initialized, false if already had been initialized.
- Throws:
Exception
-
setProperties
Description copied from interface:Plugin
Give the plugin the remaining properties. When a plugin is declared, the clause can contain extra properties. All the properties and directives are given to the plugin to use.- Specified by:
setProperties
in interfacePlugin
- Parameters:
map
- attributes and directives for this plugin's clause- See Also:
-
canWrite
public boolean canWrite()Answer if this repository can write.- Specified by:
canWrite
in interfaceRepositoryPlugin
- Returns:
- true if writable
-
putArtifact
Local helper method that tries to insert a file in the repository. This method can be overridden but MUST not change the content of the tmpFile. This method should also create a latest version of the artifact for reference by tools like ant etc. It is allowed to rename the file, the tmp file must be beneath the root directory to prevent rename problems.- Parameters:
tmpFile
- source filedigest
-- Returns:
- a File that contains the content of the tmpFile
- Throws:
Exception
-
putArtifact
protected File putArtifact(File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) throws Exception - Throws:
Exception
-
put
public RepositoryPlugin.PutResult put(InputStream stream, RepositoryPlugin.PutOptions options) throws Exception Description copied from interface:RepositoryPlugin
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.- Specified by:
put
in interfaceRepositoryPlugin
- Parameters:
stream
- The input stream with the artifactoptions
- The put options. SeeRepositoryPlugin.PutOptions
, can benull
, which will then take the default options like new PutOptions().- Returns:
- The result of the put, never null. See
RepositoryPlugin.PutResult
- Throws:
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 (seeRepositoryPlugin.PutOptions.digest
), when the implementation wants to modify the artifact but isn't allowed, or when another error has occurred.
-
setLocation
-
setReporter
Description copied from interface:Plugin
Set the current reporter. This is called at init time. This plugin should report all errors and warnings to this reporter.- Specified by:
setReporter
in interfacePlugin
-
list
Description copied from interface:RepositoryPlugin
Return a list of bsns that are present in the repository.- Specified by:
list
in interfaceRepositoryPlugin
- Parameters:
regex
- A <ahref="https://en.wikipedia.org/wiki/Glob_%28programming%29"> glob pattern to be matched against bsns present in the repository, ornull
.- Returns:
- A list of bsns that match the pattern parameter or all if pattern is null; repositories that do not support browsing or querying should return an empty list.
- Throws:
Exception
-
versions
Description copied from interface:RepositoryPlugin
Return a list of versions.- Specified by:
versions
in interfaceRepositoryPlugin
- Throws:
Exception
-
toString
-
getRoot
- Specified by:
getRoot
in interfaceRefreshable
-
refresh
Description copied from interface:Refreshable
Instructs a Refreshable to refresh itself- Specified by:
refresh
in interfaceRefreshable
- Returns:
- true if refreshed, false if not refreshed possibly due to error.
- Throws:
Exception
-
getName
- Specified by:
getName
in interfaceRepositoryPlugin
- Returns:
- The name of the repository
-
get
public File get(String bsn, Version version, Map<String, String> properties, RepositoryPlugin.DownloadListener... listeners) throws ExceptionDescription copied from interface:RepositoryPlugin
Return a URL to a matching version of the given bundle. If download listeners are specified then the returned file is not guaranteed to exist before a download listener is notified of success or failure. The callback can happen before the method has returned. If the returned file is null then download listeners are not called back. The intention of the Download Listeners is to allow a caller to obtain references to files that do not yet exist but are to be downloaded. If the downloads were done synchronously in the call, then no overlap of downloads could take place.- Specified by:
get
in interfaceRepositoryPlugin
- Parameters:
bsn
- Bundle-SymbolicName of the searched bundleversion
- Version requestedlisteners
- Zero or more download listener that will be notified of the outcome.- Returns:
- A file to the revision or null if not found
- Throws:
Exception
- when anything goes wrong, in this case no listeners will be called back.
-
setRegistry
- Specified by:
setRegistry
in interfaceRegistryPlugin
-
getLocation
Description copied from interface:RepositoryPlugin
Return a location identifier of this repository- Specified by:
getLocation
in interfaceRepositoryPlugin
-
actions
Description copied from interface:Actionable
Return a map with command names (potentially localized) and a Runnable. The caller can execute the caller at will.- Specified by:
actions
in interfaceActionable
- Parameters:
target
- the target object, null if commands for the encompassing entity is sought (e.g. the repo itself).- Returns:
- A Map with the actions or null if no actions are available.
- Throws:
Exception
-
afterAction
-
tooltip
Description copied from interface:Actionable
Return a tooltip for the given target or the encompassing entity if null is passed.- Specified by:
tooltip
in interfaceActionable
- Parameters:
target
- the target, any number of parameters to identify- Returns:
- the tooltip or null
- Throws:
Exception
-
title
Description copied from interface:Actionable
Provide a title for an element.- Specified by:
title
in interfaceActionable
- Parameters:
target
- the target, any number of parameters to identify- Returns:
- the text for this element
- Throws:
Exception
-
getLocal
-
status
-
readable
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
open
protected void open() -
beforePut
-
afterPut
-
abortPut
-
beforeGet
-
fireBundleAdded
- Throws:
Exception
-
exec
Execute a command. Used in different stages so that the repository can be synced with external tools. -
setDir
-
delete
Delete an entry from the repository and cleanup the directory- Parameters:
bsn
-version
-- Throws:
Exception
-
getDescriptor
public SearchableRepository.ResourceDescriptor getDescriptor(String bsn, Version version) throws Exception - Throws:
Exception
-
getResources
- Throws:
Exception
-
getResource
- Throws:
Exception
-
rebuildIndex
- Throws:
Exception
-
buildDescriptor
private SearchableRepository.ResourceDescriptor buildDescriptor(File f, Jar jar, byte[] digest, String bsn, Version version) throws NoSuchAlgorithmException, Exception - Throws:
NoSuchAlgorithmException
Exception
-
setIndex
public void setIndex(boolean b)
-