Search in sources :

Example 41 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project tycho by eclipse.

the class LocalArtifactRepositoryP2APITest method testReWriteArtifactFails.

@Test
public void testReWriteArtifactFails() throws Exception {
    // LocalArtifactRepository doesn't allow overwrites -> this may be different in other IArtifactRepository implementations
    ProvisionException expectedException = null;
    try {
        IArtifactSink addSink = subject.newAddingArtifactSink(ARTIFACT_A_KEY);
        addSink.beginWrite();
        addSink.commitWrite();
    } catch (ProvisionException e) {
        expectedException = e;
    }
    assertThat(expectedException, is(instanceOf(ProvisionException.class)));
    assertThat(expectedException.getStatus().getCode(), is(ProvisionException.ARTIFACT_EXISTS));
}
Also used : ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink) Test(org.junit.Test)

Example 42 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project tycho by eclipse.

the class LocalArtifactRepositoryP2APITest method testReWriteArtifactViaStreamFails.

@SuppressWarnings("deprecation")
@Test
public void testReWriteArtifactViaStreamFails() throws Exception {
    ProvisionException expectedException = null;
    try {
        OutputStream addSink = subject.getOutputStream(ARTIFACT_A_CANONICAL);
        addSink.write(new byte[1]);
        addSink.close();
    } catch (ProvisionException e) {
        expectedException = e;
    }
    assertThat(expectedException, is(instanceOf(ProvisionException.class)));
    assertThat(expectedException.getStatus().getCode(), is(ProvisionException.ARTIFACT_EXISTS));
}
Also used : ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) OutputStream(java.io.OutputStream) ProbeOutputStream(org.eclipse.tycho.repository.streaming.testutil.ProbeOutputStream) Test(org.junit.Test)

Example 43 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project tycho by eclipse.

the class LocalArtifactRepositoryTest method testGetRawArtifactDummy.

@Test
public void testGetRawArtifactDummy() throws ProvisionException, IOException {
    LocalArtifactRepository repo = new LocalArtifactRepository(localRepoIndices);
    ArtifactDescriptor p2Artifact = newBundleArtifactDescriptor(false);
    byte[] content = new byte[] { 111, 112 };
    writeDummyArtifact(repo, p2Artifact, content);
    Assert.assertTrue(repo.contains(p2Artifact.getArtifactKey()));
    ByteArrayOutputStream destination = new ByteArrayOutputStream();
    repo.getRawArtifact(p2Artifact, destination, new NullProgressMonitor());
    Assert.assertArrayEquals(content, destination.toByteArray());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 44 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project tycho by eclipse.

the class ModuleArtifactRepository method load.

private void load() throws ProvisionException {
    try {
        FileInputStream p2DataFileStream = new FileInputStream(p2DataFile);
        try {
            Set<IArtifactDescriptor> descriptors = new ArtifactsIO().readXML(p2DataFileStream);
            for (IArtifactDescriptor descriptor : descriptors) {
                ModuleArtifactDescriptor internalDescriptor = getInternalDescriptorFromLoadedDescriptor(descriptor, p2DataFile);
                // TODO check that GAV properties match module GAV
                internalAddInternalDescriptor(internalDescriptor);
            }
        } finally {
            p2DataFileStream.close();
        }
    } catch (IOException e) {
        throw failedReadException(p2DataFile, null, e);
    }
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ModuleArtifactDescriptor(org.eclipse.tycho.repository.module.ModuleArtifactRepository.ModuleArtifactDescriptor)

Example 45 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project tycho by eclipse.

the class ModuleMetadataRepository method load.

private void load() throws ProvisionException {
    try {
        MetadataIO io = new MetadataIO();
        FileInputStream is = new FileInputStream(storage);
        units.addAll(io.readXML(is));
    } catch (IOException e) {
        String message = "I/O error while reading repository from " + storage;
        int code = ProvisionException.REPOSITORY_FAILED_READ;
        Status status = new Status(IStatus.ERROR, BUNDLE_ID, code, message, e);
        throw new ProvisionException(status);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)29 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)14 IStatus (org.eclipse.core.runtime.IStatus)13 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)10 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)8 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)8 URI (java.net.URI)7 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Status (org.eclipse.core.runtime.Status)6 IOException (java.io.IOException)5 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)5 IProvisioningAgentProvider (org.eclipse.equinox.p2.core.IProvisioningAgentProvider)5 OutputStream (java.io.OutputStream)4 HashSet (java.util.HashSet)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)4 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)4