use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepository in project tycho by eclipse.
the class ModuleArtifactRepositoryTest method testPersistEmptyRepository.
@Test
public void testPersistEmptyRepository() throws Exception {
File repoDir = tempManager.newFolder("targetDir");
subject = ModuleArtifactRepository.createInstance(null, repoDir);
IArtifactRepository result = loadRepositoryViaAgent(repoDir);
assertThat(allKeysIn(result).size(), is(0));
}
use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepository in project tycho by eclipse.
the class RepositoryArtifactProviderTest method testGetArtifactWithSomeMirrorFailures.
@Test
public void testGetArtifactWithSomeMirrorFailures() throws Exception {
IArtifactRepository failingMirrorsRepository = createArtifactRepositoryMock();
when(failingMirrorsRepository.contains(BUNDLE_A_KEY)).thenReturn(true);
when(failingMirrorsRepository.getArtifactDescriptors(BUNDLE_A_KEY)).thenReturn(new IArtifactDescriptor[] { canonicalDescriptorFor(BUNDLE_A_KEY) });
when(failingMirrorsRepository.getArtifact(argThat(is(canonicalDescriptorFor(BUNDLE_A_KEY))), any(OutputStream.class), any(IProgressMonitor.class))).thenReturn(//
errorWithRetry("mirror 1 failure")).thenReturn(//
errorWithRetry("mirror 2 failure")).thenReturn(Status.OK_STATUS);
subject = new RepositoryArtifactProvider(Collections.singletonList(failingMirrorsRepository), TRANSFER_POLICY);
testSink = newArtifactSinkFor(BUNDLE_A_KEY);
status = subject.getArtifact(testSink, null);
assertThat(status, is(warningStatus()));
assertThat(status.toString(), containsString("mirror 1"));
assertThat(status.toString(), containsString("mirror 2"));
}
use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepository in project tycho by eclipse.
the class RepositoryArtifactProviderTest method createArtifactRepositoryMock.
private static IArtifactRepository createArtifactRepositoryMock() {
/*
* Create an IArtifactRepository mock instance with the default implementation of
* org.eclipse.equinox.p2.repository.artifact.IArtifactRepository.getArtifacts(
* IArtifactRequest[], IProgressMonitor)
*/
IArtifactRepository partialMock = mock(AbstractArtifactRepository2.class);
when(partialMock.getArtifacts(any(IArtifactRequest[].class), any(IProgressMonitor.class))).thenCallRealMethod();
return partialMock;
}
use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepository in project tycho by eclipse.
the class AuthoredIUAction method perform.
@Override
@SuppressWarnings("deprecation")
public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
File iuFile = new File(iuProject, "p2iu.xml");
if (!iuFile.exists())
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not find the p2iu.xml file in folder " + iuProject);
try {
FileInputStream is = new FileInputStream(iuFile);
InstallableUnitDescription iuDescriptions = new MetadataIO().readOneIU(is);
tweakIU(iuDescriptions);
Set<IInstallableUnit> ius = toIUs(iuDescriptions);
results.addIUs(ius, IPublisherResult.ROOT);
IArtifactRepository repo = info.getArtifactRepository();
boolean artifactReferenced = false;
if (repo != null) {
for (IInstallableUnit iu : ius) {
Collection<IArtifactKey> associatedKeys = iu.getArtifacts();
for (IArtifactKey key : associatedKeys) {
ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, key, null);
processArtifactPropertiesAdvice(iu, ad, info);
ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
ad.setProperty(RepositoryLayoutHelper.PROP_EXTENSION, "zip");
repo.addDescriptor(ad);
artifactReferenced = true;
}
}
}
// and fails in many places. I tried to change the code where the failures were occurring but did not succeed.
if (!artifactReferenced && repo != null) {
IInstallableUnit iu = ((IInstallableUnit) ius.iterator().next());
ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, new ArtifactKey("binary", "generated_" + iu.getId(), iu.getVersion()), null);
processArtifactPropertiesAdvice(iu, ad, info);
ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
repo.addDescriptor(ad);
artifactReferenced = true;
}
return Status.OK_STATUS;
} catch (IOException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while reading " + iuFile, e);
}
}
use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepository in project tycho by eclipse.
the class AbstractMetadataGenerator method publish.
private DependencyMetadata publish(PublisherInfo publisherInfo, List<IPublisherAction> actions) {
PublisherResult result = new PublisherResult();
Publisher publisher = new Publisher(publisherInfo, result);
IStatus status = publisher.publish(actions.toArray(new IPublisherAction[actions.size()]), monitor);
if (!status.isOK()) {
throw new RuntimeException(StatusTool.collectProblems(status), status.getException());
}
DependencyMetadata metadata = new DependencyMetadata();
metadata.setMetadata(true, result.getIUs(null, PublisherResult.ROOT));
metadata.setMetadata(false, result.getIUs(null, PublisherResult.NON_ROOT));
IArtifactRepository artifactRepository = publisherInfo.getArtifactRepository();
if (artifactRepository instanceof TransientArtifactRepository) {
metadata.setArtifacts(((TransientArtifactRepository) artifactRepository).getArtifactDescriptors());
}
return metadata;
}
Aggregations