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

WIP: Integrate changes for IBeX v2 - HiPE stateless (v2) #5

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4995aba
+ adjustments for new emoflon GT Api
arg0n1s Oct 20, 2022
b8fde1f
+ removed final compile errors
arg0n1s Oct 20, 2022
c33880a
fixed class name
arg0n1s Oct 21, 2022
eea23bd
minor fixes
arg0n1s Oct 21, 2022
5030f77
minor fix -> initialize must be called explicitly
arg0n1s Oct 26, 2022
94d38b1
+ fixed invalid edge naming
arg0n1s Oct 26, 2022
9e3f031
+ added missing comparator cases to transformation
arg0n1s Nov 9, 2022
d412863
+ fixed string literals in expressions
arg0n1s Nov 11, 2022
138b5e2
removed legacy code
Arikae Nov 21, 2022
888806e
Merge branch 'master' into refactoring_GT_TGG
Arikae Mar 2, 2023
8cac5ff
first version of hipe tgg engine
Arikae Mar 11, 2023
3310bc1
first version of hipe tgg engine
Arikae Mar 11, 2023
70126b2
started implementing tggCore2HiPE
Arikae Mar 15, 2023
825d455
implemented tgg to hipe
Arikae Mar 17, 2023
2c69982
added consistency as an operationalisation mode
Arikae Mar 17, 2023
f414b52
started connecting trafo to generate code
Arikae Mar 17, 2023
442eed2
fixed pipeline
Arikae Mar 17, 2023
c49385a
added new extension for generating tgg hipe code
Arikae Mar 18, 2023
ef4bb0b
hipe tgg code gen is now called
Arikae Mar 19, 2023
b7d3df4
fixed some npes
Arikae Mar 20, 2023
c02fe98
started fixing csp code generation
Arikae Mar 21, 2023
f066a89
fixed parts of tgg stub generation
Arikae Mar 22, 2023
5f8fcf2
fixed hipe registration helper
Arikae Mar 23, 2023
f3c1a7e
fixed problems with TGG stubs
Arikae Mar 23, 2023
84d62e5
fixed tgg engine not being initialized
Arikae Apr 1, 2023
09534df
fixed csp imports
Arikae Apr 1, 2023
a2f1a80
fixed a npe within HiPETGGEngine.java
Arikae Apr 1, 2023
51ade99
fixed a problem with generated string literals in hipe
Arikae Apr 2, 2023
2e569a7
now created src-gen and gen folder in case they are missing
Arikae Apr 11, 2023
9da6f83
reworked csp factory registration
Arikae Apr 17, 2023
4e2a8f0
now using correct relational operators for node comparisons
Arikae Apr 19, 2023
0020c59
fixed missing forward and backward rules
Arikae Apr 20, 2023
df268b2
moved HiPEBuilderUtil to emoflon-ibex
Arikae Apr 25, 2023
b3d8e93
gen folder is no longer cleared by hipe builder extension
Arikae Apr 26, 2023
fde6f38
fixed a problem where relational constraints with strings were not co…
Arikae May 2, 2023
755c815
Removed non-flattened TGG option
adrianmoeller May 4, 2023
317ec93
changed csp transformation
Arikae May 23, 2023
7f4483d
stateless hipe does not support container edges which have to be swit…
Arikae Aug 20, 2023
feb3cdb
activating stateless searchplan for GT
Arikae Sep 7, 2023
cf8de04
Removing bundle version requirement for smartemf from *gt.hipe
Arikae Feb 20, 2024
5f7c1a1
Merge remote-tracking branch 'origin/master' into stateless-hipe-inte…
maxkratz Feb 20, 2024
1b0af7e
Merge remote-tracking branch 'origin/master' into stateless-hipe-inte…
maxkratz Jun 18, 2024
deceb7a
Adds missing GT engine termination call
maxkratz Jun 25, 2024
1f87959
Merge remote-tracking branch 'origin/master' into stateless-hipe-inte…
maxkratz Sep 4, 2024
e0d07ad
added terminate statement to HiPETGGEngine
Arikae Aug 6, 2024
5883634
code refactoring of TGGHiPEBuilderExtension
Arikae Oct 23, 2024
6554af3
Merge branch 'master' into stateless-hipe-integration
maxkratz Nov 8, 2024
7ac4573
HiPEPathOptions: singleton pattern changes from upstream
maxkratz Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions org.emoflon.ibex.gt.hipe/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ Require-Bundle: net.sourceforge.plantuml.eclipse;bundle-version="1.1.24",
hipe.searchplan;bundle-version="1.0.0",
org.moflon.core.utilities,
org.emoflon.ibex.common,
org.emoflon.ibex.gt.editor.ui,
org.moflon.core.plugins,
org.moflon.core.ui,
org.emoflon.ibex.gt,
org.emoflon.ibex.patternmodel,
org.emoflon.ibex.tgg.runtime;visibility:=reexport,
org.emoflon.smartemf;bundle-version="1.0.0"
org.emoflon.smartemf,
org.emoflon.ibex.gt.gtmodel
Automatic-Module-Name: org.emoflon.ibex.gt.democles
Bundle-RequiredExecutionEnvironment: JavaSE-21
Export-Package: org.emoflon.ibex.gt.hipe.ide.codegen,
org.emoflon.ibex.gt.hipe.runtime,
Export-Package: org.emoflon.ibex.gt.build.hipe,
org.emoflon.ibex.gt.engine.hipe,
org.emoflon.ibex.gt.hipe.visualization
22 changes: 13 additions & 9 deletions org.emoflon.ibex.gt.hipe/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.emoflon.ibex.gt.GTEngineExtension">
<engine_extension class="org.emoflon.ibex.gt.hipe.ide.codegen.GTHiPEExtension"/>
</extension>
<extension
point="org.emoflon.ibex.gt.GTEngineBuilderExtension">
<builder_extension
class="org.emoflon.ibex.gt.hipe.ide.codegen.GTHiPEBuilderExtension">
</builder_extension>
</extension>
<extension
point="org.moflon.core.ui.DiagramTextProvider">
<diagram_text_provider
Expand All @@ -22,6 +13,19 @@
class="org.emoflon.ibex.gt.hipe.visualization.HiPEPatternModelVisualiser">
</diagram_text_provider>
</extension>
<extension
point="org.emoflon.ibex.common.IBeXPMEngineExtension">
<engine_extension
engine_extension="org.emoflon.ibex.gt.engine.hipe.HiPEPatternMatchingEngine"
engine_information="org.emoflon.ibex.gt.engine.hipe.GTHiPEExtension">
</engine_extension>
</extension>
<extension
point="org.emoflon.ibex.gt.IBeXGTEngineBuilderExtension">
<builder_extension
class="org.emoflon.ibex.gt.build.hipe.GTHiPEBuilderExtension">
</builder_extension>
</extension>


