Class FileRepo

    • 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 (see IO.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 by Boolean.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 by Boolean.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
      • LATEST_VERSION

        public static final Version LATEST_VERSION
      • LATEST_SET

        private static final java.util.SortedSet<Version> LATEST_SET
      • 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
      • createLatest

        boolean createLatest
      • canWrite

        boolean canWrite
      • REPO_FILE

        private static final java.util.regex.Pattern REPO_FILE
      • dirty

        boolean dirty
      • name

        java.lang.String name
      • inited

        boolean inited
      • trace

        boolean trace
      • hasIndex

        private boolean hasIndex
      • names

        private static java.lang.String[] names
    • Constructor Detail

      • FileRepo

        public FileRepo()
      • FileRepo

        public FileRepo​(java.lang.String name,
                        java.io.File location,
                        boolean canWrite)
    • Method Detail

      • init

        protected boolean init()
                        throws java.lang.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:
        java.lang.Exception
      • setProperties

        public void setProperties​(java.util.Map<java.lang.String,​java.lang.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 java.io.File putArtifact​(java.io.File tmpFile,
                                           byte[] digest)
                                    throws java.lang.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:
        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: 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 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:
        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 (see RepositoryPlugin.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: 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 java.util.List<java.lang.String> list​(java.lang.String regex)
                                              throws java.lang.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:
        java.lang.Exception
      • versions

        public java.util.SortedSet<Version> versions​(java.lang.String bsn)
                                              throws java.lang.Exception
        Description copied from interface: RepositoryPlugin
        Return a list of versions.
        Specified by:
        versions in interface RepositoryPlugin
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getRoot

        public java.io.File getRoot()
        Specified by:
        getRoot in interface Refreshable
      • refresh

        public boolean refresh()
                        throws java.lang.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:
        java.lang.Exception
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface RepositoryPlugin
        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.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:
        java.lang.Exception - when anything goes wrong, in this case no listeners will be called back.
      • actions

        public java.util.Map<java.lang.String,​java.lang.Runnable> actions​(java.lang.Object... target)
                                                                         throws java.lang.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:
        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.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:
        java.lang.Exception
      • title

        public java.lang.String title​(java.lang.Object... target)
                               throws java.lang.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:
        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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.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.Exception
        Delete an entry from the repository and cleanup the directory
        Parameters:
        bsn -
        version -
        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.NoSuchAlgorithmException
        java.lang.Exception
      • setIndex

        public void setIndex​(boolean b)