| /** |
| * ******************************************************************************* |
| * Copyright (c) 2020-2021 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| * ******************************************************************************* |
| */ |
| |
| package org.eclipse.app4mc.slg.commons.m2t.transformers; |
| |
| import org.eclipse.app4mc.amalthea.model.Amalthea; |
| import org.eclipse.app4mc.slg.commons.m2t.CustomObjectsStore; |
| import org.eclipse.app4mc.slg.config.ConfigModel; |
| import org.eclipse.app4mc.slg.config.util.ConfigurationFileLoader; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.resource.Resource; |
| import org.eclipse.emf.ecore.resource.ResourceSet; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.google.inject.Inject; |
| |
| public class AmaltheaModel2TextTransformer extends SLGBaseTransformer { |
| private static final Logger LOG = LoggerFactory.getLogger(AmaltheaModel2TextTransformer.class); |
| |
| @Inject private CustomObjectsStore customObjsStore; |
| |
| public ConfigModel configModel; |
| |
| public void transform(final Amalthea model, final String outputPath) { |
| // to be implemented in subclasses |
| } |
| |
| public void m2tTransformation(final ResourceSet inputResourceSet) { |
| |
| for (final Resource resource : inputResourceSet.getResources()) { |
| for (final EObject model : resource.getContents()) { |
| // check javadoc : https://www.eclipse.org/xtend/documentation/204_activeannotations.html#active-annotations-expression |
| LOG.info("Processing file : {}", resource.getURI()); |
| |
| final String outputFolder = this.getProperty("m2t_output_folder"); |
| final String configurationFilePath = this.getProperty("configurationFile"); |
| |
| if ((configurationFilePath != null)) { |
| configModel = new ConfigurationFileLoader().loadConfigurationFile(configurationFilePath); |
| customObjsStore.<ConfigModel>injectMembers(ConfigModel.class, configModel); |
| } else { |
| LOG.error("configuration file path is not supplied as a command line argument"); |
| } |
| |
| if ((configModel == null)) { |
| LOG.error("As no configuration model is available , unable to proceed with the load generator application !!"); |
| } |
| |
| if ((model instanceof Amalthea)) { |
| this.transform(((Amalthea) model), outputFolder); |
| } |
| |
| LOG.info("Script file generated at : {}", outputFolder); |
| |
| } |
| } |
| } |
| |
| } |