</plugin>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.emoflon.ibex.gt.hipe.ide.codegen;
package org.emoflon.ibex.gt.build.hipe;

import java.io.File;
import java.io.IOException;
Expand All @@ -10,7 +10,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -21,10 +20,8 @@
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.emoflon.ibex.common.project.BuildPropertiesHelper;
import org.emoflon.ibex.common.project.ManifestHelper;
import org.emoflon.ibex.gt.codegen.GTEngineBuilderExtension;
import org.emoflon.ibex.gt.hipe.runtime.IBeXToHiPEPatternTransformation;
import org.emoflon.ibex.patternmodel.IBeXPatternModel.IBeXModel;
import org.emoflon.ibex.patternmodel.IBeXPatternModel.IBeXPatternSet;
import org.emoflon.ibex.gt.build.IBeXGTEngineBuilderExtension;
import org.emoflon.ibex.gt.gtmodel.IBeXGTModel.GTModel;
import org.moflon.core.plugins.manifest.ManifestFileUpdater;
import org.moflon.core.utilities.ClasspathUtil;
import org.moflon.core.utilities.LogUtils;
Expand All @@ -34,27 +31,27 @@
import hipe.network.HiPENetwork;
import hipe.pattern.HiPEContainer;
import hipe.searchplan.SearchPlan;
import hipe.searchplan.simple.StatelessSearchPlan;
import hipe.searchplan.simple.TriangleSearchPlan;

