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;
}
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);
}
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;
}
});
}
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;
}
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);
}
Aggregations