From 70995722829268b51a1612be0bde5d48d60e7558 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 12 Mar 2009 15:08:29 +0000 Subject: [PATCH] + support for config file relative paths when saving simulations --- .../se/sics/cooja/avrmote/MicaZMoteType.java | 20 ++++++++++++----- .../se/sics/cooja/mspmote/ESBMoteType.java | 11 ++-------- .../se/sics/cooja/mspmote/MspMoteType.java | 22 ++++++++++++++----- .../se/sics/cooja/mspmote/SkyMoteType.java | 11 ++-------- .../cooja/mspmote/plugins/MspCodeWatcher.java | 14 +++++++----- .../cooja/contikimote/ContikiMoteType.java | 13 +++++++---- 6 files changed, 53 insertions(+), 38 deletions(-) diff --git a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMoteType.java b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMoteType.java index 943cd8362..d90f4aaa7 100644 --- a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMoteType.java +++ b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MicaZMoteType.java,v 1.2 2009/03/11 14:12:18 fros4943 Exp $ + * $Id: MicaZMoteType.java,v 1.3 2009/03/12 15:11:03 fros4943 Exp $ */ package se.sics.cooja.avrmote; @@ -51,6 +51,8 @@ import se.sics.cooja.dialogs.MessageList.MessageContainer; public class MicaZMoteType implements MoteType { private static Logger logger = Logger.getLogger(MicaZMoteType.class); + private Simulation simulation; + public static final String target = "micaz"; public static final String targetNice = "MicaZ"; @@ -150,6 +152,8 @@ public class MicaZMoteType implements MoteType { protected boolean configureAndInitMicaZType(Container parentContainer, Simulation simulation, boolean visAvailable, final String target, final String targetNice) throws MoteTypeCreationException { + this.simulation = simulation; + boolean compileFromSource = false; if (getIdentifier() == null && !visAvailable) { @@ -1060,8 +1064,8 @@ public class MicaZMoteType implements MoteType { // Source file if (fileSource != null) { element = new Element("source"); - fileSource = GUI.stripAbsoluteContikiPath(fileSource); - element.setText(fileSource.getPath().replaceAll("\\\\", "/")); + File file = simulation.getGUI().createPortablePath(fileSource); + element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); element = new Element("command"); element.setText(compileCommand); @@ -1069,9 +1073,7 @@ public class MicaZMoteType implements MoteType { } else { // ELF file element = new Element("elf"); - File file = fileFirmware; - file = GUI.stripAbsoluteContikiPath(file); - fileFirmware = file; + File file = simulation.getGUI().createPortablePath(fileFirmware); element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); } @@ -1091,10 +1093,16 @@ public class MicaZMoteType implements MoteType { description = element.getText(); } else if (name.equals("source")) { fileSource = new File(element.getText()); + if (!fileSource.exists()) { + fileSource = simulation.getGUI().restorePortablePath(fileSource); + } } else if (name.equals("command")) { compileCommand = element.getText(); } else if (name.equals("elf")) { fileFirmware = new File(element.getText()); + if (!fileFirmware.exists()) { + fileFirmware = simulation.getGUI().restorePortablePath(fileSource); + } } else { logger.fatal("Unrecognized entry in loaded configuration: " + name); throw new MoteTypeCreationException( diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java index a7c4f1ad6..aa1226c19 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMoteType.java,v 1.8 2009/03/11 17:46:59 fros4943 Exp $ + * $Id: ESBMoteType.java,v 1.9 2009/03/12 15:12:10 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -56,14 +56,6 @@ import se.sics.cooja.mspmote.interfaces.TR1001Radio; public class ESBMoteType extends MspMoteType { private static Logger logger = Logger.getLogger(ESBMoteType.class); - public ESBMoteType() { - } - - public ESBMoteType(String identifier) { - setIdentifier(identifier); - setDescription("ESB Mote Type #" + identifier); - } - public Icon getMoteTypeIcon() { Toolkit toolkit = Toolkit.getDefaultToolkit(); URL imageURL = this.getClass().getClassLoader().getResource("images/esb.jpg"); @@ -88,6 +80,7 @@ public class ESBMoteType extends MspMoteType { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) throws MoteTypeCreationException { + this.simulation = simulation; /* SPECIAL CASE: Cooja started in applet. * Use preconfigured Contiki firmware */ diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java index b9f0628e4..81f2448f8 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMoteType.java,v 1.28 2009/03/11 17:46:59 fros4943 Exp $ + * $Id: MspMoteType.java,v 1.29 2009/03/12 15:12:10 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -56,6 +56,8 @@ public abstract class MspMoteType implements MoteType { private String identifier = null; private String description = null; + protected Simulation simulation; + /* If source file is defined, the firmware is recompiled when loading simulations */ private File fileSource = null; private String compileCommands = null; @@ -214,7 +216,7 @@ public abstract class MspMoteType implements MoteType { // Source file if (fileSource != null) { element = new Element("source"); - File file = GUI.stripAbsoluteContikiPath(fileSource); + File file = simulation.getGUI().createPortablePath(fileSource); element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); element = new Element("commands"); @@ -224,7 +226,7 @@ public abstract class MspMoteType implements MoteType { // Firmware file element = new Element("firmware"); - File file = GUI.stripAbsoluteContikiPath(fileFirmware); + File file = simulation.getGUI().createPortablePath(fileFirmware); element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); @@ -241,6 +243,8 @@ public abstract class MspMoteType implements MoteType { public boolean setConfigXML(Simulation simulation, Collection configXML, boolean visAvailable) throws MoteTypeCreationException { + this.simulation = simulation; + ArrayList> intfClassList = new ArrayList>(); for (Element element : configXML) { String name = element.getName(); @@ -250,7 +254,11 @@ public abstract class MspMoteType implements MoteType { } else if (name.equals("description")) { description = element.getText(); } else if (name.equals("source")) { - fileSource = new File(element.getText()); + File file = new File(element.getText()); + if (!file.exists()) { + file = simulation.getGUI().restorePortablePath(file); + } + fileSource = file; } else if (name.equals("command")) { /* Backwards compatibility: command is now commands */ logger.warn("Old simulation config detected: old version only supports a single compile command"); @@ -258,7 +266,11 @@ public abstract class MspMoteType implements MoteType { } else if (name.equals("commands")) { compileCommands = element.getText(); } else if (name.equals("firmware")) { - fileFirmware = new File(element.getText()); + File file = new File(element.getText()); + if (!file.exists()) { + file = simulation.getGUI().restorePortablePath(file); + } + fileFirmware = file; } else if (name.equals("elf")) { /* Backwards compatibility: elf is now firmware */ logger.warn("Old simulation config detected: firmware specified as elf"); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java index 93e97e316..797a7d8e7 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMoteType.java,v 1.7 2009/03/11 17:46:59 fros4943 Exp $ + * $Id: SkyMoteType.java,v 1.8 2009/03/12 15:12:10 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -57,14 +57,6 @@ import se.sics.cooja.mspmote.interfaces.SkySerial; public class SkyMoteType extends MspMoteType { private static Logger logger = Logger.getLogger(SkyMoteType.class); - public SkyMoteType() { - } - - public SkyMoteType(String identifier) { - setIdentifier(identifier); - setDescription("Sky Mote Type #" + identifier); - } - public Icon getMoteTypeIcon() { Toolkit toolkit = Toolkit.getDefaultToolkit(); URL imageURL = this.getClass().getClassLoader().getResource("images/sky.jpg"); @@ -89,6 +81,7 @@ public class SkyMoteType extends MspMoteType { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) throws MoteTypeCreationException { + this.simulation = simulation; /* SPECIAL CASE: Cooja started in applet. * Use preconfigured Contiki firmware */ diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspCodeWatcher.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspCodeWatcher.java index 5af8525b9..3edcd9fcd 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspCodeWatcher.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/MspCodeWatcher.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspCodeWatcher.java,v 1.14 2008/11/03 18:11:44 fros4943 Exp $ + * $Id: MspCodeWatcher.java,v 1.15 2009/03/12 15:12:23 fros4943 Exp $ */ package se.sics.cooja.mspmote.plugins; @@ -309,7 +309,7 @@ public class MspCodeWatcher extends VisPlugin { * * @author Fredrik Osterlind */ - static class Breakpoints { + class Breakpoints { private Hashtable> debuggingInfo = null; private Vector breakpoints = new Vector(); private Vector listeners = new Vector(); @@ -541,8 +541,8 @@ public class MspCodeWatcher extends VisPlugin { if (codeFile != null) { element = new Element("codefile"); - codeFile = GUI.stripAbsoluteContikiPath(codeFile); - element.setText(codeFile.getPath().replaceAll("\\\\", "/")); + File file = mySimulation.getGUI().createPortablePath(codeFile); + element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); } @@ -558,7 +558,11 @@ public class MspCodeWatcher extends VisPlugin { public boolean setConfigXML(Collection configXML, boolean visAvailable) { for (Element element : configXML) { if (element.getName().equals("codefile")) { - codeFile = new File(element.getText()); + File file = new File(element.getText()); + if (!file.exists()) { + file = mySimulation.getGUI().restorePortablePath(file); + } + codeFile = file; if (!codeFile.exists()) { return false; } diff --git a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java index 9cbdbe0a7..3a15043d6 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiMoteType.java,v 1.32 2009/03/11 18:42:53 fros4943 Exp $ + * $Id: ContikiMoteType.java,v 1.33 2009/03/12 15:08:29 fros4943 Exp $ */ package se.sics.cooja.contikimote; @@ -1246,8 +1246,8 @@ public class ContikiMoteType implements MoteType { config.add(element); element = new Element("contikiapp"); - File tmp = GUI.stripAbsoluteContikiPath(getContikiSourceFile()); - element.setText(tmp.getPath().replaceAll("\\\\", "/")); /* TODO Fix Contiki-relative path */ + File file = simulation.getGUI().createPortablePath(getContikiSourceFile()); + element.setText(file.getPath().replaceAll("\\\\", "/")); config.add(element); element = new Element("commands"); @@ -1288,7 +1288,12 @@ public class ContikiMoteType implements MoteType { } else if (name.equals("description")) { description = element.getText(); } else if (name.equals("contikiapp")) { - setContikiSourceFile(new File(element.getText())); /* TODO Fix Contiki-relative paths */ + File file = new File(element.getText()); + if (!file.exists()) { + file = simulation.getGUI().restorePortablePath(file); + } + + setContikiSourceFile(file); /* XXX Do not load the generated firmware. Instead, load the unique library file directly */ File contikiFirmware = new File(