| /******************************************************************************* |
| * 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 org.eclipse.app4mc.transformation.application.base |
| |
| import com.google.inject.Guice |
| import com.google.inject.Injector |
| import java.util.ArrayList |
| import java.util.List |
| import java.util.Map |
| import java.util.Properties |
| import org.apache.log4j.Logger |
| import org.eclipse.app4mc.transformation.extensions.CustomObjectsStore |
| import org.eclipse.app4mc.transformation.extensions.base.templates.Model2ModelRootTransformer |
| import org.eclipse.app4mc.transformation.extensions.base.templates.Model2TextRootTransformer |
| |
| class ExecuteTransformation { |
| |
| def static void start(Logger logger, Properties properties) { |
| |
| var Map<String, TransformationConfig> enabledTransformationConfigurations = ExtensionExecution. |
| getEnabledTransformationConfigElementsFromExtensions(logger); |
| |
| var List<TransformationConfig> configuredTransformations = getTransformationElementsSpecifiedByUser( |
| enabledTransformationConfigurations, properties, logger); |
| |
| if (configuredTransformations.size == 0) { |
| |
| var msg = "Configured org.eclipse.app4mc.transformation.configuration are not enabled (or) they are not defined" |
| |
| logger.error(msg, new RuntimeException(msg)) |
| |
| } |
| |
| for (transformationConfig : configuredTransformations) { |
| |
| val injector = Guice::createInjector(transformationConfig.injectorModule) |
| |
| /*-- Injection of created objects into Google Guice -- */ |
| injectPreCreatedObjects(injector, properties) |
| |
| /*------------------------------------------------------- */ |
| val model2ModelTransformer = injector.getInstance(typeof(Model2ModelRootTransformer)); |
| |
| /*- M2M transformation */ |
| var m2mConfig = transformationConfig.model2ModelConfig; |
| |
| if (m2mConfig != null && model2ModelTransformer !== null) { |
| |
| m2mConfig.properties = properties |
| |
| model2ModelTransformer.injector=injector |
| |
| model2ModelTransformer.m2mTransformation(m2mConfig.inputResourceSet, m2mConfig.ouputResourceSet) |
| } |
| |
| /*- M2T transformation */ |
| val model2TextTransformer = injector.getInstance(typeof(Model2TextRootTransformer)); |
| |
| var m2tConfig = transformationConfig.model2TextConfig; |
| |
| if (m2tConfig != null && model2TextTransformer !== null) { |
| |
| m2tConfig.properties = properties |
| |
| model2TextTransformer.injector=injector |
| |
| model2TextTransformer.m2tTransformation(m2tConfig.inputResourceSet) |
| } |
| |
| } |
| |
| } |
| |
| def static List<TransformationConfig> getTransformationElementsSpecifiedByUser( |
| Map<String, TransformationConfig> map, Properties properties, Logger logger) { |
| |
| val List<TransformationConfig> transformationConfigElements = new ArrayList |
| |
| if (properties.containsKey("tranformationConfigIDs")) { |
| |
| val transformationConfigIDs = (properties.get("tranformationConfigIDs") as String).split("\\;") |
| |
| for (id : transformationConfigIDs) { |
| |
| val transConfig = map.get(id) |
| |
| if (transConfig !== null) { |
| transformationConfigElements.add(transConfig) |
| } |
| |
| } |
| } else { |
| logger.error("Input properties file doesn't contain key with name: \"tranformationConfigIDs\" ", |
| new Exception("Missing required parameter : \"tranformationConfigIDs\"")) |
| } |
| |
| return transformationConfigElements |
| } |
| |
| protected def static void injectPreCreatedObjects(Injector injector, Object... inputObjs) { |
| |
| val customObjectsStore = injector.getInstance(CustomObjectsStore) |
| |
| for (element : inputObjs) { |
| customObjectsStore.injectMembers(element.class, element) |
| } |
| } |
| |
| } |