Search in sources :

Example 11 with IArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor in project tycho by eclipse.

the class ArtifactRepositoryBaseImpl method getArtifact.

@Override
public final IStatus getArtifact(IArtifactSink sink, IProgressMonitor monitor) throws ArtifactSinkException {
    canWriteToSink(sink);
    // method signature allows calls with a IRawArtifactSink -> make sure this is only done if sink requests a raw artifact in canonical format
    canWriteCanonicalArtifactToSink(sink);
    IArtifactKey requestedKey = sink.getArtifactToBeWritten();
    IArtifactDescriptor[] availableFormats = getArtifactDescriptors(requestedKey);
    List<IArtifactDescriptor> formatsByPreference = transferPolicy.sortFormatsByPreference(availableFormats);
    for (IArtifactDescriptor descriptor : formatsByPreference) {
        IStatus result = getProcessedRawArtifact(descriptor, sink.beginWrite(), monitor);
        // trying other formats is no use case for the LocalArtifactRepository - if the preferred format (=canonical) is corrupt, it can fail straight away
        // TODO implement retry for other implementations?
        closeSinkAccordingToStatus(sink, result);
        return result;
    }
    return errorStatus("Artifact " + requestedKey + " is not available in the repository " + getLocation(), null, ProvisionException.ARTIFACT_NOT_FOUND);
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) IStatus(org.eclipse.core.runtime.IStatus)

Example 12 with IArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor in project tycho by eclipse.

the class ModuleArtifactRepository method getInternalDescriptorForAdding.

@Override
protected ModuleArtifactDescriptor getInternalDescriptorForAdding(IArtifactDescriptor descriptor) throws IllegalArgumentException {
    if (descriptor == null) {
        throw new NullPointerException();
    } else if (!(descriptor instanceof ModuleArtifactDescriptor) || descriptor.getRepository() != this) {
        throw new IllegalArgumentException("Cannot add artifact descriptor which has not been created by this repository");
    }
    ModuleArtifactDescriptor internalDescriptor = (ModuleArtifactDescriptor) descriptor;
    try {
        MavenRepositoryCoordinates coordinates = internalDescriptor.getMavenCoordinates();
        artifactsMap.addToAutomaticLocation(coordinates.getClassifier(), coordinates.getExtension());
    } catch (ProvisionException e) {
        // TODO 393004 Revise exception handling
        throw new RuntimeException(e);
    }
    return internalDescriptor;
}
Also used : MavenRepositoryCoordinates(org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) ModuleArtifactDescriptor(org.eclipse.tycho.repository.module.ModuleArtifactRepository.ModuleArtifactDescriptor)

Example 13 with IArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor in project tycho by eclipse.

the class RepositoryArtifactProvider method getArtifactFromOneMirror.

private boolean getArtifactFromOneMirror(List<IArtifactDescriptor> availableDescriptors, IArtifactRepository repository, IArtifactSink sink, List<IStatus> statusCollector, RetryTracker retryTracker, IProgressMonitor monitor) throws ArtifactSinkException {
    for (IArtifactDescriptor descriptor : availableDescriptors) {
        if (!sink.canBeginWrite()) {
            return false;
        }
        // there is no way to explicitly select a mirror - the repository magically picks one
        IStatus status = repository.getArtifact(descriptor, sink.beginWrite(), monitor);
        statusCollector.add(improveMessageIfError(status, repository, descriptor));
        if (isFatal(status)) {
            sink.abortWrite();
            /*
                 * CODE_RETRY is how the repository signals that it has more mirrors to try, and
                 * that we can call the same method with exactly the same parameters (!) again.
                 * However we try another format first, so that we don't "spoil" all mirrors by
                 * continuing to querying for a pack200 artifact that is actually broken in the
                 * master repository (cf. bug 412945).
                 */
            if (status.getCode() != IArtifactRepository.CODE_RETRY) {
                retryTracker.noMoreRetries();
            }
        } else {
            sink.commitWrite();
            return true;
        }
    }
    return false;
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IStatus(org.eclipse.core.runtime.IStatus)

Example 14 with IArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor in project tycho by eclipse.

the class RepositoryArtifactProvider method getRawArtifactFromRepository.

// TODO 393004 retry mirrors
private boolean getRawArtifactFromRepository(IArtifactRepository repository, IRawArtifactSink sink, List<IStatus> statusCollector, IProgressMonitor monitor) throws ArtifactSinkException {
    IArtifactDescriptor requestedDescriptor = sink.getArtifactFormatToBeWritten();
    if (repository.contains(requestedDescriptor)) {
        if (!sink.canBeginWrite()) {
            return false;
        }
        IStatus status = repository.getRawArtifact(requestedDescriptor, sink.beginWrite(), monitor);
        statusCollector.add(improveMessageIfError(status, repository, requestedDescriptor));
        if (isFatal(status)) {
            sink.abortWrite();
        } else {
            sink.commitWrite();
            return true;
        }
    }
    return false;
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IStatus(org.eclipse.core.runtime.IStatus)

Example 15 with IArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor in project tycho by eclipse.

the class CompositeArtifactProvider method getRawArtifactFromAnySource.

@Override
protected void getRawArtifactFromAnySource(IRawArtifactSink sink, IProgressMonitor monitor, List<IStatus> statusCollector) throws ArtifactSinkException {
    IArtifactDescriptor requestedDescriptor = sink.getArtifactFormatToBeWritten();
    for (IRawArtifactFileProvider component : components) {
        if (component.contains(requestedDescriptor)) {
            if (!sink.canBeginWrite()) {
                return;
            }
            IStatus transferStatus = component.getRawArtifact(sink, monitor);
            statusCollector.add(transferStatus);
            if (!isFatal(transferStatus)) {
                // read was successful -> done
                return;
            }
        }
    }
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IStatus(org.eclipse.core.runtime.IStatus)

Aggregations

IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)32 Test (org.junit.Test)16 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)8 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)7 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)6 OutputStream (java.io.OutputStream)5 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)5 IOException (java.io.IOException)4 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)4 FeatureRootAdviceTest (org.eclipse.tycho.p2.impl.publisher.rootfiles.FeatureRootAdviceTest)4 ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)4 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2