use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.
the class ArtifactRepositoryBaseImpl method internalRemoveDescriptor.
@Override
protected final void internalRemoveDescriptor(IArtifactDescriptor descriptor) {
IArtifactDescriptor comparableDescriptor = getComparableDescriptor(descriptor);
descriptors.remove(comparableDescriptor);
IArtifactKey artifactKey = comparableDescriptor.getArtifactKey();
Set<ArtifactDescriptorT> descriptorsForKey = descriptorsMap.get(artifactKey);
if (descriptorsForKey != null) {
descriptorsForKey.remove(comparableDescriptor);
if (descriptorsForKey.isEmpty()) {
descriptorsMap.remove(artifactKey);
}
}
}
use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.
the class BaselineServiceImpl method getProjectBaseline.
@Override
public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLocation> baselineLocations, Map<String, IP2Artifact> reactor, File target) {
// baseline repository may contain artifacts with the same id/version but different contents
// compared to what is installed (or cached) locally.
// current local repository layout does not track per-repository artifacts and does not allow
// multiple different artifacts with same id/version.
CompositeMetadataRepository baselineUnits;
CompositeArtifactRepository baselineArtifacts;
try {
IProvisioningAgent remoteAgent = remoteAgentManager.getProvisioningAgent();
IRepositoryIdManager remoteRepositoryIdManager = (IRepositoryIdManager) remoteAgent.getService(IRepositoryIdManager.SERVICE_NAME);
IMetadataRepositoryManager remoteMetadataRepositoryManager = (IMetadataRepositoryManager) remoteAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
IArtifactRepositoryManager remoteArtifactRepositoryManager = (IArtifactRepositoryManager) remoteAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
baselineUnits = CompositeMetadataRepository.createMemoryComposite(remoteAgent);
baselineArtifacts = CompositeArtifactRepository.createMemoryComposite(remoteAgent);
for (MavenRepositoryLocation location : baselineLocations) {
URI url = location.getURL();
try {
remoteRepositoryIdManager.addMapping(location.getId(), url);
// TODO offline mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=337022
// not strictly necessary, but makes sure metadata download is visible in the console/log
remoteMetadataRepositoryManager.loadRepository(url, monitor);
remoteArtifactRepositoryManager.loadRepository(url, monitor);
baselineUnits.addChild(url);
baselineArtifacts.addChild(url);
} catch (ProvisionException e) {
// baseline repository may not exist yet
mavenContext.getLogger().warn(e.getMessage(), e);
}
}
} catch (ProvisionException e) {
throw new RuntimeException(e);
}
Map<String, IP2Artifact> result = new LinkedHashMap<>();
for (Map.Entry<String, IP2Artifact> reactorArtifact : reactor.entrySet()) {
IArtifactDescriptor descriptor = (IArtifactDescriptor) reactorArtifact.getValue().getArtifactDescriptor();
IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(baselineArtifacts, descriptor);
if (baselineDescriptor == null) {
continue;
}
IArtifactKey baslineKey = baselineDescriptor.getArtifactKey();
String format = baselineDescriptor.getProperty(IArtifactDescriptor.FORMAT);
File baselineArtifact = new File(target, baslineKey.getClassifier() + "/" + baslineKey.getId() + "/" + baslineKey.getVersion() + (format != null ? "." + format : ""));
try {
baselineArtifact.getParentFile().mkdirs();
OutputStream os = new BufferedOutputStream(new FileOutputStream(baselineArtifact));
try {
IStatus status = baselineArtifacts.getRawArtifact(baselineDescriptor, os, monitor);
if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
String repository = baselineDescriptor.getRepository().getLocation().toString();
String artifactId = baselineDescriptor.getArtifactKey().getId();
String artifactVersion = baselineDescriptor.getArtifactKey().getVersion().toString();
String statusMessage = StatusTool.toLogMessage(status);
throw new RuntimeException(String.format("Error trying to download %s version %s from %s:\n%s", artifactId, artifactVersion, repository, statusMessage), StatusTool.findException(status));
}
} finally {
try {
os.close();
} catch (IOException e) {
// ignored
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
List<IInstallableUnit> units = new ArrayList<>();
for (Object _unit : reactorArtifact.getValue().getInstallableUnits()) {
IInstallableUnit unit = (IInstallableUnit) _unit;
IInstallableUnit baselineUnit = getBaselineUnit(baselineUnits, unit.getId(), unit.getVersion());
if (baselineUnit != null) {
units.add(baselineUnit);
}
}
result.put(reactorArtifact.getKey(), new P2Artifact(baselineArtifact, units, descriptor));
}
return !result.isEmpty() ? result : null;
}
use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.
the class P2ResolverImpl method addUnit.
private void addUnit(DefaultP2ResolutionResult result, IInstallableUnit iu, ReactorProject currentProject, Set<String> missingArtifacts) {
if (currentProjectUnits.contains(iu)) {
addReactorProject(result, currentProject.getIdentities(), iu);
return;
}
ReactorProjectIdentities otherProject = context.getOriginalReactorProjectMap().get(iu);
if (otherProject != null) {
addReactorProject(result, otherProject, iu);
return;
}
IArtifactFacade mavenArtifact = context.getOriginalMavenArtifactMap().get(iu);
if (mavenArtifact != null) {
addExternalMavenArtifact(result, mavenArtifact, iu);
return;
}
for (IArtifactKey key : iu.getArtifacts()) {
// this downloads artifacts if necessary; TODO parallelize download?
File artifactLocation = context.getLocalArtifactFile(key);
if (artifactLocation == null) {
missingArtifacts.add(key.toString());
} else {
addArtifactFile(result, iu, key, artifactLocation);
}
}
}
use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.
the class VerifierServiceImpl method verifyReferencedArtifactsExist.
private boolean verifyReferencedArtifactsExist(final IMetadataRepository metadata, final IArtifactRepository artifactRepository, MavenLogger logger) {
final IQueryResult<IInstallableUnit> collector = metadata.query(QueryUtil.ALL_UNITS, monitor);
boolean valid = true;
for (Iterator<IInstallableUnit> iterator = collector.iterator(); iterator.hasNext(); ) {
IInstallableUnit iu = iterator.next();
final Collection<IArtifactKey> artifacts = iu.getArtifacts();
for (IArtifactKey key : artifacts) {
valid &= verifyArtifactExists(key, artifactRepository, logger);
}
}
return valid;
}
use of org.eclipse.equinox.p2.metadata.IArtifactKey in project tycho by eclipse.
the class InstallableUnitUtil method createIUArtifact.
public static IInstallableUnit createIUArtifact(String id, String version, String artifactId, String artifactVersion) {
InstallableUnitDescription description = createIuDescription(id, version);
description.setArtifacts(new IArtifactKey[] { new ArtifactKey("type", artifactId, Version.create(artifactVersion)) });
return MetadataFactory.createInstallableUnit(description);
}
Aggregations