Search in sources :

Example 11 with Version

use of org.eclipse.equinox.p2.metadata.Version in project tycho by eclipse.

the class TargetPlatformFactoryImpl method getPreliminaryReactorProjectUIs.

private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorProjectUIs(List<ReactorProject> reactorProjects) throws DuplicateReactorIUsException {
    if (reactorProjects == null) {
        return Collections.emptyMap();
    }
    Map<IInstallableUnit, ReactorProjectIdentities> reactorUIs = new HashMap<>();
    Map<IInstallableUnit, Set<File>> duplicateReactorUIs = new HashMap<>();
    for (ReactorProject project : reactorProjects) {
        @SuppressWarnings("unchecked") Set<IInstallableUnit> projectIUs = (Set<IInstallableUnit>) project.getDependencyMetadata();
        if (projectIUs == null)
            continue;
        for (IInstallableUnit iu : projectIUs) {
            ReactorProjectIdentities otherOrigin = reactorUIs.put(iu, project.getIdentities());
            if (otherOrigin != null && !otherOrigin.equals(project.getIdentities())) {
                Set<File> duplicateLocations = duplicateReactorUIs.get(iu);
                if (duplicateLocations == null) {
                    duplicateLocations = new LinkedHashSet<>();
                    duplicateReactorUIs.put(iu, duplicateLocations);
                }
                duplicateLocations.add(otherOrigin.getBasedir());
                duplicateLocations.add(project.getBasedir());
            }
        }
    }
    if (!duplicateReactorUIs.isEmpty()) {
        // TODO 392320 we should only fail if IUs with same id and version but different content are found
        throw new DuplicateReactorIUsException(duplicateReactorUIs);
    }
    return reactorUIs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ReactorProject(org.eclipse.tycho.ReactorProject) ReactorProjectIdentities(org.eclipse.tycho.ReactorProjectIdentities) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Example 12 with Version

use of org.eclipse.equinox.p2.metadata.Version 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;
}
Also used : SystemCapability(org.eclipse.tycho.core.ee.shared.SystemCapability) IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) ArrayList(java.util.ArrayList)

Example 13 with Version

use of org.eclipse.equinox.p2.metadata.Version 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 14 with Version

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

Example 15 with Version

use of org.eclipse.equinox.p2.metadata.Version in project tycho by eclipse.

the class ProductDependenciesAction method getRequiredCapabilities.

@Override
protected Set<IRequirement> getRequiredCapabilities() {
    Set<IRequirement> required = new LinkedHashSet<>();
    if (product.useFeatures()) {
        for (IVersionedId feature : product.getFeatures()) {
            // $NON-NLS-1$
            String id = feature.getId() + FEATURE_GROUP_IU_SUFFIX;
            Version version = feature.getVersion();
            addRequiredCapability(required, id, version, null, false);
        }
    } else {
        for (FeatureEntry plugin : ((ProductFile) product).getProductEntries()) {
            addRequiredCapability(required, plugin.getId(), Version.parseVersion(plugin.getVersion()), null, true);
        }
    }
    if (product.includeLaunchers()) {
        addRequiredCapability(required, "org.eclipse.equinox.executable.feature.group", null, null, false);
    }
    return required;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) LinkedHashSet(java.util.LinkedHashSet) FeatureEntry(org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry) ProductFile(org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile) IVersionedId(org.eclipse.equinox.p2.metadata.IVersionedId) Version(org.eclipse.equinox.p2.metadata.Version)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)25 Version (org.eclipse.equinox.p2.metadata.Version)15 Test (org.junit.Test)15 File (java.io.File)12 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)12 ArrayList (java.util.ArrayList)8 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)7 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)7 IStatus (org.eclipse.core.runtime.IStatus)5 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)5 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)5 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2