Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2018-09-25 07:47:39 -0400
committerQuentin Le Menez2018-11-22 05:33:11 -0500
commit08b6358e2615217cf42d7b929304ee36a4031009 (patch)
tree4aa09289cf6b4cc0e366a635ff12722cc794a0f9
parent3408513589ec1aae6358cc010e5778e6a83ce5b2 (diff)
downloadorg.eclipse.papyrus-08b6358e2615217cf42d7b929304ee36a4031009.tar.gz
org.eclipse.papyrus-08b6358e2615217cf42d7b929304ee36a4031009.tar.xz
org.eclipse.papyrus-08b6358e2615217cf42d7b929304ee36a4031009.zip
Bug 536144 - [EMF Facet] validation of a custom file must be improved
Change-Id: I7528c23fdf7d4a2ee02dd0fef92e4d0a93322981 Signed-off-by: Patrick Tessier <patrick.tessier@cea.fr>
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/.classpath1
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/build.properties6
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java (renamed from plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src-gen/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java)10
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/v0_2_0/javaquery/internal/JavaQueryValidator.java124
5 files changed, 139 insertions, 4 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java
index 216ce60ff1c..c9e62361a7c 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java
@@ -24,7 +24,7 @@ import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
/**
- * this method is overloaded in order to launch the validator
+ *
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*
* @param arg0
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/.classpath b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/.classpath
index f9c46b584dd..756f4289006 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/.classpath
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src-gen"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/build.properties b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/build.properties
index f9652bfa7f7..8b80f43bb69 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/build.properties
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/build.properties
@@ -1,9 +1,9 @@
-source.. = src-gen/
+source.. = src-gen/,\
+ src/
output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
OSGI-INF/,\
plugin.xml
-src.includes = about.html,\
- src-gen/
+src.includes = about.html
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src-gen/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java
index ea2a17a3aa8..7a83ee11bfd 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src-gen/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/internal/Activator.java
@@ -1,6 +1,9 @@
package org.eclipse.papyrus.emf.facet.query.java.metamodel.internal;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.papyrus.emf.facet.query.java.metamodel.v0_2_0.javaquery.JavaQueryPackage;
+import org.eclipse.papyrus.emf.facet.query.java.metamodel.v0_2_0.javaquery.internal.JavaQueryValidator;
import org.osgi.framework.BundleContext;
/** The activator class controls the plug-in life cycle */
@@ -16,6 +19,13 @@ public class Activator extends Plugin {
public void start(final BundleContext context) throws Exception {
super.start(context);
Activator.plugin = this;
+ EValidator.Registry.INSTANCE.put
+ (JavaQueryPackage.eINSTANCE,
+ new EValidator.Descriptor() {
+ public EValidator getEValidator() {
+ return JavaQueryValidator.eInstance;
+ }
+ });
}
@Override
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/v0_2_0/javaquery/internal/JavaQueryValidator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/v0_2_0/javaquery/internal/JavaQueryValidator.java
new file mode 100644
index 00000000000..4051160e113
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.query.java.metamodel/src/org/eclipse/papyrus/emf/facet/query/java/metamodel/v0_2_0/javaquery/internal/JavaQueryValidator.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST.
+ *
+ * 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
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.emf.facet.query.java.metamodel.v0_2_0.javaquery.internal;
+
+import java.util.Map;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.util.EObjectValidator;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.papyrus.emf.facet.query.java.metamodel.v0_2_0.javaquery.JavaQuery;
+import org.eclipse.papyrus.emf.facet.query.java.metamodel.v0_2_0.javaquery.JavaQueryPackage;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+
+/**
+ * This class is used to validate the existence of a Java query in the custom model
+ */
+public class JavaQueryValidator extends EObjectValidator {
+
+
+ public static JavaQueryValidator eInstance= new JavaQueryValidator();
+
+ @Override
+ protected EPackage getEPackage() {
+ return JavaQueryPackage.eINSTANCE;
+ }
+ @Override
+ protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ switch (classifierID) {
+ case JavaQueryPackage.JAVA_QUERY:
+ return validateJavaQuery((JavaQuery)value, diagnostics, context);
+ default:
+ return super.validate(classifierID, value, diagnostics, context);
+ }
+ }
+
+ /**
+ *
+ * @param javaquery
+ * @param diagnostics
+ * @param context
+ * @return
+ */
+ public boolean validateJavaQuery(JavaQuery javaquery, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ boolean valid = true;
+ if (diagnostics != null) {
+ if (javaquery.getImplementationClassName() != null && !("".equals(javaquery.getImplementationClassName().trim()))) {
+ String classNameToFind=javaquery.getImplementationClassName();
+ //1. the class could only on workspace
+ //so look for it
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : projects) {
+ try {
+ if (project.getNature(IBundleProjectDescription.PLUGIN_NATURE) != null) {
+ IJavaProject javaProject= JavaCore.create(project);
+ IType foundSource=javaProject.findType(classNameToFind);
+ if (foundSource!=null) {
+ return true;
+ }
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ //2. maybe it is in the platform plugin?
+ Class<?> loadedClass = ClassLoaderHelper.loadClass(classNameToFind);
+ if (loadedClass == null) {
+ valid = false;
+ diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR,
+ JavaQueryValidator.DIAGNOSTIC_SOURCE,
+ 1, "The java query '"
+ + javaquery.getImplementationClassName() + "' references a class that does not exist " , //$NON-NLS-1$
+ new Object[] { javaquery }));
+
+ }
+
+ }
+
+ }
+ return valid;
+ }
+ /**
+ * @param facet
+ * @param diagnostics
+ * @param context
+ * @return
+ */
+ private boolean validatefacetSet_validate(FacetSet facetSet, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ boolean valid = true;
+ if (diagnostics != null) {
+ if (facetSet.getNsPrefix() == null||facetSet.getNsPrefix().equals("")) {
+ return true;
+ }
+ }
+ return valid;
+ }
+
+}

Back to the top