| /******************************************************************************* |
| * Copyright (c) 2018 Robert Bosch GmbH. |
| * 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: |
| * Robert Bosch GmbH - initial API and implementation |
| *******************************************************************************/ |
| |
| package templates |
| |
| import java.io.BufferedWriter |
| import java.io.File |
| import java.io.FileWriter |
| import org.apache.felix.service.command.CommandProcessor |
| import org.eclipse.app4mc.amalthea.model.Amalthea |
| import org.eclipse.app4mc.transformation.extensions.ICustomObjectsStore |
| import org.eclipse.app4mc.transformation.extensions.base.templates.Model2TextRootTransformer |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| import org.osgi.service.component.annotations.Component |
| import org.osgi.service.component.annotations.Reference |
| import org.osgi.service.component.annotations.ReferencePolicyOption |
| |
| @Component(property=#[ |
| // CommandProcessor.COMMAND_SCOPE + ":String=app4mc", |
| "transformation=Amalthea2Text" |
| ], service=Model2TextRootTransformer) |
| class AmaltheaModel2TextTransformer extends Model2TextRootTransformer { |
| |
| @Reference |
| ICustomObjectsStore customObjsStore |
| |
| @Reference |
| M2T_Output_Transformer textGenerator |
| |
| override m2tTransformation(ResourceSet inputResourceSet) { |
| |
| for (resource : inputResourceSet.resources) { |
| for (model : resource.contents) { |
| // TODO: model is a Amalthea model |
| // check javadoc : https://www.eclipse.org/xtend/documentation/204_activeannotations.html#active-annotations-expression |
| customObjsStore.getLogger().info("Processing file : " + resource.URI) |
| |
| var String outputFolder = getProperty("m2t_output_folder", customObjsStore); |
| // val textGenerator = new M2T_Output_Transformer |
| // ===== output 1 ===== |
| var outputFile1 = new File(outputFolder, "1.txt") |
| outputFile1.parentFile.mkdirs |
| outputFile1.createNewFile |
| |
| if (model instanceof Amalthea) { |
| val text = textGenerator.generateOutput1(model as Amalthea) |
| |
| /*saving buffer into file */ |
| val bufferedWriter = new BufferedWriter(new FileWriter(outputFile1)) |
| bufferedWriter.write(text) |
| bufferedWriter.close |
| } |
| |
| // ===== output 2 ===== |
| var outputFile2 = new File(outputFolder, "2.txt") |
| outputFile2.parentFile.mkdirs |
| outputFile2.createNewFile |
| |
| if (model instanceof Amalthea) { |
| val text = textGenerator.generateOutput2(model) |
| |
| /*saving buffer into file */ |
| val bufferedWriter = new BufferedWriter(new FileWriter(outputFile2)) |
| bufferedWriter.write(text) |
| bufferedWriter.close |
| } |
| |
| // TODO: save the file here |
| customObjsStore.logger.info("Script file generated at : " + outputFolder) |
| } |
| } |
| |
| } |
| } |