Search in sources :

Example 1 with IProvidedCapability

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

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

the class AuthoredIUAction method ensureSelfCapability.

private void ensureSelfCapability(InstallableUnitDescription iu) {
    Collection<IProvidedCapability> capabilities = iu.getProvidedCapabilities();
    for (IProvidedCapability capability : capabilities) {
        if (IInstallableUnit.NAMESPACE_IU_ID.equals(capability.getNamespace()) && iu.getId().equals(capability.getName()) && iu.getVersion().equals(capability.getVersion())) {
            return;
        }
    }
    IProvidedCapability[] newCapabilities = new IProvidedCapability[capabilities.size() + 1];
    capabilities.toArray(newCapabilities);
    newCapabilities[newCapabilities.length - 1] = createSelfCapability(iu.getId(), iu.getVersion());
    iu.setCapabilities(newCapabilities);
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability)

Example 3 with IProvidedCapability

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

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

the class TargetPlatformFilterEvaluator method getPackageCapabilities.

private List<IProvidedCapability> getPackageCapabilities(IInstallableUnit unit) {
    Collection<IProvidedCapability> allCapabilities = unit.getProvidedCapabilities();
    List<IProvidedCapability> packageCapabilities = new ArrayList<>(allCapabilities.size());
    for (IProvidedCapability capability : allCapabilities) {
        if (PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE.equals(capability.getNamespace())) {
            packageCapabilities.add(capability);
        }
    }
    return packageCapabilities;
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) ArrayList(java.util.ArrayList)

Example 5 with IProvidedCapability

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

the class ProjectorResolutionStrategy method fixSWT.

/*
     * workaround for SWT bug 361901: bundles generally require org.eclipse.swt, but this is an
     * empty shell and only native fragments of org.eclipse.swt provide classes to compile against.
     * There is no dependency from the host to the fragments, so we need to add the matching SWT
     * fragment manually.
     */
void fixSWT(Collection<IInstallableUnit> availableIUs, Collection<IInstallableUnit> resolutionResult, Map<String, String> newSelectionContext, IProgressMonitor monitor) {
    IInstallableUnit swtHost = findSWTHostIU(resolutionResult);
    if (swtHost == null) {
        return;
    } else if (swtHost.getVersion().compareTo(Version.createOSGi(3, 104, 0)) >= 0) {
        // bug 361901 was fixed in Mars
        return;
    }
    // 380934 one of rootIUs can be SWT or an SWT fragment
    for (IInstallableUnit iu : data.getRootIUs()) {
        if ("org.eclipse.swt".equals(iu.getId())) {
            return;
        }
        for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
            if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                return;
            }
        }
    }
    IInstallableUnit swtFragment = null;
    all_ius: for (Iterator<IInstallableUnit> iter = new QueryableCollection(availableIUs).query(QueryUtil.ALL_UNITS, monitor).iterator(); iter.hasNext(); ) {
        IInstallableUnit iu = iter.next();
        if (iu.getId().startsWith("org.eclipse.swt") && isApplicable(newSelectionContext, iu.getFilter()) && providesJavaPackages(iu)) {
            for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
                if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                    if (swtFragment == null || swtFragment.getVersion().compareTo(iu.getVersion()) < 0) {
                        swtFragment = iu;
                    }
                    continue all_ius;
                }
            }
        }
    }
    if (swtFragment == null) {
        throw new RuntimeException("Could not determine SWT implementation fragment bundle for environment " + newSelectionContext);
    }
    resolutionResult.add(swtFragment);
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) Iterator(java.util.Iterator) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)9 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)4 Version (org.eclipse.equinox.p2.metadata.Version)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)1 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)1 AdviceFileParser (org.eclipse.equinox.p2.publisher.AdviceFileParser)1 ICapabilityAdvice (org.eclipse.equinox.p2.publisher.actions.ICapabilityAdvice)1 SystemCapability (org.eclipse.tycho.core.ee.shared.SystemCapability)1