use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.
the class LocalMetadataRepositoryTest method addInstallableUnit.
@Test
public void addInstallableUnit() throws CoreException {
File location = new File("target/metadataRepo");
LocalMetadataRepository repository = createRepository(location);
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
iud.setId("test");
iud.setVersion(Version.parseVersion("1.0.0"));
iud.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact");
iud.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("test2");
iud2.setVersion(Version.parseVersion("1.0.0"));
iud2.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
iud2.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact2");
iud2.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
repository.addInstallableUnits(Arrays.asList(iu, iu2));
repository = (LocalMetadataRepository) loadRepository(location);
IQueryResult<IInstallableUnit> result = repository.query(QueryUtil.ALL_UNITS, monitor);
ArrayList<IInstallableUnit> allius = new ArrayList<>(result.toSet());
Assert.assertEquals(2, allius.size());
// as of e3.5.2 Collector uses HashSet internally and does not guarantee collected results order
// 3.6 IQueryResult, too, is backed by HashSet. makes no sense.
// Assert.assertEquals( iu.getId(), allius.get( 0 ).getId() );
Set<IInstallableUnit> ius = repository.getGAVs().get(RepositoryLayoutHelper.getGAV(iu.getProperties()));
Assert.assertEquals(1, ius.size());
}
use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.
the class BaselineServiceImpl method getBaselineUnit.
private IInstallableUnit getBaselineUnit(IQueryable<IInstallableUnit> units, String id, Version version) {
IQueryResult<IInstallableUnit> result = units.query(QueryUtil.createIUQuery(id, version), monitor);
if (result.isEmpty()) {
return null;
}
Iterator<IInstallableUnit> iterator = result.iterator();
IInstallableUnit unit = iterator.next();
if (iterator.hasNext()) {
throw new IllegalArgumentException();
}
return unit;
}
use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.
the class TargetPlatformFactoryImpl method gatherExternalInstallableUnits.
/**
* External installable units collected from p2 repositories, .target files and local Maven
* repository.
*/
private LinkedHashSet<IInstallableUnit> gatherExternalInstallableUnits(Set<MavenRepositoryLocation> completeRepositories, List<TargetDefinitionContent> targetDefinitionsContent, PomDependencyCollectorImpl pomDependenciesContent, boolean includeLocalMavenRepo) {
LinkedHashSet<IInstallableUnit> result = new LinkedHashSet<>();
for (TargetDefinitionContent targetDefinitionContent : targetDefinitionsContent) {
result.addAll(targetDefinitionContent.getUnits());
}
List<IMetadataRepository> metadataRepositories = new ArrayList<>();
for (MavenRepositoryLocation location : completeRepositories) {
metadataRepositories.add(loadMetadataRepository(location));
}
if (includeLocalMavenRepo) {
metadataRepositories.add(localMetadataRepository);
}
for (IMetadataRepository repository : metadataRepositories) {
IQueryResult<IInstallableUnit> matches = repository.query(QueryUtil.ALL_UNITS, monitor);
result.addAll(matches.toUnmodifiableSet());
}
result.addAll(pomDependenciesContent.gatherMavenInstallableUnits());
if (includeLocalMavenRepo && logger.isDebugEnabled()) {
IQueryResult<IInstallableUnit> locallyInstalledIUs = localMetadataRepository.query(QueryUtil.ALL_UNITS, null);
logger.debug("Added " + countElements(locallyInstalledIUs.iterator()) + " locally built units to the target platform");
}
return result;
}
use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.
the class RemoteMetadataRepositoryManager method failIfRepositoryContainsPartialIUs.
private void failIfRepositoryContainsPartialIUs(IMetadataRepository repository, URI effectiveLocation) throws ProvisionException {
IQueryResult<IInstallableUnit> allUnits = repository.query(QueryUtil.ALL_UNITS, null);
boolean hasPartialIUs = false;
for (IInstallableUnit unit : allUnits.toUnmodifiableSet()) {
if (Boolean.valueOf(unit.getProperty(IInstallableUnit.PROP_PARTIAL_IU))) {
hasPartialIUs = true;
logger.error("Partial IU: " + unit.getId());
}
}
if (hasPartialIUs) {
String message = "The p2 repository at " + effectiveLocation + " contains partial IUs (see above) from an old style update site which cannot be used for dependency resolution";
throw new ProvisionException(message);
}
}
use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.
the class P2ResolverImpl method resolveInstallableUnit.
// TODO 412416 this should be a method on the class TargetPlatform
@Override
public P2ResolutionResult resolveInstallableUnit(TargetPlatform targetPlatform, String id, String versionRange) {
setContext(targetPlatform, null);
QueryableCollection queriable = new QueryableCollection(context.getInstallableUnits());
VersionRange range = new VersionRange(versionRange);
IRequirement requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, id, range, null, 1, /* min */
Integer.MAX_VALUE, /* max */
false);
IQueryResult<IInstallableUnit> result = queriable.query(QueryUtil.createLatestQuery(QueryUtil.createMatchQuery(requirement.getMatches())), monitor);
Set<IInstallableUnit> newState = result.toUnmodifiableSet();
return toResolutionResult(newState, null);
}
Aggregations