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")) {
/* Ignored: handled by simulation */
} 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(
this, MoteInterface.class, element.getText().trim());
this, MoteInterface.class, intfClass);
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;
}

View file

@ -292,6 +292,11 @@ public class MicaZMoteType implements MoteType {
} else if (name.equals("moteinterface")) {
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 =
simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass);

View file

@ -40,7 +40,6 @@ import java.util.Hashtable;
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.contikios.cooja.ContikiError;
import org.contikios.cooja.Cooja;
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.MspBreakpoint;
import org.contikios.cooja.plugins.Visualizer;
import se.sics.mspsim.cli.CommandContext;
import se.sics.mspsim.cli.CommandHandler;
import se.sics.mspsim.cli.LineListener;
@ -409,18 +409,25 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
setWatchpointConfigXML(element.getChildren(), visAvailable);
} 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");
}
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")) {
intfClass = MspSerial.class.getName();
intfClass = MspSerial.class.getName();
}
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")) {
intfClass = MspSerial.class.getName();
intfClass = MspSerial.class.getName();
}
Class<? extends MoteInterface> moteInterfaceClass = simulation.getCooja().tryLoadClass(
this, MoteInterface.class, intfClass);

View file

@ -264,22 +264,27 @@ public abstract class MspMoteType implements MoteType {
} else if (name.equals("moteinterface")) {
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 */
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.MspIPAddress")) {
logger.warn("Old simulation config detected: IP address interface was moved");
intfClass = IPAddress.class.getName();
logger.warn("Old simulation config detected: IP address interface was moved");
intfClass = IPAddress.class.getName();
}
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.ESBLog")) {
logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial");
intfClass = MspSerial.class.getName();
logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial");
intfClass = MspSerial.class.getName();
}
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkyByteRadio")) {
logger.warn("Old simulation config detected: SkyByteRadio was replaced by Msp802154Radio");
intfClass = Msp802154Radio.class.getName();
logger.warn("Old simulation config detected: SkyByteRadio was replaced by Msp802154Radio");
intfClass = Msp802154Radio.class.getName();
}
if (intfClass.equals("org.contikios.cooja.mspmote.interfaces.SkySerial")) {
logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial");
intfClass = MspSerial.class.getName();
logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial");
intfClass = MspSerial.class.getName();
}
Class<? extends MoteInterface> moteInterfaceClass =

View file

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

View file

@ -600,6 +600,12 @@ public class Simulation extends Observable implements Runnable {
// Radio medium
if (element.getName().equals("radiomedium")) {
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(
this, RadioMedium.class, radioMediumClassName);
@ -643,6 +649,11 @@ public class Simulation extends Observable implements Runnable {
if (element.getName().equals("motetype")) {
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 */
if (visAvailable) {
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.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
@ -185,11 +184,18 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
if (name.equals("motetype_identifier")) {
/* Ignored: handled by simulation */
} 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 =
simulation.getCooja().tryLoadClass(this, MoteInterface.class, element.getText().trim());
simulation.getCooja().tryLoadClass(this, MoteInterface.class, intfClass);
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;
}

View file

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

View file

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

View file

@ -1332,6 +1332,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
for (Element element : configXML) {
if (element.getName().equals("skin")) {
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) {
if (wanted.equals(skinClass.getName())
/* Backwards compatibility */