Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calling multiple Code Generators
class DefinitionGenerator extends JvmModelGenerator {
override protected _internalDoGenerate(EObject obj, IFileSystemAccess fsa) {
generateSchema(obj as Definition, fsa)
generateDotNetCore(obj as Definition, fsa)
}
def void generateSchema(Definition definition, IFileSystemAccess fsa) {
fsa.generateFile(
definition.name + ".sql", //
DB_SCHEMA_OUTPUT, //
DbScriptGenerator.generate(definition)
)
}
def void generateDotNetCore(Definition definition, IFileSystemAccess fsa) {
fsa.generateFile(
"Startup.cs", //
DOT_NET_OUTPUT, //
Startup.getContent(definition)
)
definition.entities.forEach [ entity |
fsa.generateFile(entity.name + ".cs", //
DOT_NET_OUTPUT_MODELS, //
Model.getContent(entity))
fsa.generateFile(entity.name + "Context" + ".cs", //
DOT_NET_OUTPUT_MODELS, //
ModelContext.getContent(entity))
fsa.generateFile(entity.name + "Controller" + ".cs", //
DOT_NET_OUTPUT_CONTROLLERS, //
Controller.getContent(entity))
]
}
}
public class EntityDslOutputConfigProvider implements IOutputConfigurationProvider {
public static final String DOT_NET_OUTPUT = "DOT_NET_OUTPUT";
public static final String DOT_NET_OUTPUT_MODELS = "DOT_NET_OUTPUT_MODELS";
public static final String DOT_NET_OUTPUT_CONTROLLERS = "DOT_NET_OUTPUT_CONTROLLERS";
public static final String DB_SCHEMA_OUTPUT = "DB_SCHEMA_OUTPUT";
@Override
public Set<OutputConfiguration> getOutputConfigurations() {
OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT);
defaultOutput.setDescription("Output Folder");
defaultOutput.setOutputDirectory("./src-gen");
defaultOutput.setOverrideExistingResources(true);
defaultOutput.setCreateOutputDirectory(true);
defaultOutput.setCleanUpDerivedResources(true);
defaultOutput.setSetDerivedProperty(true);
OutputConfiguration dotNetOutput = new OutputConfiguration(DOT_NET_OUTPUT);
dotNetOutput.setDescription(".Net Output folder");
dotNetOutput.setOutputDirectory("./core");
dotNetOutput.setOverrideExistingResources(true);
dotNetOutput.setCreateOutputDirectory(true);
dotNetOutput.setCleanUpDerivedResources(true);
dotNetOutput.setCanClearOutputDirectory(true);
dotNetOutput.setSetDerivedProperty(false);
OutputConfiguration dotNetModelsOutput = new OutputConfiguration(DOT_NET_OUTPUT_MODELS);
dotNetModelsOutput.setDescription(".Net Models otput folder");
dotNetModelsOutput.setOutputDirectory("./core/Models");
dotNetModelsOutput.setOverrideExistingResources(true);
dotNetModelsOutput.setCreateOutputDirectory(true);
dotNetModelsOutput.setCleanUpDerivedResources(true);
dotNetModelsOutput.setCanClearOutputDirectory(true);
dotNetModelsOutput.setSetDerivedProperty(false);
OutputConfiguration dotNetControllersOutput = new OutputConfiguration(DOT_NET_OUTPUT_CONTROLLERS);
dotNetControllersOutput.setDescription(".Net Controllers output folder");
dotNetControllersOutput.setOutputDirectory("./core/Controllers");
dotNetControllersOutput.setOverrideExistingResources(true);
dotNetControllersOutput.setCreateOutputDirectory(true);
dotNetControllersOutput.setCleanUpDerivedResources(true);
dotNetControllersOutput.setCanClearOutputDirectory(true);
dotNetControllersOutput.setSetDerivedProperty(false);
OutputConfiguration schemaOutput = new OutputConfiguration(DB_SCHEMA_OUTPUT);
schemaOutput.setDescription("DB Schema output folder");
schemaOutput.setOutputDirectory("./schema");
schemaOutput.setOverrideExistingResources(true);
schemaOutput.setCreateOutputDirectory(true);
schemaOutput.setCleanUpDerivedResources(false);
schemaOutput.setCanClearOutputDirectory(false);
schemaOutput.setSetDerivedProperty(false);
return Sets.newHashSet(defaultOutput, //
dotNetOutput, //
dotNetModelsOutput, //
dotNetControllersOutput, //
schemaOutput);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment