Search in sources :

Example 1 with IArtifactKey

use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.

the class LocalArtifactRepositoryP2APITest method localPackedDescriptorFor.

/**
 * Returns a descriptor of the internally used {@link IArtifactDescriptor} type for the pack200
 * format of the given key.
 */
private static IArtifactDescriptor localPackedDescriptorFor(IArtifactKey key) {
    GAVArtifactDescriptor result = new GAVArtifactDescriptor(key);
    result.setProcessingSteps(new IProcessingStepDescriptor[] { new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) });
    result.setProperty(IArtifactDescriptor.FORMAT, IArtifactDescriptor.FORMAT_PACKED);
    return result;
}
Also used : IProcessingStepDescriptor(org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor) ProcessingStepDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor)

Example 2 with IArtifactKey

use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.

the class LocalArtifactRepositoryTest method testGetArtifactsErrorRequest.

@Test
public void testGetArtifactsErrorRequest() {
    LocalArtifactRepository repo = new LocalArtifactRepository(localRepoIndices);
    IArtifactRequest errorRequest = new IArtifactRequest() {

        @Override
        public void perform(IArtifactRepository sourceRepository, IProgressMonitor monitor) {
        }

        @Override
        public IStatus getResult() {
            return new Status(IStatus.ERROR, "test-bundle", "Error");
        }

        @Override
        public IArtifactKey getArtifactKey() {
            return null;
        }
    };
    IStatus status = repo.getArtifacts(new IArtifactRequest[] { errorRequest }, new NullProgressMonitor());
    assertThat(status, not(okStatus()));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) StatusMatchers.okStatus(org.eclipse.tycho.test.util.StatusMatchers.okStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IArtifactRequest(org.eclipse.equinox.p2.repository.artifact.IArtifactRequest) IArtifactRepository(org.eclipse.equinox.p2.repository.artifact.IArtifactRepository) Test(org.junit.Test)

Example 3 with IArtifactKey

use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.

the class LocalArtifactRepository method saveMaven.

private void saveMaven() {
    File location = getBasedir();
    TychoRepositoryIndex index = localRepoIndices.getArtifactsIndex();
    ArtifactsIO io = new ArtifactsIO();
    Set<IArtifactDescriptor> changedDescriptors = new HashSet<IArtifactDescriptor>(descriptors);
    changedDescriptors.removeAll(descriptorsOnLastSave);
    Set<IArtifactKey> changedKeys = new HashSet<>();
    for (IArtifactDescriptor changedDescriptor : changedDescriptors) {
        changedKeys.add(changedDescriptor.getArtifactKey());
    }
    for (IArtifactKey key : changedKeys) {
        Set<GAVArtifactDescriptor> keyDescriptors = descriptorsMap.get(key);
        if (keyDescriptors != null && !keyDescriptors.isEmpty()) {
            // all descriptors should have the same GAV
            GAVArtifactDescriptor anyDescriptorOfKey = keyDescriptors.iterator().next();
            GAV gav = anyDescriptorOfKey.getMavenCoordinates().getGav();
            index.addGav(gav);
            String relpath = getMetadataRelpath(gav);
            File file = new File(location, relpath);
            file.getParentFile().mkdirs();
            try {
                OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
                try {
                    io.writeXML(keyDescriptors, os);
                } finally {
                    os.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    try {
        index.save();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    descriptorsOnLastSave = new HashSet<IArtifactDescriptor>(descriptors);
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) IOException(java.io.IOException) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) FileOutputStream(java.io.FileOutputStream) File(java.io.File) GAV(org.eclipse.tycho.p2.repository.GAV) BufferedOutputStream(java.io.BufferedOutputStream) HashSet(java.util.HashSet)

Example 4 with IArtifactKey

use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.

the class AbstractArtifactRepository2 method getArtifact.

// implementations for old get(Raw)Artifact methods
/**
 * {@inheritDoc}
 *
 * @deprecated Obsolete. Use {@link #getArtifact(IArtifactSink, IProgressMonitor)} instead.
 */
// TODO make final?
@Override
@Deprecated
public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
    try {
        // use any format for getting the canonical artifact
        IArtifactKey requestedKey = descriptor.getArtifactKey();
        IStatus status = getArtifact(writeToStream(requestedKey, destination), monitor);
        setStatusOnStreamIfPossible(destination, status);
        return status;
    } catch (ArtifactSinkException e) {
        // the sink used shouldn't throw this exception
        return new Status(IStatus.ERROR, BUNDLE_ID, e.getMessage(), e);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) IStatus(org.eclipse.core.runtime.IStatus) ArtifactSinkException(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.ArtifactSinkException)

Example 5 with IArtifactKey

use of org.eclipse.equinox.p2.metadata.IArtifactKey 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)

Aggregations

IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)13 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)11 File (java.io.File)6 IStatus (org.eclipse.core.runtime.IStatus)6 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 Status (org.eclipse.core.runtime.Status)3 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)3 Test (org.junit.Test)3 ArtifactKey (org.eclipse.equinox.internal.p2.metadata.ArtifactKey)2 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)2 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)2 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)2 IProcessingStepDescriptor (org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor)2 ProcessingStepDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor)2 P2Artifact (org.eclipse.tycho.p2.impl.publisher.P2Artifact)2 IArtifactFacade (org.eclipse.tycho.p2.metadata.IArtifactFacade)2