Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-04-15 10:20:03 -0400
committerPatrick Tessier2019-04-16 11:10:49 -0400
commit348f441043bf9d53ed6c2b31869bb1f0dfc9ce78 (patch)
tree2251ff1c5e47a4316347b17d018822368918bb5a
parente207da1a4cf93b8a033c3e003439f474222f2385 (diff)
downloadorg.eclipse.papyrus-348f441043bf9d53ed6c2b31869bb1f0dfc9ce78.tar.gz
org.eclipse.papyrus-348f441043bf9d53ed6c2b31869bb1f0dfc9ce78.tar.xz
org.eclipse.papyrus-348f441043bf9d53ed6c2b31869bb1f0dfc9ce78.zip
Bug 546406: [Toolsmiths][Validation] Plug-ins to validate element types
plug-in must be implemented - Validate the needed basic required plug-ins Change-Id: Iea321578924e838abd405b00322abc3bdd1f7ba7 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesDependenciesChecker.java109
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java14
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesPluginChecker.java14
3 files changed, 130 insertions, 7 deletions
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesDependenciesChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesDependenciesChecker.java
new file mode 100644
index 00000000000..a5ecb8e217f
--- /dev/null
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesDependenciesChecker.java
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * 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 java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osgi.service.resolver.BundleSpecification;
+import org.eclipse.papyrus.toolsmiths.validation.common.checkers.IPluginChecker;
+import org.eclipse.papyrus.toolsmiths.validation.common.utils.MarkersService;
+import org.eclipse.papyrus.toolsmiths.validation.common.utils.ProjectManagementService;
+import org.eclipse.papyrus.toolsmiths.validation.elementtypes.constants.ElementTypesPluginValidationConstants;
+
+/**
+ * This class allows to check that the plug-in has the correct dependencies depending to the external profile references.
+ */
+public class ElementTypesDependenciesChecker implements IPluginChecker {
+
+ /**
+ * The needed required plug-ins for the element types management.
+ */
+ @SuppressWarnings("serial")
+ private final Collection<String> NEEDED_REQUIRED_PLUGINS = new HashSet<String>() {
+ {
+ add("org.eclipse.papyrus.infra.types.core"); //$NON-NLS-1$
+ add("org.eclipse.gmf.runtime.emf.type.core"); //$NON-NLS-1$
+ add("org.eclipse.papyrus.uml.service.types"); //$NON-NLS-1$
+ add("org.eclipse.papyrus.infra.services.edit"); //$NON-NLS-1$
+ add("org.eclipse.papyrus.infra.types"); //$NON-NLS-1$
+ add("org.eclipse.papyrus.uml.tools.utils"); //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * The current project resource.
+ */
+ private final IProject project;
+
+ /**
+ * Constructor.
+ *
+ * @param project
+ * The current project resource.
+ */
+ public ElementTypesDependenciesChecker(final IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * This allows to check that the plug-in has the correct dependencies depending to the external profile references.
+ * {@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 dependencies for element types."); //$NON-NLS-1$
+ }
+
+ // Manage a list of required plug-ins to check
+ final Collection<String> requiredPlugins = new HashSet<>();
+ NEEDED_REQUIRED_PLUGINS.stream().forEach(needRequiredPlugin -> requiredPlugins.add(needRequiredPlugin));
+
+ // For each external reference, get its plug-in name and search its dependency in the plug-in
+ final Collection<String> existingRequiredPlugins = new HashSet<>();
+ final List<BundleSpecification> dependencies = ProjectManagementService.getPluginDependencies(project);
+ if (null != dependencies && !dependencies.isEmpty()) {
+ dependencies.stream().forEach(dependency -> existingRequiredPlugins.add(dependency.getName()));
+ requiredPlugins.removeIf(requiredPlugin -> existingRequiredPlugins.contains(requiredPlugin));
+ }
+
+ // If requiredPlugins is not empty, that means, the dependency is not available in the profile plug-in
+ // So, create the warning markers
+ if (!requiredPlugins.isEmpty()) {
+ final IFile manifestFile = ProjectManagementService.getManifestFile(project);
+
+ requiredPlugins.stream().forEach(requiredPlugin -> {
+ MarkersService.createMarker(manifestFile,
+ ElementTypesPluginValidationConstants.ELEMENTTYPES_PLUGIN_VALIDATION_TYPE,
+ "The plug-in '" + requiredPlugin + "' must be defined as required plug-in.", //$NON-NLS-1$ //$NON-NLS-2$
+ IMarker.SEVERITY_WARNING);
+ });
+ }
+
+ 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/ElementTypesFileChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.elementtypes/src/org/eclipse/papyrus/toolsmiths/validation/elementtypes/internal/checkers/ElementTypesFileChecker.java
index acbc9640afa..4ae82ce0247 100644
--- 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
@@ -20,9 +20,7 @@ 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;
@@ -39,13 +37,21 @@ public class ElementTypesFileChecker implements IPluginChecker {
private final IFile elementTypesFile;
/**
+ * The EMF resource of the element types file.
+ */
+ private final Resource resource;
+
+ /**
* Constructor.
*
* @param elementTypesFile
* The file defining the element types.
+ * @param resource
+ * The EMF resource of the element types file.
*/
- public ElementTypesFileChecker(final IFile elementTypesFile) {
+ public ElementTypesFileChecker(final IFile elementTypesFile, final Resource resource) {
this.elementTypesFile = elementTypesFile;
+ this.resource = resource;
}
/**
@@ -62,8 +68,6 @@ public class ElementTypesFileChecker implements IPluginChecker {
}
// 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
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 ac515690563..96f665ffa6b 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
@@ -20,6 +20,9 @@ import java.util.Collection;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+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.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.papyrus.toolsmiths.validation.common.utils.MarkersService;
import org.eclipse.papyrus.toolsmiths.validation.common.utils.PluginValidationService;
@@ -58,11 +61,18 @@ public class ElementTypesPluginChecker {
// Create the plug-in validation service
final PluginValidationService pluginValidationService = new PluginValidationService();
+ // First, check the dependencies needed
+ pluginValidationService.addPluginChecker(new ElementTypesDependenciesChecker(project));
+
// For all element types files in the plug-in
for (final IFile elementTypesFile : elementTypesFiles) {
- // First, check the validation of the element types file
- pluginValidationService.addPluginChecker(new ElementTypesFileChecker(elementTypesFile));
+ // Get the resource
+ final URI elementTypesFileURI = URI.createPlatformResourceURI(elementTypesFile.getFullPath().toOSString(), true);
+ final Resource resource = new ResourceSetImpl().getResource(elementTypesFileURI, true);
+
+ // Check the validation of the element types file
+ pluginValidationService.addPluginChecker(new ElementTypesFileChecker(elementTypesFile, resource));
// Check the extension point
pluginValidationService.addPluginChecker(new ElementTypesExtensionsChecker(project, elementTypesFile));

Back to the top