Skip to content
Snippets Groups Projects
Commit b2fe96b2 authored by Thomas's avatar Thomas
Browse files

removed error output when using cached source model

parent 72dbe721
Branches
No related tags found
No related merge requests found
......@@ -6,18 +6,18 @@ import java.net.URL;
import java.util.List;
import org.eclipse.core.runtime.Platform;
import org.eclipse.epsilon.common.parse.problem.ParseProblem;
import org.eclipse.epsilon.eol.IEolExecutableModule;
import org.eclipse.epsilon.eol.IEolModule;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.models.IModel;
import org.osgi.framework.Bundle;
public abstract class EpsilonStandalone {
protected IEolExecutableModule module;
protected IEolModule module;
protected Object result;
public abstract IEolExecutableModule createModule();
public abstract IEolModule createModule();
public abstract String getSource();
......@@ -47,7 +47,7 @@ public abstract class EpsilonStandalone {
module.getContext().getModelRepository().dispose();
}
protected Object execute(IEolExecutableModule module) throws EolRuntimeException {
protected Object execute(IEolModule module) throws EolRuntimeException {
return module.execute();
}
......
......@@ -17,18 +17,21 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.epsilon.emc.emf.EmfModel;
import org.eclipse.epsilon.eol.IEolExecutableModule;
import org.eclipse.epsilon.eol.IEolModule;
import org.eclipse.epsilon.eol.dt.ExtensionPointToolNativeTypeDelegate;
import org.eclipse.epsilon.eol.models.IModel;
import org.eclipse.epsilon.etl.EtlModule;
import org.osgi.framework.Bundle;
/**
* the class is needed to perform the model transformation from the IORM to the CROM
* the class is needed to perform the model transformation from the IORM to the
* CROM
*
* @author Kevin Kassin
*/
public class TransformationExecutor extends EpsilonStandalone {
......@@ -58,8 +61,7 @@ public class TransformationExecutor extends EpsilonStandalone {
*/
private final List<File> copiedAndGeneratedFiles;
private final String generatedFolder = "generated",
generatedFile = "generatedORM2CROM.etl",
private final String generatedFolder = "generated", generatedFile = "generatedORM2CROM.etl",
importMarker = "/*{generate imports here}*/";
/**
......@@ -67,14 +69,18 @@ public class TransformationExecutor extends EpsilonStandalone {
* <p>
* It uses the following steps:<br>
* Step 1: It get the url and file to the folder 'epsilon' of this package.<br>
* Step 2: It searches for all etl files in the core and module source folder of the UI package.<br>
* Step 3: It (a) copies them into the epsilon folder of this package. This is needed to avoid a cycle of
* dependencies between the UI and the Transformation package. It (b) also add the copied file to
* Step 2: It searches for all etl files in the core and module source folder of
* the UI package.<br>
* Step 3: It (a) copies them into the epsilon folder of this package. This is
* needed to avoid a cycle of dependencies between the UI and the Transformation
* package. It (b) also add the copied file to
* {@link #copiedAndGeneratedFiles}.<br>
* Step 4: It generated a second ORM2CROM.etl file with the needed imports and sets it as {@link #transformationFile}<br>
* Step 4: It generated a second ORM2CROM.etl file with the needed imports and
* sets it as {@link #transformationFile}<br>
* <p>
* Note: The {@link FileAlreadyExistsException} is ignored in this constructor since its ok, when a file can not be
* copied with this reason. The files only need to be copied once.
* Note: The {@link FileAlreadyExistsException} is ignored in this constructor
* since its ok, when a file can not be copied with this reason. The files only
* need to be copied once.
*/
public TransformationExecutor() {
sourceModelFile = null;
......@@ -85,7 +91,10 @@ public class TransformationExecutor extends EpsilonStandalone {
File epsilonFolder = null;
try {
epsilonFolder = new File(resolveURL(FileLocator.resolve(epsilonFolderURL)));
} catch (URISyntaxException | IOException e1) { e1.printStackTrace(); };
} catch (URISyntaxException | IOException e1) {
e1.printStackTrace();
}
;
if (epsilonFolder == null) {
System.err.println("No folder 'epsilon' found");
return;
......@@ -94,52 +103,68 @@ public class TransformationExecutor extends EpsilonStandalone {
List<URL> moduleFileURLs = null, coreFileURLs = null;
Enumeration<URL> moduleFileEnumeration = UIBundle.findEntries("/modules", "*.etl", true),
coreFileEnumeration = UIBundle.findEntries("/core", "*.etl", true);
if(moduleFileEnumeration != null) moduleFileURLs = Collections.list(moduleFileEnumeration);
if((coreFileEnumeration != null)) coreFileURLs = Collections.list(coreFileEnumeration);
if (moduleFileEnumeration != null)
moduleFileURLs = Collections.list(moduleFileEnumeration);
if ((coreFileEnumeration != null))
coreFileURLs = Collections.list(coreFileEnumeration);
// Step 3
File etlFile = null;
List<String> importNames = new ArrayList<String>();
if (moduleFileURLs != null) {
for (URL url : moduleFileURLs) {
if(!packageMarkedAsNotUsed(url.toString(), "modules/") &&
!packageETLFilesMarkedAsNotUsed(url.toString(), "modules/")) {
if (!packageMarkedAsNotUsed(url.toString(), "modules/")
&& !packageETLFilesMarkedAsNotUsed(url.toString(), "modules/")) {
// (a)
try {
etlFile = new File(resolveURL(FileLocator.resolve(url)));
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
try {
try {
Path path = Files.copy(Paths.get(etlFile.getPath()),
Paths.get(epsilonFolder.getPath() + File.separator + File.separator + generatedFolder + File.separator + etlFile.getName()),
Paths.get(epsilonFolder.getPath() + File.separator + File.separator
+ generatedFolder + File.separator + etlFile.getName()),
StandardCopyOption.REPLACE_EXISTING);
copiedAndGeneratedFiles.add(new File(path.toString()));
// Note
} catch (FileAlreadyExistsException e) {}
} catch (IOException e) { e.printStackTrace(); }
} catch (FileAlreadyExistsException e) {
}
} catch (IOException e) {
e.printStackTrace();
}
// (b)
importNames.add(etlFile.getName());
} }
}
}
}
if (coreFileURLs != null) {
for (URL url : coreFileURLs) {
if(!packageMarkedAsNotUsed(url.toString(), "core/") &&
!packageETLFilesMarkedAsNotUsed(url.toString(), "core/")) {
if (!packageMarkedAsNotUsed(url.toString(), "core/")
&& !packageETLFilesMarkedAsNotUsed(url.toString(), "core/")) {
// (a)
try {
etlFile = new File(resolveURL(FileLocator.resolve(url)));
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
try {
try {
Path path = Files.copy(Paths.get(etlFile.getPath()),
Paths.get(epsilonFolder.getPath() + File.separator + File.separator + generatedFolder + File.separator + etlFile.getName()),
Paths.get(epsilonFolder.getPath() + File.separator + File.separator
+ generatedFolder + File.separator + etlFile.getName()),
StandardCopyOption.REPLACE_EXISTING);
copiedAndGeneratedFiles.add(new File(path.toString()));
// Note
} catch (FileAlreadyExistsException e) {}
} catch (IOException e) { e.printStackTrace(); }
} catch (FileAlreadyExistsException e) {
}
} catch (IOException e) {
e.printStackTrace();
}
// (b)
importNames.add(etlFile.getName());
} }
}
}
}
// Step 4
generateORM2CROMWithImports(importNames, epsilonFolder);
......@@ -148,6 +173,7 @@ public class TransformationExecutor extends EpsilonStandalone {
/**
* checks if the package part of a file url starts and ends with an _
*
* @param url the string url to check against
* @param sourceFolder the source folder in which the class is located in
* @return if the package part of a class url starts and ends with an _
......@@ -155,12 +181,14 @@ public class TransformationExecutor extends EpsilonStandalone {
public boolean packageMarkedAsNotUsed(String url, String sourceFolder) {
url = url.substring(url.indexOf(sourceFolder) + sourceFolder.length());
url = url.substring(0, url.indexOf("/"));
if(url.startsWith("_")) return true;
if (url.startsWith("_"))
return true;
return false;
}
/**
* checks if the etl file name part of a file url starts and ends with an _
*
* @param url the string url to check against
* @param sourceFolder the source folder in which the class is located in
* @return if the etl file name part of a url starts and ends with an _
......@@ -168,19 +196,21 @@ public class TransformationExecutor extends EpsilonStandalone {
public boolean packageETLFilesMarkedAsNotUsed(String url, String sourceFolder) {
url = url.substring(url.indexOf(sourceFolder) + sourceFolder.length());
url = url.substring(url.indexOf("/") + 1, url.indexOf(".etl"));
if(url.startsWith("_")) return true;
if (url.startsWith("_"))
return true;
return false;
}
/**
* generates a second ORM2CROM.etl file with the needed imports of file found in importNames using the following
* steps:
* generates a second ORM2CROM.etl file with the needed imports of file found in
* importNames using the following steps:
* <p>
* Step 1: It gets the original ORM2CROM file.<br>
* Step 2: It reads the text content of the original ORM2CROM file.<br>
* Step 3: It adds the needed imports to the text content.<br>
* Step 4: It generates a new file with the changed text content and adds the generated file to
* {@link #copiedAndGeneratedFiles}.
* Step 4: It generates a new file with the changed text content and adds the
* generated file to {@link #copiedAndGeneratedFiles}.
*
* @param importNames the list of names of needed imports
* @param epsilonFolder the folder to create the generated file in
* @return the name of the generated file
......@@ -202,13 +232,16 @@ public class TransformationExecutor extends EpsilonStandalone {
fileText = fileText + str + "\n";
}
buff.close();
} catch (URISyntaxException | IOException e) { e.printStackTrace(); }
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
// Step 3
for (String s : importNames)
fileText = fileText.replace(importMarker, importMarker + "\n import \"" + s + "\";\n");
// Step 4
try {
String generatedORM2CROMPath = epsilonFolder.getPath() + File.separator + File.separator + generatedFolder + File.separator + generatedFile;
String generatedORM2CROMPath = epsilonFolder.getPath() + File.separator + File.separator
+ generatedFolder + File.separator + generatedFile;
File generatedORM2CROM = new File(generatedORM2CROMPath);
generatedORM2CROM.createNewFile();
copiedAndGeneratedFiles.add(generatedORM2CROM);
......@@ -216,7 +249,9 @@ public class TransformationExecutor extends EpsilonStandalone {
for (int i = 0; i < fileText.length(); i++)
fileOutputStream.write((byte) fileText.charAt(i));
fileOutputStream.close();
} catch (Exception e) { e.printStackTrace(); }
} catch (Exception e) {
e.printStackTrace();
}
}
return generatedFile;
}
......@@ -226,11 +261,14 @@ public class TransformationExecutor extends EpsilonStandalone {
*/
public void deleteCopiedAndGeneratedFiles() {
for (File file : copiedAndGeneratedFiles) {
if(file.exists()) file.delete();
} }
if (file.exists())
file.delete();
}
}
/**
* getter method for {@link module}
*
* @return the module that belongs to the {@link #transformationFile}
*/
public String getModule() {
......@@ -239,6 +277,7 @@ public class TransformationExecutor extends EpsilonStandalone {
/**
* getter method for {@link sourceModelFile}
*
* @return the IORM model file
*/
public Resource getSourceModelFile() {
......@@ -254,6 +293,7 @@ public class TransformationExecutor extends EpsilonStandalone {
/**
* getter method for {@link targetModelFile}
*
* @return the CROM model file
*/
public Resource getTargetModelFile() {
......@@ -269,6 +309,7 @@ public class TransformationExecutor extends EpsilonStandalone {
/**
* sets the {@link #transformationFile} as forced transforamtion file
*
* @param transformationFileName the name of the transformation to set
*/
public void setForcedTransformation(String transformationFileName) {
......@@ -279,7 +320,7 @@ public class TransformationExecutor extends EpsilonStandalone {
* creates a module with the extension point to the native java classes
*/
@Override
public IEolExecutableModule createModule() {
public IEolModule createModule() {
EtlModule module = new EtlModule();
module.getContext().getNativeTypeDelegates().add(new ExtensionPointToolNativeTypeDelegate());
return module;
......@@ -304,6 +345,18 @@ public class TransformationExecutor extends EpsilonStandalone {
emfModel.setMetamodelUri("http://iorm/1.0");
emfModel.setModelFileUri(sourceModelFile.getURI());
emfModel.setReadOnLoad(true);
/*
* Disabled caching due to Error of the unknown Diagram element, as the source
* model also contains model elements of the pictogram model of Graphiti.
*
* Cannot find meta-class 'Diagram' in model 'source' at
* org.eclipse.epsilon.emc.emf.AbstractEmfModel.classForName(AbstractEmfModel.
* java:214) at org.eclipse.epsilon.emc.emf.AbstractEmfModel.getCacheKeyForType(
* AbstractEmfModel.java:198) at
* org.eclipse.epsilon.eol.models.CachedModel.removeFromCache(CachedModel.java:
* 98)
*/
emfModel.setCachingEnabled(false);
emfModel.setStoredOnDisposal(true);
emfModel.setName("source");
emfModel.load();
......@@ -322,8 +375,9 @@ public class TransformationExecutor extends EpsilonStandalone {
}
/**
* Translator from URLs to URIs that creates correct URIs, in contrast to URL.toURI().
* (cf. https://stackoverflow.com/questions/14676966/escape-result-of-filelocator-resolveurl/14677157)
* Translator from URLs to URIs that creates correct URIs, in contrast to
* URL.toURI(). (cf.
* https://stackoverflow.com/questions/14676966/escape-result-of-filelocator-resolveurl/14677157)
*
* @param url the given URL
* @return a new correctly initialized URI object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment