Search in sources :

Example 1 with VersionRange

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

the class BundleDependenciesAction method createAdviceFileAdvice.

@Override
protected void createAdviceFileAdvice(BundleDescription bundleDescription, IPublisherInfo publisherInfo) {
    String location = bundleDescription.getLocation();
    if (location == null)
        return;
    File adviceFile = new File(location, AdviceFileAdvice.BUNDLE_ADVICE_FILE.toString());
    if (!adviceFile.canRead()) {
        return;
    }
    Map<String, String> advice = new LinkedHashMap<>();
    try {
        InputStream is = new BufferedInputStream(new FileInputStream(adviceFile));
        try {
            Properties props = new Properties();
            props.load(is);
            for (Map.Entry<Object, Object> p : props.entrySet()) {
                advice.put((String) p.getKey(), (String) p.getValue());
            }
        } finally {
            try {
                is.close();
            } catch (IOException secondary) {
            // secondary exception
            }
        }
    } catch (IOException e) {
        // TODO log
        return;
    }
    final String symbolicName = bundleDescription.getSymbolicName();
    final Version bundleVersion = PublisherHelper.fromOSGiVersion(bundleDescription.getVersion());
    AdviceFileParser parser = new AdviceFileParser(symbolicName, bundleVersion, advice) {

        @Override
        protected IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) {
            if (optionalAction == OptionalResolutionAction.OPTIONAL) {
                return super.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
            }
            return BundleDependenciesAction.this.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
        }
    };
    try {
        parser.parse();
    } catch (Exception e) {
        // TODO log
        return;
    }
    final IProvidedCapability[] provided = parser.getProvidedCapabilities();
    final IRequirement[] required = parser.getRequiredCapabilities();
    if (provided == null && required == null) {
        return;
    }
    publisherInfo.addAdvice(new ICapabilityAdvice() {

        @Override
        public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
            return symbolicName.equals(id) && bundleVersion.equals(version);
        }

        @Override
        public IRequirement[] getRequiredCapabilities(InstallableUnitDescription iu) {
            return required;
        }

        @Override
        public IProvidedCapability[] getProvidedCapabilities(InstallableUnitDescription iu) {
            return provided;
        }

        @Override
        public IRequirement[] getMetaRequiredCapabilities(InstallableUnitDescription iu) {
            return null;
        }
    });
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) BufferedInputStream(java.io.BufferedInputStream) Version(org.eclipse.equinox.p2.metadata.Version) AdviceFileParser(org.eclipse.equinox.p2.publisher.AdviceFileParser) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ICapabilityAdvice(org.eclipse.equinox.p2.publisher.actions.ICapabilityAdvice)

Example 2 with VersionRange

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

the class BundleDependenciesAction method addImportPackageRequirement.

@Override
protected void addImportPackageRequirement(ArrayList<IRequirement> reqsDeps, ImportPackageSpecification importSpec, ManifestElement[] rawImportPackageHeader) {
    if (optionalAction == OptionalResolutionAction.OPTIONAL) {
        super.addImportPackageRequirement(reqsDeps, importSpec, rawImportPackageHeader);
        return;
    }
    VersionRange versionRange = PublisherHelper.fromOSGiVersionRange(importSpec.getVersionRange());
    final boolean required = !isOptional(importSpec) || optionalAction == OptionalResolutionAction.REQUIRE;
    if (required) {
        // TODO this needs to be refined to take into account all the attribute handled by imports
        reqsDeps.add(MetadataFactory.createRequirement(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, importSpec.getName(), versionRange, null, 1, 1, true));
    }
}
Also used : VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Example 3 with VersionRange

use of org.eclipse.equinox.p2.metadata.VersionRange 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 4 with VersionRange

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

the class FeatureDependenciesAction method getVersionRange.

/**
 * Copy&Paste from 3.7
 * org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction.getVersionRange(FeatureEntry)
 */
private VersionRange getVersionRange(FeatureEntry entry) {
    String versionSpec = entry.getVersion();
    if (versionSpec == null)
        return VersionRange.emptyRange;
    String match = entry.getMatch();
    if (// $NON-NLS-1$
    "versionRange".equals(match))
        return new VersionRange(versionSpec);
    Version version = Version.parseVersion(versionSpec);
    if (version.equals(Version.emptyVersion))
        return VersionRange.emptyRange;
    if (!entry.isRequires())
        return new VersionRange(version, true, version, true);
    if (match == null)
        // TODO should really be returning VersionRange.emptyRange here...
        return null;
    if (// $NON-NLS-1$
    match.equals("perfect"))
        return new VersionRange(version, true, version, true);
    org.osgi.framework.Version osgiVersion = PublisherHelper.toOSGiVersion(version);
    if (match.equals("equivalent")) {
        // $NON-NLS-1$
        Version upper = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor() + 1, 0);
        return new VersionRange(version, true, upper, false);
    }
    if (match.equals("compatible")) {
        // $NON-NLS-1$
        Version upper = Version.createOSGi(osgiVersion.getMajor() + 1, 0, 0);
        return new VersionRange(version, true, upper, false);
    }
    if (// $NON-NLS-1$
    match.equals("greaterOrEqual"))
        return new VersionRange(version, true, new VersionRange(null).getMaximum(), true);
    return null;
}
Also used : Version(org.eclipse.equinox.p2.metadata.Version) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Example 5 with VersionRange

use of org.eclipse.equinox.p2.metadata.VersionRange 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)

Aggregations

VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)16 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)7 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)3 Version (org.eclipse.equinox.p2.metadata.Version)3 LinkedHashSet (java.util.LinkedHashSet)2 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)2 IllegalArtifactReferenceException (org.eclipse.tycho.artifacts.IllegalArtifactReferenceException)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 RequiredCapability (org.eclipse.equinox.internal.p2.metadata.RequiredCapability)1