Class DefaultRepositorySystemSession

  • All Implemented Interfaces:
    RepositorySystemSession

    public final class DefaultRepositorySystemSession
    extends java.lang.Object
    implements RepositorySystemSession
    A simple repository system session.

    Note: This class is not thread-safe. It is assumed that the mutators get only called during an initialization phase and that the session itself is not changed once initialized and being used by the repository system. It is recommended to call setReadOnly() once the session has been fully initialized to prevent accidental manipulation of it afterwards.

    • Field Detail

      • readOnly

        private boolean readOnly
      • offline

        private boolean offline
      • ignoreArtifactDescriptorRepositories

        private boolean ignoreArtifactDescriptorRepositories
      • checksumPolicy

        private java.lang.String checksumPolicy
      • updatePolicy

        private java.lang.String updatePolicy
      • systemProperties

        private java.util.Map<java.lang.String,​java.lang.String> systemProperties
      • systemPropertiesView

        private java.util.Map<java.lang.String,​java.lang.String> systemPropertiesView
      • userProperties

        private java.util.Map<java.lang.String,​java.lang.String> userProperties
      • userPropertiesView

        private java.util.Map<java.lang.String,​java.lang.String> userPropertiesView
      • configProperties

        private java.util.Map<java.lang.String,​java.lang.Object> configProperties
      • configPropertiesView

        private java.util.Map<java.lang.String,​java.lang.Object> configPropertiesView
    • Constructor Detail

      • DefaultRepositorySystemSession

        public DefaultRepositorySystemSession()
        Creates an uninitialized session. Note: The new session is not ready to use, as a bare minimum, setLocalRepositoryManager(LocalRepositoryManager) needs to be called but usually other settings also need to be customized to achieve meaningful behavior.
      • DefaultRepositorySystemSession

        public DefaultRepositorySystemSession​(RepositorySystemSession session)
        Creates a shallow copy of the specified session. Actually, the copy is not completely shallow, all maps holding system/user/config properties are copied as well. In other words, invoking any mutator on the new session itself has no effect on the original session. Other mutable objects like the session data and cache (if any) are not copied and will be shared with the original session unless reconfigured.
        Parameters:
        session - The session to copy, must not be null.
    • Method Detail

      • isOffline

        public boolean isOffline()
        Description copied from interface: RepositorySystemSession
        Indicates whether the repository system operates in offline mode and avoids/refuses any access to remote repositories.
        Specified by:
        isOffline in interface RepositorySystemSession
        Returns:
        true if the repository system is in offline mode, false otherwise.
      • setOffline

        public DefaultRepositorySystemSession setOffline​(boolean offline)
        Controls whether the repository system operates in offline mode and avoids/refuses any access to remote repositories.
        Parameters:
        offline - true if the repository system is in offline mode, false otherwise.
        Returns:
        This session for chaining, never null.
      • isIgnoreArtifactDescriptorRepositories

        public boolean isIgnoreArtifactDescriptorRepositories()
        Description copied from interface: RepositorySystemSession
        Indicates whether repositories declared in artifact descriptors should be ignored during transitive dependency collection. If enabled, only the repositories originally provided with the collect request will be considered.
        Specified by:
        isIgnoreArtifactDescriptorRepositories in interface RepositorySystemSession
        Returns:
        true if additional repositories from artifact descriptors are ignored, false to merge those with the originally specified repositories.
      • setIgnoreArtifactDescriptorRepositories

        public DefaultRepositorySystemSession setIgnoreArtifactDescriptorRepositories​(boolean ignoreArtifactDescriptorRepositories)
        Controls whether repositories declared in artifact descriptors should be ignored during transitive dependency collection. If enabled, only the repositories originally provided with the collect request will be considered.
        Parameters:
        ignoreArtifactDescriptorRepositories - true to ignore additional repositories from artifact descriptors, false to merge those with the originally specified repositories.
        Returns:
        This session for chaining, never null.
      • setResolutionErrorPolicy

        public DefaultRepositorySystemSession setResolutionErrorPolicy​(ResolutionErrorPolicy resolutionErrorPolicy)
        Sets the policy which controls whether resolutions errors from remote repositories should be cached.
        Parameters:
        resolutionErrorPolicy - The resolution error policy for this session, may be null if resolution errors should generally not be cached.
        Returns:
        This session for chaining, never null.
      • setArtifactDescriptorPolicy

        public DefaultRepositorySystemSession setArtifactDescriptorPolicy​(ArtifactDescriptorPolicy artifactDescriptorPolicy)
        Sets the policy which controls how errors related to reading artifact descriptors should be handled.
        Parameters:
        artifactDescriptorPolicy - The descriptor error policy for this session, may be null if descriptor errors should generally not be tolerated.
        Returns:
        This session for chaining, never null.
      • setLocalRepositoryManager

        public DefaultRepositorySystemSession setLocalRepositoryManager​(LocalRepositoryManager localRepositoryManager)
        Sets the local repository manager used during this session. Note: Eventually, a valid session must have a local repository manager set.
        Parameters:
        localRepositoryManager - The local repository manager used during this session, may be null.
        Returns:
        This session for chaining, never null.
      • getWorkspaceReader

        public WorkspaceReader getWorkspaceReader()
        Description copied from interface: RepositorySystemSession
        Gets the workspace reader used during this session. If set, the workspace reader will usually be consulted first to resolve artifacts.
        Specified by:
        getWorkspaceReader in interface RepositorySystemSession
        Returns:
        The workspace reader for this session or null if none.
      • setWorkspaceReader

        public DefaultRepositorySystemSession setWorkspaceReader​(WorkspaceReader workspaceReader)
        Sets the workspace reader used during this session. If set, the workspace reader will usually be consulted first to resolve artifacts.
        Parameters:
        workspaceReader - The workspace reader for this session, may be null if none.
        Returns:
        This session for chaining, never null.
      • setRepositoryListener

        public DefaultRepositorySystemSession setRepositoryListener​(RepositoryListener repositoryListener)
        Sets the listener being notified of actions in the repository system.
        Parameters:
        repositoryListener - The repository listener, may be null if none.
        Returns:
        This session for chaining, never null.
      • setTransferListener

        public DefaultRepositorySystemSession setTransferListener​(TransferListener transferListener)
        Sets the listener being notified of uploads/downloads by the repository system.
        Parameters:
        transferListener - The transfer listener, may be null if none.
        Returns:
        This session for chaining, never null.
      • copySafe

        private <T> java.util.Map<java.lang.String,​T> copySafe​(java.util.Map<?,​?> table,
                                                                     java.lang.Class<T> valueType)
      • getSystemProperties

        public java.util.Map<java.lang.String,​java.lang.String> getSystemProperties()
        Description copied from interface: RepositorySystemSession
        Gets the system properties to use, e.g. for processing of artifact descriptors. System properties are usually collected from the runtime environment like System.getProperties() and environment variables.
        Specified by:
        getSystemProperties in interface RepositorySystemSession
        Returns:
        The (read-only) system properties, never null.
      • setSystemProperties

        public DefaultRepositorySystemSession setSystemProperties​(java.util.Map<?,​?> systemProperties)
        Sets the system properties to use, e.g. for processing of artifact descriptors. System properties are usually collected from the runtime environment like System.getProperties() and environment variables.

        Note: System properties are of type Map<String, String> and any key-value pair in the input map that doesn't match this type will be silently ignored.

        Parameters:
        systemProperties - The system properties, may be null or empty if none.
        Returns:
        This session for chaining, never null.
      • setSystemProperty

        public DefaultRepositorySystemSession setSystemProperty​(java.lang.String key,
                                                                java.lang.String value)
        Sets the specified system property.
        Parameters:
        key - The property key, must not be null.
        value - The property value, may be null to remove/unset the property.
        Returns:
        This session for chaining, never null.
      • getUserProperties

        public java.util.Map<java.lang.String,​java.lang.String> getUserProperties()
        Description copied from interface: RepositorySystemSession
        Gets the user properties to use, e.g. for processing of artifact descriptors. User properties are similar to system properties but are set on the discretion of the user and hence are considered of higher priority than system properties.
        Specified by:
        getUserProperties in interface RepositorySystemSession
        Returns:
        The (read-only) user properties, never null.
      • setUserProperties

        public DefaultRepositorySystemSession setUserProperties​(java.util.Map<?,​?> userProperties)
        Sets the user properties to use, e.g. for processing of artifact descriptors. User properties are similar to system properties but are set on the discretion of the user and hence are considered of higher priority than system properties in case of conflicts.

        Note: User properties are of type Map<String, String> and any key-value pair in the input map that doesn't match this type will be silently ignored.

        Parameters:
        userProperties - The user properties, may be null or empty if none.
        Returns:
        This session for chaining, never null.
      • setUserProperty

        public DefaultRepositorySystemSession setUserProperty​(java.lang.String key,
                                                              java.lang.String value)
        Sets the specified user property.
        Parameters:
        key - The property key, must not be null.
        value - The property value, may be null to remove/unset the property.
        Returns:
        This session for chaining, never null.
      • getConfigProperties

        public java.util.Map<java.lang.String,​java.lang.Object> getConfigProperties()
        Description copied from interface: RepositorySystemSession
        Gets the configuration properties used to tweak internal aspects of the repository system (e.g. thread pooling, connector-specific behavior, etc.)
        Specified by:
        getConfigProperties in interface RepositorySystemSession
        Returns:
        The (read-only) configuration properties, never null.
        See Also:
        ConfigurationProperties
      • setConfigProperties

        public DefaultRepositorySystemSession setConfigProperties​(java.util.Map<?,​?> configProperties)
        Sets the configuration properties used to tweak internal aspects of the repository system (e.g. thread pooling, connector-specific behavior, etc.).

        Note: Configuration properties are of type Map<String, Object> and any key-value pair in the input map that doesn't match this type will be silently ignored.

        Parameters:
        configProperties - The configuration properties, may be null or empty if none.
        Returns:
        This session for chaining, never null.
      • setConfigProperty

        public DefaultRepositorySystemSession setConfigProperty​(java.lang.String key,
                                                                java.lang.Object value)
        Sets the specified configuration property.
        Parameters:
        key - The property key, must not be null.
        value - The property value, may be null to remove/unset the property.
        Returns:
        This session for chaining, never null.
      • setMirrorSelector

        public DefaultRepositorySystemSession setMirrorSelector​(MirrorSelector mirrorSelector)
        Sets the mirror selector to use for repositories discovered in artifact descriptors. Note that this selector is not used for remote repositories which are passed as request parameters to the repository system, those repositories are supposed to denote the effective repositories.
        Parameters:
        mirrorSelector - The mirror selector to use, may be null.
        Returns:
        This session for chaining, never null.
      • setProxySelector

        public DefaultRepositorySystemSession setProxySelector​(ProxySelector proxySelector)
        Sets the proxy selector to use for repositories discovered in artifact descriptors. Note that this selector is not used for remote repositories which are passed as request parameters to the repository system, those repositories are supposed to have their proxy (if any) already set.
        Parameters:
        proxySelector - The proxy selector to use, may be null.
        Returns:
        This session for chaining, never null.
        See Also:
        RemoteRepository.getProxy()
      • setAuthenticationSelector

        public DefaultRepositorySystemSession setAuthenticationSelector​(AuthenticationSelector authenticationSelector)
        Sets the authentication selector to use for repositories discovered in artifact descriptors. Note that this selector is not used for remote repositories which are passed as request parameters to the repository system, those repositories are supposed to have their authentication (if any) already set.
        Parameters:
        authenticationSelector - The authentication selector to use, may be null.
        Returns:
        This session for chaining, never null.
        See Also:
        RemoteRepository.getAuthentication()
      • setArtifactTypeRegistry

        public DefaultRepositorySystemSession setArtifactTypeRegistry​(ArtifactTypeRegistry artifactTypeRegistry)
        Sets the registry of artifact types recognized by this session.
        Parameters:
        artifactTypeRegistry - The artifact type registry, may be null.
        Returns:
        This session for chaining, never null.
      • setDependencyTraverser

        public DefaultRepositorySystemSession setDependencyTraverser​(DependencyTraverser dependencyTraverser)
        Sets the dependency traverser to use for building dependency graphs.
        Parameters:
        dependencyTraverser - The dependency traverser to use for building dependency graphs, may be null.
        Returns:
        This session for chaining, never null.
      • setDependencyManager

        public DefaultRepositorySystemSession setDependencyManager​(DependencyManager dependencyManager)
        Sets the dependency manager to use for building dependency graphs.
        Parameters:
        dependencyManager - The dependency manager to use for building dependency graphs, may be null.
        Returns:
        This session for chaining, never null.
      • setDependencySelector

        public DefaultRepositorySystemSession setDependencySelector​(DependencySelector dependencySelector)
        Sets the dependency selector to use for building dependency graphs.
        Parameters:
        dependencySelector - The dependency selector to use for building dependency graphs, may be null.
        Returns:
        This session for chaining, never null.
      • setVersionFilter

        public DefaultRepositorySystemSession setVersionFilter​(VersionFilter versionFilter)
        Sets the version filter to use for building dependency graphs.
        Parameters:
        versionFilter - The version filter to use for building dependency graphs, may be null to not filter versions.
        Returns:
        This session for chaining, never null.
      • setDependencyGraphTransformer

        public DefaultRepositorySystemSession setDependencyGraphTransformer​(DependencyGraphTransformer dependencyGraphTransformer)
        Sets the dependency graph transformer to use for building dependency graphs.
        Parameters:
        dependencyGraphTransformer - The dependency graph transformer to use for building dependency graphs, may be null.
        Returns:
        This session for chaining, never null.
      • setData

        public DefaultRepositorySystemSession setData​(SessionData data)
        Sets the custom data associated with this session.
        Parameters:
        data - The session data, may be null.
        Returns:
        This session for chaining, never null.
      • setCache

        public DefaultRepositorySystemSession setCache​(RepositoryCache cache)
        Sets the cache the repository system may use to save data for future reuse during the session.
        Parameters:
        cache - The repository cache, may be null if none.
        Returns:
        This session for chaining, never null.
      • setReadOnly

        public void setReadOnly()
        Marks this session as read-only such that any future attempts to call its mutators will fail with an exception. Marking an already read-only session as read-only has no effect. The session's data and cache remain writable though.
      • failIfReadOnly

        private void failIfReadOnly()