Search in sources :

Example 6 with IRequirement

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));
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 7 with IRequirement

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));
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 8 with IRequirement

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);
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)

Example 9 with IRequirement

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;
        }
    });
}
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 10 with IRequirement

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));
    }
}
Also used : VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Aggregations

IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)31 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)23 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)11 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8 File (java.io.File)7 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)6 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)6 LinkedHashSet (java.util.LinkedHashSet)5 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)5 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)5 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)4 List (java.util.List)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Version (org.eclipse.equinox.p2.metadata.Version)2 FeatureEntry (org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry)2