Search in sources :

Example 41 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class TargetPlatformFactoryImpl method createTargetPlatform.

/**
 * Computes the target platform from the given configuration and content.
 *
 * <p>
 * Used as entry point for tests, which can provide the execution environment configuration via
 * the more low-level type {@link ExecutionEnvironmentResolutionHandler}.
 * </p>
 *
 * @param tpConfiguration
 * @param eeResolutionHandler
 *            Representation of the target execution environment profile. In case of a custom EE
 *            profile, the handler also reads the full specification from the target platform.
 * @param reactorProjects
 *            may be <code>null</code>
 * @param pomDependencies
 *            may be <code>null</code>
 *
 * @see #createTargetPlatform(TargetPlatformConfigurationStub,
 *      ExecutionEnvironmentConfiguration, List, PomDependencyCollector)
 */
public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpConfiguration, ExecutionEnvironmentResolutionHandler eeResolutionHandler, List<ReactorProject> reactorProjects, PomDependencyCollector pomDependencies) {
    List<TargetDefinitionContent> targetFileContent = resolveTargetDefinitions(tpConfiguration, eeResolutionHandler.getResolutionHints());
    PomDependencyCollectorImpl pomDependenciesContent = (PomDependencyCollectorImpl) pomDependencies;
    // TODO 412416 remove when the RepositoryBlackboardKey registration is gone
    if (pomDependenciesContent == null)
        pomDependenciesContent = new PomDependencyCollectorImpl(mavenContext);
    // TODO 372780 get rid of this special handling of pomDependency artifacts: there should be one p2 artifact repo view on the target platform
    IRawArtifactFileProvider pomDependencyArtifactRepo = pomDependenciesContent.getArtifactRepoOfPublishedBundles();
    RepositoryBlackboardKey blackboardKey = RepositoryBlackboardKey.forResolutionContextArtifacts(pomDependenciesContent.getProjectLocation());
    ArtifactRepositoryBlackboard.putRepository(blackboardKey, new ProviderOnlyArtifactRepository(pomDependencyArtifactRepo, Activator.getProvisioningAgent(), blackboardKey.toURI()));
    logger.debug("Registered artifact repository " + blackboardKey);
    Set<MavenRepositoryLocation> completeRepositories = tpConfiguration.getP2Repositories();
    registerRepositoryIDs(completeRepositories);
    // collect & process metadata
    boolean includeLocalMavenRepo = shouldIncludeLocallyInstalledUnits(tpConfiguration);
    LinkedHashSet<IInstallableUnit> externalUIs = gatherExternalInstallableUnits(completeRepositories, targetFileContent, pomDependenciesContent, includeLocalMavenRepo);
    Map<IInstallableUnit, ReactorProjectIdentities> reactorProjectUIs = getPreliminaryReactorProjectUIs(reactorProjects);
    List<TargetPlatformFilter> iuFilters = tpConfiguration.getFilters();
    TargetPlatformFilterEvaluator filter = !iuFilters.isEmpty() ? new TargetPlatformFilterEvaluator(iuFilters, logger) : null;
    applyConfiguredFilter(filter, reactorProjectUIs.keySet());
    applyFilters(filter, externalUIs, reactorProjectUIs.keySet(), eeResolutionHandler.getResolutionHints());
    PreliminaryTargetPlatformImpl targetPlatform = new // 
    PreliminaryTargetPlatformImpl(// 
    reactorProjectUIs, // 
    externalUIs, // 
    pomDependenciesContent.getMavenInstallableUnits(), // 
    eeResolutionHandler.getResolutionHints(), // 
    filter, // 
    localMetadataRepository, createExternalArtifactProvider(completeRepositories, targetFileContent, pomDependencyArtifactRepo, // 
    tpConfiguration.getIncludePackedArtifacts()), // 
    localArtifactRepository, // 
    includeLocalMavenRepo, logger);
    eeResolutionHandler.readFullSpecification(targetPlatform.getInstallableUnits());
    return targetPlatform;
}
Also used : IRawArtifactFileProvider(org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactFileProvider) ReactorProjectIdentities(org.eclipse.tycho.ReactorProjectIdentities) RepositoryBlackboardKey(org.eclipse.tycho.repository.registry.facade.RepositoryBlackboardKey) TargetPlatformFilterEvaluator(org.eclipse.tycho.p2.target.filters.TargetPlatformFilterEvaluator) MavenRepositoryLocation(org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation) ProviderOnlyArtifactRepository(org.eclipse.tycho.repository.p2base.artifact.repository.ProviderOnlyArtifactRepository) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) TargetPlatformFilter(org.eclipse.tycho.artifacts.TargetPlatformFilter)

Example 42 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class TargetPlatformFactoryImpl method applyFilters.

