Cooja backwards compatibility with simulation files that uses non-Contiki Java package names

This commit is contained in:
Fredrik Osterlind 2013-11-19 12:49:59 +01:00
parent b5c94910ac
commit 51e62e8cb3
10 changed files with 97 additions and 39 deletions

View File

@ -221,11 +221,17 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
if (name.equals("motetype_identifier")) { if (name.equals("motetype_identifier")) {
/* Ignored: handled by simulation */ /* Ignored: handled by simulation */
} else if (name.equals("interface_config")) { } else if (name.equals("interface_config")) {
/* Backwards compatibility: se.sics -> org.contikios */
String intfClass = element.getText().trim();
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
Class<? extends MoteInterface> moteInterfaceClass = simulation.getCooja().tryLoadClass( Class<? extends MoteInterface> moteInterfaceClass = simulation.getCooja().tryLoadClass(
this, MoteInterface.class, element.getText().trim()); this, MoteInterface.class, intfClass);
if (moteInterfaceClass == null) { if (moteInterfaceClass == null) {
logger.fatal("Could not load mote interface class: " + element.getText().trim()); logger.fatal("Could not load mote interface class: " + intfClass);
return false; return false;
} }

View File

@ -292,6 +292,11 @@ public class MicaZMoteType implements MoteType {
} else if (name.equals("moteinterface")) { } else if (name.equals("moteinterface")) {
String intfClass = element.getText().trim(); String intfClass = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
Class<? extends MoteInterface> moteInterfaceClass = Class<? extends MoteInterface> moteInterfaceClass =
simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass); simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass);

View File

@ -40,7 +40,6 @@ import java.util.Hashtable;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import org.contikios.cooja.ContikiError; import org.contikios.cooja.ContikiError;
import org.contikios.cooja.Cooja; import org.contikios.cooja.Cooja;
import org.contikios.cooja.Mote; import org.contikios.cooja.Mote;
@ -58,6 +57,7 @@ import org.contikios.cooja.mspmote.interfaces.MspSerial;
import org.contikios.cooja.mspmote.plugins.CodeVisualizerSkin; import org.contikios.cooja.mspmote.plugins.CodeVisualizerSkin;
import org.contikios.cooja.mspmote.plugins.MspBreakpoint; import org.contikios.cooja.mspmote.plugins.MspBreakpoint;
import org.contikios.cooja.plugins.Visualizer; import org.contikios.cooja.plugins.Visualizer;
import se.sics.mspsim.cli.CommandContext; import se.sics.mspsim.cli.CommandContext;
import se.sics.mspsim.cli.CommandHandler; import se.sics.mspsim.cli.CommandHandler;
import se.sics.mspsim.cli.LineListener; import se.sics.mspsim.cli.LineListener;
@ -409,18 +409,25 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
setWatchpointConfigXML(element.getChildren(), visAvailable); setWatchpointConfigXML(element.getChildren(), visAvailable);
} else if (name.equals("interface_config")) { } else if (name.equals("interface_config")) {
String intfClass = element.getText().trim(); String intfClass = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.MspIPAddress")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.MspIPAddress")) {
intfClass = IPAddress.class.getName(); intfClass = IPAddress.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.ESBLog")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.ESBLog")) {
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkyByteRadio")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkyByteRadio")) {
intfClass = Msp802154Radio.class.getName(); intfClass = Msp802154Radio.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkySerial")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkySerial")) {
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
Class<? extends MoteInterface> moteInterfaceClass = simulation.getCooja().tryLoadClass( Class<? extends MoteInterface> moteInterfaceClass = simulation.getCooja().tryLoadClass(
this, MoteInterface.class, intfClass); this, MoteInterface.class, intfClass);

View File

@ -264,22 +264,27 @@ public abstract class MspMoteType implements MoteType {
} else if (name.equals("moteinterface")) { } else if (name.equals("moteinterface")) {
String intfClass = element.getText().trim(); String intfClass = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
/* Backwards compatibility: MspIPAddress -> IPAddress */ /* Backwards compatibility: MspIPAddress -> IPAddress */
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.MspIPAddress")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.MspIPAddress")) {
logger.warn("Old simulation config detected: IP address interface was moved"); logger.warn("Old simulation config detected: IP address interface was moved");
intfClass = IPAddress.class.getName(); intfClass = IPAddress.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.ESBLog")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.ESBLog")) {
logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial"); logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial");
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkyByteRadio")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkyByteRadio")) {
logger.warn("Old simulation config detected: SkyByteRadio was replaced by Msp802154Radio"); logger.warn("Old simulation config detected: SkyByteRadio was replaced by Msp802154Radio");
intfClass = Msp802154Radio.class.getName(); intfClass = Msp802154Radio.class.getName();
} }
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkySerial")) { if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkySerial")) {
logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial"); logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial");
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
Class<? extends MoteInterface> moteInterfaceClass = Class<? extends MoteInterface> moteInterfaceClass =

