blob: aea52cec22768995ac16a9f1d62c8469c8e09667 [file] [log] [blame]
/*******************************************************************************
* 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.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.transformation.extensions.base.templates.Model2TextRootTransformer
import org.eclipse.emf.ecore.resource.ResourceSet
class AmaltheaModel2TextTransformer extends Model2TextRootTransformer {
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
getLogger.info("Processing file : " + resource.URI)
var String outputFolder = getProperty("m2t_output_folder");
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)
/*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
logger.info("Script file generated at : " + outputFolder)
}
}
}
}