| /******************************************************************************* |
| * Copyright (c) 2018, 2020 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 app4mc.example.transform.m2t.transformers |
| |
| import java.io.BufferedWriter |
| import java.io.File |
| import java.io.FileWriter |
| import java.util.Map |
| import org.eclipse.app4mc.amalthea.model.Amalthea |
| import org.eclipse.app4mc.transformation.ServiceConstants |
| import org.eclipse.app4mc.transformation.transformers.Model2TextRootTransformer |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| import org.osgi.service.component.annotations.Activate |
| import org.osgi.service.component.annotations.Component |
| import org.osgi.service.component.annotations.ConfigurationPolicy |
| import org.osgi.service.component.annotations.Reference |
| import org.slf4j.Logger |
| import org.slf4j.LoggerFactory |
| |
| @Component(configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID, |
| configurationPolicy = ConfigurationPolicy.REQUIRE, |
| property=#[ |
| "transformation=Amalthea2Text" |
| ], service=Model2TextRootTransformer) |
| class AmaltheaModel2TextTransformer extends Model2TextRootTransformer { |
| |
| static final Logger LOG = LoggerFactory.getLogger(typeof(AmaltheaModel2TextTransformer)) |
| |
| @Reference |
| M2T_Output_Transformer textGenerator |
| |
| String outputFolder |
| |
| @Activate |
| def package void activate(Map<String, ?> properties) { |
| LOG.debug("AmaltheaModel2TextTransformer activated : "+this.hashCode) |
| |
| outputFolder = getProperty("m2t_output_folder", properties) |
| } |
| |
| override m2tTransformation(ResourceSet inputResourceSet) { |
| |
| for (resource : inputResourceSet.resources) { |
| for (model : resource.contents) { |
| LOG.info("Processing file : " + resource.URI) |
| |
| //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 |
| } |
| |
| LOG.info("Script file generated at : " + outputFolder) |
| } |
| } |
| |
| } |
| } |