| /** |
| ******************************************************************************** |
| * Copyright (c) 2018 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 app4mc.example.transform.app; |
| |
| import java.io.File; |
| import java.io.FileInputStream; |
| import java.io.FileNotFoundException; |
| import java.io.IOException; |
| import java.util.Properties; |
| |
| import org.apache.log4j.Logger; |
| import org.eclipse.app4mc.transformation.application.base.Application; |
| import org.eclipse.equinox.app.IApplicationContext; |
| |
| public class SampleApplication extends Application { |
| |
| @Override |
| public Object start(IApplicationContext context) throws Exception { |
| return super.start(context); |
| } |
| |
| @Override |
| protected Properties getInputParameters(IApplicationContext context) throws IOException, FileNotFoundException { |
| |
| |
| |
| String[] args = (String[]) context.getArguments().get("application.args"); |
| |
| if (args != null && args.length > 0) { |
| |
| String inputPropsFile = args[1]; |
| |
| File propertiesFile = new File(inputPropsFile); |
| |
| Properties properties = new Properties(); |
| |
| properties.load(new FileInputStream(propertiesFile)); |
| |
| //Now checking if the user has specified absolute paths in the properties file ? |
| |
| Object inputModelsFolder = properties.get("input_models_folder"); |
| Object m2m_outputModelsFolder = properties.get("m2m_output_folder"); |
| Object m2t_output_folder = properties.get("m2t_output_folder"); |
| Object logFile = properties.get("log_file"); |
| |
| if(inputModelsFolder !=null) { |
| String path=inputModelsFolder.toString(); |
| |
| String newPath=new File(path).exists()?path:new File(propertiesFile.getParent()+File.separator+ path).getCanonicalPath() ; |
| |
| properties.put("input_models_folder", newPath); |
| |
| } |
| if(m2m_outputModelsFolder !=null) { |
| String path=m2m_outputModelsFolder.toString(); |
| |
| String newPath=new File(path).exists()?path:new File(propertiesFile.getParent()+File.separator+ path).getCanonicalPath(); |
| |
| properties.put("m2m_output_folder", newPath); |
| |
| } |
| if(m2t_output_folder !=null) { |
| String path=m2t_output_folder.toString(); |
| |
| String newPath=new File(path).exists()?path:new File(propertiesFile.getParent()+File.separator+ path).getCanonicalPath(); |
| |
| properties.put("m2t_output_folder", newPath); |
| |
| } |
| if(logFile !=null) { |
| String path=logFile.toString(); |
| |
| String newPath=new File(path).exists()?path:new File(propertiesFile.getParent()+File.separator+ path).getCanonicalPath() ; |
| |
| properties.put("log_file", newPath); |
| |
| } |
| |
| |
| return properties; |
| } |
| |
| return null; |
| |
| } |
| |
| @Override |
| protected Logger getLogger(Properties inputParameters) { |
| return super.getLogger(inputParameters); |
| } |
| } |