Java tutorial
/* * TURNUS, the co-exploration framework * * Copyright (C) 2015 EPFL SCI STI MM * * This file is part of TURNUS. * * TURNUS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * TURNUS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TURNUS. If not, see <http://www.gnu.org/licenses/>. * * Additional permission under GNU GPL version 3 section 7 * * If you modify this Program, or any covered work, by linking or combining it * with Eclipse (or a modified version of Eclipse or an Eclipse plugin or * an Eclipse library), containing parts covered by the terms of the * Eclipse Public License (EPL), the licensors of this Program grant you * additional permission to convey the resulting work. Corresponding Source * for a non-source form of such a combination shall include the source code * for the parts of Eclipse libraries used as well as that of the covered work. * */ package co.turnus.analysis.profiler.orcc.code; import java.io.File; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.configuration.Configuration; import org.eclipse.core.resources.IProject; import org.eclipse.debug.core.ILaunchConfiguration; import co.turnus.TurnusRuntimeException; import co.turnus.util.EcoreHelper; import co.turnus.versioning.impl.GitVersioner; public class OrccStaticProfilerOptions { /** This is a String containing the {@link IProject} name of the network */ public static final String ORCC_PROJECT = "co.turnus.analysis.profiler.orcc.static.project"; /** This is a String containing the XDF file name of the simulated network */ public static final String ORCC_XDF = "co.turnus.analysis.profiler.orcc.static.xdf"; /** This is a String containing the output path where results are exported */ public static final String OUTPUT_PATH = "co.turnus.analysis.profiler.orcc.static.outputPath"; /** This is a String containing the user custom output path */ public static final String OUTPUT_PATH_CUSTOM_VALUE = "co.turnus.analysis.profiler.orcc.static.outputPath.custom"; /** This is a Boolean indicating if the output path is defined by the user */ public static final String OUTPUT_PATH_CUSTOM_USE = "co.turnus.analysis.profiler.orcc.static.outputPath.custom.use"; /** * This is a Boolean indicating if the profiler should be verbose (i.e. * warning messages, file loading, ...) */ public static final String VERBOSE = "co.turnus.analysis.profiler.orcc.static.verbose"; public static final String VERSIONER = "co.turnus.analysis.profiler.orcc.static.versioner"; public static Configuration getConfiguration(ILaunchConfiguration configuration, String mode) { Configuration conf = new BaseConfiguration(); try { conf.setProperty(VERBOSE, mode.equals("debug")); String stmp = configuration.getAttribute(ORCC_PROJECT, ""); conf.setProperty(ORCC_PROJECT, stmp); stmp = configuration.getAttribute(ORCC_XDF, ""); conf.setProperty(ORCC_XDF, stmp); stmp = configuration.getAttribute(VERSIONER, GitVersioner.NAME); conf.setProperty(VERSIONER, stmp); // set the output path stmp = configuration.getAttribute(OUTPUT_PATH_CUSTOM_USE, false) ? configuration.getAttribute(OUTPUT_PATH_CUSTOM_VALUE, "") : ""; setOutputPath(conf, stmp); } catch (Exception e) { throw new TurnusRuntimeException("Error parsing the launch configuration options", e); } return conf; } private static void setOutputPath(Configuration conf, String customPath) { // store the root path for the output. File outPath = null; if (customPath != null && !customPath.isEmpty()) { outPath = new File(customPath); } else { String project = conf.getString(ORCC_PROJECT); IProject pojo = EcoreHelper.getProject(project); outPath = pojo.getRawLocation().makeAbsolute().toFile(); outPath = new File(outPath, "turnus"); outPath = new File(outPath, "code"); } conf.setProperty(OUTPUT_PATH, outPath.getAbsolutePath()); } }