Search in sources :

Example 11 with IQueryResult

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());
}
Also used : InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File) Test(org.junit.Test)

Example 12 with IQueryResult

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;
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 13 with IQueryResult

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenRepositoryLocation(org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 14 with IQueryResult

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);
    }
}
Also used : ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 15 with IQueryResult

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);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)17 ArrayList (java.util.ArrayList)6 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)5 HashMap (java.util.HashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)2 IProfile (org.eclipse.equinox.p2.engine.IProfile)2 IProfileRegistry (org.eclipse.equinox.p2.engine.IProfileRegistry)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)2 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)2 IQuery (org.eclipse.equinox.p2.query.IQuery)2 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)2 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1