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,6 +409,12 @@ 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();
} }
@ -421,6 +427,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
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,6 +264,11 @@ 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");

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,6 +3634,11 @@ 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") ||

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,19 +1320,22 @@ 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 { /* 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( simulation.getCooja().tryLoadClass(
this, MoteInterface.class, element.getText().trim()); 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);
} else { } else {
moteInterfacesClasses.add(moteInterfaceClass); moteInterfacesClasses.add(moteInterfaceClass);
} }
}
} else if ( } else if (
name.equals("contikibasedir") || name.equals("contikibasedir") ||
name.equals("contikicoredir") || name.equals("contikicoredir") ||

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 */