Class Workspace

  • All Implemented Interfaces:
    Constants, Registry, aQute.service.reporter.Report, aQute.service.reporter.Reporter, java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<java.lang.String>

    public class Workspace
    extends Processor
    • Field Detail

      • BND_DEFAULT_WS

        public static final java.io.File BND_DEFAULT_WS
      • BND_CACHE_REPONAME

        public static final java.lang.String BND_CACHE_REPONAME
        See Also:
        Constant Field Values
      • CACHEDIR

        public static final java.lang.String CACHEDIR
      • STANDALONE_REPO_CLASS

        public static final java.lang.String STANDALONE_REPO_CLASS
        See Also:
        Constant Field Values
      • remoteWorkspaces

        public static boolean remoteWorkspaces
    • Constructor Detail

      • Workspace

        public Workspace​(java.io.File workspaceDir)
                  throws java.lang.Exception
        Create a workspace on the given directory, assuming that it contains a cnf directory. See Workspace(File, String)
        Parameters:
        workspaceDir - the worksapce directory
        Throws:
        java.lang.Exception
      • Workspace

        public Workspace​(java.io.File workspaceDir,
                         java.lang.String bndDir)
                  throws java.lang.Exception
        Create a workspace with the given directory and the bnd directory, normally cnf. (Though there are some use cases where this is in another place.) This will create a WorkspaceLayout.BND layout set the base to the workspaceDir, and read the properties in the `build.bnd` file in the bndDir sub directory.

        This will read the version specific defaults after the properties are read from build.bnd in an _intermediate_ processor.

        Parameters:
        workspaceDir - the workspace directory
        bndDir - the bnd directory with build.bnd
        Throws:
        java.lang.Exception
    • Method Detail

      • getProject

        public static Project getProject​(java.io.File projectDir)
                                  throws java.lang.Exception
        This static method finds the workspace and creates a project (or returns an existing project)
        Parameters:
        projectDir -
        Throws:
        java.lang.Exception
      • getDefaults

        public static Processor getDefaults()
      • createDefaultWorkspace

        public static Workspace createDefaultWorkspace()
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getWorkspace

        public static Workspace getWorkspace​(java.io.File workspaceDir)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getWorkspaceWithoutException

        public static Workspace getWorkspaceWithoutException​(java.io.File workspaceDir)
                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • findWorkspace

        public static Workspace findWorkspace​(java.io.File base)
                                       throws java.lang.Exception
        /* Return the nearest workspace
        Throws:
        java.lang.Exception
      • getWorkspace

        public static Workspace getWorkspace​(java.io.File workspaceDir,
                                             java.lang.String bndDir)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • open

        public void open()
        Open the workspace. This will start sending events and, when interactive, might start some processes to create initial configuration like repos.
      • setFileSystem

        public void setFileSystem​(java.io.File workspaceDir,
                                  java.lang.String bndDir)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getProjectFromFile

        public Project getProjectFromFile​(java.io.File projectDir)
      • getProject

        public Project getProject​(java.lang.String bsn)
      • isPresent

        public boolean isPresent​(java.lang.String name)
      • refreshProjects

        public void refreshProjects()
        Signal that the driver has detected a dynamic change in the workspace directory, for example a project was added or removed in the IDE. Since this does not affect the inherited properties we can only change the list of projects.
      • forceRefreshProjects

        public void forceRefreshProjects()
      • _workspace

        public java.lang.String _workspace​(java.lang.String[] args)
      • addCommand

        public void addCommand​(java.lang.String menu,
                               Action action)
      • removeCommand

        public void removeCommand​(java.lang.String menu)
      • fillActions

        public void fillActions​(java.util.Map<java.lang.String,​Action> all)
      • getAllProjects

        public java.util.Collection<Project> getAllProjects()
      • changedFile

        public void changedFile​(java.io.File f)
        Inform any listeners that we changed a file (created/deleted/changed).
        Parameters:
        f - The changed file
      • bracket

        public void bracket​(boolean begin)
      • signal

        public void signal​(aQute.service.reporter.Reporter reporter)
      • syncCache

        public void syncCache()
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getInitializedRepositories

        public org.osgi.util.promise.Promise<java.util.List<RepositoryPlugin>> getInitializedRepositories()
        Get the repositories and ensure they are all ready.
        Returns:
        a promise with the list of repos
      • getBuildOrder

        public java.util.Collection<Project> getBuildOrder()
                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getWorkspace

        public static Workspace getWorkspace​(java.lang.String path)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getMaven

        public Maven getMaven()
      • isOffline

        public boolean isOffline()
      • getOffline

        public java.util.concurrent.atomic.AtomicBoolean getOffline()
      • setOffline

        public Workspace setOffline​(boolean on)
      • _global

        public java.lang.String _global​(java.lang.String[] args)
                                 throws java.lang.Exception
        Provide access to the global settings of this machine.
        Throws:
        java.lang.Exception
      • _user

        public java.lang.String _user​(java.lang.String[] args)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • _repodigests

        public java.lang.Object _repodigests​(java.lang.String[] args)
                                      throws java.lang.Exception
        Return the repository signature digests. These digests are a unique id for the contents of the repository
        Throws:
        java.lang.Exception
      • getRun

        public static Run getRun​(java.io.File file)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • report

        public void report​(java.util.Map<java.lang.String,​java.lang.Object> table)
                    throws java.lang.Exception
        Report details of this workspace
        Overrides:
        report in class Processor
        Throws:
        java.lang.Exception
      • getCache

        public java.io.File getCache​(java.lang.String name)
      • getWorkspaceRepository

        public WorkspaceRepository getWorkspaceRepository()
        Return the workspace repo
      • checkStructure

        public void checkStructure()
      • getBuildDir

        public java.io.File getBuildDir()
      • setBuildDir

        public void setBuildDir​(java.io.File buildDir)
      • isValid

        public boolean isValid()
      • getRepository

        public RepositoryPlugin getRepository​(java.lang.String repo)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Processor
      • getDriver

        public java.lang.String getDriver()
        Get the bnddriver, can be null if not set. The overallDriver is the environment that runs this bnd.
      • setDriver

        public static void setDriver​(java.lang.String driver)
        Set the driver of this environment
      • _driver

        public java.lang.String _driver​(java.lang.String[] args)
        Macro to return the driver. Without any arguments, we return the name of the driver. If there are arguments, we check each of the arguments against the name of the driver. If it matches, we return the driver name. If none of the args match the driver name we return an empty string (which is false).
      • addGestalt

        public static void addGestalt​(java.lang.String part,
                                      Attrs attrs)
        Add a gestalt to all workspaces. The gestalt is a set of parts describing the environment. Each part has a name and optionally attributes. This method adds a gestalt to the VM. Per workspace it is possible to augment this.
      • getGestalt

        public Attrs getGestalt​(java.lang.String part)
        Get the attrs for a gestalt part
      • getGestalt

        public Parameters getGestalt()
        Get the complete gestalt
      • getLayout

        public WorkspaceLayout getLayout()
        Get the layout style of the workspace.
      • _gestalt

        public java.lang.String _gestalt​(java.lang.String[] args)
        The macro to access the gestalt

        $ gestalt;part[;key[;value]]

      • toString

        public java.lang.String toString()
        Description copied from class: Processor
        Printout of the status of this processor for toString()
        Overrides:
        toString in class Processor
      • addPlugin

        public boolean addPlugin​(java.lang.Class<?> plugin,
                                 java.lang.String alias,
                                 java.util.Map<java.lang.String,​java.lang.String> parameters,
                                 boolean force)
                          throws java.lang.Exception
        Add a plugin
        Parameters:
        plugin -
        Throws:
        java.lang.Exception
      • removePlugin

        public boolean removePlugin​(java.lang.String alias)
      • createStandaloneWorkspace

        public static Workspace createStandaloneWorkspace​(Processor run,
                                                          java.net.URI base)
                                                   throws java.lang.Exception
        Create a workspace that does not inherit from a cnf directory etc.
        Parameters:
        run -
        Throws:
        java.lang.Exception
      • isDefaultWorkspace

        public boolean isDefaultWorkspace()
      • isInteractive

        public boolean isInteractive()
        Description copied from class: Processor
        Return if this is an interactive environment like Eclipse or runs in batch mode. If interactive, things can get refreshed.
        Overrides:
        isInteractive in class Processor
      • resetStatic

        public static void resetStatic()
      • createProject

        public Project createProject​(java.lang.String name)
                              throws java.lang.Exception
        Create a project in this workspace
        Throws:
        java.lang.Exception
      • createWorkspace

        public static Workspace createWorkspace​(java.io.File wsdir)
                                         throws java.lang.Exception
        Create a new Workspace
        Parameters:
        wsdir -
        Throws:
        java.lang.Exception
      • readLocked

        public <T> T readLocked​(java.util.concurrent.Callable<T> callable,
                                java.util.function.BooleanSupplier canceled,
                                long timeoutInMs)
                         throws java.lang.Exception
        Lock the workspace for reading. The callable parameter when called can freely use any read function in the workspace.
        Parameters:
        callable - the Callable to run
        canceled - Has the operation been cancelled?
        timeoutInMs - the timeout in milliseconds
        Returns:
        the value of the lambda
        Throws:
        java.lang.InterruptedException - If the thread is interrupted while waiting for the lock.
        java.util.concurrent.TimeoutException - If the lock was not obtained within the timeout period or the specified monitor is cancelled while waiting to obtain the lock.
        java.lang.Exception - If the callable throws an exception.
      • readLocked

        public <T> T readLocked​(java.util.concurrent.Callable<T> callable,
                                java.util.function.BooleanSupplier canceled)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readLocked

        public <T> T readLocked​(java.util.concurrent.Callable<T> callable,
                                long timeoutInMs)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readLocked

        public <T> T readLocked​(java.util.concurrent.Callable<T> callable)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T> T writeLocked​(java.util.concurrent.Callable<T> callable,
                                 java.util.function.BooleanSupplier canceled,
                                 long timeoutInMs)
                          throws java.lang.Exception
        Lock the workspace for all functions including modification. The callable parameter when called can freely use any function in the workspace.
        Parameters:
        callable - the Callable to run
        canceled - Has the operation been cancelled?
        timeoutInMs - the timeout in milliseconds
        Returns:
        the value of the lambda
        Throws:
        java.lang.InterruptedException - If the thread is interrupted while waiting for the lock.
        java.util.concurrent.TimeoutException - If the lock was not obtained within the timeout period or the specified monitor is cancelled while waiting to obtain the lock.
        java.lang.Exception - If the callable throws an exception.
      • writeLocked

        public <T> T writeLocked​(java.util.concurrent.Callable<T> callable,
                                 java.util.function.BooleanSupplier canceled)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T> T writeLocked​(java.util.concurrent.Callable<T> callable,
                                 long timeoutInMs)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T> T writeLocked​(java.util.concurrent.Callable<T> callable)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T,​U> T writeLocked​(java.util.concurrent.Callable<U> underWrite,
                                         aQute.bnd.exceptions.FunctionWithException<U,​T> underRead,
                                         java.util.function.BooleanSupplier canceled,
                                         long timeoutInMs)
                                  throws java.lang.Exception
        Lock the workspace for all functions including modification. The callable parameter when called can freely use any function in the workspace. After the callable returns, the write lock is downgraded to a read lock and the function is called with the result of the callable.
        Parameters:
        underWrite - the Callable to run under the write lock
        underRead - the Function to run under the read lock
        canceled - Has the operation been cancelled?
        timeoutInMs - the timeout in milliseconds
        Returns:
        the value of the function
        Throws:
        java.lang.InterruptedException - If the thread is interrupted while waiting for the lock.
        java.util.concurrent.TimeoutException - If the lock was not obtained within the timeout period or the specified monitor is cancelled while waiting to obtain the lock.
        java.lang.Exception - If the callable or function throws an exception.
      • writeLocked

        public <T,​U> T writeLocked​(java.util.concurrent.Callable<U> underWrite,
                                         aQute.bnd.exceptions.FunctionWithException<U,​T> underRead,
                                         java.util.function.BooleanSupplier canceled)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T,​U> T writeLocked​(java.util.concurrent.Callable<U> underWrite,
                                         aQute.bnd.exceptions.FunctionWithException<U,​T> underRead,
                                         long timeoutInMs)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeLocked

        public <T,​U> T writeLocked​(java.util.concurrent.Callable<U> underWrite,
                                         aQute.bnd.exceptions.FunctionWithException<U,​T> underRead)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • _projectswhere

        public java.lang.String _projectswhere​(java.lang.String[] args)
      • search

        public aQute.bnd.result.Result<java.util.Map<java.lang.String,​java.util.List<BundleId>>> search​(java.lang.String partialFqn)
                                                                                                       throws java.lang.Exception
        Search for a partial class name. The partialFqn name may be a simple class name (Foo) or a fully qualified class name line (foo.bar.Foo), including nested classes, or only a package name prefix (foo.bar or even foo.ba).

        This method uses the heuristic in determine() to split the package name from the (possibly nested) class name - the start of the class name is taken as the first element that starts with a capital letter. This heuristic works fine in most cases, but it is not foolproof. In contexts where you have a better idea of how to separate the package name from the class name, you can use search(String, String) for this purpose.

        Parameters:
        partialFqn - a packagename ( '.' classname )*
        Returns:
        a multi-map containing the search matches with the matching fully-qualified class name as each entry's key, and a list of matching bundles as the value.
        Throws:
        java.lang.Exception
        See Also:
        search(String, String)
      • search

        public aQute.bnd.result.Result<java.util.Map<java.lang.String,​java.util.List<BundleId>>> search​(java.lang.String packageName,
                                                                                                              java.lang.String className)
                                                                                                       throws java.lang.Exception
        Search for a class name inside particular package. Use this in preference to search(String) when you know that the qualifier resolves to a package and not to a class.
        Parameters:
        packageName - the package to search
        className - a classname ( '.' classname )*
        Returns:
        a multi-map containing the search matches with the matching fully-qualified class name as each entry's key, and a list of matching bundles as the value.
        Throws:
        java.lang.Exception
        See Also:
        search(String)
      • getResourceRepository

        public org.osgi.service.repository.Repository getResourceRepository​(Workspace.ResourceRepositoryStrategy strategy)
                                                                     throws java.lang.Exception
        Return an aggregate repository of all the repositories to search. This resource repository must be obtained for each operation, it might become stale over time.
        Parameters:
        strategy - Strategy to use for which repositories to search.
        Returns:
        an aggregate repository
        Throws:
        java.lang.Exception
      • _findproviders

        public java.lang.String _findproviders​(java.lang.String[] args)
                                        throws java.lang.Exception
        A macro that returns a set of resources in bundle selection format from the repositories. For example:
         ${findproviders;osgi.wiring.package;(osgi.wiring.package=aQute.bnd.build);ALL}
         
        Throws:
        java.lang.Exception
      • findProviders

        public java.util.stream.Stream<org.osgi.resource.Capability> findProviders​(java.lang.String namespace,
                                                                                   java.lang.String filter)
                                                                            throws java.lang.Exception
        Find capability providers in the resources in the workspace's repositories.
        Parameters:
        namespace - Capability namespace.
        filter - Filter expression to limit the capabilities. Optional, may be null or an empty string.
        Returns:
        A stream of capabilities found. May be an empty stream.
        Throws:
        java.lang.Exception
      • getBundle

        public aQute.bnd.result.Result<java.io.File> getBundle​(org.osgi.resource.Resource resource)
      • getBundle

        public aQute.bnd.result.Result<java.io.File> getBundle​(java.lang.String bsn,
                                                               Version version,
                                                               java.util.Map<java.lang.String,​java.lang.String> attrs)
      • getBundle

        public aQute.bnd.result.Result<java.io.File> getBundle​(java.lang.String bsn,
                                                               Version version,
                                                               java.util.Map<java.lang.String,​java.lang.String> attrs,
                                                               Workspace.ResourceRepositoryStrategy strategy)
      • on

        public OnWorkspace on​(java.lang.String ownerName)
        Get a new notifier that receives notifications from the workspace & projects. This object should be closed if it is not longer needed.
      • doExtend

        public boolean doExtend​(Processor processor)
        Functions that the workspace likes to apply to its children before the properties are processed. I.e. this should be called in Processor.propertiesChanged()

        This is initially used to do the library functionality but it is open for others where the properties might be affected after some initial processing.

        Parameters:
        processor - the processor to augment
        Returns:
        true if the properties were changed
      • getExpandedInCache

        public aQute.bnd.result.Result<java.io.File> getExpandedInCache​(org.osgi.resource.Resource resource)
        Get a cached directory of an expanded resource. The resource must be a JAR file.
        Parameters:
        resource - a resource
        Returns:
        a result with the directory or an error
      • getExpandedInCache

        public aQute.bnd.result.Result<java.io.File> getExpandedInCache​(java.lang.String urn,
                                                                        java.io.File file)
                                                                 throws java.io.IOException
        Get a cached directory of an inputstream to a Jar.
        Parameters:
        urn - A unique resource name of the structure 'urn:' scheme ':' ...
        file - an file of a Jar
        Returns:
        a result with the directory or an error
        Throws:
        java.io.IOException