blob: b0a1ef2a37704771c4b09d95be4b0f0716ee9278 [file] [log] [blame]
/**
********************************************************************************
* 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.amlt2systemc.m2t;
import java.util.Map;
import org.eclipse.app4mc.amalthea.model.AmaltheaFactory;
import org.eclipse.app4mc.amalthea.model.io.AmaltheaLoader;
import org.eclipse.app4mc.amlt2systemc.m2t.module.PropertyKeys;
import org.eclipse.app4mc.transformation.ServiceConstants;
import org.eclipse.app4mc.transformation.executiontype.IModelToTextConfig;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(
configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
property = { ServiceConstants.TRANSFORMATION_PROPERTY + "=APP4MCSIM" },
service = IModelToTextConfig.class)
public class M2TTransformationConfig implements IModelToTextConfig {
private static final Logger LOG = LoggerFactory.getLogger(M2TTransformationConfig.class);
private String folderPath;
@Activate
void activate(Map<String, ?> properties) {
folderPath = (String) properties.get(PropertyKeys.INPUT_MODELS_FOLDER);
}
public ResourceSet getInputResourceSet() {
if (folderPath != null) {
ResourceSet resourceSet = AmaltheaLoader.loadFromDirectoryNamed(folderPath);
if (resourceSet.getResources().isEmpty()) {
LOG.error(
"No Amalthea model files are loaded. Verify if the model version is : {}",
AmaltheaFactory.eINSTANCE.createAmalthea().getVersion());
}
return resourceSet;
} else {
LOG.error("Input_models_folder parameter not set",
new NullPointerException("input_models_folder property not set"));
}
return null;
}
}