private void applyFilters(TargetPlatformFilterEvaluator filter, Collection<IInstallableUnit> collectionToModify, Set<IInstallableUnit> reactorProjectUIs, ExecutionEnvironmentResolutionHints eeResolutionHints) {
    Set<String> reactorIUIDs = new HashSet<>();
    for (IInstallableUnit unit : reactorProjectUIs) {
        reactorIUIDs.add(unit.getId());
    }
    // a.jre/config.a.jre installable units
    // partial installable units
    // installable units shadowed by reactor projects
    Iterator<IInstallableUnit> iter = collectionToModify.iterator();
    while (iter.hasNext()) {
        IInstallableUnit unit = iter.next();
        if (eeResolutionHints.isNonApplicableEEUnit(unit) || isPartialIU(unit) || reactorIUIDs.contains(unit.getId())) {
            // TODO debug log output?
            iter.remove();
            continue;
        }
    }
    applyConfiguredFilter(filter, collectionToModify);
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 43 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class TargetPlatformFactoryImpl method createTargetPlatformWithUpdatedReactorUnits.

P2TargetPlatform createTargetPlatformWithUpdatedReactorUnits(PreliminaryTargetPlatformImpl preliminaryTP, Map<IInstallableUnit, ReactorProjectIdentities> reactorUnitsMap, List<IRawArtifactFileProvider> reactorArtifacts) {
    LinkedHashSet<IInstallableUnit> allUnits = preliminaryTP.getExternalUnits();
    // external units are already filtered, only reactor units need to be filtered again
    if (reactorUnitsMap != null) {
        Collection<IInstallableUnit> reactorUnits = new LinkedList<>(reactorUnitsMap.keySet());
        TargetPlatformFilterEvaluator configuredFilters = preliminaryTP.getFilter();
        if (configuredFilters != null) {
            configuredFilters.filterUnits(reactorUnits);
        }
        allUnits.addAll(reactorUnits);
    }
    IRawArtifactFileProvider jointArtifacts = createJointArtifactProvider(reactorArtifacts, preliminaryTP.getExternalArtifacts());
    return new FinalTargetPlatformImpl(allUnits, preliminaryTP.getEEResolutionHints(), jointArtifacts, localArtifactRepository, preliminaryTP.getOriginalMavenArtifactMap(), reactorUnitsMap);
}
Also used : IRawArtifactFileProvider(org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactFileProvider) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) TargetPlatformFilterEvaluator(org.eclipse.tycho.p2.target.filters.TargetPlatformFilterEvaluator) LinkedList(java.util.LinkedList)

Example 44 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class CustomEEResolutionHandler method readCapabilities.

private List<SystemCapability> readCapabilities(IInstallableUnit specificationUnit) {
    List<SystemCapability> result = new ArrayList<>();
    for (IProvidedCapability capability : specificationUnit.getProvidedCapabilities()) {
        String namespace = capability.getNamespace();
        String name = capability.getName();
        String version = capability.getVersion().toString();
        if (JREAction.NAMESPACE_OSGI_EE.equals(namespace)) {
            result.add(new SystemCapability(Type.OSGI_EE, name, version));
        } else if (PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE.equals(namespace)) {
            result.add(new SystemCapability(Type.JAVA_PACKAGE, name, version));
        } else {
        // ignore
        }
    }
    return result;
}
Also used : SystemCapability(org.eclipse.tycho.core.ee.shared.SystemCapability) IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) ArrayList(java.util.ArrayList)

Example 45 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class AuthoredIUAction method perform.

@Override
@SuppressWarnings("deprecation")
public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
    File iuFile = new File(iuProject, "p2iu.xml");
    if (!iuFile.exists())
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not find the p2iu.xml file in folder " + iuProject);
    try {
        FileInputStream is = new FileInputStream(iuFile);
        InstallableUnitDescription iuDescriptions = new MetadataIO().readOneIU(is);
        tweakIU(iuDescriptions);
        Set<IInstallableUnit> ius = toIUs(iuDescriptions);
        results.addIUs(ius, IPublisherResult.ROOT);
        IArtifactRepository repo = info.getArtifactRepository();
        boolean artifactReferenced = false;
        if (repo != null) {
            for (IInstallableUnit iu : ius) {
                Collection<IArtifactKey> associatedKeys = iu.getArtifacts();
                for (IArtifactKey key : associatedKeys) {
                    ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, key, null);
                    processArtifactPropertiesAdvice(iu, ad, info);
                    ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
                    ad.setProperty(RepositoryLayoutHelper.PROP_EXTENSION, "zip");
                    repo.addDescriptor(ad);
                    artifactReferenced = true;
                }
            }
        }
        // and fails in many places. I tried to change the code where the failures were occurring but did not succeed.
        if (!artifactReferenced && repo != null) {
            IInstallableUnit iu = ((IInstallableUnit) ius.iterator().next());
            ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, new ArtifactKey("binary", "generated_" + iu.getId(), iu.getVersion()), null);
            processArtifactPropertiesAdvice(iu, ad, info);
            ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
            repo.addDescriptor(ad);
            artifactReferenced = true;
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while reading " + iuFile, e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ArtifactKey(org.eclipse.equinox.internal.p2.metadata.ArtifactKey) IArtifactRepository(org.eclipse.equinox.p2.repository.artifact.IArtifactRepository) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)153 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)44 File (java.io.File)38 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)25 HashSet (java.util.HashSet)18 IStatus (org.eclipse.core.runtime.IStatus)18 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)16 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)11 CoreException (org.eclipse.core.runtime.CoreException)11 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)11 ResourceUtil.resourceFile (org.eclipse.tycho.p2.tools.test.util.ResourceUtil.resourceFile)11 URI (java.net.URI)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)9 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)9 Status (org.eclipse.core.runtime.Status)8 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8