public class GTHiPEBuilderExtension implements GTEngineBuilderExtension{
public class GTHiPEBuilderExtension implements IBeXGTEngineBuilderExtension {

public static final String BUILDER_ID = "org.emoflon.ibex.gt.editor.ui.hipe.builder";
private static Logger logger = Logger.getLogger(GTHiPEBuilderExtension.class);

private String packageName;
private String packagePath;
private String projectPath;

@Override
public void run(IProject project, IPath packagePath, IBeXModel ibexModel) {
LogUtils.info(logger, "## HiPE ## Generating HiPE-Engine code..");
public void run(IProject project, GTModel ibexModel) {
LogUtils.info(logger, "## HiPE ## Generating HiPE-Engine code..");
double tic = System.currentTimeMillis();

packageName = packagePath.toString().replace("/", ".");

IBeXPatternSet ibexPatterns = ibexModel.getPatternSet();

projectPath = project.getLocation().toPortableString();
packageName = ibexModel.getMetaData().getPackage();
projectPath = ibexModel.getMetaData().getProjectPath();
packagePath = projectPath + "/" + ibexModel.getMetaData().getPackagePath();

LogUtils.info(logger, "Cleaning old code..");
cleanOldCode();

Expand All @@ -67,28 +64,30 @@ public void run(IProject project, IPath packagePath, IBeXModel ibexModel) {
} catch (CoreException e1) {
LogUtils.error(logger, e1.getMessage());
}

LogUtils.info(logger, "Converting IBeX to HiPE Patterns..");
IBeXToHiPEPatternTransformation transformation = new IBeXToHiPEPatternTransformation();
HiPEContainer container = transformation.transform(ibexPatterns);
HiPEContainer container = transformation.transform(ibexModel);

LogUtils.info(logger, "Creating search plan & generating Rete network..");
SearchPlan searchPlan = new TriangleSearchPlan(container);
SearchPlan searchPlan = new StatelessSearchPlan(container);
// SearchPlan searchPlan = new TriangleSearchPlan(container);
// SearchPlan searchPlan = new SimpleSearchPlan(container);
searchPlan.generateSearchPlan();
HiPENetwork network = searchPlan.getNetwork();

LogUtils.info(logger, "Generating Code..");
HiPEGeneratorConfig config = new HiPEGeneratorConfig();
HiPEGenerator.generateCode(packageName+".", projectPath, network, config);

config.setEnforcedBidirectionalRefs(true);
HiPEGenerator.generateCode(packageName + ".", projectPath, network, config);

double toc = System.currentTimeMillis();
LogUtils.info(logger, "Code generation completed in "+ (toc-tic)/1000.0 + " seconds.");
LogUtils.info(logger, "Code generation completed in " + (toc - tic) / 1000.0 + " seconds.");

LogUtils.info(logger, "Saving HiPE patterns and HiPE network..");
saveResource(container, projectPath + "/src-gen/" + packagePath.toString() +"/hipe/engine/hipe-patterns.xmi");
saveResource(network, projectPath + "/src-gen/" + packagePath.toString() +"/hipe/engine/hipe-network.xmi");
saveResource(container, packagePath.replace("src", "src-gen") + "/hipe/engine/hipe-patterns.xmi");
saveResource(network, packagePath.replace("src", "src-gen") + "/hipe/engine/hipe-network.xmi");

LogUtils.info(logger, "Refreshing workspace and cleaning build ..");
try {
project.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
Expand All @@ -97,98 +96,100 @@ public void run(IProject project, IPath packagePath, IBeXModel ibexModel) {
}
LogUtils.info(logger, "## HiPE ## --> HiPE build complete!");
}

private void updateManifest(IProject project) {
try {
IFile manifest = ManifestFileUpdater.getManifestFile(project);
ManifestHelper helper = new ManifestHelper();
helper.loadManifest(manifest);

File rawManifest = new File(projectPath+"/"+manifest.getFullPath().removeFirstSegments(1).toPortableString());

File rawManifest = new File(
projectPath + "/" + manifest.getFullPath().removeFirstSegments(1).toPortableString());

helper.updateManifest(rawManifest);

} catch (CoreException | IOException e) {
LogUtils.error(logger, "Failed to update MANIFEST.MF \n"+e.getMessage());
LogUtils.error(logger, "Failed to update MANIFEST.MF \n" + e.getMessage());
}
}

private void updateBuildProperties() {
File buildProps = new File(projectPath+"/build.properties");
File buildProps = new File(projectPath + "/build.properties");
BuildPropertiesHelper helper = new BuildPropertiesHelper();
try {
helper.loadProperties(buildProps);
if(!helper.containsSection("source..")) {

if (!helper.containsSection("source..")) {
helper.appendSection("source..");
}
if(!helper.sectionContainsContent("source..", "src-gen/")) {

if (!helper.sectionContainsContent("source..", "src-gen/")) {
helper.addContentToSection("source..", "src-gen/");
}

helper.updateProperties(buildProps);

} catch (CoreException | IOException e) {
LogUtils.error(logger, "Failed to update build.properties \n"+e.getMessage());
LogUtils.error(logger, "Failed to update build.properties \n" + e.getMessage());
}

}

private static boolean deleteDirectory(File dir) {
File[] contents = dir.listFiles();
if(contents != null) {
for(File file : contents) {
File[] contents = dir.listFiles();
if (contents != null) {
for (File file : contents) {
deleteDirectory(file);
}
}
return dir.delete();
}

private static void createNewDirectory(String path) {
File dir = new File(path);
if(!dir.exists()) {
if(!dir.mkdir()) {
LogUtils.error(logger, "Directory in: "+path+" could not be created!");
}else {
LogUtils.info(logger, "--> Directory in: "+path+" created!");
if (!dir.exists()) {
if (!dir.mkdir()) {
LogUtils.error(logger, "Directory in: " + path + " could not be created!");
} else {
LogUtils.info(logger, "--> Directory in: " + path + " created!");
}
}else {
LogUtils.info(logger, "--> Directory already present in: "+path+", nothing to do.");
} else {
LogUtils.info(logger, "--> Directory already present in: " + path + ", nothing to do.");
}
}

private void cleanOldCode() {
File dir = new File(projectPath+"/src-gen/" + packageName.replace(".", "//") + "/hipe");
if(dir.exists()) {
LogUtils.info(logger, "--> Cleaning old source files in root folder: "+projectPath+"/src-gen/" + packageName.replace(".", "//") + "/hipe");
if(!deleteDirectory(dir)) {
File dir = new File(projectPath + "/src-gen/" + packageName.replace(".", "//") + "/hipe");
if (dir.exists()) {
LogUtils.info(logger, "--> Cleaning old source files in root folder: " + projectPath + "/src-gen/"
+ packageName.replace(".", "//") + "/hipe");
if (!deleteDirectory(dir)) {
LogUtils.error(logger, "Folder couldn't be deleted!");
}
} else {
LogUtils.info(logger, "--> No previously generated code found, nothing to do!");
}
}

public static void saveResource(EObject model, String path) {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());

URI uri = URI.createFileURI(path);
Resource modelResource = rs.createResource(uri);
modelResource.getContents().add(model);
Map<Object, Object> saveOptions = ((XMIResource)modelResource).getDefaultSaveOptions();
saveOptions.put(XMIResource.OPTION_ENCODING,"UTF-8");

Map<Object, Object> saveOptions = ((XMIResource) modelResource).getDefaultSaveOptions();
saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8");
saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION,Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION, Boolean.TRUE);

try {
((XMIResource)modelResource).save(saveOptions);
((XMIResource) modelResource).save(saveOptions);
} catch (IOException e) {
LogUtils.error(logger, "Couldn't save debug resource: \n "+e.getMessage());
LogUtils.error(logger, "Couldn't save debug resource: \n " + e.getMessage());
}
}

Expand Down
Loading