Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-04-12 05:29:37 -0400
committerPatrick Tessier2019-04-15 04:14:44 -0400
commitd23d3677570137311a64c5775296305ba6fdc952 (patch)
tree5b3c13176a87b80d5fa969265b51974041ce01f3
parent9fed6130689257ace6a04ca243da12eee7a647b1 (diff)
downloadorg.eclipse.papyrus-d23d3677570137311a64c5775296305ba6fdc952.tar.gz
org.eclipse.papyrus-d23d3677570137311a64c5775296305ba6fdc952.tar.xz
org.eclipse.papyrus-d23d3677570137311a64c5775296305ba6fdc952.zip
Bug 546239: [Toolsmiths][Validation] Plug-ins to validate profile
plug-in must be implemented - Implement the check of dependencies depending to the external references in the profile. Change-Id: I8bc4ec9a3760988226fcb4b2dac764e317d63961 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF3
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/ProjectManagementUtils.java25
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileDependenciesChecker.java201
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java2
-rw-r--r--plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java67
5 files changed, 279 insertions, 19 deletions
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
index d14cdc8c16f..1b2f2aeb13d 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/META-INF/MANIFEST.MF
@@ -3,7 +3,8 @@ Require-Bundle:
org.eclipse.ui;bundle-version="[3.112.0,4.0.0)",
org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)",
org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)",
- org.eclipse.pde.core;bundle-version="[3.12.0,4.0.0)"
+ org.eclipse.pde.core;bundle-version="[3.12.0,4.0.0)",
+ org.eclipse.papyrus.infra.core;bundle-version="[3.0.0,4.0.0)"
Export-Package:
org.eclipse.papyrus.toolsmiths.validation.common,
org.eclipse.papyrus.toolsmiths.validation.common.utils
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/ProjectManagementUtils.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/ProjectManagementUtils.java
index c9b22436cfd..cbd6f27b42e 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/ProjectManagementUtils.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/ProjectManagementUtils.java
@@ -27,6 +27,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.papyrus.toolsmiths.validation.common.Activator;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.core.plugin.IPluginExtension;
@@ -63,6 +64,18 @@ public class ProjectManagementUtils {
}
/**
+ * This allows to get the list of required plug-ins.
+ *
+ * @param project
+ * The current project.
+ * @return The list of required plug-ins (can be empty).
+ */
+ public static List<BundleSpecification> getPluginDependencies(final IProject project) {
+ final IPluginModelBase pluginModelBase = ProjectManagementUtils.getPluginModelBase(project);
+ return null != pluginModelBase ? Arrays.asList(pluginModelBase.getBundleDescription().getRequiredBundles()) : Collections.emptyList();
+ }
+
+ /**
* This allows to get the build model of the project.
*
* @param project
@@ -144,6 +157,18 @@ public class ProjectManagementUtils {
}
/**
+ * This allows to get the 'MANIFEST.MF' file.
+ *
+ * @param container
+ * The container.
+ * @return The found file 'MANIFEST.MF' or <code>null</code>.
+ */
+ public static IFile getManifestFile(final IContainer container) {
+ final Collection<IFile> manifestFiles = ProjectManagementUtils.getFilesFromProject(container, "MANIFEST.MF", false); //$NON-NLS-1$
+ return manifestFiles.isEmpty() ? null : manifestFiles.iterator().next();
+ }
+
+ /**
* This allows to get the 'plugin.xml' file.
*
* @param container
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileDependenciesChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileDependenciesChecker.java
new file mode 100644
index 00000000000..f94de65ca8b
--- /dev/null
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileDependenciesChecker.java
@@ -0,0 +1,201 @@
+/*****************************************************************************
+ * 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.profile.checkers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+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.URIMappingRegistryImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.toolsmiths.validation.common.utils.MarkersManagementUtils;
+import org.eclipse.papyrus.toolsmiths.validation.common.utils.ProjectManagementUtils;
+import org.eclipse.papyrus.toolsmiths.validation.profile.constants.ProfilePluginValidationConstants;
+
+/**
+ * This class allows to check that the plug-in has the correct dependencies depending to the external profile references.
+ */
+public class ProfileDependenciesChecker {
+
+ /**
+ * The plug-ins to detect as warning instead of errors.
+ * This can be filled.
+ */
+ @SuppressWarnings("serial")
+ private static Set<String> WARNING_PLUGINS_EXCEPTION = new HashSet<String>() {
+ {
+ add("org.eclipse.uml2.uml.resources"); //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * This allows to check that the plug-in has the correct dependencies depending to the external profile references.
+ *
+ * @param project
+ * The current project to check.
+ * @param profileFile
+ * The file or the UML profile.
+ * @param resource
+ * The EMF resource.
+ */
+ public static void checkDependencies(final IProject project, final IFile profileFile, final Resource resource) {
+
+ // Get the external reference paths
+ final Collection<URI> externalReferencesPaths = getExternalReferencesPaths(project, profileFile, resource);
+
+ // Calculate plug-ins names from URI
+ final Collection<String> requiredPlugins = new HashSet<>();
+ externalReferencesPaths.stream().forEach(externalReferencePath -> requiredPlugins.add(getPluginNameFromURI(externalReferencePath)));
+
+ // For each external reference, get its plug-in name and search its dependency in the plug-in
+ final Collection<String> existingRequiredPlugins = new HashSet<>();
+ ProjectManagementUtils.getPluginDependencies(project).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 = ProjectManagementUtils.getManifestFile(project);
+
+ requiredPlugins.stream().forEach(requiredPlugin -> {
+ int severity = IMarker.SEVERITY_ERROR;
+ if (WARNING_PLUGINS_EXCEPTION.contains(requiredPlugin)) {
+ severity = IMarker.SEVERITY_WARNING;
+ }
+ MarkersManagementUtils.createMarker(manifestFile,
+ ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE,
+ "The plug-in '" + requiredPlugin + "' must be defined as required plug-in (for profile '" + profileFile.getName() + "').", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ severity);
+ });
+ }
+ }
+
+ /**
+ * This allows to get the external references paths.
+ *
+ * @param project
+ * The current project.
+ * @param profileFile
+ * The file or the UML profile.
+ * @param resource
+ * The resource to get external references paths.
+ * @return The external references paths.
+ */
+ public static Collection<URI> getExternalReferencesPaths(final IProject project, final IFile profileFile, final Resource resource) {
+ final Collection<URI> externalReferencesPaths = new HashSet<>();
+
+ // First step, resolve all references
+ EcoreUtil.resolveAll(resource);
+
+ for (final Resource currentResource : resource.getResourceSet().getResources()) {
+ // Check that the resource is not the current one or is not available in the same plugin
+ if (isExternalReferenceToManage(project, currentResource)) {
+ final URI resourceURI = currentResource.getURI();
+
+ // React differently if this is a pathmap
+ if (resourceURI.toString().startsWith("pathmap://")) { //$NON-NLS-1$
+ // Try to resolve the pathmap
+ final URI correspondingURI = getCorrespondingURIFromPathmap(resourceURI);
+ if (null == correspondingURI) {
+ // If this case, the pathmap cannot be resolved, so create a marker
+ MarkersManagementUtils.createMarker(profileFile,
+ ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE,
+ "The pathmap '" + resourceURI.toString() + "' cannot be resolved.", //$NON-NLS-1$ //$NON-NLS-2$
+ IMarker.SEVERITY_ERROR);
+ } else {
+ externalReferencesPaths.add(correspondingURI);
+ }
+ } else {
+ externalReferencesPaths.add(resourceURI);
+ }
+ }
+ }
+
+ return externalReferencesPaths;
+ }
+
+ /**
+ * This allows to determinate if the external reference must be managed or not.
+ * For example, we don't have to manage references of files from the same plug-in.
+ * Moreover, some pathmaps don't need to be include in the dependencies.
+ *
+ * @param project
+ * The current project.
+ * @param resource
+ * The resource to check.
+ * @return <code>true</code> if we have to manage reference, <code>false</code> otherwise.
+ */
+ private static boolean isExternalReferenceToManage(final IProject project, final Resource resource) {
+ final String resourceURI = resource.getURI().toString();
+
+ // We don't have to manage references of files from the same plug-in
+ if (resourceURI.startsWith("platform:/plugin/" + project.getName()) || //$NON-NLS-1$
+ resourceURI.startsWith("platform:/resource/" + project.getName())) { //$NON-NLS-1$
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * This allows to resolve pathmap. To do this, we trim last segments until we got the correct corresponding URI.
+ * It is possible that we don't find pathmap, in this case, just return null.
+ *
+ * @param uri
+ * The pathmap URI to search.
+ * @return The corresponding URI to the pathmap.
+ */
+ private static URI getCorrespondingURIFromPathmap(final URI uri) {
+ URI copiedURI = URI.createURI(uri.toString());
+ URI foundCorrespondingURI = null;
+
+ while (null == foundCorrespondingURI) {
+ foundCorrespondingURI = URIMappingRegistryImpl.INSTANCE.get(copiedURI);
+ if (null == foundCorrespondingURI) {
+ if (copiedURI.segmentCount() <= 0) {
+ break;
+ }
+ copiedURI = copiedURI.trimSegments(1);
+ }
+ }
+
+ return foundCorrespondingURI;
+ }
+
+ /**
+ * This allows to get the plug-in name from the URI.
+ *
+ * @param uri
+ * The initial URI.
+ * @return The plug-in name from URI or <code>null</code> if any problem occurred.
+ */
+ private static String getPluginNameFromURI(final URI uri) {
+ String pluginName = null;
+
+ // Take we correct segment (without authority)
+ final int takenSegment = uri.hasAuthority() ? 0 : 1;
+ if (uri.segmentCount() > takenSegment) {
+ pluginName = uri.segment(takenSegment);
+ }
+
+ return pluginName;
+ }
+}
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java
index ee39fc01e4e..3ba7026d3ed 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java
@@ -108,7 +108,7 @@ public class ProfileExtensionsChecker {
MarkersManagementUtils.createMarker(
pluginXMLFile,
ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE,
- "The extension point '" + ProfilePluginValidationConstants.UMLPROFILE_EXTENSION_POINT + "' should be created for file '" + profileFile.getName() + "'", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "The extension point '" + ProfilePluginValidationConstants.UMLPROFILE_EXTENSION_POINT + "' should be created for profile '" + profileFile.getName() + "'", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IMarker.SEVERITY_WARNING);
}
// Create markers (one by missing profile) for uml generated package extension point if needed
diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java
index 651d157613c..f32a2f51c3a 100644
--- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java
+++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.toolsmiths.validation.profile.checkers;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -26,10 +27,13 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.papyrus.toolsmiths.validation.common.utils.MarkersManagementUtils;
import org.eclipse.papyrus.toolsmiths.validation.common.utils.ProjectManagementUtils;
import org.eclipse.papyrus.toolsmiths.validation.profile.Activator;
import org.eclipse.papyrus.toolsmiths.validation.profile.constants.ProfilePluginValidationConstants;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Profile;
/**
@@ -45,27 +49,56 @@ public class ProfilePluginChecker {
*/
public static void checkProfilePlugin(final IProject project) {
- // First of all, delete the existing markers for project
- MarkersManagementUtils.deleteMarkers(project, ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE);
+ // Get the shell to manage the validation in an UI
+ final Shell shell = Display.getCurrent().getActiveShell();
- final Collection<IFile> profileFiles = ProjectManagementUtils.getFilesFromProject(project, "profile.uml", true); //$NON-NLS-1$
- // For all profiles files in the plug-in
- for (final IFile profileFile : profileFiles) {
+ try {
+ // Open the progress monitor dialog
+ new ProgressMonitorDialog(shell).run(true, true, monitor -> {
+ final Collection<IFile> profileFiles = ProjectManagementUtils.getFilesFromProject(project, "profile.uml", true); //$NON-NLS-1$
+ monitor.beginTask("Validate Profile plug-in.", 1 + (profileFiles.size() * 4)); // $NON-NLS-1$
- // get the existing profiles
- final URI profileFileURI = URI.createPlatformResourceURI(profileFile.getFullPath().toOSString(), true);
- final Collection<Profile> profiles = loadProfiles(profileFileURI);
+ monitor.subTask("Prepare validation."); //$NON-NLS-1$
+ // First of all, delete the existing markers for project
+ MarkersManagementUtils.deleteMarkers(project, ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE);
+ monitor.worked(1);
- // First, check the extensions
- if (!profiles.isEmpty()) {
- ProfileExtensionsChecker.checkPluginXMLFile(project, profileFile, profiles);
-
- // Check the profile definition (no definition must be done for static profiles)
- ProfileDefinitionChecker.checkProfilesDefinition(project, profileFile, profiles);
- }
+ // For all profiles files in the plug-in
+ for (final IFile profileFile : profileFiles) {
+
+ // get the existing profiles
+ final URI profileFileURI = URI.createPlatformResourceURI(profileFile.getFullPath().toOSString(), true);
+ final Collection<Profile> profiles = loadProfiles(profileFileURI);
+
+ if (!profiles.isEmpty()) {
+ monitor.subTask("Validate 'plugin.xml' file for profile '" + profileFile.getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ // First, check the extensions
+ ProfileExtensionsChecker.checkPluginXMLFile(project, profileFile, profiles);
+ monitor.worked(1);
- // Check the build for file
- ProfileBuildChecker.checkBuildFile(project, profileFile);
+ monitor.subTask("Validate profiles definitions for profile '" + profileFile.getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ // Check the profile definition (no definition must be done for static profiles)
+ ProfileDefinitionChecker.checkProfilesDefinition(project, profileFile, profiles);
+ monitor.worked(1);
+
+ monitor.subTask("Validate dependencies for profile '" + profileFile.getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ // Check the dependencies depending to the external profile references
+ ProfileDependenciesChecker.checkDependencies(project, profileFile, profiles.iterator().next().eResource());
+ monitor.worked(1);
+ } else {
+ monitor.worked(3);
+ }
+
+ monitor.subTask("Validate 'build.properties' file for profile '" + profileFile.getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ // Check the build for file
+ ProfileBuildChecker.checkBuildFile(project, profileFile);
+ monitor.worked(1);
+ }
+ });
+ } catch (InvocationTargetException e) {
+ Activator.log.error(e);
+ } catch (InterruptedException e) {
+ // Do nothing, just cancelled by user
}
}

Back to the top