Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kermeta3 validation rule moved into gemoc-debugging from the K3 validation plugin #170

Merged
merged 1 commit into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.gemoc.xdsmlframework.extensions.kermeta3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Gemoc extension for Kermeta3
Bundle-SymbolicName: org.eclipse.gemoc.xdsmlframework.extensions.kermeta3;singleton:=true
Bundle-Version: 4.0.0.qualifier
Automatic-Module-Name: org.eclipse.gemoc.xdsmlframework.extension.kermeta3
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.resources,
org.eclipse.equinox.registry,
org.eclipse.gemoc.dsl;bundle-version="3.0.0",
org.eclipse.gemoc.xdsmlframework.api;bundle-version="4.0.0",
org.eclipse.jdt.core;bundle-version="3.14.0"
Export-Package: org.eclipse.gemoc.xdsmlframework.extensions.kermeta3
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

</plugin>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017 Inria and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
Inria - initial API and implementation
-->

<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<relativePath>../..</relativePath>
<groupId>org.eclipse.gemoc.modeldebugging.xdsmlframework</groupId>
<artifactId>org.eclipse.gemoc.modeldebugging.xdsmlframework.root</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.gemoc.xdsmlframework.extensions.kermeta3</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
@@ -0,0 +1,95 @@
package org.eclipse.gemoc.xdsmlframework.extensions.kermeta3;

import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.gemoc.dsl.Dsl;
import org.eclipse.gemoc.dsl.Entry;
import org.eclipse.gemoc.xdsmlframework.api.extensions.metaprog.IRule;
import org.eclipse.gemoc.xdsmlframework.api.extensions.metaprog.Message;
import org.eclipse.gemoc.xdsmlframework.api.extensions.metaprog.Severity;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;

public class Kermeta3Rule implements IRule{

boolean tagTests;

public Kermeta3Rule(boolean performsTagTest) {
tagTests = performsTagTest;
}

@Override
public Message execute(Dsl dsl) {
ArrayList<String> entriesNames = new ArrayList<String>();

for (Entry e : dsl.getEntries()) {
entriesNames.add(e.getKey());
}

if(!entriesNames.contains("k3")) {
return (new Message("Missing entry \"k3\"", Severity.ERROR));
}

return (new Message("",Severity.DEFAULT));
}

@Override
public Message execute(Entry entry) {
if("k3".matches(entry.getKey())) {
String aspectsFields = entry.getValue();

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFile(new Path(entry.eResource().getURI().toPlatformString(true)));

IProject proj = file.getProject();
IJavaProject jProj = JavaCore.create(proj);

if(jProj == null) {
return (new Message("No project dsa in the workspace", Severity.ERROR));
}

ArrayList<String> aspectsName = new ArrayList<>();
ArrayList<String> aspectsAnnotation = new ArrayList<>();

for(String s : aspectsFields.split(",")) {
aspectsName.add(s.trim());
}


for(String asp : aspectsName) {
try {
IType type = jProj.findType(asp);
for(IMethod meth : type.getMethods()) {
for(IAnnotation annot : meth.getAnnotations()) {
aspectsAnnotation.add(annot.getElementName());
}
}
} catch (Exception e) {
return (new Message("No aspect matching \""+asp+ "\" in the project", Severity.ERROR));
}
}

if(tagTests) {

if(!aspectsAnnotation.contains("Main")) {
return (new Message("No method annotated with \"Main\" in the project", Severity.ERROR));
}

if(!aspectsAnnotation.contains("InitializeModel")) {
return (new Message("No method annotated with \"InitializeModel\" in the project", Severity.WARNING));
}

}

}
return (new Message("", Severity.DEFAULT));
}
}
3 changes: 2 additions & 1 deletion framework/xdsml_framework/pom.xml
Expand Up @@ -18,7 +18,8 @@
<!-- plugins -->
<module>plugins/org.eclipse.gemoc.xdsmlframework.ui.utils</module>
<module>plugins/org.eclipse.gemoc.xdsmlframework.ide.ui</module>
<module>plugins/org.eclipse.gemoc.xdsmlframework.extensions.sirius</module>
<module>plugins/org.eclipse.gemoc.xdsmlframework.extensions.sirius</module>
<module>plugins/org.eclipse.gemoc.xdsmlframework.extensions.kermeta3</module>
<module>tests/org.eclipse.gemoc.xdsmlframework.test.lib</module>

<!-- feature -->
Expand Down