Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-04-15 06:14:57 -0400
committerPatrick Tessier2019-04-15 07:31:30 -0400
commit51afff35e2a563f66f7674b6d55120c81d16414b (patch)
treeeea2a430cbb9263bdfddff5913a2f38ed552ca5a /plugins/toolsmiths
parentfad8054cd71d3c3ee5a086a60aed118529678b01 (diff)
downloadorg.eclipse.papyrus-51afff35e2a563f66f7674b6d55120c81d16414b.tar.gz
org.eclipse.papyrus-51afff35e2a563f66f7674b6d55120c81d16414b.tar.xz
org.eclipse.papyrus-51afff35e2a563f66f7674b6d55120c81d16414b.zip
Bug 546406: [Toolsmiths][Validation] Plug-ins to validate element types
plug-in must be implemented - Validate the element types file Change-Id: I95fe00b24d6ba1cf793de506cb785706a7a1ea3d Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/toolsmiths')
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java86
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java7
2 files changed, 91 insertions, 2 deletions
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java
new file mode 100644
index 00000000000..acbc9640afa
--- /dev/null
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.toolsmiths.validation.elementtypes.internal.checkers;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.papyrus.toolsmiths.validation.common.checkers.IPluginChecker;
+import org.eclipse.papyrus.toolsmiths.validation.common.utils.MarkersService;
+import org.eclipse.papyrus.toolsmiths.validation.elementtypes.constants.ElementTypesPluginValidationConstants;
+
+/**
+ * This class allows to check the element types file.
+ */
+public class ElementTypesFileChecker implements IPluginChecker {
+
+ /**
+ * The file defining the element types.
+ */
+ private final IFile elementTypesFile;
+
+ /**
+ * Constructor.
+ *
+ * @param elementTypesFile
+ * The file defining the element types.
+ */
+ public ElementTypesFileChecker(final IFile elementTypesFile) {
+ this.elementTypesFile = elementTypesFile;
+ }
+
+ /**
+ * This allows to validate the element types file.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.toolsmiths.validation.common.checkers.IPluginChecker#check(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void check(final IProgressMonitor monitor) {
+
+ if (null != monitor) {
+ monitor.subTask("Validate element types file '" + elementTypesFile.getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Get the resource and validate it
+ final URI elementTypesFileURI = URI.createPlatformResourceURI(elementTypesFile.getFullPath().toOSString(), true);
+ final Resource resource = new ResourceSetImpl().getResource(elementTypesFileURI, true);
+ final Diagnostic diagnostic = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
+
+ // Create markers if the validation is not OK
+ if (diagnostic.getSeverity() != Diagnostic.OK) {
+ for (final Diagnostic child : diagnostic.getChildren()) {
+ int severity = child.getSeverity() == IStatus.ERROR ? IMarker.SEVERITY_ERROR : child.getSeverity() == IStatus.WARNING ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_INFO;
+ MarkersService.createMarker(
+ elementTypesFile,
+ ElementTypesPluginValidationConstants.ELEMENTTYPES_PLUGIN_VALIDATION_TYPE,
+ child.getMessage(),
+ severity);
+ }
+ }
+
+ if (null != monitor) {
+ monitor.worked(1);
+ }
+ }
+
+}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java
index 94784785160..b932622bd12 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java
@@ -51,7 +51,7 @@ public class ElementTypesPluginChecker {
final Collection<IFile> elementTypesFiles = ProjectManagementService.getFilesFromProject(project, "elementtypesconfigurations", true); //$NON-NLS-1$
monitor.beginTask("Validate Element Types plug-in", 1 + (elementTypesFiles.size() * 3)); // $NON-NLS-1$
- monitor.subTask("Prepare plug-in validation");
+ monitor.subTask("Prepare plug-in validation"); //$NON-NLS-1$
// First of all, delete the existing markers for project
MarkersService.deleteMarkers(project, ElementTypesPluginValidationConstants.ELEMENTTYPES_PLUGIN_VALIDATION_TYPE);
@@ -60,7 +60,10 @@ public class ElementTypesPluginChecker {
// For all element types files in the plug-in
for (final IFile elementTypesFile : elementTypesFiles) {
- // TODO : comming with future gerrits
+
+ // First, check the validation of the element types file
+ pluginValidationService.addPluginChecker(new ElementTypesFileChecker(elementTypesFile));
+
}
monitor.worked(1);

Back to the top