Search in sources :

Example 11 with IRequirement

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

the class BundleDependenciesAction method addRequireBundleRequirement.

@Override
protected void addRequireBundleRequirement(ArrayList<IRequirement> reqsDeps, BundleSpecification requiredBundle, ManifestElement[] rawRequireBundleHeader) {
    if (optionalAction == OptionalResolutionAction.OPTIONAL) {
        super.addRequireBundleRequirement(reqsDeps, requiredBundle, rawRequireBundleHeader);
        return;
    }
    VersionRange versionRange = PublisherHelper.fromOSGiVersionRange(requiredBundle.getVersionRange());
    final boolean required = !requiredBundle.isOptional() || optionalAction == OptionalResolutionAction.REQUIRE;
    if (required) {
        reqsDeps.add(MetadataFactory.createRequirement(CAPABILITY_NS_OSGI_BUNDLE, requiredBundle.getName(), versionRange, null, 1, 1, true));
    }
}
Also used : VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Example 12 with IRequirement

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

the class ProductDependenciesAction method getRequiredCapabilities.

@Override
protected Set<IRequirement> getRequiredCapabilities() {
    Set<IRequirement> required = new LinkedHashSet<>();
    if (product.useFeatures()) {
        for (IVersionedId feature : product.getFeatures()) {
            // $NON-NLS-1$
            String id = feature.getId() + FEATURE_GROUP_IU_SUFFIX;
            Version version = feature.getVersion();
            addRequiredCapability(required, id, version, null, false);
        }
    } else {
        for (FeatureEntry plugin : ((ProductFile) product).getProductEntries()) {
            addRequiredCapability(required, plugin.getId(), Version.parseVersion(plugin.getVersion()), null, true);
        }
    }
    if (product.includeLaunchers()) {
        addRequiredCapability(required, "org.eclipse.equinox.executable.feature.group", null, null, false);
    }
    return required;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) LinkedHashSet(java.util.LinkedHashSet) FeatureEntry(org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry) ProductFile(org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile) IVersionedId(org.eclipse.equinox.p2.metadata.IVersionedId) Version(org.eclipse.equinox.p2.metadata.Version)

Example 13 with IRequirement

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

the class DependencyCollectorTest method missingDependencies.

@Test
public void missingDependencies() {
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    String time = Long.toString(System.currentTimeMillis());
    iud.setId(time);
    iud.setVersion(Version.createOSGi(0, 0, 0, time));
    ArrayList<IRequirement> requirements = new ArrayList<>();
    VersionRange range = new VersionRange("[1.2.3,1.2.4)");
    requirements.add(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "this.is.a.missing.iu", range, null, 1, /* min */
    1, /* max */
    true));
    iud.setRequirements(requirements.toArray(new IRequirement[requirements.size()]));
    HashSet<IInstallableUnit> rootUIs = new HashSet<>();
    rootUIs.add(MetadataFactory.createInstallableUnit(iud));
    ResolutionDataImpl data = new ResolutionDataImpl(ExecutionEnvironmentTestUtils.NOOP_EE_RESOLUTION_HINTS);
    data.setRootIUs(rootUIs);
    data.setAdditionalRequirements(new ArrayList<IRequirement>());
    data.setAvailableIUs(Collections.<IInstallableUnit>emptyList());
    DependencyCollector dc = new DependencyCollector(logVerifier.getLogger());
    dc.setData(data);
    try {
        dc.resolve(Collections.<String, String>emptyMap(), new NullProgressMonitor());
        Assert.fail();
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause instanceof ProvisionException);
        ProvisionException pe = (ProvisionException) cause;
        Assert.assertTrue(pe.getStatus().isMultiStatus());
        MultiStatus status = (MultiStatus) pe.getStatus();
        Assert.assertEquals(1, status.getChildren().length);
        Assert.assertTrue(e.toString().contains("this.is.a.missing.iu"));
    }
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with IRequirement

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

the class AbstractMetadataGenerator method extractExtraEntriesAsIURequirement.

private IRequirement[] extractExtraEntriesAsIURequirement(File location) {
    BuildProperties buildProps = buildPropertiesParser.parse(location);
    ArrayList<IRequirement> result = new ArrayList<>();
    for (Entry<String, List<String>> entry : buildProps.getJarToExtraClasspathMap().entrySet()) {
        createRequirementFromExtraClasspathProperty(result, entry.getValue());
    }
    createRequirementFromExtraClasspathProperty(result, buildProps.getJarsExtraClasspath());
    if (result.isEmpty())
        return null;
    return result.toArray(new IRequirement[result.size()]);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) BuildProperties(org.eclipse.tycho.core.shared.BuildProperties) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with IRequirement

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

the class AbstractSiteDependenciesAction method getRequirement.

// This is roughly inspired from org.eclipse.equinox.internal.p2.updatesite.SiteXMLAction
private IRequirement getRequirement(SiteIU iu) {
    String id = iu.getID();
    String range = iu.getRange();
    String type = iu.getQueryType();
    String expression = iu.getQueryExpression();
    String[] params = iu.getQueryParams();
    if (id != null) {
        VersionRange vRange = new VersionRange(range);
        return MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, id, vRange, null, false, false);
    } else if ("match".equals(type)) {
        IMatchExpression<IInstallableUnit> iuMatcher = ExpressionUtil.getFactory().<IInstallableUnit>matchExpression(ExpressionUtil.parse(expression), params);
        return MetadataFactory.createRequirement(iuMatcher, null, 0, 1, true);
    } else if ("context".equals(type)) {
        throw new IllegalStateException("Context iu queries are not supported in Tycho. Faulty expression is " + expression);
    }
    return null;
}
Also used : VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) IMatchExpression(org.eclipse.equinox.p2.metadata.expression.IMatchExpression)

Aggregations

IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)31 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)23 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)11 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8 File (java.io.File)7 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)6 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)6 LinkedHashSet (java.util.LinkedHashSet)5 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)5 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)5 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)4 List (java.util.List)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Version (org.eclipse.equinox.p2.metadata.Version)2 FeatureEntry (org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry)2