Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2018-02-16 12:18:24 +0000
committervincent lorenzo2018-02-27 14:42:36 +0000
commitcff5c9af3804ec54a7565d9f527a0039147589d2 (patch)
tree200e8f19d3c9bf5d6d9d4554e5c82a6203a90bd3 /tests/junit/plugins
parent2254db96aee5eebb8d4df751760216ca06c87f11 (diff)
downloadorg.eclipse.papyrus-cff5c9af3804ec54a7565d9f527a0039147589d2.tar.gz
org.eclipse.papyrus-cff5c9af3804ec54a7565d9f527a0039147589d2.tar.xz
org.eclipse.papyrus-cff5c9af3804ec54a7565d9f527a0039147589d2.zip
Bug 531270: [EMF][Expressions]Papyrus must provide a common way to save and load all Papyrus EMF models with the same options
Change-Id: I49305997e6e80c4ef7e3fb32bb364a2d20d1dd0c Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'tests/junit/plugins')
-rw-r--r--tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/META-INF/MANIFEST.MF2
-rw-r--r--tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/OSGI-INF/l10n/bundle.properties3
-rw-r--r--tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/pom.xml2
-rwxr-xr-x[-rw-r--r--]tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/bundles/tests/BundlesTests.java87
-rwxr-xr-xtests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescription.java364
-rwxr-xr-xtests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescriptionRegistry.java79
6 files changed, 528 insertions, 9 deletions
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/META-INF/MANIFEST.MF
index 45c63ec3ab4..6eb39e52f5e 100644
--- a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/META-INF/MANIFEST.MF
@@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)",
Export-Package: org.eclipse.papyrus.bundles.tests
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.3.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.bundles.tests.Activator
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/OSGI-INF/l10n/bundle.properties b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/OSGI-INF/l10n/bundle.properties
index 82564655b18..ab1126caaed 100644
--- a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/OSGI-INF/l10n/bundle.properties
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/OSGI-INF/l10n/bundle.properties
@@ -1,3 +1,4 @@
#Properties file for org.eclipse.papyrus.bundles.tests
Bundle-Vendor = Eclipse Modeling Project
-Bundle-Name = Papyrus Bundles Tests \ No newline at end of file
+Bundle-Name = Papyrus Bundles Tests
+pluginDescription = This plugin provides some Tests on the Bundle \ No newline at end of file
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/pom.xml b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/pom.xml
index 9fbbd9b4971..7b01dd022ed 100644
--- a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/pom.xml
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/pom.xml
@@ -10,7 +10,7 @@
</parent>
<groupId>org.eclipse.papyrus.tests</groupId>
<artifactId>org.eclipse.papyrus.bundles.tests</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<build>
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/bundles/tests/BundlesTests.java b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/bundles/tests/BundlesTests.java
index f636d230648..9ac4563248c 100644..100755
--- a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/bundles/tests/BundlesTests.java
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/bundles/tests/BundlesTests.java
@@ -20,11 +20,17 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.internal.bundles.tests.PapyrusBundleDescription;
+import org.eclipse.papyrus.internal.bundles.tests.PapyrusBundleDescriptionRegistry;
import org.eclipse.papyrus.junit.framework.classification.InvalidTest;
import org.eclipse.papyrus.junit.framework.classification.NotImplemented;
import org.eclipse.papyrus.junit.framework.classification.rules.Condition;
@@ -76,7 +82,7 @@ public class BundlesTests extends AbstractPapyrusTest {
@Override
public void describeTo(Description description) {
- description.appendText("Does not contain ");
+ description.appendText("Does not contain "); //$NON-NLS-1$
description.appendText(INCUBATION_KEYWORD);
}
};
@@ -139,9 +145,9 @@ public class BundlesTests extends AbstractPapyrusTest {
@Override
public void describeTo(Description description) {
- description.appendText("Matching regex(");
+ description.appendText("Matching regex("); //$NON-NLS-1$
description.appendValue(regex);
- description.appendText(")");
+ description.appendText(")"); //$NON-NLS-1$
}
};
@@ -379,7 +385,7 @@ public class BundlesTests extends AbstractPapyrusTest {
}
// Pattern pattern = Pattern.compile("(" + partialDependencyName + REGEX_PLUGIN + ")" + REGEX_DEPENDENCY); //$NON-NLS-1$ //$NON-NLS-2$
- Pattern pattern = Pattern.compile("(" + partialDependencyName + REGEX_PLUGIN + ")" + "(" + REGEX_REEXPORT + REGEX_BUNDLE + ")");
+ Pattern pattern = Pattern.compile("(" + partialDependencyName + REGEX_PLUGIN + ")" + "(" + REGEX_REEXPORT + REGEX_BUNDLE + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Matcher matcher = pattern.matcher(value);
final StringBuilder localBuilder = new StringBuilder();
while (matcher.find()) {
@@ -393,7 +399,7 @@ public class BundlesTests extends AbstractPapyrusTest {
}
if (versionString == null) {
if (localBuilder.length() == 0) {
- localBuilder.append(NLS.bind("Incorrect version for {0}, got {1} and not {2} \n", new String[] {pluginName, current.getSymbolicName(), wantedVersion})); //$NON-NLS-1$
+ localBuilder.append(NLS.bind("Incorrect version for {0}, got {1} and not {2} \n", new String[] { pluginName, current.getSymbolicName(), wantedVersion })); //$NON-NLS-1$
}
localBuilder.append(NLS.bind("No Version number for {0}\n", pluginName)); //$NON-NLS-1$
nb++;
@@ -403,7 +409,7 @@ public class BundlesTests extends AbstractPapyrusTest {
if (localBuilder.length() == 0) {
localBuilder.append(NLS.bind("{0} incorrect required bundle-version:\n", current.getSymbolicName())); //$NON-NLS-1$
}
- localBuilder.append(NLS.bind("Bad version for {0}, got {1} and not {2} \n", new String[] {pluginName, versionString, wantedVersion})); //$NON-NLS-1$
+ localBuilder.append(NLS.bind("Bad version for {0}, got {1} and not {2} \n", new String[] { pluginName, versionString, wantedVersion })); //$NON-NLS-1$
nb++;
}
}
@@ -476,4 +482,73 @@ public class BundlesTests extends AbstractPapyrusTest {
// Assert.assertTrue(nbWarning + "warning!" + warningMessage, nbWarning == 0);//$NON-NLS-1$
}
+ /**
+ * This test checks that nobody adds an unexpected dependency on the plugin org.eclipse.papyrus.emf
+ *
+ * @since 1.3
+ */
+ @Test
+ public void checkPapyrusEMFPluginDependency() {
+ final String bundleIDToCheck = "org.eclipse.papyrus.emf"; //$NON-NLS-1$
+ final Map<String, Version> dependencies = new HashMap<>();
+ final Version undefinedVersion = new Version(null);
+ dependencies.put("org.eclipse.ui", undefinedVersion); //$NON-NLS-1$
+ dependencies.put("org.eclipse.core.runtime", undefinedVersion); //$NON-NLS-1$
+ dependencies.put("org.eclipse.emf.ecore", undefinedVersion); //$NON-NLS-1$
+ dependencies.put("org.eclipse.emf.ecore.xmi", undefinedVersion); //$NON-NLS-1$
+
+ strictCheckOfDependenciesList(bundleIDToCheck, dependencies, Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
+
+ }
+
+
+ /**
+ *
+ * This method check all dependencies on the bundle. The version are checked using the method {@link Version#inIncludedIn(Version)}
+ * If there are more or less dependencies in the tested bundle, the test will fails
+ *
+ * @param bundleSymbolicNameToCheck
+ * the name of the bundle to check
+ * @param bundleDependenciesWithVersion
+ * the complete list of the dependencies to have for this bundle
+ * @param reexportedDependencies
+ * the completed list of re-exported dependencies for this bundle
+ * @param greedyDependencies
+ * the complete list of greedy dependencies for this bundle
+ * @param optionalDependencies
+ * the complete list of optional dependencies for this bundle
+ *
+ * @since 1.3
+ */
+ private void strictCheckOfDependenciesList(final String bundleSymbolicNameToCheck, final Map<String, Version> bundleDependenciesWithVersion, final Set<String> reexportedDependencies, final Set<String> greedyDependencies,
+ final Set<String> optionalDependencies) {
+
+ Assert.assertNotNull(bundleSymbolicNameToCheck);
+ Assert.assertNotNull(bundleDependenciesWithVersion);
+ Assert.assertNotNull(reexportedDependencies);
+ Assert.assertNotNull(greedyDependencies);
+ Assert.assertNotNull(optionalDependencies);
+
+ final PapyrusBundleDescription bundleToCheck = PapyrusBundleDescriptionRegistry.INSTANCE.getPapyrusBundleDescription(bundleSymbolicNameToCheck);
+ Assert.assertNotNull(NLS.bind("The bundle {0} has not been found.", bundleSymbolicNameToCheck), bundleToCheck); //$NON-NLS-1$
+
+ final Set<String> expectedDependencies = bundleDependenciesWithVersion.keySet();
+ Assert.assertEquals("The current dependencies are not the expected ones.", expectedDependencies, PapyrusBundleDescription.asSymbolicNameSet(bundleToCheck.getDependencies())); //$NON-NLS-1$
+
+ Assert.assertEquals("The current reexported dependencies are not the expected ones.", reexportedDependencies, PapyrusBundleDescription.asSymbolicNameSet(bundleToCheck.getReexportedDependencies())); //$NON-NLS-1$
+
+ Assert.assertEquals("The current greedy dependencies are not the expected ones.", greedyDependencies, PapyrusBundleDescription.asSymbolicNameSet(bundleToCheck.getGreedyDependencies())); //$NON-NLS-1$
+
+ Assert.assertEquals("The current optional dependencies are not the expected ones.", optionalDependencies, PapyrusBundleDescription.asSymbolicNameSet(bundleToCheck.getOptionalDependencies())); //$NON-NLS-1$
+
+
+ // we check the dependency range
+ for (final Entry<String, Version> current : bundleDependenciesWithVersion.entrySet()) {
+ Assert.assertTrue(NLS.bind("The dependency {0} is not registered with compatible version range", current.getKey()), bundleToCheck.getRegisteredDependencyVersion(current.getKey()).inIncludedIn(current.getValue())); //$NON-NLS-1$
+ }
+
+ }
+
+
+
}
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescription.java b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescription.java
new file mode 100755
index 00000000000..4644c0196fa
--- /dev/null
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescription.java
@@ -0,0 +1,364 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.internal.bundles.tests;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.bundles.tests.BundlesTests.Version;
+import org.osgi.framework.Bundle;
+
+/**
+ * This class allows to parse the headers values of a bundle
+ *
+ * @since 1.3
+ */
+public class PapyrusBundleDescription {
+
+ /**
+ * the string required-bundle
+ */
+ private static final String REQUIRE_BUNDLE = "Require-Bundle"; //$NON-NLS-1$
+
+ /**
+ * the string bundle version
+ */
+ private static final String BUNDLE_VERSION = "bundle-version=";//$NON-NLS-1$
+
+ /**
+ * the string visibility reexport
+ */
+ private static final String VISIBILITY_REEXPORT = "visibility:=reexport";//$NON-NLS-1$
+
+ /**
+ * the string resolution optional
+ */
+ private static final String RESOLUTION_OPTIONAL = "resolution:=optional";//$NON-NLS-1$
+
+ /**
+ * the string installation greedy
+ */
+ private static final String X_INSTALLATION_GREEDY = "x-installation:=greedy";//$NON-NLS-1$
+
+
+ /**
+ * starting regex group string
+ */
+ private static final String REGEX_START_GROUP = "(";//$NON-NLS-1$
+
+ /**
+ * ending regex group string
+ */
+ private static final String REGEX_END_GROUP = ")";//$NON-NLS-1$
+
+ /**
+ * the regex string for optional char/group
+ */
+ private static final String REGEX_OPTIONAL = "?";//$NON-NLS-1$
+
+ /**
+ * the separator used between properties of the require bundle field
+ */
+ private static final String PROPERTY_SEPARATOR = ";";//$NON-NLS-1$
+
+ /**
+ * the regex group used to get a dependency name
+ */
+ private static final String BUNDLE_NAME_REGEX_GROUP_1 = REGEX_START_GROUP + "[a-zA-Z0-9_\\.]*" + REGEX_END_GROUP; //$NON-NLS-1$ // this regex allows to match the name of the plugin
+
+ /**
+ * the regex group used to get the dependency version range
+ */
+ private static final String BUNDLE_VERSION_REGEX_GROUP_2 = REGEX_START_GROUP + PROPERTY_SEPARATOR + BUNDLE_VERSION + "\"[\\[\\(\\d\\.\\]\\),]*\"" + REGEX_END_GROUP; //$NON-NLS-1$
+
+ /**
+ * the regex group used to get the optional value of a dependency
+ */
+ private static final String BUNDLE_OPTIONAL_REGEX_GROUP_3 = REGEX_START_GROUP + PROPERTY_SEPARATOR + RESOLUTION_OPTIONAL + REGEX_END_GROUP;
+
+ /**
+ * the regrex group used to get the reexport value of a dependency
+ */
+ private static final String BUNDLE_REEXPORT_REGEX_GROUP_4 = REGEX_START_GROUP + PROPERTY_SEPARATOR + VISIBILITY_REEXPORT + REGEX_END_GROUP;
+
+ /**
+ * the regex group used to get the greedy value of a dependency
+ */
+ private static final String BUNDLE_GREEDY_GROUP_5 = REGEX_START_GROUP + PROPERTY_SEPARATOR + X_INSTALLATION_GREEDY + REGEX_END_GROUP;
+
+
+ /**
+ * group matching on "," for next bundle, ";" for next property of the current bundle, and "nothing" for the end of the bundle list
+ */
+ private static final String DEPENDENCY_SEPARATOR_REGEX_GROUP = REGEX_START_GROUP + "," + REGEX_END_GROUP; //$NON-NLS-1$
+
+ /**
+ * the regex used to parse the field {@link #REQUIRE_BUNDLE} in a manifest
+ */
+ private static final Pattern PATTERN = Pattern.compile(
+ // the first group is the plugin name
+ BUNDLE_NAME_REGEX_GROUP_1
+ // the second group is the version, optional
+ + BUNDLE_VERSION_REGEX_GROUP_2 + REGEX_OPTIONAL
+ // the third group is the optional information for bundle, optional
+ + BUNDLE_OPTIONAL_REGEX_GROUP_3 + REGEX_OPTIONAL
+ // the fourth group is the reexport, optional
+ + BUNDLE_REEXPORT_REGEX_GROUP_4 + REGEX_OPTIONAL
+ // the fifth group is the greedy value, optional
+ + BUNDLE_GREEDY_GROUP_5 + REGEX_OPTIONAL
+ // the end of the description of a bundle
+ + DEPENDENCY_SEPARATOR_REGEX_GROUP + "?");//$NON-NLS-1$ not here for the last dependency
+
+
+ /**
+ * the represented bundle
+ */
+ private Bundle bundle;
+
+ /**
+ * the list of the dependencies, with there version
+ */
+ private Map<PapyrusBundleDescription, Version> dependencies;
+
+ /**
+ * the list of the reexported dependencies
+ */
+ private Set<PapyrusBundleDescription> reexportedDependencies;
+
+ /**
+ * the list of the optional dependencies
+ */
+ private Set<PapyrusBundleDescription> optionalDependencies;
+
+ /**
+ * the list of the greedy dependencies
+ */
+ private Set<PapyrusBundleDescription> greedyDependencies;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param bundleName
+ * the name of the bundle to read
+ */
+ public PapyrusBundleDescription(final String bundleName) {
+ this(Platform.getBundle(bundleName));
+
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param bundle
+ * the bundle to read
+ */
+ private PapyrusBundleDescription(final Bundle bundle) {
+ Assert.isNotNull(bundle);
+ this.bundle = bundle;
+ }
+
+ /**
+ *
+ * @return
+ * the collection of the dependencies for the current bundle
+ */
+ public Collection<PapyrusBundleDescription> getDependencies() {
+ if (null == this.dependencies) {
+ initDependenciesFields();
+ }
+ return new HashSet<>(this.dependencies.keySet());
+ }
+
+ /**
+ *
+ * @return
+ * the collection of the reexported dependencies for the current bundle
+ */
+ public Collection<PapyrusBundleDescription> getReexportedDependencies() {
+ if (null == this.reexportedDependencies) {
+ initDependenciesFields();
+ }
+ return new HashSet<>(this.reexportedDependencies);
+ }
+
+ /**
+ * @return the collection of the optiona dependencies for the current bundle
+ */
+ public Collection<PapyrusBundleDescription> getOptionalDependencies() {
+ if (null == this.optionalDependencies) {
+ initDependenciesFields();
+ }
+ return new HashSet<>(this.optionalDependencies);
+ }
+
+ /**
+ * @return the collection of the greedy dependencies for the current bundle
+ */
+ public Collection<PapyrusBundleDescription> getGreedyDependencies() {
+ if (null == this.greedyDependencies) {
+ initDependenciesFields();
+ }
+ return new HashSet<>(this.greedyDependencies);
+ }
+
+
+
+ /**
+ * This method init the fields concerning the dependencies of the represented bundle
+ */
+ private void initDependenciesFields() {
+ this.dependencies = new HashMap<>();
+ this.reexportedDependencies = new HashSet<>();
+ this.optionalDependencies = new HashSet<>();
+ this.greedyDependencies = new HashSet<>();
+ final String value = this.bundle.getHeaders().get(REQUIRE_BUNDLE);
+ final Matcher matcher = PATTERN.matcher(value);
+ while (matcher.find()) {
+ final String dependencyNameGroup1 = matcher.group(1);
+ final String versionGroup2 = matcher.group(2);
+ final String optionalGroup3 = matcher.group(3);
+ final String reexportGroup4 = matcher.group(4);
+ final String greedyGroup5 = matcher.group(5);
+
+ if (null != dependencyNameGroup1 && !dependencyNameGroup1.isEmpty()) {
+ final PapyrusBundleDescription newContainer = PapyrusBundleDescriptionRegistry.INSTANCE.getPapyrusBundleDescription(dependencyNameGroup1);
+ if (null != versionGroup2 && !versionGroup2.isEmpty()) {
+ // to be notified if we meet a manifest where the current regex doesn't work
+ Assert.isTrue(versionGroup2.contains(BUNDLE_VERSION), NLS.bind("Please, fill a bug, the regex doesn't work for {0}.", this.bundle.getSymbolicName())); //$NON-NLS-1$
+ String version = versionGroup2.replaceFirst(PROPERTY_SEPARATOR + BUNDLE_VERSION + "\"", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ version = version.substring(0, version.length() - 1);
+ dependencies.put(newContainer, new Version(versionGroup2));
+ } else {
+ dependencies.put(newContainer, new Version(null));
+ }
+
+ if (null != optionalGroup3 && !optionalGroup3.isEmpty()) {
+ // to be notified if we meet a manifest where the current regex doesn't work
+ Assert.isTrue(optionalGroup3.contains(RESOLUTION_OPTIONAL), NLS.bind("Please, fill a bug, the regex doesn't work for {0}.", this.bundle.getSymbolicName())); //$NON-NLS-1$
+ this.optionalDependencies.add(newContainer);
+ }
+
+ if (null != reexportGroup4 && !reexportGroup4.isEmpty()) {
+ // to be notified if we meet a manifest where the current regex doesn't work
+ Assert.isTrue(reexportGroup4.contains(VISIBILITY_REEXPORT), NLS.bind("Please, fill a bug, the regex doesn't work for {0}.", this.bundle.getSymbolicName())); //$NON-NLS-1$
+ this.reexportedDependencies.add(newContainer);
+ }
+
+
+ if (null != greedyGroup5 && !greedyGroup5.isEmpty()) {
+ // to be notified if we meet a manifest where the current regex doesn't work
+ Assert.isTrue(greedyGroup5.contains(X_INSTALLATION_GREEDY), NLS.bind("Please, fill a bug, the regex doesn't work for {0}.", this.bundle.getSymbolicName())); //$NON-NLS-1$
+ this.greedyDependencies.add(newContainer);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param description
+ * a papyrus bundle description which should declared as dependency of the represented plugin
+ * @return
+ * the expected version range for this dependency, or <code>null</code> if the {@link PapyrusBundleDescription} is not a dependency of the current bundle
+ */
+ public Version getRegisteredDependencyVersion(final PapyrusBundleDescription aDependency) {
+ Assert.isNotNull(aDependency);
+ if (!this.dependencies.containsKey(aDependency)) {
+ return null;
+ }
+ return this.dependencies.get(aDependency);
+ }
+
+ /**
+ *
+ * @param dependencyName
+ * the name of an expected dependency
+ * @return
+ * the expected version range for this dependency, or <code>null</code> if the {@link PapyrusBundleDescription} is not a dependency of the current bundle
+ */
+ public Version getRegisteredDependencyVersion(final String dependencyName) {
+ final PapyrusBundleDescription currentDesc = PapyrusBundleDescriptionRegistry.INSTANCE.getPapyrusBundleDescription(dependencyName);
+ if (null != currentDesc) {
+ return getRegisteredDependencyVersion(currentDesc);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @return
+ * the name of the represented bundle
+ */
+ public final String getBundleSymbolicName() {
+ return this.bundle.getSymbolicName();
+ }
+
+ /**
+ *
+ * @param coll
+ * a collection of {@link PapyrusBundleDescription}
+ * @return
+ * a set of string representing the {@link PapyrusBundleDescription} with their symbolic name
+ */
+ public static final Set<String> asSymbolicNameSet(final Collection<PapyrusBundleDescription> coll) {
+ final Set<String> values = new HashSet<String>();
+ for (PapyrusBundleDescription curr : coll) {
+ values.add(curr.getBundleSymbolicName());
+ }
+ return values;
+ }
+
+ /**
+ *
+ * @param dependencyName
+ * the name of a dependency
+ * @return
+ * <code>true</code> if the current bundle has a dependency on wanted bundle identified by its name
+ */
+ public boolean hasDependencyOn(final String dependencyName) {
+ return hasDependencyOn(PapyrusBundleDescriptionRegistry.INSTANCE.getPapyrusBundleDescription(dependencyName));
+ }
+
+ /**
+ *
+ * @param aPossibleDependency
+ * a possible dependency
+ * @return
+ * <code>true</code> if the current bundle registers the argument as a dependency
+ */
+ public boolean hasDependencyOn(final PapyrusBundleDescription aPossibleDependency) {
+ return this.dependencies.containsKey(aPossibleDependency);
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ *
+ * @return
+ */
+ @Override
+ public String toString() {
+ return "Represented bundle: " + this.bundle.getSymbolicName(); //$NON-NLS-1$
+ }
+
+}
diff --git a/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescriptionRegistry.java b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescriptionRegistry.java
new file mode 100755
index 00000000000..c4ac11eb3c5
--- /dev/null
+++ b/tests/junit/plugins/developer/org.eclipse.papyrus.bundles.tests/src/org/eclipse/papyrus/internal/bundles/tests/PapyrusBundleDescriptionRegistry.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.internal.bundles.tests;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Vincent LORENZO
+ * @since 1.3
+ */
+public final class PapyrusBundleDescriptionRegistry {
+
+ /**
+ * a cache to avoid to load and parse several time the same bundle
+ */
+ private final Map<String, PapyrusBundleDescription> loadedBundlesCache;
+
+ /**
+ * the singleton of this class
+ */
+ public static final PapyrusBundleDescriptionRegistry INSTANCE = new PapyrusBundleDescriptionRegistry();
+
+ /**
+ *
+ * @param bundleName
+ * the name of a bundle
+ * @return
+ * the {@link PapyrusBundleDescription} wrapping the {@link Bundle}, if exists, or <code>null</code>
+ */
+ public final PapyrusBundleDescription getPapyrusBundleDescription(final String bundleName) {
+ if (null != bundleName) {
+ final Bundle bundle = Platform.getBundle(bundleName);
+ if (null != bundle) {
+ // ok the bundle exists
+ if (null == loadedBundlesCache.get(bundleName)) {
+ loadedBundlesCache.put(bundleName, new PapyrusBundleDescription(bundleName));
+ }
+ return loadedBundlesCache.get(bundleName);
+
+ }
+ }
+ return null;
+ }
+
+ /**
+ * this method clear the registry
+ */
+ public final void clearRegistry() {
+ this.loadedBundlesCache.clear();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ private PapyrusBundleDescriptionRegistry() {
+ // to prevent instanciation
+ loadedBundlesCache = new HashMap<String, PapyrusBundleDescription>();
+ }
+
+
+
+}

Back to the top