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) Stringstatic final StringProperty for commands.static final StringProperty for commands.static final StringProperty for commands.static final StringCalled before a before get.static final StringProperty for commands.static final StringProperty for commands.static final StringProperty for commands.static final StringProperty for commands.static final StringPath property for commands.static final StringProperty for commands.static final StringThe name ( and path) of the shell to execute the commands.(package private) static final JSONCodec(package private) boolean(package private) static final RepositoryPlugin.PutOptionsOptions used when the options are null(package private) boolean(package private) File[]private boolean(package private) PersistentMap<SearchableRepository.ResourceDescriptor>static final StringShould this file repo have an index? Either true or false (absent)(package private) String(package private) booleanstatic final StringProperty name for the latest option of the repository.private static final Stringstatic final Versionstatic final StringProperty name for the location of the repo, must be a valid path name using forward slashes (seeIO.getFile(String).private static final org.slf4j.Loggerstatic final int(package private) Stringstatic final StringSet the name of this repository (optional)private static String[](package private) String(package private) Stringstatic final StringProperty name for the readonly state of the repository.(package private) String(package private) Registryprivate static final Pattern(package private) Reporterprotected File(package private) String(package private) booleanstatic final StringIf set, will trace to stdout. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReturn a map with command names (potentially localized) and a Runnable.protected voidafterAction(File f, String key) protected voidprotected voidprotected voidbuildDescriptor(File f, Jar jar, byte[] digest, String bsn, Version version) booleancanWrite()Answer if this repository can write.voidclose()voidDelete an entry from the repository and cleanup the directory(package private) voidExecute a command.protected voidfireBundleAdded(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 FileReturn a location identifier of this repositorygetName()getResource(byte[] sha) getRoot()protected booleaninit()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 voidopen()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 FileputArtifact(File tmpFile, byte[] digest) Local helper method that tries to insert a file in the repository.protected FileputArtifact(File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) private Objectreadable(long length, int n) (package private) voidbooleanrefresh()Instructs a Refreshable to refresh itselfvoidvoidsetIndex(boolean b) voidsetLocation(String string) voidsetProperties(Map<String, String> map) Give the plugin the remaining properties.voidsetRegistry(Registry registry) voidsetReporter(Reporter reporter) Set the current reporter.protected StringProvide 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.
-
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:PluginGive 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:
setPropertiesin 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:
canWritein 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:RepositoryPluginPut 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:
putin 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:PluginSet the current reporter. This is called at init time. This plugin should report all errors and warnings to this reporter.- Specified by:
setReporterin interfacePlugin
-
list
Description copied from interface:RepositoryPluginReturn a list of bsns that are present in the repository.- Specified by:
listin 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:RepositoryPluginReturn a list of versions.- Specified by:
versionsin interfaceRepositoryPlugin- Throws:
Exception
-
toString
-
getRoot
- Specified by:
getRootin interfaceRefreshable
-
refresh
Description copied from interface:RefreshableInstructs a Refreshable to refresh itself- Specified by:
refreshin interfaceRefreshable- Returns:
- true if refreshed, false if not refreshed possibly due to error.
- Throws:
Exception
-
getName
- Specified by:
getNamein 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:RepositoryPluginReturn 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:
getin 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:
setRegistryin interfaceRegistryPlugin
-
getLocation
Description copied from interface:RepositoryPluginReturn a location identifier of this repository- Specified by:
getLocationin interfaceRepositoryPlugin
-
actions
Description copied from interface:ActionableReturn a map with command names (potentially localized) and a Runnable. The caller can execute the caller at will.- Specified by:
actionsin 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:ActionableReturn a tooltip for the given target or the encompassing entity if null is passed.- Specified by:
tooltipin interfaceActionable- Parameters:
target- the target, any number of parameters to identify- Returns:
- the tooltip or null
- Throws:
Exception
-
title
Description copied from interface:ActionableProvide a title for an element.- Specified by:
titlein 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:
closein interfaceAutoCloseable- Specified by:
closein 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:
NoSuchAlgorithmExceptionException
-
setIndex
public void setIndex(boolean b)
-