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;
}
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()));
}
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);
}
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);
}
}
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);
}
Aggregations