use of org.eclipse.equinox.p2.publisher.AdviceFileParser 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;
}
});
}
Aggregations