From 51afff35e2a563f66f7674b6d55120c81d16414b Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Mon, 15 Apr 2019 12:14:57 +0200 Subject: 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 --- .../internal/checkers/ElementTypesFileChecker.java | 86 ++++++++++++++++++++++ .../checkers/ElementTypesPluginChecker.java | 7 +- 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java (limited to 'plugins/toolsmiths') 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 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); -- cgit v1.2.3