use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.
the class KuraGenerator method generate.
@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseClasspathTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseProjectFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ManifestTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new BuildPropertiesTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ComponentXmlTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new IDataServiceTemplate()));
if (invocationContext.getConfigurationProperties().getOrDefault("boschcloud", "false").equalsIgnoreCase("true")) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschDataServiceTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ThingClientFactoryTemplate()));
} else if (invocationContext.getConfigurationProperties().getOrDefault("boschhub", "false").equalsIgnoreCase("true")) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubDataService()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubClientTemplate()));
} else {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new KuraCloudDataServiceTemplate()));
}
if (invocationContext.getConfigurationProperties().getOrDefault("bluetooth", "false").equalsIgnoreCase("true")) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new MetatypeTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceBluetoothFinderTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ConfigurationTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceFilterTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceToInformationModelTransformerTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelConsumerTemplate()));
} else {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DefaultAppTemplate()));
}
generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelTemplate()));
for (FunctionblockProperty fbProperty : context.getProperties()) {
new GeneratorTaskFromFileTemplate<>(new FunctionblockTemplate(context)).generate(fbProperty.getType(), invocationContext, outputter);
}
generator.generate(context, invocationContext, outputter);
return outputter;
}
use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.
the class LatexGenerator method generate.
public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
generator.addTask(new LatexInformationModelGeneratorTask(LATEX_FILE_EXTENSION, LATEX_TARGET_PATH));
generator.generate(infomodel, invocationContext, zipOutputter);
return zipOutputter;
}
use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.
the class MQTTPlatformGenerator method generate.
@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
for (FunctionblockProperty property : context.getProperties()) {
ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
if (property.getType().getFunctionblock().getStatus() != null) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new IClientHandlerTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new MqttConfigurationTemplate()));
}
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
generator.generate(property.getType(), invocationContext, outputter);
}
IGenerationResult javaResult = invocationContext.lookupGenerator(JavabeanGenerator.KEY).generate(context, invocationContext, monitor);
return GenerationResultBuilder.from(outputter).append(javaResult).build();
}
use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.
the class ProSystGenerator method generate.
@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext ctx, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
Set<EObject> visited = new HashSet<>();
Set<String> exports = new HashSet<>();
for (FunctionblockProperty fbp : infomodel.getProperties()) {
Set<String> imports = new HashSet<>();
FunctionBlock fb = fbp.getType().getFunctionblock();
for (Entity entity : Utils.getReferencedEntities(fb)) {
if (!visited.contains(entity)) {
generateForEntity(infomodel, ctx, entity, zipOutputter);
visited.add(entity);
}
imports.add(entity.getNamespace());
exports.add(entity.getNamespace());
}
for (Enum en : Utils.getReferencedEnums(fb)) {
if (!visited.contains(en)) {
generateForEnum(infomodel, ctx, en, zipOutputter);
visited.add(en);
}
imports.add(en.getNamespace());
exports.add(en.getNamespace());
}
exports.add(infomodel.getNamespace());
generateForFunctionBlock(infomodel, ctx, fbp.getType(), zipOutputter, imports.toArray(new String[imports.size()]));
}
generateEclipseProject(infomodel, ctx, zipOutputter, exports);
return zipOutputter;
}
use of org.eclipse.vorto.codegen.api.GenerationResultZip in project vorto by eclipse.
the class CodeGenerationController method generate.
@RequestMapping(value = "/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> generate(@PathVariable String namespace, @PathVariable String name, @PathVariable String version, final HttpServletRequest request) {
byte[] modelResources = downloadModelWithReferences(namespace, name, version);
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelResources))).read();
Model model = workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get();
InformationModel infomodel = null;
if (model instanceof InformationModel) {
infomodel = (InformationModel) model;
} else if (model instanceof FunctionblockModel) {
infomodel = Utils.wrapFunctionBlock((FunctionblockModel) model);
}
IGenerationResult result = null;
try {
Map<String, String> requestParams = new HashMap<>();
request.getParameterMap().entrySet().stream().forEach(x -> requestParams.put(x.getKey(), x.getValue()[0]));
result = vortoGenerator.generate(infomodel, createInvocationContext(infomodel, vortoGenerator.getServiceKey(), requestParams), null);
} catch (Exception e) {
GenerationResultZip output = new GenerationResultZip(infomodel, vortoGenerator.getServiceKey());
Generated generated = new Generated("generation_error.log", "/generated", e.getMessage());
output.write(generated);
result = output;
}
return ResponseEntity.ok().contentLength(result.getContent().length).header("content-disposition", "attachment; filename = " + result.getFileName()).contentType(MediaType.parseMediaType(result.getMediatype())).body(new InputStreamResource(new ByteArrayInputStream(result.getContent())));
}
Aggregations