1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2011 protos software gmbh (http://www.protos.de).
* 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:
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.generator.c;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.c.gen.Validator;
import org.eclipse.etrice.generator.c.setup.GeneratorModule;
import org.eclipse.xtext.generator.IGenerator;
import com.google.inject.Inject;
public class Main extends AbstractGenerator {
public static final String OPTION_LIB = "-lib";
public static final String OPTION_GEN_INST_DIAG = "-genInstDiag";
public static final String OPTION_SAVE_GEN_MODEL = "-saveGenModel";
/**
* print usage message to stderr
*/
private static void printUsage() {
output.println(Main.class.getName()+" [-saveGenModel <genmodel path>] [-genInstDiag] [-lib] <list of model file paths>");
output.println(" <list of model file paths> # model file paths may be specified as");
output.println(" # e.g. C:\\path\\to\\model\\mymodel.room");
output.println(" -saveGenModel <genmodel path> # if specified the generator model will be saved to this location");
output.println(" -genInstDiag # if specified an instance diagram is created for each subsystem");
output.println(" -lib # if specified all classes are generated and no instances");
}
public static void main(String[] args) {
int ret = createAndRunGenerator(new GeneratorModule(), args);
if (isTerminateOnError() && ret!=GENERATOR_OK)
System.exit(ret);
}
@Inject
private IGenerator mainGenerator;
@Inject
protected org.eclipse.etrice.generator.doc.gen.MainGen mainDocGenerator;
@Inject
private Validator validator;
public int runGenerator(String[] args) {
if (args.length == 0) {
logger.logError(Main.class.getName()+" - aborting: no arguments!", null);
printUsage();
return GENERATOR_ERROR;
}
// parsing arguments
String genModelPath = null;
List<String> uriList = new ArrayList<String>();
boolean genInstDiag = false;
boolean asLibrary = false;
for (int i=0; i<args.length; ++i) {
if (args[i].equals(OPTION_SAVE_GEN_MODEL)) {
if (++i<args.length) {
genModelPath = args[i]+"/genmodel.egm";
}
}
else if (args[i].equals(OPTION_GEN_INST_DIAG)) {
genInstDiag = true;
}
else if (args[i].equals(OPTION_LIB)) {
asLibrary = true;
}
else {
uriList.add(args[i]);
}
}
setupRoomModel();
if (!runGenerator(uriList, genModelPath, genInstDiag, asLibrary))
return GENERATOR_ERROR;
return GENERATOR_OK;
}
protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genInstDiag, boolean asLibrary) {
ResourceSet rs = resourceSetProvider.get();
loadModels(uriList, rs);
if (!validateModels(rs))
return false;
Root genModel = createGeneratorModel(rs, asLibrary, genModelPath);
if (genModel==null)
return false;
if (!validator.validate(genModel))
return false;
logger.logInfo("-- starting code generation");
fileAccess.setOutputPath("src-gen/");
mainGenerator.doGenerate(genModel.eResource(), fileAccess);
if (genInstDiag) {
mainDocGenerator.doGenerate(genModel);
}
logger.logInfo("-- finished code generation");
return true;
}
}
|