Skip to content
Snippets Groups Projects
Commit 006fb56a authored by Etxaniz Errazkin, Iñaki's avatar Etxaniz Errazkin, Iñaki
Browse files

y1 commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 587 additions and 0 deletions
Source Code/PiacereIDEIntegration.KR03/Piacere/PiacereIcon_16x16.png

2.02 KiB

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
Piacere/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="PiacereToolCustomization.preferences.page1"
class="eu.piacere.ide.toolIntegration.kr03.preferencePage.KR03PreferencePage"
id="PiacereIDEIntegration.KR03.preferences.page1"
name="Infrastructural Code Generator Preferences">
</page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="eu.piacere.ide.toolIntegration.kr03.preferencePage.KR03PreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="eu.piacere.piacereModelsCommands.category.id"
defaultHandler="eu.piacere.ide.toolIntegration.kr03.commandHandlers.CodeGeneratorCommandHandler"
id="eu.piacere.piacereModelsCommands.codeGeneratorCommand.id"
name="Generate Code">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:eu.piacere.eclipsePopupMenu.id">
<command
commandId="eu.piacere.piacereModelsCommands.codeGeneratorCommand.id"
icon="Piacere/PiacereIcon_16x16.png"
label="Generate IaC Code"
style="push"
tooltip="Generate IaC code using DOML">
<visibleWhen
checkEnabled="false">
<reference
definitionId="eu.piacere.piacereTool.propertyTesters.extensionPropertyTester.isDOMLXModel.id">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
package eu.piacere.ide.toolIntegration.kr03.commandHandlers;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.json.JSONException;
import eu.piacere.piacereTool.utils.FileUtils;
import eu.piacere.piacereTool.utils.ToolCustomizationUtils;
public class CodeGeneratorCommandHandler extends AbstractHandler{
private void doPostRequestToValidator(String fileContent, String path, String defaultFileName) throws ClientProtocolException, IOException, JSONException {
HttpClient httpClient = HttpClientBuilder.create().build();
String url=ToolCustomizationUtils.getPreference(this.getClass(), "KR03.protocol")+"://"+ToolCustomizationUtils.getPreference(this.getClass(), "KR03.host")+":"+ToolCustomizationUtils.getPreference(this.getClass(), "KR03.port")+"/iac/files";
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(fileContent);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/xml");
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode()==200) {
String generationFileName=ToolCustomizationUtils.doDialogAsk("IaC Code Generator", "Enter the IaC Code File Name", defaultFileName);
FileOutputStream fos = new FileOutputStream(path + "//" + generationFileName+"_"+FileUtils.getTimestamp()+".tar.gz");
int br = -1;
byte[] buffer = new byte[4096];
while ((br = response.getEntity().getContent().read(buffer)) != -1 ) {
fos.write(buffer, 0, br);
}
fos.close();
}
else {
ToolCustomizationUtils.showErrorDialog("Code Generator", "Error: " + response.getStatusLine().getStatusCode() + ".\n\nCan not generate the IaC code.");
}
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ToolCustomizationUtils.saveWorkbench();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof StructuredSelection) {
if(((StructuredSelection)selection).getFirstElement() instanceof IFile){
IFile res = (IFile)((StructuredSelection) selection).getFirstElement();
String fileContent=FileUtils.getIFileContents(res);
if(fileContent==null) {
return null;
}
String path = res.getLocation().removeLastSegments(1).toString();
try {
doPostRequestToValidator(fileContent, path, res.getFullPath().lastSegment().replace(".domlx", ""));
res.getParent().refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (IOException | JSONException | CoreException e2) {
e2.printStackTrace();
}
}
}
return null;
}
}
package eu.piacere.ide.toolIntegration.kr03.preferencePage;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.FrameworkUtil;
import eu.piacere.ide.toolIntegration.kr03.preferencePage.KR03PreferenceInitializer;
public class KR03PreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
ScopedPreferenceStore scopedPreferenceStore = new ScopedPreferenceStore(ConfigurationScope.INSTANCE,(FrameworkUtil.getBundle(KR03PreferenceInitializer.class)).getSymbolicName());
scopedPreferenceStore.setDefault("KR03.host", "icg.ci.piacere.digital.tecnalia.dev");
scopedPreferenceStore.setDefault("KR03.port", 443);
scopedPreferenceStore.setDefault("KR03.protocol", "https");
}
}
\ No newline at end of file
package eu.piacere.ide.toolIntegration.kr03.preferencePage;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.FrameworkUtil;
public class KR03PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public KR03PreferencePage() {
super(GRID);
}
@Override
public void init(IWorkbench workbench) {
//WHICH SCOPE SHOULD I SELECT: https://wiki.eclipse.org/FAQ_What_is_a_preference_scope%3F
setPreferenceStore(new ScopedPreferenceStore(ConfigurationScope.INSTANCE, (FrameworkUtil.getBundle(KR03PreferenceInitializer.class)).getSymbolicName()));
setDescription("These Are The Infrastructural Code Generator Preferences");
}
@Override
protected void createFieldEditors() {
addField(new StringFieldEditor("KR03.host", "Endpoint Host", getFieldEditorParent()));
addField(new IntegerFieldEditor("KR03.port", "Endpoint Port", getFieldEditorParent()));
addField(new RadioGroupFieldEditor("KR03.protocol", "Protocol", 1, new String[][] {{"HTTP","http"},{"HTTPS","https"}}, getFieldEditorParent()));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PiacereIDEIntegration.KR05</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>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: KR05
Bundle-SymbolicName: PiacereIDEIntegration.KR05;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: PiacereIDEIntegration.KR05
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.apache.httpcomponents.httpcore
Import-Package: eu.piacere.doml.doml.commons,
eu.piacere.piacereTool.utils,
org.apache.commons.io,
org.apache.http.client;version="4.5.13",
org.apache.http.client.methods;version="4.5.13",
org.apache.http.impl.client;version="4.5.13",
org.eclipse.core.resources,
org.eclipse.core.runtime.preferences;version="3.4.0",
org.eclipse.emf.common.util,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.resource,
org.eclipse.emf.ecore.resource.impl,
org.eclipse.emf.ecore.util,
org.json
Source Code/PiacereIDEIntegration.KR05/Piacere/PiacereIcon_16x16.png

2.02 KiB

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
Piacere/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="PiacereToolCustomization.preferences.page1"
class="eu.piacere.ide.toolIntegration.kr05.preferencePage.KR05PreferencePage"
id="PiacereIDEIntegration.KR05.preferences.page1"
name="Model Checker Preferences">
</page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="eu.piacere.ide.toolIntegration.kr05.preferencePage.KR05PreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="eu.piacere.piacereModelsCommands.category.id"
defaultHandler="eu.piacere.ide.toolIntegration.kr05.commandHandlers.ValidateDOMLCommandHandler"
id="eu.piacere.piacereModelsCommands.validateDOMLCommand.id"
name="Validate DOML">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:eu.piacere.eclipsePopupMenu.id">
<command
commandId="eu.piacere.piacereModelsCommands.validateDOMLCommand.id"
icon="Piacere/PiacereIcon_16x16.png"
label="Validate DOML"
style="push"
tooltip="Validate the DOML Specification">
<visibleWhen
checkEnabled="false">
<reference
definitionId="eu.piacere.piacereTool.propertyTesters.extensionPropertyTester.isDOMLXModel.id">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
package eu.piacere.ide.toolIntegration.kr05.commandHandlers;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.json.JSONException;
import org.json.JSONObject;
import eu.piacere.piacereTool.utils.FileUtils;
import eu.piacere.piacereTool.utils.ToolCustomizationUtils;
public class ValidateDOMLCommandHandler extends AbstractHandler {
private JSONObject doPostRequestToValidator(String fileContent) throws ClientProtocolException, IOException, JSONException {
HttpClient httpClient = HttpClientBuilder.create().build();
String url=ToolCustomizationUtils.getPreference(this.getClass(), "KR05.protocol")+"://"+ToolCustomizationUtils.getPreference(this.getClass(), "KR05.host");
if(ToolCustomizationUtils.getPreference(this.getClass(), "KR05.port")!=null) {
if(!ToolCustomizationUtils.getPreference(this.getClass(), "KR05.port").equals("")) {
url=url+":"+ToolCustomizationUtils.getPreference(this.getClass(), "KR05.port");
}
}
url=url+"/modelcheck";
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(fileContent);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/xml");
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode()==200) {
String content = EntityUtils.toString(response.getEntity());
JSONObject responseAsJSON=new JSONObject(content);
return responseAsJSON;
}
else if(response.getStatusLine().getStatusCode()==400) {
String content = EntityUtils.toString(response.getEntity());
JSONObject responseAsJSON =new JSONObject(content);
ToolCustomizationUtils.showErrorDialog("Model Checking Result","Model Checker Raised an Error HTTP-400:\n Message:" + responseAsJSON.getString("message") + "\n Debug Message:" + responseAsJSON.getString("debug_message"));
return null;
}
else {
String content = EntityUtils.toString(response.getEntity());
ToolCustomizationUtils.showErrorDialog("Model Checking Result","Unknown error" + content);
return null;
}
}
private void saveFileInWorkspace(IContainer container, String fileContent, String defaultFileName) {
String domlModelName=ToolCustomizationUtils.doDialogAsk("DOML Model Validation", "Enter the DOML Model Validation Results File Name", defaultFileName);
ProgressMonitorDialog pd=new ProgressMonitorDialog(ToolCustomizationUtils.getActiveShell());
pd.open();
try {
FileUtils.createFile(domlModelName+"_"+FileUtils.getTimestamp()+".validation" , container, fileContent, pd);
} catch (Exception e1) {
e1.printStackTrace();
}
pd.close();
try {
container.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
private void interpretResult(JSONObject responseFromValidator) {
try {
if(responseFromValidator.getString("result").equals("sat")) {
ToolCustomizationUtils.showInformationDialog("Model Checking Result", "Your Requirements are SATISFIED");
}
else if(responseFromValidator.getString("result").equals("unsat")) {
ToolCustomizationUtils.showErrorDialog("Model Checking Result", "Your Requirements are UNSATISFIED:\n\n"+responseFromValidator.getString("description"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ToolCustomizationUtils.saveWorkbench();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof StructuredSelection) {
if(((StructuredSelection)selection).getFirstElement() instanceof IFile){
IFile res = (IFile)((StructuredSelection) selection).getFirstElement();
String fileContent=FileUtils.getIFileContents(res);
if(fileContent==null) {
//ARROJAR ERROR
return null;
}
JSONObject responseFromValidator=null;
try {
responseFromValidator=doPostRequestToValidator(fileContent);
} catch (IOException | JSONException e2) {
e2.printStackTrace();
}
if(responseFromValidator==null) {
//ARROJAR ERROR
return null;
}
interpretResult(responseFromValidator);
if(ToolCustomizationUtils.showQuestionDialog("Save Result", "Do you want to save the validation result on workspace?")) {
try {
saveFileInWorkspace(res.getParent(), responseFromValidator.toString(4), res.getFullPath().lastSegment().replace(".domlx", ""));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
return null;
}
}
package eu.piacere.ide.toolIntegration.kr05.preferencePage;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.FrameworkUtil;
public class KR05PreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
ScopedPreferenceStore scopedPreferenceStore = new ScopedPreferenceStore(ConfigurationScope.INSTANCE,(FrameworkUtil.getBundle(KR05PreferenceInitializer.class)).getSymbolicName());
scopedPreferenceStore.setDefault("KR05.host", "dmc.ci.piacere.digital.tecnalia.dev");
scopedPreferenceStore.setDefault("KR05.port", 443);
scopedPreferenceStore.setDefault("KR05.protocol", "https");
}
}
package eu.piacere.ide.toolIntegration.kr05.preferencePage;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.FrameworkUtil;
public class KR05PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public KR05PreferencePage() {
super(GRID);
}
@Override
public void init(IWorkbench workbench) {
//WHICH SCOPE SHOULD I SELECT: https://wiki.eclipse.org/FAQ_What_is_a_preference_scope%3F
setPreferenceStore(new ScopedPreferenceStore(ConfigurationScope.INSTANCE, (FrameworkUtil.getBundle(KR05PreferenceInitializer.class)).getSymbolicName()));
setDescription("Model Checker Preferences");
}
@Override
protected void createFieldEditors() {
StringFieldEditor hostFieldEditor = new StringFieldEditor("KR05.host", "Endpoint Host", getFieldEditorParent());
addField(hostFieldEditor);
IntegerFieldEditor portfieldeditor= new IntegerFieldEditor("KR05.port", "Endpoint Port", getFieldEditorParent());
addField(portfieldeditor);
RadioGroupFieldEditor protocolFieldEditor = new RadioGroupFieldEditor("KR05.protocol", "Protocol", 1, new String[][] {{"HTTP","http"},{"HTTPS","https"}}, getFieldEditorParent());
addField(protocolFieldEditor);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PiacereIDEIntegration.KR06And07</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>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: KR06And07
Bundle-SymbolicName: PiacereIDEIntegration.KR06And07;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: VRAIN
Automatic-Module-Name: PiacereIDEIntegration.KR06And07
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.apache.httpcomponents.httpcore
Import-Package: eu.piacere.doml.doml.commons,
eu.piacere.piacereTool.utils,
org.apache.commons.io,
org.apache.http.client;version="4.5.13",
org.apache.http.client.methods;version="4.5.13",
org.apache.http.entity.mime;version="4.5.13",
org.apache.http.entity.mime.content;version="4.5.13",
org.apache.http.impl.client;version="4.5.13",
org.eclipse.core.resources,
org.eclipse.core.runtime.preferences;version="3.4.0",
org.eclipse.emf.common.util,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.resource,
org.eclipse.emf.ecore.resource.impl,
org.eclipse.emf.ecore.util,
org.json
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment