"Error when creating temporary directory: " + e1.getMessage()
).initCause(e1);
}
/* Unpacking project JARs */
ProjectConfig config = gui.getProjectConfig();
String[] projectJARs = config.getStringArrayValue(GUI.class.getName() + ".JARFILES");
for (String jar: projectJARs) {
/* Locate project */
File project = config.getUserProjectDefining(GUI.class, "JARFILES", jar);
File jarFile = new File(project, jar);
if (!jarFile.exists()) {
jarFile = new File(project, "lib/" + jar);
}
if (!jarFile.exists()) {
throw new RuntimeException(
"Project JAR could not be found: " + jarFile.getAbsolutePath()
);
}
logger.info("Unpacking project JAR " + jar + " (" + project + ")");
try {
Process unjarProcess = Runtime.getRuntime().exec(
new String[] { "jar", "xf", jarFile.getAbsolutePath()},
null,
workingDir
);
unjarProcess.waitFor();
} catch (Exception e1) {
throw (RuntimeException) new RuntimeException(
"Error unpacking JAR file: " + e1.getMessage()
).initCause(e1);
}
}
/* Unpacking COOJA core JARs */
String[] coreJARs = new String[] {
"tools/cooja/lib/jdom.jar", "tools/cooja/lib/log4j.jar", "tools/cooja/dist/cooja.jar"
};
for (String jar: coreJARs) {
File jarFile = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), jar);
if (!jarFile.exists()) {
throw new RuntimeException(
"Project JAR could not be found: " + jarFile.getAbsolutePath()
);
}
logger.info("Unpacking core JAR " + jar);
try {
Process unjarProcess = Runtime.getRuntime().exec(
new String[] { "jar", "xf", jarFile.getAbsolutePath()},
null,
workingDir
);
unjarProcess.waitFor();
} catch (Exception e1) {
throw (RuntimeException) new RuntimeException(
"Error unpacking JAR file: " + e1.getMessage()
).initCause(e1);
}
}
/* Prepare simulation config */
Element rootElement = gui.extractSimulationConfig();
logger.info("Extracting simulation configuration");
handleExportAttributesToJAR(rootElement, gui, workingDir);
/* Save simulation config */
File configFile = new File(workingDir, SIMCONFIG_FILENAME);
try {
Document doc = new Document(rootElement);
FileOutputStream out = new FileOutputStream(configFile);
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(doc, out);
out.close();
} catch (Exception e1) {
throw (RuntimeException) new RuntimeException(
"Error when writing simulation configuration: " + configFile
).initCause(e1);
}
logger.info("Wrote simulation configuration: " + configFile.getName());
/* Export external tools config (without projects) */
try {
File externalToolsConfig = new File(workingDir, EXTERNALTOOLS_FILENAME);
FileOutputStream out = new FileOutputStream(externalToolsConfig);
Properties differingSettings = new Properties();
Enumeration<Object> keyEnum = GUI.currentExternalToolsSettings.keys();
while (keyEnum.hasMoreElements()) {
String key = (String) keyEnum.nextElement();
String defaultSetting = GUI.getExternalToolsDefaultSetting(key, "");
String currentSetting = GUI.currentExternalToolsSettings.getProperty(key, "");
if (key.equals("DEFAULT_PROJECTDIRS")) {
differingSettings.setProperty(key, "");
} else if (!defaultSetting.equals(currentSetting)) {
differingSettings.setProperty(key, currentSetting);
}
}
differingSettings.store(out, "Cooja External Tools (User specific)");
out.close();
logger.info("Wrote external tools config: " + externalToolsConfig.getName());
} catch (Exception e2) {
throw (RuntimeException) new RuntimeException(
"Error when writing external tools configuration: " + e2.getMessage()
).initCause(e2);
}
/* Export current project configuration */
try {
ProjectConfig pConfig = gui.getProjectConfig().clone();
Enumeration<String> pValues = pConfig.getPropertyNames();
File newConfigFile = new File(workingDir, PROJECT_DEFAULT_CONFIG_FILENAME);
Properties newConfig = new Properties();
while (pValues.hasMoreElements()) {
String name = pValues.nextElement();
newConfig.setProperty(name, pConfig.getStringValue(name));
}
FileOutputStream out = new FileOutputStream(newConfigFile);
newConfig.store(out, "Cooja Project Config");
logger.info("Wrote project config: " + newConfigFile.getName());
} catch (Exception e1) {