| /** |
| ******************************************************************************** |
| * 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.linux.transformers; |
| |
| import static org.eclipse.app4mc.slg.linux.transformers.LinuxBaseSettings.INC_TYPE; |
| import static org.eclipse.app4mc.slg.linux.transformers.LinuxBaseSettings.SRC_TYPE; |
| |
| import java.util.Properties; |
| |
| import org.eclipse.app4mc.amalthea.model.Amalthea; |
| import org.eclipse.app4mc.amalthea.model.Runnable; |
| import org.eclipse.app4mc.amalthea.model.SWModel; |
| import org.eclipse.app4mc.amalthea.model.StimuliModel; |
| import org.eclipse.app4mc.amalthea.model.Task; |
| import org.eclipse.app4mc.amalthea.model.util.ModelUtil; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.AmaltheaModel2TextTransformer; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.InstrumentationTransformer; |
| import org.eclipse.app4mc.slg.commons.m2t.transformers.RunnableTransformer; |
| import org.eclipse.app4mc.slg.linux.transformers.stimuli.LinuxStimulusTransformer; |
| import org.eclipse.app4mc.slg.linux.transformers.sw.LinuxMakeTransformer; |
| import org.eclipse.app4mc.slg.linux.transformers.sw.LinuxRealisticCodeTransformer; |
| import org.eclipse.app4mc.slg.linux.transformers.sw.LinuxRunnableTransformer; |
| import org.eclipse.app4mc.slg.linux.transformers.sw.LinuxTaskTransformer; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.google.inject.Inject; |
| |
| public class LinuxModel2TextTransformer extends AmaltheaModel2TextTransformer { |
| |
| @Inject OutputBuffer outputBuffer; |
| @Inject LinuxMakeTransformer linuxMakeTransformer; |
| @Inject LinuxRealisticCodeTransformer realisticCodeBasedOnCodeSnippet; |
| @Inject LinuxStimulusTransformer stimuliTransformer; |
| @Inject LinuxRunnableTransformer linuxRunnableTransformer; |
| @Inject RunnableTransformer defaultRunnableTransformer; |
| @Inject LinuxTaskTransformer taskTransformer; |
| @Inject InstrumentationTransformer instrumentationTransformer; |
| @Inject Properties properties; |
| |
| private static final Logger LOG = LoggerFactory.getLogger(LinuxModel2TextTransformer.class); |
| |
| @Override |
| public void transform(final Amalthea model, final String outputFolder) { |
| |
| final boolean experimentalCodeSnippetMatching = Boolean |
| .parseBoolean(properties.getProperty("experimentalCodeSnippetMatching")); |
| final boolean enableInstrumentation = Boolean |
| .parseBoolean(properties.getProperty("enableInstrumentation")); |
| |
| final StimuliModel stimuliModel = ModelUtil.getOrCreateStimuliModel(model); |
| final SWModel swModel = ModelUtil.getOrCreateSwModel(model); |
| |
| LOG.info("Starting Linux SLG code generation"); |
| |
| LinuxBaseSettings.initializeOutputBuffer(outputBuffer, properties.getProperty("m2t_output_folder")); |
| |
| if (experimentalCodeSnippetMatching) { |
| realisticCodeBasedOnCodeSnippet.transform(); |
| } |
| |
| this.stimuliTransformer.transform(stimuliModel.getStimuli()); |
| |
| for (Runnable runnable : swModel.getRunnables()) { |
| if (experimentalCodeSnippetMatching) { |
| linuxRunnableTransformer.transform(runnable); |
| } else { |
| defaultRunnableTransformer.transform(runnable); |
| } |
| } |
| |
| for (Task task : swModel.getTasks()) { |
| taskTransformer.transform(task); |
| } |
| |
| if (enableInstrumentation) { |
| instrumentationTransformer.transform("synthetic_gen/instrument"); |
| } |
| |
| linuxMakeTransformer.transform(); |
| |
| // ensure that the following files will be created |
| |
| if (experimentalCodeSnippetMatching) { |
| outputBuffer.appendTo(SRC_TYPE, "synthetic_gen/ticksUtils/_src/ticksUtils", ""); |
| outputBuffer.appendTo(INC_TYPE, "synthetic_gen/ticksUtils/_inc/ticksUtils", ""); |
| outputBuffer.appendTo(SRC_TYPE, "synthetic_gen/labels/_src/labels", ""); |
| outputBuffer.appendTo(INC_TYPE, "synthetic_gen/labels/_inc/labels", ""); |
| } else { |
| outputBuffer.appendTo(SRC_TYPE, "synthetic_gen/codesnippets/_src/codesnippets", ""); |
| outputBuffer.appendTo(INC_TYPE, "synthetic_gen/codesnippets/_inc/codesnippets", ""); |
| } |
| |
| outputBuffer.appendTo(SRC_TYPE, "synthetic_gen/runnables/_src/runnables", ""); |
| outputBuffer.appendTo(INC_TYPE, "synthetic_gen/runnables/_inc/runnables", ""); |
| |
| outputBuffer.finish(); |
| |
| LOG.info("Finished Linux SLG code generation"); |
| } |
| |
| } |