Skip to content

Commit

Permalink
Cleanup Code + Remove data parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Graband <[email protected]>
  • Loading branch information
sgraband authored and CamilleLetavernier committed Sep 17, 2020
1 parent 2a8e87a commit 854875d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 38 deletions.
45 changes: 22 additions & 23 deletions client/theia-ecore/src/node/ecore-file-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ export class EcoreFileGenServer implements FileGenServer, BackendApplicationCont
@inject(ILogger) private readonly logger: ILogger) { }

generateEcore(name: string, prefix: string, uri: string, workspacePath: string): Promise<string> {
const jarPath = path.resolve(__dirname, "..", "..", "..", "..",
"server", "org.eclipse.emfcloud.ecore.backend-app", "org.eclipse.emfcloud.ecore.codegen.product",
"target", "products", "org.eclipse.emfcloud.ecore.codegen.product", "linux", "gtk", "x86_64", "plugins",
"org.eclipse.equinox.launcher_1.5.600.v20191014-2022.jar");
if (jarPath.length === 0) {
throw new Error("The eclipse.equinox.launcher is not found. ");
}
const jarPath = this.getEclipseProductJar();

const command = "java";
const args: string[] = [];
Expand All @@ -43,7 +37,6 @@ export class EcoreFileGenServer implements FileGenServer, BackendApplicationCont
args.push(
"-cp", jarPath,
"org.eclipse.equinox.launcher.Main",
"-data", workspacePath,
"-application", "org.eclipse.emfcloud.ecore.backend.app.create-ecore",
name, prefix, uri, platformWorkspacePath
);
Expand All @@ -59,27 +52,24 @@ export class EcoreFileGenServer implements FileGenServer, BackendApplicationCont
process.process.on("exit", (code: any) => {
switch (code) {
case 0: resolve("OK"); break;
case -10: resolve("Name is missing"); break;
case -11: resolve("Prefix is missing"); break;
case -12: resolve("Uri is missing"); break;
case -13: resolve("Workspace Path is missing"); break;
default: resolve("UNKNOWN ERROR"); break;
}
});
});
}

generateGenModel(workspacePath: string,ecorePath: string, customPackageName: string, folderName: string): Promise<string> {
const jarPath = path.resolve(__dirname, "..", "..", "..", "..",
"server", "org.eclipse.emfcloud.ecore.backend-app", "org.eclipse.emfcloud.ecore.codegen.product",
"target", "products", "org.eclipse.emfcloud.ecore.codegen.product", "linux", "gtk", "x86_64", "plugins",
"org.eclipse.equinox.launcher_1.5.600.v20191014-2022.jar");
if (jarPath.length === 0) {
throw new Error("The eclipse.equinox.launcher is not found. ");
}
const jarPath = this.getEclipseProductJar();

const command = "java";
const args: string[] = [];
args.push(
"-cp", jarPath,
"org.eclipse.equinox.launcher.Main",
"-data", workspacePath,
"-application", "org.eclipse.emfcloud.ecore.backend.app.create-genmodel",
ecorePath, customPackageName, folderName
);
Expand All @@ -101,20 +91,17 @@ export class EcoreFileGenServer implements FileGenServer, BackendApplicationCont
process.process.on("exit", (code: any) => {
switch (code) {
case 0: resolve("OK"); break;
case -10: resolve("Ecore File Path is missing"); break;
case -11: resolve("Custom Root Package is missing"); break;
case -12: resolve("Outputfolder is missing"); break;
default: resolve("UNKNOWN ERROR " + code); break;
}
});
});
}

generateCode(genmodelPath: string, workspacePath: string): Promise<string> {
const jarPath = path.resolve(__dirname, "..", "..", "..", "..",
"server", "org.eclipse.emfcloud.ecore.backend-app", "org.eclipse.emfcloud.ecore.codegen.product",
"target", "products", "org.eclipse.emfcloud.ecore.codegen.product", "linux", "gtk", "x86_64", "plugins",
"org.eclipse.equinox.launcher_1.5.600.v20191014-2022.jar");
if (jarPath.length === 0) {
throw new Error("The eclipse.equinox.launcher is not found. ");
}
const jarPath = this.getEclipseProductJar();

const command = "java";
const args: string[] = [];
Expand Down Expand Up @@ -155,6 +142,18 @@ export class EcoreFileGenServer implements FileGenServer, BackendApplicationCont
// do nothing
}

