use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project tycho by eclipse.
the class RemoteAgentMavenMirrorsTest method loadRepositories.
private Repositories loadRepositories(String id, URI specifiedUrl) throws Exception {
IRepositoryIdManager idManager = (IRepositoryIdManager) subject.getService(IRepositoryIdManager.SERVICE_NAME);
idManager.addMapping(id, specifiedUrl);
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) subject.getService(IMetadataRepositoryManager.SERVICE_NAME);
IMetadataRepository metadataRepo = metadataManager.loadRepository(specifiedUrl, null);
IArtifactRepositoryManager artifactsManager = (IArtifactRepositoryManager) subject.getService(IArtifactRepositoryManager.SERVICE_NAME);
IArtifactRepository artifactsRepo = artifactsManager.loadRepository(specifiedUrl, null);
return new Repositories(metadataRepo, artifactsRepo);
}
use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project tycho by eclipse.
the class MetadataSerializableImplTest method deserialize.
private Set<IInstallableUnit> deserialize(File tmpDir) throws ProvisionException {
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
IMetadataRepository repository = manager.loadRepository(tmpDir.toURI(), null);
IQueryResult<IInstallableUnit> queryResult = repository.query(QueryUtil.ALL_UNITS, null);
Set<IInstallableUnit> result = queryResult.toSet();
return result;
}
use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project gemoc-studio by eclipse.
the class PrepareInstallProfileJob method addRepositories.
private List<IMetadataRepository> addRepositories(SubMonitor monitor) throws MalformedURLException, URISyntaxException, ProvisionException {
// tell p2 that it's okay to use these repositories
ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
repositoryLocations = new HashSet<URI>();
monitor.setWorkRemaining(installableConnectors.size() * 5);
for (InstallableComponent descriptor : installableConnectors) {
for (String url : descriptor.getSitesURLS()) {
addASiteURL(monitor, session, repositoryTracker, url);
}
}
// fetch meta-data for these repositories
ArrayList<IMetadataRepository> repositories = new ArrayList<IMetadataRepository>();
monitor.setWorkRemaining(repositories.size());
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
for (URI uri : repositoryLocations) {
checkCancelled(monitor);
IMetadataRepository repository = manager.loadRepository(uri, monitor.newChild(1));
repositories.add(repository);
}
return repositories;
}
use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project tycho by eclipse.
the class PublishingRepositoryLoader method getModuleMetadataRepository.
public ModuleMetadataRepository getModuleMetadataRepository() {
IMetadataRepositoryManager repoManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
// TODO use p2metadata.xml file instead of folder? Could prevent loading a content.xml from the folder
URI location = project.getBuildDirectory().getLocation().toURI();
return getModuleMetadataRepository(repoManager, location);
}
use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager 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;
}
Aggregations