View File

@ -124,7 +124,6 @@ import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder; import org.jdom.input.SAXBuilder;
import org.jdom.output.Format; import org.jdom.output.Format;
import org.jdom.output.XMLOutputter; import org.jdom.output.XMLOutputter;
import org.contikios.cooja.MoteType.MoteTypeCreationException; import org.contikios.cooja.MoteType.MoteTypeCreationException;
import org.contikios.cooja.VisPlugin.PluginRequiresVisualizationException; import org.contikios.cooja.VisPlugin.PluginRequiresVisualizationException;
import org.contikios.cooja.contikimote.ContikiMoteType; import org.contikios.cooja.contikimote.ContikiMoteType;
@ -3635,14 +3634,19 @@ public class Cooja extends Observable {
// Read plugin class // Read plugin class
String pluginClassName = pluginElement.getText().trim(); String pluginClassName = pluginElement.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (pluginClassName.startsWith("se.sics")) {
pluginClassName = pluginClassName.replaceFirst("se\\.sics", "org.contikios");
}
/* Backwards compatibility: old visualizers were replaced */ /* Backwards compatibility: old visualizers were replaced */
if (pluginClassName.equals("org.contikios.cooja.plugins.VisUDGM") || if (pluginClassName.equals("org.contikios.cooja.plugins.VisUDGM") ||
pluginClassName.equals("org.contikios.cooja.plugins.VisBattery") || pluginClassName.equals("org.contikios.cooja.plugins.VisBattery") ||
pluginClassName.equals("org.contikios.cooja.plugins.VisTraffic") || pluginClassName.equals("org.contikios.cooja.plugins.VisTraffic") ||
pluginClassName.equals("org.contikios.cooja.plugins.VisState") || pluginClassName.equals("org.contikios.cooja.plugins.VisState") ||
pluginClassName.equals("org.contikios.cooja.plugins.VisUDGM")) { pluginClassName.equals("org.contikios.cooja.plugins.VisUDGM")) {
logger.warn("Old simulation config detected: visualizers have been remade"); logger.warn("Old simulation config detected: visualizers have been remade");
pluginClassName = "org.contikios.cooja.plugins.Visualizer"; pluginClassName = "org.contikios.cooja.plugins.Visualizer";
} }
Class<? extends Plugin> pluginClass = Class<? extends Plugin> pluginClass =

View File

@ -600,6 +600,12 @@ public class Simulation extends Observable implements Runnable {
// Radio medium // Radio medium
if (element.getName().equals("radiomedium")) { if (element.getName().equals("radiomedium")) {
String radioMediumClassName = element.getText().trim(); String radioMediumClassName = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (radioMediumClassName.startsWith("se.sics")) {
radioMediumClassName = radioMediumClassName.replaceFirst("se\\.sics", "org.contikios");
}
Class<? extends RadioMedium> radioMediumClass = cooja.tryLoadClass( Class<? extends RadioMedium> radioMediumClass = cooja.tryLoadClass(
this, RadioMedium.class, radioMediumClassName); this, RadioMedium.class, radioMediumClassName);
@ -643,6 +649,11 @@ public class Simulation extends Observable implements Runnable {
if (element.getName().equals("motetype")) { if (element.getName().equals("motetype")) {
String moteTypeClassName = element.getText().trim(); String moteTypeClassName = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (moteTypeClassName.startsWith("se.sics")) {
moteTypeClassName = moteTypeClassName.replaceFirst("se\\.sics", "org.contikios");
}
/* Try to recreate simulation using a different mote type */ /* Try to recreate simulation using a different mote type */
if (visAvailable) { if (visAvailable) {
String[] availableMoteTypes = getCooja().getProjectConfig().getStringArrayValue("org.contikios.cooja.Cooja.MOTETYPES"); String[] availableMoteTypes = getCooja().getProjectConfig().getStringArrayValue("org.contikios.cooja.Cooja.MOTETYPES");

View File

@ -35,7 +35,6 @@ import java.util.Collection;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import org.contikios.cooja.Mote; import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface; import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler; import org.contikios.cooja.MoteInterfaceHandler;
@ -185,11 +184,18 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
if (name.equals("motetype_identifier")) { if (name.equals("motetype_identifier")) {
/* Ignored: handled by simulation */ /* Ignored: handled by simulation */
} else if (name.equals("interface_config")) { } else if (name.equals("interface_config")) {
String intfClass = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
Class<? extends MoteInterface> moteInterfaceClass = Class<? extends MoteInterface> moteInterfaceClass =
simulation.getCooja().tryLoadClass(this, MoteInterface.class, element.getText().trim()); simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass);
if (moteInterfaceClass == null) { if (moteInterfaceClass == null) {
logger.fatal("Could not load mote interface class: " + element.getText().trim()); logger.fatal("Could not load mote interface class: " + intfClass);
return false; return false;
} }

View File

@ -1320,18 +1320,21 @@ public class ContikiMoteType implements MoteType {
} else if (name.equals("netstack")) { } else if (name.equals("netstack")) {
netStack = NetworkStack.parseConfig(element.getText()); netStack = NetworkStack.parseConfig(element.getText());
} else if (name.equals("moteinterface")) { } else if (name.equals("moteinterface")) {
if (element.getText().trim().equals("org.contikios.cooja.contikimote.interfaces.ContikiLog")) { String intfClass = element.getText().trim();
/* Backwards compatibility: ContikiLog was removed */
} else {
Class<? extends MoteInterface> moteInterfaceClass =
simulation.getCooja().tryLoadClass(
this, MoteInterface.class, element.getText().trim());
if (moteInterfaceClass == null) { /* Backwards compatibility: se.sics -> org.contikios */
logger.warn("Can't find mote interface class: " + element.getText()); if (intfClass.startsWith("se.sics")) {
} else { intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
moteInterfacesClasses.add(moteInterfaceClass); }
}
Class<? extends MoteInterface> moteInterfaceClass =
simulation.getCooja().tryLoadClass(
this, MoteInterface.class, intfClass);
if (moteInterfaceClass == null) {
logger.warn("Can't find mote interface class: " + intfClass);
} else {
moteInterfacesClasses.add(moteInterfaceClass);
} }
} else if ( } else if (
name.equals("contikibasedir") || name.equals("contikibasedir") ||

View File

@ -37,7 +37,6 @@ import java.util.Properties;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import org.contikios.cooja.Mote; import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface; import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler; import org.contikios.cooja.MoteInterfaceHandler;
@ -154,11 +153,18 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
if (name.equals("motetype_identifier")) { if (name.equals("motetype_identifier")) {
/* Ignored: handled by simulation */ /* Ignored: handled by simulation */
} else if (name.equals("interface_config")) { } else if (name.equals("interface_config")) {
String intfClass = element.getText().trim();
/* Backwards compatibility: se.sics -> org.contikios */
if (intfClass.startsWith("se.sics")) {
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
}
Class<? extends MoteInterface> moteInterfaceClass = Class<? extends MoteInterface> moteInterfaceClass =
simulation.getCooja().tryLoadClass(this, MoteInterface.class, element.getText().trim()); simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass);
if (moteInterfaceClass == null) { if (moteInterfaceClass == null) {
logger.warn("Can't find mote interface class: " + element.getText()); logger.warn("Can't find mote interface class: " + intfClass);
return false; return false;
} }

View File

@ -1332,6 +1332,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
for (Element element : configXML) { for (Element element : configXML) {
if (element.getName().equals("skin")) { if (element.getName().equals("skin")) {
String wanted = element.getText(); String wanted = element.getText();
/* Backwards compatibility: se.sics -> org.contikios */
if (wanted.startsWith("se.sics")) {
wanted = wanted.replaceFirst("se\\.sics", "org.contikios");
}
for (Class<? extends VisualizerSkin> skinClass: visualizerSkins) { for (Class<? extends VisualizerSkin> skinClass: visualizerSkins) {
if (wanted.equals(skinClass.getName()) if (wanted.equals(skinClass.getName())
/* Backwards compatibility */ /* Backwards compatibility */