private getEclipseProductJar(): string{
const jarPath = path.resolve(__dirname, "..", "..", "..", "..",
"server", "org.eclipse.emfcloud.ecore.backend-app", "org.eclipse.emfcloud.ecore.codegen.product",
"target", "products", "org.eclipse.emfcloud.ecore.codegen.product", "linux", "gtk", "x86_64", "plugins",
"org.eclipse.equinox.launcher_1.5.600.v20191014-2022.jar");
if (jarPath.length === 0) {
throw new Error("The eclipse.equinox.launcher is not found. ");
}

return jarPath;
}

private spawnProcess(command: string, args?: string[]): RawProcess | undefined {
const rawProcess = this.processFactory({ command, args });
if (rawProcess.process === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,42 @@ public class CreateEcoreApplication implements IApplication {

@Override
public Object start(IApplicationContext context) throws Exception {
String[] args = getArgs(context);
createEcore(args[0], args[1], args[2], Paths.get(args[3], args[0]+".ecore"));
String[] args = getArgs(context);
String name = null;
String prefix = null;
String uri = null;
String workspacePath = null;
for (int i = 0; i < args.length; i++) {
switch (i) {
case 0:
name = args[i];
break;
case 1:
prefix = args[i];
break;
case 2:
uri = args[i];
break;
case 3:
workspacePath = args[i];
break;
}
}

if (name == null) {
System.exit(-10);
}
if (prefix == null) {
System.exit(-11);
}
if (uri == null) {
System.exit(-12);
}
if (workspacePath == null) {
System.exit(-13);
}

createEcore(name, prefix, uri, Paths.get(workspacePath, name+".ecore"));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,65 @@ public class GenModelApplication implements IApplication {
public Object start(IApplicationContext context) throws Exception {
Generator codegen = new Generator();
String[] args = getArgs(context);

String ecoreFilePath = null;
String customRootPackage = null;
String customOutputFolder = null;

for (int i = 0; i < args.length; i++) {
switch (i) {
case 0:
ecoreFilePath = args[i];
break;
case 1:
customRootPackage = args[i];
break;
case 2:
customOutputFolder = args[i];
break;
}
}
if (ecoreFilePath == null) {
System.exit(-10);
}
if (customRootPackage == null) {
System.exit(-11);
}
if (customOutputFolder == null) {
System.exit(-12);
}

ResourceSet resourceSet = new ResourceSetImpl();
File ecoreFile = new File(args[0]);
File ecoreFile = new File(ecoreFilePath);
if (!ecoreFile.exists()) {
throw new RuntimeException("Ecore file not found: " + ecoreFile.getAbsolutePath());
}
URI uri = URI.createFileURI(ecoreFile.getAbsolutePath());
Resource ecorePackageResource = resourceSet.getResource(uri, true);
EPackage rootPackage = (EPackage) ecorePackageResource.getContents().get(0);
if(args[1].equals("") || args[2].equals("")){
//get default values
if(args[1].equals("")){
args[1] = rootPackage.getName();
}
if(args[2].equals("")){
args[2] = "src";
}

//get default values
if(customRootPackage.equals("")){
customRootPackage = rootPackage.getName();
}
if(customOutputFolder.equals("")){
customOutputFolder = "src";
}

//remove leading /
if(args[2].charAt(0) == '/') args[2] = args[2].substring(1);
if(customOutputFolder.charAt(0) == '/') customOutputFolder = customOutputFolder.substring(1);
//initialize args for genmodel creation
String[] genmodelArgs = new String[]{"-ecore2GenModel", args[0], args[1], rootPackage.getNsPrefix()};
String[] genmodelArgs = new String[]{"-ecore2GenModel", ecoreFilePath, customRootPackage, rootPackage.getNsPrefix()};
codegen.run(genmodelArgs);
String genmodelPath = args[0].substring(0, args[0].lastIndexOf(".")) + ".genmodel";

String genmodelPath = ecoreFilePath.substring(0, ecoreFilePath.lastIndexOf(".")) + ".genmodel";
File genmodelFile = new File(genmodelPath);
URI genmodelUri = URI.createFileURI(genmodelFile.getAbsolutePath());
Resource genmodelResource = resourceSet.getResource(genmodelUri, true);
GenModel genmodel = (GenModel) genmodelResource.getContents().get(0);
genmodel.setModelDirectory("/" + args[2]);
genmodel.setModelDirectory("/" + customOutputFolder);
genmodelResource.save(null);

return null;
}

Expand Down

0 comments on commit 854875d

Please sign in to comment.