diff options
author | Nicolas FAUVERGUE | 2019-04-11 07:40:59 +0000 |
---|---|---|
committer | Nicolas FAUVERGUE | 2019-04-11 09:28:41 +0000 |
commit | 081d2d417502fa32b229950a2b830c75a0080524 (patch) | |
tree | f0f525169109e18946cf57a6c6e2682f9b603e69 /plugins | |
parent | 620b62ed81aad98ce7b13136b1e13c065ad720f1 (diff) | |
download | org.eclipse.papyrus-081d2d417502fa32b229950a2b830c75a0080524.tar.gz org.eclipse.papyrus-081d2d417502fa32b229950a2b830c75a0080524.tar.xz org.eclipse.papyrus-081d2d417502fa32b229950a2b830c75a0080524.zip |
Bug 546239: [Toolsmiths][Validation] Plug-ins to validate profile
plug-in must be implemented
- Implement the plugin.xml validation
Change-Id: I661dbf38264cdab327f165e1f1acdda570644134
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins')
10 files changed, 468 insertions, 13 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 18d401b4be5..d14cdc8c16f 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 @@ -2,7 +2,8 @@ Manifest-Version: 1.0 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.core.resources;bundle-version="[3.13.0,4.0.0)", + org.eclipse.pde.core;bundle-version="[3.12.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/MarkersManagementUtils.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/MarkersManagementUtils.java new file mode 100644 index 00000000000..1409400e5b5 --- /dev/null +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.common/src/org/eclipse/papyrus/toolsmiths/validation/common/utils/MarkersManagementUtils.java @@ -0,0 +1,70 @@ +/***************************************************************************** + * 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.common.utils; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.papyrus.toolsmiths.validation.common.Activator; + +/** + * This allows to manage markers + */ +public class MarkersManagementUtils { + + /** + * This allows to create a marker for a resource. + * + * @param resource + * The resource where create the marker. + * @param type + * The type of the marker validation. + * @param message + * The message of the marker. + * @param severity + * The severity of the marker. + * @return The created marker or <code>null</code> if there is an error. + */ + public static IMarker createMarker(final IResource resource, final String type, final String message, final int severity) { + IMarker createdMarker = null; + try { + createdMarker = resource.createMarker(type); + createdMarker.setAttribute(IMarker.MESSAGE, message); + createdMarker.setAttribute(IMarker.SEVERITY, severity); + } catch (CoreException e) { + Activator.log.error("Error while creating marker", e); //$NON-NLS-1$ + } + + return createdMarker; + } + + /** + * This allows to delete markers of a resource. + * + * @param resource + * The resource. + * @param type + * The type of markers to delete. + */ + public static void deleteMarkers(final IResource resource, final String type) { + try { + resource.deleteMarkers(type, true, IResource.DEPTH_INFINITE); + } catch (CoreException e) { + Activator.log.error("Error while deleting markers", e); //$NON-NLS-1$ + } + } + +} 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 9bf2ba1c374..5b2cc9dceb1 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 @@ -16,13 +16,22 @@ package org.eclipse.papyrus.toolsmiths.validation.common.utils; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import org.eclipse.core.resources.IContainer; 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.papyrus.toolsmiths.validation.common.Activator; +import org.eclipse.pde.core.build.IBuildModel; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; /** * This allows to define utils methods and functions corresponding to project. @@ -30,7 +39,62 @@ import org.eclipse.papyrus.toolsmiths.validation.common.Activator; public class ProjectManagementUtils { /** - * This allows to get the file corresponding to the file name in parameter. + * This allows to get the plugin model base from the project. + * This allows to manipulate the 'plugin.xml' and 'MANIFEST.MF' files content. + * + * @param project + * The current project. + * @return The {@link IPluginModelBase} representing the plug-in project content. + */ + public static IPluginModelBase getPluginModelBase(final IProject project) { + return PluginRegistry.findModel(project); + } + + /** + * This allows to get the list of extensions in the 'plugin.xml' file. + * + * @param project + * The current project. + * @return The list of extensions (can be empty). + */ + public static List<IPluginExtension> getPluginExtensions(final IProject project) { + final IPluginModelBase pluginModelBase = ProjectManagementUtils.getPluginModelBase(project); + return null != pluginModelBase ? Arrays.asList(pluginModelBase.getExtensions().getExtensions()) : Collections.emptyList(); + } + + /** + * This allows to check the file corresponding to the file name in parameter exists. + * + * @param container + * The container resource. + * @param foundFile + * The name of the found file. + * @param isExtensionCheck + * <code>true</code> if the found file is an extension to find, <code>false</code> otherwise. + * @return The corresponding file or <code>null</code>. + */ + public static boolean existFileFromProject(final IContainer container, final String foundFile, final boolean isExtensionCheck) { + boolean result = false; + + try { + final Iterator<IResource> members = Arrays.asList(container.members()).iterator(); + while (members.hasNext() && !result) { + final IResource member = members.next(); + if (member instanceof IFile && isCorrespondingFile((IFile) member, foundFile, isExtensionCheck)) { + result = true; + } else if (member instanceof IContainer) { + result = existFileFromProject((IContainer) member, foundFile, isExtensionCheck); + } + } + } catch (final CoreException e) { + Activator.log.error(e); + } + + return result; + } + + /** + * This allows to get the files corresponding to the file name in parameter. * * @param container * The container resource. @@ -40,17 +104,17 @@ public class ProjectManagementUtils { * <code>true</code> if the found file is an extension to find, <code>false</code> otherwise. * @return The corresponding file or <code>null</code>. */ - public static IFile getFileFromProject(final IContainer container, final String foundFile, final boolean isExtensionCheck) { - IFile result = null; + public static Collection<IFile> getFilesFromProject(final IContainer container, final String foundFile, final boolean isExtensionCheck) { + final Collection<IFile> result = new HashSet<>(); try { final Iterator<IResource> members = Arrays.asList(container.members()).iterator(); - while (members.hasNext() && null == result) { + while (members.hasNext()) { final IResource member = members.next(); if (member instanceof IFile && isCorrespondingFile((IFile) member, foundFile, isExtensionCheck)) { - result = (IFile) member; + result.add((IFile) member); } else if (member instanceof IContainer) { - result = getFileFromProject((IContainer) member, foundFile, isExtensionCheck); + result.addAll(getFilesFromProject((IContainer) member, foundFile, isExtensionCheck)); } } } catch (final CoreException e) { @@ -61,6 +125,30 @@ public class ProjectManagementUtils { } /** + * This allows to get the 'plugin.xml' file. + * + * @param container + * The container. + * @return The found file 'plugin.xml' or <code>null</code>. + */ + public static IFile getPluginXMLFile(final IContainer container) { + final Collection<IFile> pluginXMLFiles = ProjectManagementUtils.getFilesFromProject(container, "plugin.xml", false); //$NON-NLS-1$ + return pluginXMLFiles.isEmpty() ? null : pluginXMLFiles.iterator().next(); + } + + /** + * This allows to get the 'build.properties' file. + * + * @param container + * The container. + * @return The found file 'build.properties' or <code>null</code>. + */ + public static IFile getBuildFile(final IContainer container) { + final Collection<IFile> buildPropertiesFiles = ProjectManagementUtils.getFilesFromProject(container, "build.properties", false); //$NON-NLS-1$ + return buildPropertiesFiles.isEmpty() ? null : buildPropertiesFiles.iterator().next(); + } + + /** * This allows to check if the current file is corresponding to the find one. * * @param file @@ -72,7 +160,6 @@ public class ProjectManagementUtils { * @return <code>true</code> if the file is corresponding to the found file, <code>false</code> otherwise. */ private static boolean isCorrespondingFile(final IFile file, final String foundFile, final boolean isExtensionCheck) { - return isExtensionCheck ? file.getName().endsWith("." + foundFile) : file.getName().equals(foundFile); + return isExtensionCheck ? file.getName().endsWith("." + foundFile) : file.getName().equals(foundFile); //$NON-NLS-1$ } - } diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/META-INF/MANIFEST.MF b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/META-INF/MANIFEST.MF index 68fc4c2eb01..59a4e9b9de3 100644 --- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/META-INF/MANIFEST.MF +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/META-INF/MANIFEST.MF @@ -5,9 +5,14 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.6.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)", org.eclipse.papyrus.toolsmiths.validation.common;bundle-version="[1.0.0,2.0.0)", - org.eclipse.papyrus.dev.ui;bundle-version="[0.0.1,2.0.0)" + org.eclipse.papyrus.dev.ui;bundle-version="[0.0.1,2.0.0)", + org.eclipse.pde.core;bundle-version="[3.12.0,4.0.0)", + org.eclipse.emf.ecore;bundle-version="[2.17.0,3.0.0)", + org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)" Export-Package: org.eclipse.papyrus.toolsmiths.validation.profile, + org.eclipse.papyrus.toolsmiths.validation.profile.checkers, + org.eclipse.papyrus.toolsmiths.validation.profile.constants, org.eclipse.papyrus.toolsmiths.validation.profile.handlers, org.eclipse.papyrus.toolsmiths.validation.profile.testers Bundle-Vendor: %providerName diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/plugin.xml b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/plugin.xml index c47680b87f9..a997cd9a764 100644 --- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/plugin.xml +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/plugin.xml @@ -61,6 +61,17 @@ type="org.eclipse.core.resources.IProject"> </propertyTester> </extension> + <extension + id="diagnostic" + name="Papyrus Toolsmiths Profile Plug-in problems" + point="org.eclipse.core.resources.markers"> + <super + type="org.eclipse.core.resources.problemmarker"> + </super> + <persistent + value="true"> + </persistent> + </extension> 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 new file mode 100644 index 00000000000..c7bfc0ef44b --- /dev/null +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfileExtensionsChecker.java @@ -0,0 +1,127 @@ +/***************************************************************************** + * 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.Iterator; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.emf.ecore.xmi.XMIResource; +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; +import org.eclipse.pde.core.plugin.IPluginAttribute; +import org.eclipse.pde.core.plugin.IPluginElement; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginObject; +import org.eclipse.uml2.uml.Profile; + +/** + * This class allows to check the extensions of the 'plugin.xml' needed for the profiles. + */ +public class ProfileExtensionsChecker { + + /** + * This allows to check the extensions of the profile. + * + * @param project + * The current project to check. + * @param profileFile + * The profile for which one to check. + * @param existingProfiles + * The existing profiles in the file. + */ + public static void checkPluginXMLFile(final IProject project, final IFile profileFile, final Collection<Profile> existingProfiles) { + + // Create the conditions: + // - Copy of existing profiles (that will be removed if there are found in uml generated package extension points) + // - Boolean to check if the UMLProfile is defined for the profile + final Collection<Profile> profiles = new HashSet<>(existingProfiles); + boolean foundExtensionUMLProfile = false; + + // Get all the extensions of the plug-in to check + final Iterator<IPluginExtension> extensions = ProjectManagementUtils.getPluginExtensions(project).iterator(); + while (extensions.hasNext()) { + final IPluginExtension extension = extensions.next(); + // Check if the UML profile extension point is managed (warning because this one can be managed outside of this plug-in) + if (!foundExtensionUMLProfile && extension.getPoint().equals(ProfilePluginValidationConstants.UMLPROFILE_EXTENSION_POINT)) { + for (final IPluginObject pluginObject : extension.getChildren()) { + if (pluginObject instanceof IPluginElement && pluginObject.getName().equals("profile")) { //$NON-NLS-1$ + for (final IPluginAttribute pluginAtttribute : ((IPluginElement) pluginObject).getAttributes()) { + if (pluginAtttribute.getName().equals("path")) { //$NON-NLS-1$ + final String locationValue = pluginAtttribute.getValue(); + if (locationValue.endsWith(profileFile.getName())) { + foundExtensionUMLProfile = true; + } + } + } + } + } + } + + // Manage the uml profile registration (check only if + if (!profiles.isEmpty() && extension.getPoint().equals(ProfilePluginValidationConstants.UML_GENERATED_PACKAGE_EXTENSION_POINT)) { + for (final IPluginObject pluginObject : extension.getChildren()) { + if (pluginObject instanceof IPluginElement && pluginObject.getName().equals("profile")) { //$NON-NLS-1$ + for (final IPluginAttribute pluginAtttribute : ((IPluginElement) pluginObject).getAttributes()) { + if (pluginAtttribute.getName().equals("location")) { //$NON-NLS-1$ + final String locationValue = pluginAtttribute.getValue(); + + final Iterator<Profile> profilesIt = profiles.iterator(); + while (profilesIt.hasNext()) { + final Profile currentProfile = profilesIt.next(); + final String profileId = ((XMIResource) currentProfile.eResource()).getID(currentProfile); + if (locationValue.endsWith(profileFile.getName() + "#" + profileId)) { //$NON-NLS-1$ + profilesIt.remove(); + break; + } + } + } + } + } + } + } + } + + // If there is a problem, get the plugin.xml file to mark the correct file for problems + if (!foundExtensionUMLProfile || !profiles.isEmpty()) { + final IFile pluginXMLFile = ProjectManagementUtils.getPluginXMLFile(project); + + // Create marker for UMLProfile extension point if needed + if (!foundExtensionUMLProfile) { + MarkersManagementUtils.createMarker( + pluginXMLFile, + ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE, + "The extension point '" + ProfilePluginValidationConstants.UMLPROFILE_EXTENSION_POINT + "' should be created.", //$NON-NLS-1$ //$NON-NLS-2$ + IMarker.SEVERITY_WARNING); + } + // Create markers (one by missing profile) for uml generated package extension point if needed + if (!profiles.isEmpty()) { + for (final Profile profile : profiles) { + MarkersManagementUtils.createMarker( + pluginXMLFile, + ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE, + "There is no extension point '" + ProfilePluginValidationConstants.UML_GENERATED_PACKAGE_EXTENSION_POINT + "' for profile '" + profile.getName() + "'.", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + IMarker.SEVERITY_ERROR); + } + } + } + } + +} 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 new file mode 100644 index 00000000000..9a82300433a --- /dev/null +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/checkers/ProfilePluginChecker.java @@ -0,0 +1,98 @@ +/***************************************************************************** + * 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.Iterator; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.emf.common.util.URI; +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.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.uml2.uml.Profile; + +/** + * This allows to check a profile plug-in (extensions, builds, dependencies). + */ +public class ProfilePluginChecker { + + /** + * This allows to check the profile plug-in. + * + * @param project + * The current project to check. + */ + public static void checkProfilePlugin(final IProject project) { + + // First of all, delete the existing markers for project + MarkersManagementUtils.deleteMarkers(project, ProfilePluginValidationConstants.PROFILE_PLUGIN_VALIDATION_TYPE); + + 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) { + + // get the existing profiles + final URI profileFileURI = URI.createPlatformResourceURI(profileFile.getFullPath().toOSString(), true); + final Collection<Profile> profiles = loadProfiles(profileFileURI); + + // First, check the extensions + if (!profiles.isEmpty()) { + ProfileExtensionsChecker.checkPluginXMLFile(project, profileFile, profiles); + } + } + } + + /** + * Loads the EObject from the given URI. + * + * @param uri + * The URI from which the EObject is loaded. + * @return + * The profiles available in the model (can be empty if no profile or if an error occurred). + */ + private static Collection<Profile> loadProfiles(final URI uri) { + final Collection<Profile> profiles = new HashSet<>(); + + final ResourceSet resourceSet = new ResourceSetImpl(); + try { + final Resource resource = resourceSet.getResource(uri, true); + if (resource != null) { + if (!resource.getContents().isEmpty()) { + final Iterator<EObject> contentIt = resource.getAllContents(); + while (contentIt.hasNext()) { + final EObject content = contentIt.next(); + if (content instanceof Profile) { + profiles.add((Profile) content); + } + } + } + } + } catch (final Exception ex) { + Activator.log.error("Cannot load file: " + uri.toString(), ex); //$NON-NLS-1$ + } + + return profiles; + } + +} diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/constants/ProfilePluginValidationConstants.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/constants/ProfilePluginValidationConstants.java new file mode 100644 index 00000000000..0f409ff8298 --- /dev/null +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/constants/ProfilePluginValidationConstants.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * 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.constants; + +/** + * The profile plug-in validation constants. + */ +public class ProfilePluginValidationConstants { + + /** + * The type for the validation of profile plugin. + */ + public static final String PROFILE_PLUGIN_VALIDATION_TYPE = "org.eclipse.papyrus.toolsmiths.validation.profile.diagnostic"; //$NON-NLS-1$ + + /** + * The UMLProfile extension point identifier. + */ + public static final String UMLPROFILE_EXTENSION_POINT = "org.eclipse.papyrus.uml.extensionpoints.UMLProfile"; //$NON-NLS-1$ + + /** + * The uml generated package extension point identifier. + */ + public static final String UML_GENERATED_PACKAGE_EXTENSION_POINT = "org.eclipse.uml2.uml.generated_package"; //$NON-NLS-1$ +} diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/handlers/ValidateProfilePluginHandler.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/handlers/ValidateProfilePluginHandler.java index 2c044212e7d..3a4e7bff878 100644 --- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/handlers/ValidateProfilePluginHandler.java +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/handlers/ValidateProfilePluginHandler.java @@ -18,9 +18,14 @@ package org.eclipse.papyrus.toolsmiths.validation.profile.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.toolsmiths.validation.profile.checkers.ProfilePluginChecker; +import org.eclipse.ui.handlers.HandlerUtil; /** - * This handler allows to validate papyrus profile plugin. + * This handler allows to validate papyrus profile plug-ins. */ public class ValidateProfilePluginHandler extends AbstractHandler { @@ -30,7 +35,21 @@ public class ValidateProfilePluginHandler extends AbstractHandler { * * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ + @Override public Object execute(final ExecutionEvent event) throws ExecutionException { + final ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection == null || !(selection instanceof StructuredSelection) || selection.isEmpty()) { + return null; + } + + final StructuredSelection structuredSelection = (StructuredSelection) selection; + for (final Object selectedElement : structuredSelection.toList()) { + if (selectedElement instanceof IProject) { + final IProject project = (IProject) selectedElement; + ProfilePluginChecker.checkProfilePlugin(project); + } + } + return null; } diff --git a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/testers/ValidateProfilePluginTester.java b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/testers/ValidateProfilePluginTester.java index b740ea0d661..1eea72dca68 100644 --- a/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/testers/ValidateProfilePluginTester.java +++ b/plugins/toolsmiths/validation/org.eclipse.papyrus.toolsmiths.validation.profile/src/org/eclipse/papyrus/toolsmiths/validation/profile/testers/ValidateProfilePluginTester.java @@ -36,8 +36,8 @@ public class ValidateProfilePluginTester extends PropertyTester { if (receiver instanceof IProject) { final IProject selectedProject = (IProject) receiver; - result = null != ProjectManagementUtils.getFileFromProject(selectedProject, "profile.uml", true) //$NON-NLS-1$ - && null != ProjectManagementUtils.getFileFromProject(selectedProject, "genmodel", true); //$NON-NLS-1$ + result = ProjectManagementUtils.existFileFromProject(selectedProject, "profile.uml", true) //$NON-NLS-1$ + && ProjectManagementUtils.existFileFromProject(selectedProject, "genmodel", true); //$NON-NLS-1$ } return expectedValue instanceof Boolean ? ((Boolean) expectedValue).booleanValue() == result : result; } |