Package aQute.lib.deployer
Class FileRepo
- java.lang.Object
-
- aQute.lib.deployer.FileRepo
-
- All Implemented Interfaces:
Actionable,Plugin,Refreshable,RegistryPlugin,RepositoryPlugin,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
InfoFileRepo,Workspace.CachedFileRepo
public class FileRepo extends java.lang.Object implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, java.io.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 theRepositoryPlugin,Refreshable,Actionable, andCloseable. 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_SHELLand theCMD_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 Classes Modifier and Type Class Description (package private) static interfaceFileRepo.Config-
Nested classes/interfaces inherited from interface aQute.bnd.service.RepositoryPlugin
RepositoryPlugin.DownloadListener, RepositoryPlugin.PutOptions, RepositoryPlugin.PutResult
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.StringabortPut(package private) java.lang.Stringaction(package private) java.lang.StringafterPut(package private) java.lang.StringbeforeGet(package private) java.lang.StringbeforePut(package private) booleancanWrite(package private) java.lang.Stringclosestatic java.lang.StringCMD_ABORT_PUTProperty for commands.static java.lang.StringCMD_AFTER_ACTIONProperty for commands.static java.lang.StringCMD_AFTER_PUTProperty for commands.static java.lang.StringCMD_BEFORE_GETCalled before a before get.static java.lang.StringCMD_BEFORE_PUTProperty for commands.static java.lang.StringCMD_CLOSEProperty for commands.static java.lang.StringCMD_INITProperty for commands.static java.lang.StringCMD_OPENProperty for commands.static java.lang.StringCMD_PATHPath property for commands.static java.lang.StringCMD_REFRESHProperty for commands.static java.lang.StringCMD_SHELLThe name ( and path) of the shell to execute the commands.(package private) static JSONCodeccodec(package private) booleancreateLatest(package private) static RepositoryPlugin.PutOptionsDEFAULTOPTIONSOptions used when the options are null(package private) booleandirty(package private) java.io.File[]EMPTY_FILESprivate booleanhasIndex(package private) PersistentMap<SearchableRepository.ResourceDescriptor>indexstatic java.lang.StringINDEXShould this file repo have an index? Either true or false (absent)(package private) java.lang.Stringinit(package private) booleaninitedstatic java.lang.StringLATEST_OPTIONProperty name for the latest option of the repository.private static java.lang.StringLATEST_POSTFIXprivate static java.util.SortedSet<Version>LATEST_SETstatic VersionLATEST_VERSIONstatic java.lang.StringLOCATIONProperty name for the location of the repo, must be a valid path name using forward slashes (seeIO.getFile(String).private static org.slf4j.Loggerloggerstatic intMAX_MAJOR(package private) java.lang.Stringnamestatic java.lang.StringNAMESet the name of this repository (optional)private static java.lang.String[]names(package private) java.lang.Stringopen(package private) java.lang.Stringpathstatic java.lang.StringREADONLYProperty name for the readonly state of the repository.(package private) java.lang.Stringrefresh(package private) Registryregistryprivate static java.util.regex.PatternREPO_FILE(package private) Reporterreporterprotected java.io.Fileroot(package private) java.lang.Stringshell(package private) booleantracestatic java.lang.StringTRACEIf set, will trace to stdout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidabortPut(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 voidafterAction(java.io.File f, java.lang.String key)protected voidafterPut(java.io.File file, java.lang.String bsn, Version version, java.lang.String sha)protected voidbeforeGet(java.lang.String bsn, Version version)protected voidbeforePut(java.io.File tmp)private SearchableRepository.ResourceDescriptorbuildDescriptor(java.io.File f, Jar jar, byte[] digest, java.lang.String bsn, Version version)booleancanWrite()Answer if this repository can write.voidclose()voiddelete(java.lang.String bsn, Version version)Delete an entry from the repository and cleanup the directory(package private) voidexec(java.lang.String line, java.lang.Object... args)Execute a command.protected voidfireBundleAdded(java.io.File file)java.io.Fileget(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.ResourceDescriptorgetDescriptor(java.lang.String bsn, Version version)protected java.io.FilegetLocal(java.lang.String bsn, Version version, java.util.Map<java.lang.String,java.lang.String> properties)java.lang.StringgetLocation()Return a location identifier of this repositoryjava.lang.StringgetName()SearchableRepository.ResourceDescriptorgetResource(byte[] sha)java.util.SortedSet<SearchableRepository.ResourceDescriptor>getResources()java.io.FilegetRoot()protected booleaninit()Initialize the repository Subclasses should first call this method and then if it returns true, do their own initializationjava.util.List<java.lang.String>list(java.lang.String regex)Return a list of bsns that are present in the repository.protected voidopen()RepositoryPlugin.PutResultput(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.FileputArtifact(java.io.File tmpFile, byte[] digest)Local helper method that tries to insert a file in the repository.protected java.io.FileputArtifact(java.io.File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest)private java.lang.Objectreadable(long length, int n)(package private) voidrebuildIndex()booleanrefresh()Instructs a Refreshable to refresh itselfvoidsetDir(java.io.File repoDir)voidsetIndex(boolean b)voidsetLocation(java.lang.String string)voidsetProperties(java.util.Map<java.lang.String,java.lang.String> map)Give the plugin the remaining properties.voidsetRegistry(Registry registry)voidsetReporter(Reporter reporter)Set the current reporter.protected java.lang.Stringstatus(java.lang.String bsn, Version version)java.lang.Stringtitle(java.lang.Object... target)Provide a title for an element.java.lang.Stringtooltip(java.lang.Object... target)Return a tooltip for the given target or the encompassing entity if null is passed.java.lang.StringtoString()java.util.SortedSet<Version>versions(java.lang.String bsn)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 Detail
-
logger
private static final org.slf4j.Logger logger
-
TRACE
public static final java.lang.String TRACE
If set, will trace to stdout. Works only if no reporter is set.- See Also:
- Constant Field Values
-
LOCATION
public static final java.lang.String LOCATION
Property name for the location of the repo, must be a valid path name using forward slashes (seeIO.getFile(String).- See Also:
- Constant Field Values
-
READONLY
public static final java.lang.String 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:
- Constant Field Values
-
LATEST_OPTION
public static final java.lang.String 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:
- Constant Field Values
-
NAME
public static final java.lang.String NAME
Set the name of this repository (optional)- See Also:
- Constant Field Values
-
INDEX
public static final java.lang.String INDEX
Should this file repo have an index? Either true or false (absent)- See Also:
- Constant Field Values
-
CMD_PATH
public static final java.lang.String 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:
- Constant Field Values
-
CMD_SHELL
public static final java.lang.String 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:
- Constant Field Values
-
CMD_INIT
public static final java.lang.String CMD_INIT
Property for commands. The command only runs when the location does not exist.- See Also:
- Constant Field Values
-
CMD_OPEN
public static final java.lang.String CMD_OPEN
Property for commands. Command is run before the repo is first used.- See Also:
- Constant Field Values
-
CMD_AFTER_PUT
public static final java.lang.String CMD_AFTER_PUT
Property for commands. The command runs after a put operation.- See Also:
- Constant Field Values
-
CMD_REFRESH
public static final java.lang.String CMD_REFRESH
Property for commands. The command runs when the repository is refreshed.- See Also:
- Constant Field Values
-
CMD_BEFORE_PUT
public static final java.lang.String CMD_BEFORE_PUT
Property for commands. The command runs after the file is put.- See Also:
- Constant Field Values
-
CMD_ABORT_PUT
public static final java.lang.String CMD_ABORT_PUT
Property for commands. The command runs when a put is aborted after file changes were made.- See Also:
- Constant Field Values
-
CMD_CLOSE
public static final java.lang.String CMD_CLOSE
Property for commands. The command runs after the file is put.- See Also:
- Constant Field Values
-
CMD_AFTER_ACTION
public static final java.lang.String CMD_AFTER_ACTION
Property for commands. Will be run after an action has been executed.- See Also:
- Constant Field Values
-
CMD_BEFORE_GET
public static final java.lang.String CMD_BEFORE_GET
Called before a before get.- See Also:
- Constant Field Values
-
DEFAULTOPTIONS
static final RepositoryPlugin.PutOptions DEFAULTOPTIONS
Options used when the options are null
-
MAX_MAJOR
public static final int MAX_MAJOR
- See Also:
- Constant Field Values
-
LATEST_POSTFIX
private static final java.lang.String LATEST_POSTFIX
- See Also:
- Constant Field Values
-
LATEST_VERSION
public static final Version LATEST_VERSION
-
LATEST_SET
private static final java.util.SortedSet<Version> LATEST_SET
-
codec
static final JSONCodec codec
-
shell
java.lang.String shell
-
path
java.lang.String path
-
init
java.lang.String init
-
open
java.lang.String open
-
refresh
java.lang.String refresh
-
beforePut
java.lang.String beforePut
-
afterPut
java.lang.String afterPut
-
abortPut
java.lang.String abortPut
-
beforeGet
java.lang.String beforeGet
-
close
java.lang.String close
-
action
java.lang.String action
-
EMPTY_FILES
java.io.File[] EMPTY_FILES
-
root
protected java.io.File root
-
registry
Registry registry
-
createLatest
boolean createLatest
-
canWrite
boolean canWrite
-
REPO_FILE
private static final java.util.regex.Pattern REPO_FILE
-
reporter
Reporter reporter
-
dirty
boolean dirty
-
name
java.lang.String name
-
inited
boolean inited
-
trace
boolean trace
-
index
PersistentMap<SearchableRepository.ResourceDescriptor> index
-
hasIndex
private boolean hasIndex
-
names
private static java.lang.String[] names
-
-
Method Detail
-
init
protected boolean init() throws java.lang.ExceptionInitialize 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:
java.lang.Exception
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.String> map)
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:
Plugin.setProperties(java.util.Map)
-
canWrite
public boolean canWrite()
Answer if this repository can write.- Specified by:
canWritein interfaceRepositoryPlugin- Returns:
- true if writable
-
putArtifact
protected java.io.File putArtifact(java.io.File tmpFile, byte[] digest) throws java.lang.ExceptionLocal 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:
java.lang.Exception
-
putArtifact
protected java.io.File putArtifact(java.io.File tmpFile, RepositoryPlugin.PutOptions options, byte[] digest) throws java.lang.Exception- Throws:
java.lang.Exception
-
put
public RepositoryPlugin.PutResult put(java.io.InputStream stream, RepositoryPlugin.PutOptions options) throws java.lang.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:
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 (seeRepositoryPlugin.PutOptions.digest), when the implementation wants to modify the artifact but isn't allowed, or when another error has occurred.
-
setLocation
public void setLocation(java.lang.String string)
-
setReporter
public void setReporter(Reporter reporter)
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
public java.util.List<java.lang.String> list(java.lang.String regex) throws java.lang.ExceptionDescription copied from interface:RepositoryPluginReturn a list of bsns that are present in the repository.- Specified by:
listin interfaceRepositoryPlugin- Parameters:
regex- Aglob pattern to be matched against bsns present in the repository, or null.- 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:
java.lang.Exception
-
versions
public java.util.SortedSet<Version> versions(java.lang.String bsn) throws java.lang.Exception
Description copied from interface:RepositoryPluginReturn a list of versions.- Specified by:
versionsin interfaceRepositoryPlugin- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getRoot
public java.io.File getRoot()
- Specified by:
getRootin interfaceRefreshable
-
refresh
public boolean refresh() throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceRepositoryPlugin- Returns:
- The name of the repository
-
get
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.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:
java.lang.Exception- when anything goes wrong, in this case no listeners will be called back.
-
setRegistry
public void setRegistry(Registry registry)
- Specified by:
setRegistryin interfaceRegistryPlugin
-
getLocation
public java.lang.String getLocation()
Description copied from interface:RepositoryPluginReturn a location identifier of this repository- Specified by:
getLocationin interfaceRepositoryPlugin
-
actions
public java.util.Map<java.lang.String,java.lang.Runnable> actions(java.lang.Object... target) throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
afterAction
protected void afterAction(java.io.File f, java.lang.String key)
-
tooltip
public java.lang.String tooltip(java.lang.Object... target) throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
title
public java.lang.String title(java.lang.Object... target) throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
getLocal
protected java.io.File getLocal(java.lang.String bsn, Version version, java.util.Map<java.lang.String,java.lang.String> properties)
-
status
protected java.lang.String status(java.lang.String bsn, Version version)
-
readable
private java.lang.Object readable(long length, int n)
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
open
protected void open()
-
beforePut
protected void beforePut(java.io.File tmp)
-
afterPut
protected void afterPut(java.io.File file, java.lang.String bsn, Version version, java.lang.String sha)
-
abortPut
protected void abortPut(java.io.File tmpFile)
-
beforeGet
protected void beforeGet(java.lang.String bsn, Version version)
-
fireBundleAdded
protected void fireBundleAdded(java.io.File file) throws java.lang.Exception- Throws:
java.lang.Exception
-
exec
void exec(java.lang.String line, java.lang.Object... args)Execute a command. Used in different stages so that the repository can be synced with external tools.
-
setDir
public void setDir(java.io.File repoDir)
-
delete
public void delete(java.lang.String bsn, Version version) throws java.lang.ExceptionDelete an entry from the repository and cleanup the directory- Parameters:
bsn-version-- Throws:
java.lang.Exception
-
getDescriptor
public SearchableRepository.ResourceDescriptor getDescriptor(java.lang.String bsn, Version version) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getResources
public java.util.SortedSet<SearchableRepository.ResourceDescriptor> getResources() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getResource
public SearchableRepository.ResourceDescriptor getResource(byte[] sha) throws java.lang.Exception
- Throws:
java.lang.Exception
-
rebuildIndex
void rebuildIndex() throws java.lang.Exception- Throws:
java.lang.Exception
-
buildDescriptor
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
- Throws:
java.security.NoSuchAlgorithmExceptionjava.lang.Exception
-
setIndex
public void setIndex(boolean b)
-
-