Class ArtifactRepositoryBaseImpl<ArtifactDescriptorT extends org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor>
- java.lang.Object
-
- org.eclipse.core.runtime.PlatformObject
-
- org.eclipse.equinox.p2.repository.spi.AbstractRepository<org.eclipse.equinox.p2.metadata.IArtifactKey>
-
- org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository
-
- org.eclipse.tycho.repository.p2base.artifact.repository.AbstractArtifactRepository2
-
- org.eclipse.tycho.repository.p2base.artifact.repository.ArtifactRepositoryBaseImpl<ArtifactDescriptorT>
-
- All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable
,org.eclipse.equinox.p2.query.IQueryable<org.eclipse.equinox.p2.metadata.IArtifactKey>
,org.eclipse.equinox.p2.repository.artifact.IArtifactRepository
,org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository
,org.eclipse.equinox.p2.repository.IRepository<org.eclipse.equinox.p2.metadata.IArtifactKey>
,IArtifactFileProvider
,IArtifactProvider
,IRawArtifactFileProvider
,IRawArtifactProvider
- Direct Known Subclasses:
LocalArtifactRepository
,MavenBundlesArtifactRepository
,ModuleArtifactRepository
public abstract class ArtifactRepositoryBaseImpl<ArtifactDescriptorT extends org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor> extends AbstractArtifactRepository2 implements org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository, IRawArtifactFileProvider
Base implementation of a mutable, file system based p2 artifact repository. This class manages changes to the index. Sub-classes need to- provide the storage location of artifacts – see
getArtifactFile(IArtifactDescriptor)
, and - provide the internal artifact descriptor instances – see
getInternalDescriptorForAdding(IArtifactDescriptor)
,getComparableDescriptor(IArtifactDescriptor)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ArtifactRepositoryBaseImpl.AddingArtifactSink
private class
ArtifactRepositoryBaseImpl.RawAddingArtifactSink
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<org.eclipse.equinox.p2.metadata.IArtifactKey,java.util.Set<ArtifactDescriptorT>>
descriptorsMap
private static org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[]
EMPTY_DESCRIPTOR_ARRAY
private ArtifactTransferPolicy
transferPolicy
-
Constructor Summary
Constructors Modifier Constructor Description protected
ArtifactRepositoryBaseImpl(org.eclipse.equinox.p2.core.IProvisioningAgent agent, java.net.URI location, ArtifactTransferPolicy transferPolicy)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
closeProcessingSteps(java.io.OutputStream destinationWithProcessing)
private static void
closeSinkAccordingToStatus(IArtifactSink sink, org.eclipse.core.runtime.IStatus status)
boolean
contains(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Returnstrue
if this is a provider for the given artifact.boolean
contains(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returnstrue
if this a provider for an artifact in the given formatorg.eclipse.equinox.p2.query.IQueryable<org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor>
descriptorQueryable()
(package private) static org.eclipse.core.runtime.IStatus
errorStatus(java.lang.String message, java.lang.Throwable cause)
(package private) static org.eclipse.core.runtime.IStatus
errorStatus(java.lang.String message, java.lang.Throwable cause, int code)
protected java.util.stream.Stream<ArtifactDescriptorT>
flattenedValues()
org.eclipse.core.runtime.IStatus
getArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination, org.eclipse.core.runtime.IProgressMonitor monitor)
Deprecated.Obsolete.org.eclipse.core.runtime.IStatus
getArtifact(IArtifactSink sink, org.eclipse.core.runtime.IProgressMonitor monitor)
Writes the requested artifact to the givenIArtifactSink
.org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[]
getArtifactDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Return the raw artifact formats in which the given artifact can be provided.java.io.File
getArtifactFile(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Returns the file system location of the given artifact.java.io.File
getArtifactFile(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns the file system location of the given artifact in the given format.protected abstract org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor
getComparableDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns anIArtifactDescriptor
instance which is comparable to the artifact descriptors stored in the index (i.e.protected abstract ArtifactDescriptorT
getInternalDescriptorForAdding(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns an artifact descriptor of the internal descriptor typeArtifactDescriptorT
which may be added to the index.private org.eclipse.core.runtime.IStatus
getProcessedRawArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination, org.eclipse.core.runtime.IProgressMonitor monitor)
org.eclipse.core.runtime.IStatus
getRawArtifact(IRawArtifactSink sink, org.eclipse.core.runtime.IProgressMonitor monitor)
Writes the requested artifact in the specified raw format to the givenIRawArtifactSink
.protected void
internalAddDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
protected void
internalAddInternalDescriptor(ArtifactDescriptorT internalDescriptor)
protected abstract java.io.File
internalGetArtifactStorageLocation(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns the file system location where the given artifact is or would be stored.protected ArtifactRepositoryBaseImpl.AddingArtifactSink
internalNewAddingArtifactSink(ArtifactDescriptorT canonicalDescriptorToBeAdded)
protected void
internalRemoveAllDescriptors()
protected void
internalRemoveDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
protected void
internalRemoveDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey key)
protected void
internalRemoveDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey[] keys)
protected void
internalRemoveDescriptors(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[] descriptors)
protected void
internalStore(org.eclipse.core.runtime.IProgressMonitor monitor)
Persists the index of this repository.IArtifactSink
newAddingArtifactSink(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Returns a newIArtifactSink
instance that adds the received artifact to this repository onIArtifactSink.commitWrite()
.IRawArtifactSink
newAddingRawArtifactSink(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor newDescriptor)
Returns a newIRawArtifactSink
instance that adds the received artifact to this repository onIArtifactSink.commitWrite()
.org.eclipse.equinox.p2.query.IQueryResult<org.eclipse.equinox.p2.metadata.IArtifactKey>
query(org.eclipse.equinox.p2.query.IQuery<org.eclipse.equinox.p2.metadata.IArtifactKey> query, org.eclipse.core.runtime.IProgressMonitor monitor)
private org.eclipse.core.runtime.IStatus
readRawArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination)
-
Methods inherited from class org.eclipse.tycho.repository.p2base.artifact.repository.AbstractArtifactRepository2
addDescriptor, addDescriptor, addDescriptors, addDescriptors, getArtifacts, getOutputStream, getRawArtifact, isFatal, removeAll, removeAll, removeDescriptor, removeDescriptor, removeDescriptor, removeDescriptor, removeDescriptors, removeDescriptors, removeDescriptors, removeDescriptors, setStatusOnStreamIfPossible
-
Methods inherited from class org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository
createArtifactDescriptor, createArtifactKey, equals, executeBatch, hashCode
-
Methods inherited from class org.eclipse.equinox.p2.repository.spi.AbstractRepository
assertModifiable, getDescription, getLocation, getName, getProperties, getProperty, getProvider, getProvisioningAgent, getType, getVersion, isModifiable, setDescription, setLocation, setName, setProperties, setProperty, setProperty, setProvider, setType, setVersion
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.tycho.repository.p2base.artifact.provider.IArtifactFileProvider
isFileAlreadyAvailable
-
Methods inherited from interface org.eclipse.equinox.p2.repository.artifact.IArtifactRepository
addDescriptor, addDescriptor, addDescriptors, addDescriptors, createArtifactDescriptor, createArtifactKey, executeBatch, getArtifacts, getOutputStream, getRawArtifact, removeAll, removeAll, removeDescriptor, removeDescriptor, removeDescriptor, removeDescriptor, removeDescriptors, removeDescriptors, removeDescriptors, removeDescriptors
-
-
-
-
Field Detail
-
EMPTY_DESCRIPTOR_ARRAY
private static final org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[] EMPTY_DESCRIPTOR_ARRAY
-
descriptorsMap
protected java.util.Map<org.eclipse.equinox.p2.metadata.IArtifactKey,java.util.Set<ArtifactDescriptorT extends org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor>> descriptorsMap
-
transferPolicy
private ArtifactTransferPolicy transferPolicy
-
-
Constructor Detail
-
ArtifactRepositoryBaseImpl
protected ArtifactRepositoryBaseImpl(org.eclipse.equinox.p2.core.IProvisioningAgent agent, java.net.URI location, ArtifactTransferPolicy transferPolicy)
-
-
Method Detail
-
getComparableDescriptor
protected abstract org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor getComparableDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns anIArtifactDescriptor
instance which is comparable to the artifact descriptors stored in the index (i.e. thedescriptorsMap
member). A valid implementation is to convert the argument to the internal descriptor typeArtifactDescriptorT
, but this is not a requirement. This method should be implemented in a way so that callingdescriptors.contains(getComparableDescriptor(foreignDescriptor))
with a descriptor from a foreign artifact repository returnstrue
if and only if copying that foreign artifact to this repository withAbstractArtifactRepository2.getOutputStream(IArtifactDescriptor)
would not add a new artifact to this repository.This method may be called by any API method with an
IArtifactDescriptor
argument.- Parameters:
descriptor
- AnIArtifactDescriptor
from any artifact repository.
-
contains
public final boolean contains(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Description copied from interface:IArtifactProvider
Returnstrue
if this is a provider for the given artifact.- Specified by:
contains
in interfaceIArtifactProvider
- Specified by:
contains
in interfaceorg.eclipse.equinox.p2.repository.artifact.IArtifactRepository
- Specified by:
contains
in classorg.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository
- Parameters:
key
- An artifact key- Returns:
true
if this instance can provide the artifact for the given key
-
contains
public final boolean contains(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Description copied from interface:IRawArtifactProvider
Returnstrue
if this a provider for an artifact in the given format- Specified by:
contains
in interfaceorg.eclipse.equinox.p2.repository.artifact.IArtifactRepository
- Specified by:
contains
in interfaceIRawArtifactProvider
- Specified by:
contains
in classorg.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository
- Parameters:
descriptor
- An artifact descriptor- Returns:
true
if this instance can provide the artifact as raw artifact in the described format
-
getArtifactDescriptors
public final org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[] getArtifactDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Description copied from interface:IRawArtifactProvider
Return the raw artifact formats in which the given artifact can be provided.- Specified by:
getArtifactDescriptors
in interfaceorg.eclipse.equinox.p2.repository.artifact.IArtifactRepository
- Specified by:
getArtifactDescriptors
in interfaceIRawArtifactProvider
- Specified by:
getArtifactDescriptors
in classorg.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository
- Parameters:
key
- An artifact key- Returns:
- The descriptors associated with the given key
-
query
public final org.eclipse.equinox.p2.query.IQueryResult<org.eclipse.equinox.p2.metadata.IArtifactKey> query(org.eclipse.equinox.p2.query.IQuery<org.eclipse.equinox.p2.metadata.IArtifactKey> query, org.eclipse.core.runtime.IProgressMonitor monitor)
- Specified by:
query
in interfaceorg.eclipse.equinox.p2.query.IQueryable<ArtifactDescriptorT extends org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor>
-
descriptorQueryable
public final org.eclipse.equinox.p2.query.IQueryable<org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor> descriptorQueryable()
- Specified by:
descriptorQueryable
in interfaceorg.eclipse.equinox.p2.repository.artifact.IArtifactRepository
-
flattenedValues
protected final java.util.stream.Stream<ArtifactDescriptorT> flattenedValues()
-
getInternalDescriptorForAdding
protected abstract ArtifactDescriptorT getInternalDescriptorForAdding(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor) throws java.lang.IllegalArgumentException
Returns an artifact descriptor of the internal descriptor typeArtifactDescriptorT
which may be added to the index. Implementations may require that the descriptor argument is a descriptor instance created by this repository – seeAbstractArtifactRepository.createArtifactDescriptor(IArtifactKey)
.This method is called by methods that add entries to the index, i.e. from
newAddingArtifactSink(IArtifactKey)
.- Parameters:
descriptor
- AnIArtifactDescriptor
instance- Throws:
java.lang.IllegalArgumentException
- if the provided descriptor cannot be added
-
internalAddDescriptor
protected final void internalAddDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
- Specified by:
internalAddDescriptor
in classAbstractArtifactRepository2
-
internalAddInternalDescriptor
protected final void internalAddInternalDescriptor(ArtifactDescriptorT internalDescriptor)
-
internalRemoveDescriptor
protected final void internalRemoveDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
- Specified by:
internalRemoveDescriptor
in classAbstractArtifactRepository2
-
internalRemoveDescriptors
protected final void internalRemoveDescriptors(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor[] descriptors)
- Specified by:
internalRemoveDescriptors
in classAbstractArtifactRepository2
-
internalRemoveDescriptors
protected final void internalRemoveDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey key)
- Specified by:
internalRemoveDescriptors
in classAbstractArtifactRepository2
-
internalRemoveDescriptors
protected final void internalRemoveDescriptors(org.eclipse.equinox.p2.metadata.IArtifactKey[] keys)
- Specified by:
internalRemoveDescriptors
in classAbstractArtifactRepository2
-
internalRemoveAllDescriptors
protected final void internalRemoveAllDescriptors()
- Specified by:
internalRemoveAllDescriptors
in classAbstractArtifactRepository2
-
internalStore
protected void internalStore(org.eclipse.core.runtime.IProgressMonitor monitor)
Persists the index of this repository.This method is called after every (bulk) change to the index.
- Specified by:
internalStore
in classAbstractArtifactRepository2
-
internalGetArtifactStorageLocation
protected abstract java.io.File internalGetArtifactStorageLocation(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Returns the file system location where the given artifact is or would be stored. UnlikegetArtifactFile(IArtifactDescriptor)
, this method does not check if the given artifact exists in the repository and never returnsnull
.This method may be called by any API method for reading or writing artifacts.
-
getArtifactFile
public final java.io.File getArtifactFile(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor)
Description copied from interface:IRawArtifactFileProvider
Returns the file system location of the given artifact in the given format.- Specified by:
getArtifactFile
in interfaceorg.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository
- Specified by:
getArtifactFile
in interfaceIRawArtifactFileProvider
- Parameters:
descriptor
- The key and format of an artifact- Returns:
- The location of the specified raw artifact, or
null
the that artifact does not exist in the given format.
-
getArtifactFile
public final java.io.File getArtifactFile(org.eclipse.equinox.p2.metadata.IArtifactKey key)
Description copied from interface:IArtifactFileProvider
Returns the file system location of the given artifact.- Specified by:
getArtifactFile
in interfaceIArtifactFileProvider
- Specified by:
getArtifactFile
in interfaceorg.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository
- Parameters:
key
- An artifact key- Returns:
- The location of the specified artifact, or
null
the given artifact does not exist.
-
getArtifact
@Deprecated public final org.eclipse.core.runtime.IStatus getArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination, org.eclipse.core.runtime.IProgressMonitor monitor)
Deprecated.Obsolete. UsegetArtifact(IArtifactSink, IProgressMonitor)
instead.- Specified by:
getArtifact
in interfaceorg.eclipse.equinox.p2.repository.artifact.IArtifactRepository
- Overrides:
getArtifact
in classAbstractArtifactRepository2
-
getArtifact
public final org.eclipse.core.runtime.IStatus getArtifact(IArtifactSink sink, org.eclipse.core.runtime.IProgressMonitor monitor) throws ArtifactSinkException
Description copied from interface:IArtifactProvider
Writes the requested artifact to the givenIArtifactSink
.The implementation is free to pick the most suitable internal storage format to serve the request, e.g. it may extract the artifact from a pack200-compressed format. If an error is detected while streaming the artifact (e.g. an MD5 checksum error), the implementation may re-attempt the read from all other available sources. In case there were multiple read attempts, a multi-status with the results of all attempts is returned.
- Specified by:
getArtifact
in interfaceIArtifactProvider
- Parameters:
sink
- A sink for a specific artifact. When this method returns, the sink will either be closed (withIArtifactSink.commitWrite()
orIArtifactSink.abortWrite()
, depending on the status), or not have received any content.monitor
- A progress monitor, ornull
- Returns:
- A non-fatal status (warning or better) if the read operation was successful.
- Throws:
ArtifactSinkException
- if that exception is thrown by the givenIArtifactSink
- See Also:
IArtifactSink.getArtifactToBeWritten()
-
getProcessedRawArtifact
private org.eclipse.core.runtime.IStatus getProcessedRawArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination, org.eclipse.core.runtime.IProgressMonitor monitor)
-
closeProcessingSteps
private void closeProcessingSteps(java.io.OutputStream destinationWithProcessing) throws java.io.IOException
- Throws:
java.io.IOException
-
getRawArtifact
public final org.eclipse.core.runtime.IStatus getRawArtifact(IRawArtifactSink sink, org.eclipse.core.runtime.IProgressMonitor monitor) throws ArtifactSinkException
Description copied from interface:IRawArtifactProvider
Writes the requested artifact in the specified raw format to the givenIRawArtifactSink
.If an error is detected while streaming the artifact (e.g. an MD5 checksum error) and there are other sources available (e.g. in a composite provider), the implementation may re-attempt the read from these other sources. In case there were multiple read attempts, a multi-status with the results of all attempts is returned.
- Specified by:
getRawArtifact
in interfaceIRawArtifactProvider
- Parameters:
sink
- A sink for a specific artifact in a specific format. When this method returns, the sink will either be closed (withIArtifactSink.commitWrite()
orIArtifactSink.abortWrite()
, depending on the status), or not have received any content.monitor
- A progress monitor, ornull
- Returns:
- A non-fatal status (warning or better) if the read operation was successful.
- Throws:
ArtifactSinkException
- if that exception is thrown by the givenIArtifactSink
- See Also:
IArtifactSink.getArtifactToBeWritten()
,IRawArtifactSink.getArtifactFormatToBeWritten()
-
readRawArtifact
private org.eclipse.core.runtime.IStatus readRawArtifact(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor descriptor, java.io.OutputStream destination)
-
closeSinkAccordingToStatus
private static void closeSinkAccordingToStatus(IArtifactSink sink, org.eclipse.core.runtime.IStatus status) throws ArtifactSinkException
- Throws:
ArtifactSinkException
-
newAddingArtifactSink
public final IArtifactSink newAddingArtifactSink(org.eclipse.equinox.p2.metadata.IArtifactKey key) throws org.eclipse.equinox.p2.core.ProvisionException
Description copied from class:AbstractArtifactRepository2
Returns a newIArtifactSink
instance that adds the received artifact to this repository onIArtifactSink.commitWrite()
.- Specified by:
newAddingArtifactSink
in classAbstractArtifactRepository2
- Parameters:
key
- The artifact key to be added to this repository- Throws:
org.eclipse.equinox.p2.core.ProvisionException
- if the artifact is already stored in the repository (in canonical format)
-
internalNewAddingArtifactSink
protected final ArtifactRepositoryBaseImpl.AddingArtifactSink internalNewAddingArtifactSink(ArtifactDescriptorT canonicalDescriptorToBeAdded) throws org.eclipse.equinox.p2.core.ProvisionException
- Throws:
org.eclipse.equinox.p2.core.ProvisionException
-
newAddingRawArtifactSink
public final IRawArtifactSink newAddingRawArtifactSink(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor newDescriptor) throws org.eclipse.equinox.p2.core.ProvisionException
Description copied from class:AbstractArtifactRepository2
Returns a newIRawArtifactSink
instance that adds the received artifact to this repository onIArtifactSink.commitWrite()
.- Specified by:
newAddingRawArtifactSink
in classAbstractArtifactRepository2
- Parameters:
newDescriptor
- The artifact descriptor to the added to this repository- Throws:
org.eclipse.equinox.p2.core.ProvisionException
- if the artifact is already stored in the repository in the given format.
-
errorStatus
static org.eclipse.core.runtime.IStatus errorStatus(java.lang.String message, java.lang.Throwable cause)
-
errorStatus
static org.eclipse.core.runtime.IStatus errorStatus(java.lang.String message, java.lang.Throwable cause, int code)
-
-