Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2020-12-15 18:43:50 +0000
committerChristian W. Damus2020-12-15 18:43:50 +0000
commit6aa4567154cf0e3a27d3d865c8a1f86df26f3bc8 (patch)
tree99e7fe5113d69e97f380b77dda7e0ce081d6070b
parent05cd33fc7684849d41f558752045dabf562b5019 (diff)
downloadorg.eclipse.papyrus-6aa4567154cf0e3a27d3d865c8a1f86df26f3bc8.tar.gz
org.eclipse.papyrus-6aa4567154cf0e3a27d3d865c8a1f86df26f3bc8.tar.xz
org.eclipse.papyrus-6aa4567154cf0e3a27d3d865c8a1f86df26f3bc8.zip
Bug 569357: [Toolsmiths] ElementTypes: Model and Plug-in Validation
- improved handling of HREFs that don't imply bundle names Change-Id: I7a953f7e3bc337ee4e69b60032bfdbc1314910ee Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/ModelDependenciesChecker.java24
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug569357/BookStore-weirdHREF.profile.uml75
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/build.properties3
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/resources/BookStore.profile.uml6
-rw-r--r--tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java71
5 files changed, 160 insertions, 19 deletions
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/ModelDependenciesChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/ModelDependenciesChecker.java
index dc5e20fb888..b6c2289c6c1 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/ModelDependenciesChecker.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/checkers/ModelDependenciesChecker.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.function.Function;
@@ -53,6 +54,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.service.resolver.BundleSpecification;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.toolsmiths.validation.common.Activator;
import org.eclipse.papyrus.toolsmiths.validation.common.utils.ProjectManagementService;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
@@ -180,7 +182,7 @@ public class ModelDependenciesChecker extends AbstractPluginChecker {
* This allows to check that the plug-in has the correct dependencies depending to the external cross-deocument references.
*/
@Override
- public void check(DiagnosticChain diagnostics, final IProgressMonitor monitor) {
+ public void check(final DiagnosticChain diagnostics, final IProgressMonitor monitor) {
String resourceName = getModelFile() == null ? getProject().getName() : getModelFile().getName();
SubMonitor subMonitor = SubMonitor.convert(monitor, "Validate dependencies for '" + resourceName + "'.", 3);
@@ -191,8 +193,8 @@ public class ModelDependenciesChecker extends AbstractPluginChecker {
// Calculate plug-ins names from URI. Initial set is the "additional requirements" from the client
final Collection<String> requiredPlugins = new HashSet<>(additionalRequirements);
- externalReferencesPaths.stream().map(this::getPluginNameFromURI).forEach(requiredPlugins::add);
- additionalDependencyFunctions.stream().map(func -> func.apply(resource)).forEach(requiredPlugins::addAll);
+ externalReferencesPaths.stream().map(uri -> getPluginNameFromURI(uri, diagnostics)).filter(Objects::nonNull).forEach(requiredPlugins::add);
+ additionalDependencyFunctions.stream().map(func -> func.apply(resource)).filter(Objects::nonNull).forEach(requiredPlugins::addAll);
// For each external reference, get its plug-in name and search its dependency in the plug-in
final List<BundleSpecification> dependencies = ProjectManagementService.getPluginDependencies(getProject());
@@ -388,7 +390,7 @@ public class ModelDependenciesChecker extends AbstractPluginChecker {
private boolean isResolved(URI href, Resource context) {
// We already tried to load it in scanning the cross-reference graph
Resource resolved = context.getResourceSet().getResource(href, false);
- return resolved != null && resolved.isLoaded();
+ return resolved != null && resolved.isLoaded() && !resolved.getContents().isEmpty();
}
/**
@@ -464,9 +466,12 @@ public class ModelDependenciesChecker extends AbstractPluginChecker {
*
* @param uri
* The initial URI.
- * @return The plug-in name from URI or <code>null</code> if any problem occurred.
+ * @param diagnostics
+ * Sink for problems to report in the determination of bundle names
+ * @return The plug-in name from URI or <code>null</code> if any problem occurred,
+ * which then would have been reported to the {@code diagnostics}.
*/
- private String getPluginNameFromURI(final URI uri) {
+ private String getPluginNameFromURI(final URI uri, final DiagnosticChain diagnostics) {
String pluginName = null;
if ((uri.isPlatformPlugin() || uri.isPlatformResource()) && uri.segmentCount() > 1) {
@@ -490,11 +495,8 @@ public class ModelDependenciesChecker extends AbstractPluginChecker {
pluginName = bundle.getSymbolicName();
}
} else {
- // Best guess. Take the correct segment (without authority)
- final int takenSegment = uri.hasAuthority() ? 0 : 1;
- if (uri.segmentCount() > takenSegment) {
- pluginName = uri.segment(takenSegment);
- }
+ // This doesn't look like any URI that resolves into a bundle
+ diagnostics.add(createDiagnostic(Diagnostic.WARNING, 0, NLS.bind("Suspicious URI: cannot infer bundle name in ''{0}''", uri)));
}
}
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug569357/BookStore-weirdHREF.profile.uml b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug569357/BookStore-weirdHREF.profile.uml
new file mode 100644
index 00000000000..2c116fb7a8e
--- /dev/null
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/bug569357/BookStore-weirdHREF.profile.uml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Profile xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Km1S4D7mEeuL4ce7dqV7ZQ" name="BookStore" URI="http://www.eclipse.org/Papyrus/2020/test/toolsmiths/validation/common/BookStore" metaclassReference="_O6NMkD7mEeuL4ce7dqV7ZQ _O6NzoD7mEeuL4ce7dqV7ZQ">
+ <eAnnotations xmi:id="_oI-iID7mEeuL4ce7dqV7ZQ" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <eAnnotations xmi:id="_wHX8ED7mEeuL4ce7dqV7ZQ" source="PapyrusVersion">
+ <details xmi:id="_wHX8ET7mEeuL4ce7dqV7ZQ" key="Version" value="0.0.0"/>
+ <details xmi:id="_wHX8Ej7mEeuL4ce7dqV7ZQ" key="Comment" value="&lt;undefined>"/>
+ <details xmi:id="_wHX8Ez7mEeuL4ce7dqV7ZQ" key="Copyright" value=""/>
+ <details xmi:id="_wHX8FD7mEeuL4ce7dqV7ZQ" key="Date" value=""/>
+ <details xmi:id="_wHX8FT7mEeuL4ce7dqV7ZQ" key="Author" value="&lt;undefined>"/>
+ </eAnnotations>
+ <contents xmi:type="ecore:EPackage" xmi:id="_oI_JMD7mEeuL4ce7dqV7ZQ" name="BookStore" nsURI="http://www.eclipse.org/Papyrus/2020/test/toolsmiths/validation/common/BookStore" nsPrefix="BookStore">
+ <eAnnotations xmi:id="_oJAXUD7mEeuL4ce7dqV7ZQ" source="PapyrusVersion">
+ <details xmi:id="_oJAXUT7mEeuL4ce7dqV7ZQ" key="Version" value="0.0.1"/>
+ <details xmi:id="_oJAXUj7mEeuL4ce7dqV7ZQ" key="Comment" value=""/>
+ <details xmi:id="_oJAXUz7mEeuL4ce7dqV7ZQ" key="Copyright" value="Copyright (c) 2020 Christian W. Damus, CEA LIST, and others.&#xA;&#xA;All rights reserved. This program and the accompanying materials&#xA;are made available under the terms of the Eclipse Public License 2.0&#xA;which accompanies this distribution, and is available at&#xA;https://www.eclipse.org/legal/epl-2.0/&#xA;&#xA;SPDX-License-Identifier: EPL-2.0&#xA;&#xA;Contributors:&#xA; Christian W. Damus - Initial API and implementation&#xA;"/>
+ <details xmi:id="_oJAXVD7mEeuL4ce7dqV7ZQ" key="Date" value="2020-12-15"/>
+ <details xmi:id="_oJAXVT7mEeuL4ce7dqV7ZQ" key="Author" value="Christian W. Damus"/>
+ </eAnnotations>
+ <eClassifiers xmi:type="ecore:EClass" xmi:id="_oI_JMT7mEeuL4ce7dqV7ZQ" name="BookStore">
+ <eAnnotations xmi:id="_oI_JMj7mEeuL4ce7dqV7ZQ" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_Qt27gD7mEeuL4ce7dqV7ZQ"/>
+ <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_oI_JMz7mEeuL4ce7dqV7ZQ" name="base_Package" ordered="false">
+ <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Package"/>
+ </eStructuralFeatures>
+ <eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_OMyuID8AEeuYB657Az5Z-A" name="corporationKind" lowerBound="1">
+ <eType xmi:type="ecore:EEnum" href="http://schema.eclipse.org/BookStore#/ecore/CorporationKind"/>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xmi:type="ecore:EClass" xmi:id="_oI_JNT7mEeuL4ce7dqV7ZQ" name="Book">
+ <eAnnotations xmi:id="_oI_JNj7mEeuL4ce7dqV7ZQ" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_ShKsMD7mEeuL4ce7dqV7ZQ"/>
+ <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_oI_JNz7mEeuL4ce7dqV7ZQ" name="base_Class" ordered="false">
+ <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Class"/>
+ </eStructuralFeatures>
+ <eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_oI_JOT7mEeuL4ce7dqV7ZQ" name="isbn" ordered="false" lowerBound="1">
+ <eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/uml2/5.0.0/Types#//String"/>
+ </eStructuralFeatures>
+ </eClassifiers>
+ </contents>
+ </eAnnotations>
+ <elementImport xmi:id="_O6NMkD7mEeuL4ce7dqV7ZQ" alias="Package">
+ <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Package"/>
+ </elementImport>
+ <elementImport xmi:id="_O6NzoD7mEeuL4ce7dqV7ZQ" alias="Class">
+ <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
+ </elementImport>
+ <packageImport xmi:id="_Kuh2UD7mEeuL4ce7dqV7ZQ">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
+ </packageImport>
+ <packageImport xmi:id="_KujrgD7mEeuL4ce7dqV7ZQ">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML_METAMODELS/UML.metamodel.uml#_0"/>
+ </packageImport>
+ <packagedElement xmi:type="uml:Stereotype" xmi:id="_Qt27gD7mEeuL4ce7dqV7ZQ" name="BookStore">
+ <ownedAttribute xmi:id="_Tel9wD7mEeuL4ce7dqV7ZQ" name="base_Package" association="_TejhgD7mEeuL4ce7dqV7ZQ">
+ <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Package"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_Tel9wT7mEeuL4ce7dqV7ZQ"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_gvxWkD7_EeuYB657Az5Z-A" name="corporationKind">
+ <type xmi:type="uml:Enumeration" href="http://schema.eclipse.org/BookStore#/uml/CorporationKind"/>
+ </ownedAttribute>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Stereotype" xmi:id="_ShKsMD7mEeuL4ce7dqV7ZQ" name="Book">
+ <ownedAttribute xmi:id="_VDoB4D7mEeuL4ce7dqV7ZQ" name="base_Class" association="_VDna0D7mEeuL4ce7dqV7ZQ">
+ <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_VDoB4T7mEeuL4ce7dqV7ZQ"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_X2i1cD7mEeuL4ce7dqV7ZQ" name="isbn">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
+ </ownedAttribute>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Extension" xmi:id="_TejhgD7mEeuL4ce7dqV7ZQ" name="E_BookStore_Package" memberEnd="_TelWsD7mEeuL4ce7dqV7ZQ _Tel9wD7mEeuL4ce7dqV7ZQ">
+ <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_TelWsD7mEeuL4ce7dqV7ZQ" name="extension_BookStore" type="_Qt27gD7mEeuL4ce7dqV7ZQ" aggregation="composite" association="_TejhgD7mEeuL4ce7dqV7ZQ"/>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Extension" xmi:id="_VDna0D7mEeuL4ce7dqV7ZQ" name="E_Book_Class" memberEnd="_VDna0T7mEeuL4ce7dqV7ZQ _VDoB4D7mEeuL4ce7dqV7ZQ">
+ <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_VDna0T7mEeuL4ce7dqV7ZQ" name="extension_Book" type="_ShKsMD7mEeuL4ce7dqV7ZQ" aggregation="composite" association="_VDna0D7mEeuL4ce7dqV7ZQ"/>
+ </packagedElement>
+</uml:Profile>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/build.properties b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/build.properties
index c6a3d75ed7f..211857fb948 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/build.properties
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/build.properties
@@ -13,7 +13,8 @@
bin.includes = .,\
META-INF/,\
plugin.xml,\
- plugin.properties
+ plugin.properties.\
+ resources/
jars.compile.order = .
source.. = src
output.. = bin/
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/resources/BookStore.profile.uml b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/resources/BookStore.profile.uml
index c523554689d..6f73275958a 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/resources/BookStore.profile.uml
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/resources/org.eclipse.papyrus.toolsmiths.validation.common.example/resources/BookStore.profile.uml
@@ -12,7 +12,7 @@
<eAnnotations xmi:id="_oJAXUD7mEeuL4ce7dqV7ZQ" source="PapyrusVersion">
<details xmi:id="_oJAXUT7mEeuL4ce7dqV7ZQ" key="Version" value="0.0.1"/>
<details xmi:id="_oJAXUj7mEeuL4ce7dqV7ZQ" key="Comment" value=""/>
- <details xmi:id="_oJAXUz7mEeuL4ce7dqV7ZQ" key="Copyright" value="Copyright (c) 202 Christian W. Damus, CEA LIST, and others.&#xA;&#xA;All rights reserved. This program and the accompanying materials&#xA;are made available under the terms of the Eclipse Public License 2.0&#xA;which accompanies this distribution, and is available at&#xA;https://www.eclipse.org/legal/epl-2.0/&#xA;&#xA;SPDX-License-Identifier: EPL-2.0&#xA;&#xA;Contributors:&#xA; Christian W. Damus - Initial API and implementation&#xA;"/>
+ <details xmi:id="_oJAXUz7mEeuL4ce7dqV7ZQ" key="Copyright" value="Copyright (c) 2020 Christian W. Damus, CEA LIST, and others.&#xA;&#xA;All rights reserved. This program and the accompanying materials&#xA;are made available under the terms of the Eclipse Public License 2.0&#xA;which accompanies this distribution, and is available at&#xA;https://www.eclipse.org/legal/epl-2.0/&#xA;&#xA;SPDX-License-Identifier: EPL-2.0&#xA;&#xA;Contributors:&#xA; Christian W. Damus - Initial API and implementation&#xA;"/>
<details xmi:id="_oJAXVD7mEeuL4ce7dqV7ZQ" key="Date" value="2020-12-15"/>
<details xmi:id="_oJAXVT7mEeuL4ce7dqV7ZQ" key="Author" value="Christian W. Damus"/>
</eAnnotations>
@@ -60,10 +60,10 @@
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
</packagedElement>
- <packagedElement xmi:type="uml:Extension" xmi:id="_TejhgD7mEeuL4ce7dqV7ZQ" name="E_BookStore_Package7" memberEnd="_TelWsD7mEeuL4ce7dqV7ZQ _Tel9wD7mEeuL4ce7dqV7ZQ">
+ <packagedElement xmi:type="uml:Extension" xmi:id="_TejhgD7mEeuL4ce7dqV7ZQ" name="E_BookStore_Package" memberEnd="_TelWsD7mEeuL4ce7dqV7ZQ _Tel9wD7mEeuL4ce7dqV7ZQ">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_TelWsD7mEeuL4ce7dqV7ZQ" name="extension_BookStore" type="_Qt27gD7mEeuL4ce7dqV7ZQ" aggregation="composite" association="_TejhgD7mEeuL4ce7dqV7ZQ"/>
</packagedElement>
- <packagedElement xmi:type="uml:Extension" xmi:id="_VDna0D7mEeuL4ce7dqV7ZQ" name="E_Book_Class8" memberEnd="_VDna0T7mEeuL4ce7dqV7ZQ _VDoB4D7mEeuL4ce7dqV7ZQ">
+ <packagedElement xmi:type="uml:Extension" xmi:id="_VDna0D7mEeuL4ce7dqV7ZQ" name="E_Book_Class" memberEnd="_VDna0T7mEeuL4ce7dqV7ZQ _VDoB4D7mEeuL4ce7dqV7ZQ">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_VDna0T7mEeuL4ce7dqV7ZQ" name="extension_Book" type="_ShKsMD7mEeuL4ce7dqV7ZQ" aggregation="composite" association="_VDna0D7mEeuL4ce7dqV7ZQ"/>
</packagedElement>
</uml:Profile>
diff --git a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java
index 4f4283ddacc..4dabb495c0b 100644
--- a/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java
+++ b/tests/junit/plugins/toolsmiths/org.eclipse.papyrus.toolsmiths.validation.common.tests/src/org/eclipse/papyrus/toolsmiths/validation/common/tests/ModelDependenciesCheckerTest.java
@@ -15,17 +15,32 @@
package org.eclipse.papyrus.toolsmiths.validation.common.tests;
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.isEmpty;
import static org.eclipse.papyrus.junit.matchers.MoreMatchers.regexMatches;
+import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import java.util.List;
+import java.util.function.Consumer;
+
import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
import org.eclipse.papyrus.junit.matchers.MoreMatchers;
import org.eclipse.papyrus.toolsmiths.validation.common.checkers.ModelDependenciesChecker;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.Build;
+import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.OverlayFile;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProject;
import org.eclipse.papyrus.toolsmiths.validation.common.tests.rules.TestProjectFixture;
import org.junit.Rule;
@@ -50,15 +65,63 @@ public class ModelDependenciesCheckerTest {
*/
@Test
public void noSpuriousDependencyProblemsFromDynamicProfileDefinition() {
- Resource profile = project.loadModelResource(BOOKSTORE_PROFILE);
+ List<Diagnostic> diagnostics = checkModel(BOOKSTORE_PROFILE);
+
+ assertThat(diagnostics, not(hasItem(MoreMatchers.diagnosticWithMessage(containsString("must be declared as required plug-in"))))); //$NON-NLS-1$
+ assertThat(diagnostics, not(hasItem(MoreMatchers.diagnosticWithMessage(containsString("Cross-document reference by file URI"))))); //$NON-NLS-1$
+ assertThat(diagnostics, not(hasItem(MoreMatchers.diagnosticWithMessage(regexMatches("The URI .* cannot be resolved"))))); //$NON-NLS-1$
+ }
+
+ /**
+ * Verify the reporting of cross-document URIs (HREFs) with schemes that do
+ * not imply a bundle name, even if the authority looks like one.
+ */
+ @Test
+ @OverlayFile(value = "bug569357/Bookstore-weirdHREF.profile.uml", path = BOOKSTORE_PROFILE)
+ public void unresolvedNonBundleDeployedURI() {
+ List<Diagnostic> diagnostics = checkModel(BOOKSTORE_PROFILE,
+ // Pre-resolve the HREF that doesn't imply bundle deployment
+ rset -> {
+ URI libraryURI = URI.createURI("http://schema.eclipse.org/BookStore"); //$NON-NLS-1$
+ Resource library = Resource.Factory.Registry.INSTANCE.getFactory(libraryURI, EcorePackage.eCONTENT_TYPE).createResource(libraryURI);
+ library.getContents().add(EcoreFactory.eINSTANCE.createEPackage());
+ rset.getResources().add(library);
+ });
+
+ assertThat(diagnostics, both(everyItem(MoreMatchers.diagnosticWithMessage(containsString("Suspicious URI: cannot infer bundle name"))))
+ .and(not(isEmpty())));
+ }
+
+ //
+ // Test framework
+ //
+
+ List<Diagnostic> checkModel(String path) {
+ return checkModel(path, null);
+ }
+
+ List<Diagnostic> checkModel(String path, Consumer<? super ResourceSet> doctorResourceSet) {
+ Resource profile = project.loadModelResource(path);
+ if (doctorResourceSet != null) {
+ Runnable doctorIt = () -> doctorResourceSet.accept(profile.getResourceSet());
+ TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(profile);
+ if (domain == null) {
+ doctorIt.run();
+ } else {
+ try {
+ TransactionHelper.run(domain, doctorIt);
+ } catch (Exception e) {
+ throw new AssertionError("Failed to doctor the resource set in the test.", e);
+ }
+ }
+ }
+
ModelDependenciesChecker checker = new ModelDependenciesChecker(project.getProject(), project.getFile(BOOKSTORE_PROFILE), profile);
BasicDiagnostic diagnostics = new BasicDiagnostic();
checker.check(diagnostics, null);
- assertThat(diagnostics.getChildren(), not(hasItem(MoreMatchers.diagnosticWithMessage(containsString("must be declared as required plug-in"))))); //$NON-NLS-1$
- assertThat(diagnostics.getChildren(), not(hasItem(MoreMatchers.diagnosticWithMessage(containsString("Cross-document reference by file URI"))))); //$NON-NLS-1$
- assertThat(diagnostics.getChildren(), not(hasItem(MoreMatchers.diagnosticWithMessage(regexMatches("The URI .* cannot be resolved"))))); //$NON-NLS-1$
+ return diagnostics.getChildren();
}
}

Back to the top