aQute.lib.deployer
Class FileRepo

java.lang.Object
  extended by aQute.lib.deployer.FileRepo
All Implemented Interfaces:
Actionable, Plugin, Refreshable, RegistryPlugin, RepositoryPlugin, Closeable

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:

Additionally, it is possible to set the 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 classes/interfaces inherited from interface aQute.bnd.service.RepositoryPlugin
RepositoryPlugin.DownloadListener, RepositoryPlugin.PutOptions, RepositoryPlugin.PutResult
 
Field Summary
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 Summary
FileRepo()
           
FileRepo(String name, File location, boolean canWrite)
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE

public static final String TRACE
If set, will trace to stdout. Works only if no reporter is set.

See Also:
Constant Field Values

LOCATION

public static final String LOCATION
Property name for the location of the repo, must be a valid path name using forward slashes (see IO.getFile(String).

See Also:
Constant Field Values

READONLY

public static final String READONLY
Property name for the readonly state of the repository. If no, will read/write, otherwise it must be a boolean value read by Boolean.parseBoolean(String). Read only repositories will not accept writes. Defaults to false.

See Also:
Constant Field Values

LATEST_OPTION

public static final 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 by Boolean.parseBoolean(String)). Defaults to true.

See Also:
Constant Field Values

NAME

public static final String NAME
Set the name of this repository (optional)

See Also:
Constant Field Values

INDEX

public static final String INDEX
Should this file repo have an index? Either true or false (absent)

See Also:
Constant Field Values

CMD_PATH

public static final 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 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 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 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 String CMD_AFTER_PUT
Property for commands. The command runs after a put operation.

See Also:
Constant Field Values

CMD_REFRESH

public static final 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 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 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 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 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 String CMD_BEFORE_GET
Called before a before get.

See Also:
Constant Field Values

MAX_MAJOR

public static final int MAX_MAJOR
See Also:
Constant Field Values

LATEST_VERSION

public static final Version LATEST_VERSION

root

protected File root
Constructor Detail

FileRepo

public FileRepo()

FileRepo

public FileRepo(String name,
                File location,
                boolean canWrite)
Method Detail

init

protected boolean init()
                throws Exception
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

public void setProperties(Map<String,String> map)
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 interface Plugin
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:
canWrite in interface RepositoryPlugin
Returns:
true if writable

putArtifact

protected File putArtifact(File tmpFile,
                           byte[] digest)
                    throws Exception
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 file
digest -
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 (see RepositoryPlugin.PutOptions#allowArtifactChange).

Specified by:
put in interface RepositoryPlugin
Parameters:
stream - The input stream with the artifact
options - The put options. See RepositoryPlugin.PutOptions, can be null, 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 (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.

setLocation

public void setLocation(String string)

setReporter

public void setReporter(Reporter reporter)
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 interface Plugin

list

public List<String> list(String regex)
                  throws Exception
Description copied from interface: RepositoryPlugin
Return a list of bsns that are present in the repository.

Specified by:
list in interface RepositoryPlugin
Parameters:
regex - A glob 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:
Exception

versions

public SortedSet<Version> versions(String bsn)
                            throws Exception
Description copied from interface: RepositoryPlugin
Return a list of versions.

Specified by:
versions in interface RepositoryPlugin
Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object

getRoot

public File getRoot()
Specified by:
getRoot in interface Refreshable

refresh

public boolean refresh()
                throws Exception
Description copied from interface: Refreshable
Instructs a Refreshable to refresh itself

Specified by:
refresh in interface Refreshable
Returns:
true if refreshed, false if not refreshed possibly due to error.
Throws:
Exception

getName

public String getName()
Specified by:
getName in interface RepositoryPlugin
Returns:
The name of the repository

get

public File get(String bsn,
                Version version,
                Map<String,String> properties,
                RepositoryPlugin.DownloadListener... listeners)
         throws Exception
Description 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 interface RepositoryPlugin
Parameters:
bsn - Bundle-SymbolicName of the searched bundle
version - Version requested
listeners - 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

public void setRegistry(Registry registry)
Specified by:
setRegistry in interface RegistryPlugin

getLocation

public String getLocation()
Description copied from interface: RepositoryPlugin
Return a location identifier of this repository

Specified by:
getLocation in interface RepositoryPlugin

actions

public Map<String,Runnable> actions(Object... target)
                             throws Exception
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 interface Actionable
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

protected void afterAction(File f,
                           String key)

tooltip

public String tooltip(Object... target)
               throws Exception
Description copied from interface: Actionable
Return a tooltip for the given target or the encompassing entity if null is passed.

Specified by:
tooltip in interface Actionable
Parameters:
target - the target, any number of parameters to identify
Returns:
the tooltip or null
Throws:
Exception

title

public String title(Object... target)
             throws Exception
Description copied from interface: Actionable
Provide a title for an element.

Specified by:
title in interface Actionable
Parameters:
target - the target, any number of parameters to identify
Returns:
the text for this element
Throws:
Exception

getLocal

protected File getLocal(String bsn,
                        Version version,
                        Map<String,String> properties)

status

protected String status(String bsn,
                        Version version)

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

open

protected void open()

beforePut

protected void beforePut(File tmp)

afterPut

protected void afterPut(File file,
                        String bsn,
                        Version version,
                        String sha)

abortPut

protected void abortPut(File tmpFile)

beforeGet

protected void beforeGet(String bsn,
                         Version version)

fireBundleAdded

protected void fireBundleAdded(File file)

setDir

public void setDir(File repoDir)

delete

public void delete(String bsn,
                   Version version)
            throws Exception
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

public SortedSet<SearchableRepository.ResourceDescriptor> getResources()
                                                                throws Exception
Throws:
Exception

getResource

public SearchableRepository.ResourceDescriptor getResource(byte[] sha)
                                                    throws Exception
Throws:
Exception


Copyright © 2014 aQute SARL. All rights reserved.