use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.
the class P2DependencyGeneratorImplTest method rcp_with_p2_inf.
@Test
public void rcp_with_p2_inf() throws Exception {
generateDependencies("rcp-p2-inf", PackagingType.TYPE_ECLIPSE_APPLICATION);
assertEquals(2, units.size());
IInstallableUnit unit = getUnitWithId("org.eclipse.tycho.p2.impl.test.rcp-p2-inf", units);
assertNotNull(unit);
assertEquals("1.0.0.qualifier", unit.getVersion().toString());
List<IRequirement> requirements = new ArrayList<>(unit.getRequirements());
assertEquals(1, requirements.size());
IRequiredCapability p2InfCapability = getRequiredCapability("required.p2.inf", requirements);
assertNotNull(p2InfCapability);
assertEquals(0, artifacts.size());
assertNotNull(getUnitWithId("iu.p2.inf", units));
}
use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.
the class P2DependencyGeneratorImplTest method bundle_with_p2_inf.
@Test
public void bundle_with_p2_inf() throws Exception {
generateDependencies("bundle-p2-inf", PackagingType.TYPE_ECLIPSE_PLUGIN);
assertEquals(2, units.size());
IInstallableUnit unit = getUnitWithId("org.eclipse.tycho.p2.impl.test.bundle-p2-inf", units);
assertNotNull(unit);
assertEquals("1.0.0.qualifier", unit.getVersion().toString());
List<IRequirement> requirements = new ArrayList<>(unit.getRequirements());
assertEquals(1, requirements.size());
IRequiredCapability requirement = (IRequiredCapability) requirements.get(0);
assertEquals(IInstallableUnit.NAMESPACE_IU_ID, requirement.getNamespace());
assertEquals("required.p2.inf", requirement.getName());
assertNotNull(getUnitWithId("iu.p2.inf", units));
}
use of org.eclipse.equinox.p2.metadata.IRequirement in project tycho by eclipse.
the class InstallableUnitUtil method createIURequirement.
public static IInstallableUnit createIURequirement(String id, String version, String requiredId, String requiredVersionRange) {
InstallableUnitDescription description = createIuDescription(id, version);
final IRequirement requiredCapability = createRequirement(requiredId, requiredVersionRange);
description.addRequirements(Arrays.asList(requiredCapability));
return MetadataFactory.createInstallableUnit(description);
}
use of org.eclipse.equinox.p2.metadata.IRequirement 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.IRequirement 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));
}
}
Aggregations