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