*added support for library files in user platforms (for example in dev and sys subdirectories)
*added user platform history in platform configs *throwing 'include user platform directories' flags to compiler *fixed bug in platform config viewer *removed old custom class loader
This commit is contained in:
parent
e10f020fec
commit
c8f379adf7
|
@ -1,143 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the Institute nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* $Id: DirectoryClassLoader.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
package se.sics.cooja;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads an external file from the given directory as a Java class.
|
|
||||||
*
|
|
||||||
* @author Fredrik Osterlind
|
|
||||||
*/
|
|
||||||
public class DirectoryClassLoader extends ClassLoader {
|
|
||||||
private static Logger logger = Logger.getLogger(DirectoryClassLoader.class);
|
|
||||||
private File directory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new class loader reading from given directory.
|
|
||||||
*
|
|
||||||
* @param directory
|
|
||||||
* Directory
|
|
||||||
*/
|
|
||||||
public DirectoryClassLoader(File directory) {
|
|
||||||
super();
|
|
||||||
this.directory = directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new class loader reading from given directory, with the given
|
|
||||||
* class loader as parent class loader.
|
|
||||||
*
|
|
||||||
* @param parent
|
|
||||||
* Parent class loader
|
|
||||||
* @param directory
|
|
||||||
* Directory
|
|
||||||
*/
|
|
||||||
public DirectoryClassLoader(ClassLoader parent, File directory) {
|
|
||||||
super(parent);
|
|
||||||
this.directory = directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
String fullFilePath = directory.getPath() + File.separatorChar + name
|
|
||||||
+ ".class";
|
|
||||||
|
|
||||||
// Read external file
|
|
||||||
//logger.info("Directory class loader reading file: " + fullFilePath);
|
|
||||||
byte[] classData = loadClassData(fullFilePath);
|
|
||||||
if (classData == null) {
|
|
||||||
throw new ClassNotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create class
|
|
||||||
return defineClass(name, classData, 0, classData.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] loadClassData(String name) {
|
|
||||||
// Support for fill class names in configuration file
|
|
||||||
// TODO Quick-fix (may contain bugs)
|
|
||||||
name = name.replace('.', File.separatorChar);
|
|
||||||
name = name.replace(File.separatorChar + "class", ".class");
|
|
||||||
|
|
||||||
// Open file for read access
|
|
||||||
File classFile = new File(name);
|
|
||||||
InputStream inputStream = null;
|
|
||||||
if (!classFile.exists()) {
|
|
||||||
//logger.fatal("File " + classFile + " does not exist!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
inputStream = new FileInputStream(classFile);
|
|
||||||
|
|
||||||
if (inputStream == null) {
|
|
||||||
logger.fatal("File input stream is null!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
logger.fatal("Could not open file (not found?)!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
long fileSize = classFile.length();
|
|
||||||
|
|
||||||
if (fileSize > Integer.MAX_VALUE) {
|
|
||||||
logger.fatal("Class file is too large");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read class data
|
|
||||||
byte[] classData = new byte[(int) fileSize];
|
|
||||||
int offset = 0;
|
|
||||||
int numRead = 0;
|
|
||||||
try {
|
|
||||||
while (offset < classData.length
|
|
||||||
&& (numRead = inputStream.read(classData, offset, classData.length
|
|
||||||
- offset)) >= 0) {
|
|
||||||
offset += numRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.fatal("Error when reading class file");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure all the bytes have been read in
|
|
||||||
if (offset < classData.length) {
|
|
||||||
logger.fatal("Could not read entire class file");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return classData;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: GUI.java,v 1.3 2006/08/22 12:25:24 nifi Exp $
|
* $Id: GUI.java,v 1.4 2006/08/22 15:28:17 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -560,24 +560,15 @@ public class GUI extends JDesktopPane {
|
||||||
unregisterPositioners();
|
unregisterPositioners();
|
||||||
unregisterRadioMediums();
|
unregisterRadioMediums();
|
||||||
|
|
||||||
|
try {
|
||||||
// Read default configuration
|
// Read default configuration
|
||||||
platformConfig = new PlatformConfig();
|
platformConfig = new PlatformConfig(true);
|
||||||
// logger.info("Loading default platform configuration: " +
|
// logger.info("Loading default platform configuration: " +
|
||||||
// PLATFORM_DEFAULT_CONFIG_FILENAME);
|
// PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
try {
|
} catch (FileNotFoundException e) {
|
||||||
InputStream input =
|
|
||||||
GUI.class.getResourceAsStream(PLATFORM_DEFAULT_CONFIG_FILENAME);
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
platformConfig.appendConfig(input);
|
|
||||||
} finally {
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.fatal("Could not find default platform config file: "
|
logger.fatal("Could not find default platform config file: "
|
||||||
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
|
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("Error when reading default platform config file: "
|
logger.fatal("Error when reading default platform config file: "
|
||||||
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
|
+ PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
|
@ -586,20 +577,18 @@ public class GUI extends JDesktopPane {
|
||||||
|
|
||||||
// Append user platform configurations
|
// Append user platform configurations
|
||||||
for (File userPlatform : currentUserPlatforms) {
|
for (File userPlatform : currentUserPlatforms) {
|
||||||
File userPlatformConfig = new File(userPlatform.getPath()
|
|
||||||
+ File.separatorChar + PLATFORM_CONFIG_FILENAME);
|
|
||||||
// logger.info("Loading platform configuration: " + userPlatformConfig);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Append config to general config
|
// Append config to general config
|
||||||
platformConfig.appendConfig(userPlatformConfig);
|
// logger.info("Appending user platform configuration: " + userPlatform);
|
||||||
|
platformConfig.appendUserPlatform(userPlatform);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.fatal("Could not find platform config file: "
|
logger.fatal("Could not find platform config file: "
|
||||||
+ userPlatformConfig);
|
+ userPlatform);
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("Error when reading platform config file: "
|
logger.fatal("Error when reading platform config file: "
|
||||||
+ userPlatformConfig);
|
+ userPlatform);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1570,10 +1559,8 @@ public class GUI extends JDesktopPane {
|
||||||
urls.add((new File(userPlatform, "java")).toURL());
|
urls.add((new File(userPlatform, "java")).toURL());
|
||||||
|
|
||||||
// Read configuration to check if any JAR files should be loaded
|
// Read configuration to check if any JAR files should be loaded
|
||||||
File userPlatformConfigFile =
|
PlatformConfig userPlatformConfig = new PlatformConfig(false);
|
||||||
new File(userPlatform, PLATFORM_CONFIG_FILENAME);
|
userPlatformConfig.appendUserPlatform(userPlatform);
|
||||||
PlatformConfig userPlatformConfig = new PlatformConfig();
|
|
||||||
userPlatformConfig.appendConfig(userPlatformConfigFile);
|
|
||||||
String[] platformJarFiles = userPlatformConfig.getStringArrayValue(
|
String[] platformJarFiles = userPlatformConfig.getStringArrayValue(
|
||||||
GUI.class, "JARFILES");
|
GUI.class, "JARFILES");
|
||||||
if (platformJarFiles != null && platformJarFiles.length > 0) {
|
if (platformJarFiles != null && platformJarFiles.length > 0) {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: PlatformConfig.java,v 1.1 2006/08/21 12:12:56 fros4943 Exp $
|
* $Id: PlatformConfig.java,v 1.2 2006/08/22 15:28:17 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -86,13 +86,124 @@ import org.apache.log4j.Logger;
|
||||||
public class PlatformConfig {
|
public class PlatformConfig {
|
||||||
private static Logger logger = Logger.getLogger(PlatformConfig.class);
|
private static Logger logger = Logger.getLogger(PlatformConfig.class);
|
||||||
|
|
||||||
private Properties myConfig = new Properties();
|
private Properties myConfig = null;
|
||||||
|
private Vector<File> myUserPlatformHistory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new empty platform configuration.
|
* Creates new platform configuration.
|
||||||
|
*
|
||||||
|
* @param useDefault
|
||||||
|
* If true the default configuration will be loaded
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* If file was not found
|
||||||
|
* @throws IOException
|
||||||
|
* Stream read error
|
||||||
*/
|
*/
|
||||||
public PlatformConfig() {
|
public PlatformConfig(boolean useDefault) throws IOException,
|
||||||
|
FileNotFoundException {
|
||||||
|
// Create empty configuration
|
||||||
myConfig = new Properties();
|
myConfig = new Properties();
|
||||||
|
myUserPlatformHistory = new Vector<File>();
|
||||||
|
|
||||||
|
if (useDefault) {
|
||||||
|
InputStream input = GUI.class
|
||||||
|
.getResourceAsStream(GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
|
if (input != null) {
|
||||||
|
try {
|
||||||
|
appendConfigStream(input);
|
||||||
|
} finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new FileNotFoundException(GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the given user platform's config file. Thus method also saved a
|
||||||
|
* local history of which user platforms has been loaded.
|
||||||
|
*
|
||||||
|
* @param userPlatform
|
||||||
|
* User platform
|
||||||
|
* @return True if loaded OK
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* If file was not found
|
||||||
|
* @throws IOException
|
||||||
|
* Stream read error
|
||||||
|
*/
|
||||||
|
public boolean appendUserPlatform(File userPlatform)
|
||||||
|
throws FileNotFoundException, IOException {
|
||||||
|
File userPlatformConfig = new File(userPlatform.getPath()
|
||||||
|
+ File.separatorChar + GUI.PLATFORM_CONFIG_FILENAME);
|
||||||
|
myUserPlatformHistory.add(userPlatform);
|
||||||
|
return appendConfigFile(userPlatformConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user platform earlier appended to this configuration that
|
||||||
|
* defined the given key. If the key is of an array format and the given array
|
||||||
|
* element is non-null, then the user platform that added this element will be
|
||||||
|
* returned instead. If no such user platform can be found null is returned
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* @param callingClass
|
||||||
|
* Class which value belongs to
|
||||||
|
* @param key
|
||||||
|
* Key
|
||||||
|
* @param value
|
||||||
|
* Element of array
|
||||||
|
* @return User platform
|
||||||
|
*/
|
||||||
|
public File getUserPlatformDefining(Class callingClass, String key, String arrayElement) {
|
||||||
|
|
||||||
|
// Check that key really exists in current config
|
||||||
|
if (getStringValue(callingClass, key, null) == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that element really exists, if any
|
||||||
|
if (arrayElement != null) {
|
||||||
|
String[] array = getStringArrayValue(callingClass, key);
|
||||||
|
boolean foundValue = false;
|
||||||
|
for (int c=0; c < array.length; c++) {
|
||||||
|
if (array[c].equals(arrayElement))
|
||||||
|
foundValue = true;
|
||||||
|
}
|
||||||
|
if (!foundValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search in all user platform in reversed order
|
||||||
|
try {
|
||||||
|
PlatformConfig remadeConfig = new PlatformConfig(false);
|
||||||
|
|
||||||
|
for (int i=myUserPlatformHistory.size()-1; i >= 0; i--) {
|
||||||
|
remadeConfig.appendUserPlatform(myUserPlatformHistory.get(i));
|
||||||
|
|
||||||
|
if (arrayElement != null) {
|
||||||
|
// Look for array
|
||||||
|
String[] array = remadeConfig.getStringArrayValue(callingClass, key);
|
||||||
|
for (int c=0; c < array.length; c++) {
|
||||||
|
if (array[c].equals(arrayElement))
|
||||||
|
return myUserPlatformHistory.get(i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Look for key
|
||||||
|
if (remadeConfig.getStringValue(callingClass, key, null) != null) {
|
||||||
|
return myUserPlatformHistory.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.fatal("Exception when searching in user platform history: " + e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,6 +211,9 @@ public class PlatformConfig {
|
||||||
* If a property already exists it will be overwritten, unless the new value
|
* If a property already exists it will be overwritten, unless the new value
|
||||||
* begins with a '+' in which case the old value will be extended.
|
* begins with a '+' in which case the old value will be extended.
|
||||||
*
|
*
|
||||||
|
* WARNING! The user platform history will not be saved if this method is
|
||||||
|
* called, instead the appendUserPlatform method should be used.
|
||||||
|
*
|
||||||
* @param propertyFile
|
* @param propertyFile
|
||||||
* Property file to read
|
* Property file to read
|
||||||
* @return True if file was read ok, false otherwise
|
* @return True if file was read ok, false otherwise
|
||||||
|
@ -108,35 +222,33 @@ public class PlatformConfig {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* Stream read error
|
* Stream read error
|
||||||
*/
|
*/
|
||||||
public boolean appendConfig(File propertyFile) throws FileNotFoundException,
|
public boolean appendConfigFile(File propertyFile)
|
||||||
IOException {
|
throws FileNotFoundException, IOException {
|
||||||
return appendConfig(myConfig, propertyFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean appendConfig(Properties currentValues,
|
|
||||||
File propertyFile) throws FileNotFoundException, IOException {
|
|
||||||
// Open file
|
|
||||||
FileInputStream in = new FileInputStream(propertyFile);
|
FileInputStream in = new FileInputStream(propertyFile);
|
||||||
return appendConfig(currentValues, in);
|
return appendConfigStream(myConfig, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads propertues from the given stream and appends them to the current
|
* Reads properties from the given stream and appends them to the current
|
||||||
* configuration. If a property already exists it will be overwritten, unless
|
* configuration. If a property already exists it will be overwritten, unless
|
||||||
* the new value begins with a '+' in which case the old value will be
|
* the new value begins with a '+' in which case the old value will be
|
||||||
* extended.
|
* extended.
|
||||||
*
|
*
|
||||||
|
* WARNING! The user platform history will not be saved if this method is
|
||||||
|
* called, instead the appendUserPlatform method should be used.
|
||||||
|
*
|
||||||
* @param configFileStream
|
* @param configFileStream
|
||||||
* Stream to read from
|
* Stream to read from
|
||||||
* @return True if stream was read ok, false otherwise
|
* @return True if stream was read ok, false otherwise
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* Stream read error
|
* Stream read error
|
||||||
*/
|
*/
|
||||||
public boolean appendConfig(InputStream configFileStream) throws IOException {
|
public boolean appendConfigStream(InputStream configFileStream)
|
||||||
return appendConfig(myConfig, configFileStream);
|
throws IOException {
|
||||||
|
return appendConfigStream(myConfig, configFileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean appendConfig(Properties currentValues,
|
private static boolean appendConfigStream(Properties currentValues,
|
||||||
InputStream configFileStream) throws IOException {
|
InputStream configFileStream) throws IOException {
|
||||||
|
|
||||||
// Read from stream
|
// Read from stream
|
||||||
|
@ -151,7 +263,8 @@ public class PlatformConfig {
|
||||||
String property = newProps.getProperty(key);
|
String property = newProps.getProperty(key);
|
||||||
if (property.startsWith("+ ")) {
|
if (property.startsWith("+ ")) {
|
||||||
if (currentValues.getProperty(key) != null)
|
if (currentValues.getProperty(key) != null)
|
||||||
currentValues.setProperty(key, currentValues.getProperty(key) + " " + property.substring(1).trim());
|
currentValues.setProperty(key, currentValues.getProperty(key) + " "
|
||||||
|
+ property.substring(1).trim());
|
||||||
else
|
else
|
||||||
currentValues.setProperty(key, property.substring(1).trim());
|
currentValues.setProperty(key, property.substring(1).trim());
|
||||||
} else
|
} else
|
||||||
|
@ -189,7 +302,8 @@ public class PlatformConfig {
|
||||||
String val = currentValues.getProperty(callingClass.getName() + "." + id);
|
String val = currentValues.getProperty(callingClass.getName() + "." + id);
|
||||||
|
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
logger.warn("Could not find key named '" + callingClass.getName() + "." + id + "'");
|
logger.warn("Could not find key named '" + callingClass.getName() + "."
|
||||||
|
+ id + "'");
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +367,21 @@ public class PlatformConfig {
|
||||||
return getStringValue(callingClass, id);
|
return getStringValue(callingClass, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get string array value with given id.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* Id of value to return
|
||||||
|
* @return Value or null if id wasn't found
|
||||||
|
*/
|
||||||
|
public String[] getStringArrayValue(String id) {
|
||||||
|
String stringVal = getStringValue(id);
|
||||||
|
if (stringVal == null)
|
||||||
|
return new String[0];
|
||||||
|
|
||||||
|
return getStringValue(id).split(" ");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get integer value with given id.
|
* Get integer value with given id.
|
||||||
*
|
*
|
||||||
|
@ -352,8 +481,13 @@ public class PlatformConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlatformConfig clone() {
|
public PlatformConfig clone() {
|
||||||
PlatformConfig clone = new PlatformConfig();
|
try {
|
||||||
|
PlatformConfig clone = new PlatformConfig(false);
|
||||||
clone.myConfig = (Properties) this.myConfig.clone();
|
clone.myConfig = (Properties) this.myConfig.clone();
|
||||||
|
clone.myUserPlatformHistory = (Vector<File>) this.myUserPlatformHistory.clone();
|
||||||
return clone;
|
return clone;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ContikiMoteTypeDialog.java,v 1.3 2006/08/22 12:26:36 nifi Exp $
|
* $Id: ContikiMoteTypeDialog.java,v 1.4 2006/08/22 15:28:18 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -898,8 +898,19 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
String[] projectSourceFiles = newMoteTypeConfig.getStringArrayValue(
|
String[] projectSourceFiles = newMoteTypeConfig.getStringArrayValue(
|
||||||
ContikiMoteType.class, "C_SOURCES");
|
ContikiMoteType.class, "C_SOURCES");
|
||||||
for (String projectSourceFile : projectSourceFiles) {
|
for (String projectSourceFile : projectSourceFiles) {
|
||||||
if (!projectSourceFile.trim().equals("")) {
|
if (!projectSourceFile.equals("")) {
|
||||||
filesToCompile.add(new File(projectSourceFile));
|
File file = new File(projectSourceFile);
|
||||||
|
if (file.getParent() != null) {
|
||||||
|
// Find which user platform added this file
|
||||||
|
File userPlatform = newMoteTypeConfig.getUserPlatformDefining(
|
||||||
|
ContikiMoteType.class, "C_SOURCES", projectSourceFile);
|
||||||
|
if (userPlatform != null) {
|
||||||
|
// We found a user platform - Add directory
|
||||||
|
filesToCompile.add(new File(userPlatform.getPath(),
|
||||||
|
file.getParent()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filesToCompile.add(new File(file.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1165,16 +1176,20 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
|
|
||||||
String sourceDirs = System.getProperty("PROJECTDIRS", "");
|
String sourceDirs = System.getProperty("PROJECTDIRS", "");
|
||||||
String sourceFileNames = "";
|
String sourceFileNames = "";
|
||||||
|
String ccFlags = GUI.getExternalToolsSetting("COMPILER_ARGS", "");
|
||||||
|
|
||||||
for (File sourceFile : sourceFiles) {
|
for (File sourceFile : sourceFiles) {
|
||||||
if (sourceFile.isDirectory()) {
|
if (sourceFile.isDirectory()) {
|
||||||
// Add directory to search path
|
// Add directory to search path
|
||||||
sourceDirs += " "
|
sourceDirs += " "
|
||||||
+ sourceFile.getPath().replace(File.separatorChar, '/');
|
+ sourceFile.getPath().replace(File.separatorChar, '/');
|
||||||
|
ccFlags += " -I" + sourceFile.getPath().replace(File.separatorChar, '/');
|
||||||
} else if (sourceFile.isFile()) {
|
} else if (sourceFile.isFile()) {
|
||||||
// Add both file name and directory
|
// Add both file name and directory
|
||||||
|
if (sourceFile.getParent() != null) {
|
||||||
sourceDirs += " " +
|
sourceDirs += " " +
|
||||||
sourceFile.getParent().replace(File.separatorChar, '/');
|
sourceFile.getParent().replace(File.separatorChar, '/');
|
||||||
|
}
|
||||||
sourceFileNames += " " + sourceFile.getName();
|
sourceFileNames += " " + sourceFile.getName();
|
||||||
} else {
|
} else {
|
||||||
// Add filename and hope Contiki knows where to find it...
|
// Add filename and hope Contiki knows where to find it...
|
||||||
|
@ -1182,12 +1197,16 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("Project dirs: " + sourceDirs);
|
||||||
|
logger.info("Project sources: " + sourceFileNames);
|
||||||
|
logger.info("Compiler flags: " + ccFlags);
|
||||||
|
|
||||||
String[] env = new String[]{
|
String[] env = new String[]{
|
||||||
"CONTIKI=" + contikiDir.getPath().replace(File.separatorChar, '/'),
|
"CONTIKI=" + contikiDir.getPath().replace(File.separatorChar, '/'),
|
||||||
"TARGET=cooja", "TYPEID=" + identifier,
|
"TARGET=cooja", "TYPEID=" + identifier,
|
||||||
"LD_ARGS_1=" + GUI.getExternalToolsSetting("LINKER_ARGS_1", ""),
|
"LD_ARGS_1=" + GUI.getExternalToolsSetting("LINKER_ARGS_1", ""),
|
||||||
"LD_ARGS_2=" + GUI.getExternalToolsSetting("LINKER_ARGS_2", ""),
|
"LD_ARGS_2=" + GUI.getExternalToolsSetting("LINKER_ARGS_2", ""),
|
||||||
"EXTRA_CC_ARGS=" + GUI.getExternalToolsSetting("COMPILER_ARGS", ""),
|
"EXTRA_CC_ARGS=" + ccFlags,
|
||||||
"CC=" + GUI.getExternalToolsSetting("PATH_C_COMPILER"),
|
"CC=" + GUI.getExternalToolsSetting("PATH_C_COMPILER"),
|
||||||
"LD=" + GUI.getExternalToolsSetting("PATH_LINKER"), "COMPILE_MAIN=1",
|
"LD=" + GUI.getExternalToolsSetting("PATH_LINKER"), "COMPILE_MAIN=1",
|
||||||
"PROJECTDIRS=" + sourceDirs,
|
"PROJECTDIRS=" + sourceDirs,
|
||||||
|
@ -2008,18 +2027,12 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
|
|
||||||
// Merge with all user platform configs (if any)
|
// Merge with all user platform configs (if any)
|
||||||
for (File userPlatform : moteTypeUserPlatforms) {
|
for (File userPlatform : moteTypeUserPlatforms) {
|
||||||
File userPlatformConfig = new File(userPlatform.getPath()
|
|
||||||
+ File.separatorChar + GUI.PLATFORM_CONFIG_FILENAME);
|
|
||||||
if (userPlatformConfig.exists()) {
|
|
||||||
try {
|
try {
|
||||||
newMoteTypeConfig.appendConfig(userPlatformConfig);
|
newMoteTypeConfig.appendUserPlatform(userPlatform);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Error when parsing user platform config: " + ex);
|
logger.fatal("Error when parsing user platform config: " + ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
logger.fatal("Could not find user platform config file: "
|
|
||||||
+ userPlatformConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all mote interfaces available from config
|
// Get all mote interfaces available from config
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: UserPlatformsDialog.java,v 1.2 2006/08/22 08:56:08 nifi Exp $
|
* $Id: UserPlatformsDialog.java,v 1.3 2006/08/22 15:28:18 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
|
@ -220,22 +220,14 @@ public class UserPlatformsDialog extends JDialog {
|
||||||
button = new JButton("View resulting config");
|
button = new JButton("View resulting config");
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PlatformConfig config;
|
||||||
|
try {
|
||||||
// Create default configuration
|
// Create default configuration
|
||||||
PlatformConfig config = new PlatformConfig();
|
config = new PlatformConfig(true);
|
||||||
try {
|
} catch (FileNotFoundException ex) {
|
||||||
InputStream input =
|
logger.fatal("Could not find default platform config file: "
|
||||||
GUI.class.getResourceAsStream(GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
config.appendConfig(input);
|
|
||||||
} finally {
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.fatal("Could not find default platform config file1: "
|
|
||||||
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.fatal("Error when reading default platform config file: "
|
logger.fatal("Error when reading default platform config file: "
|
||||||
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
+ GUI.PLATFORM_DEFAULT_CONFIG_FILENAME);
|
||||||
|
@ -245,10 +237,8 @@ public class UserPlatformsDialog extends JDialog {
|
||||||
// Add the fixed platform configurations
|
// Add the fixed platform configurations
|
||||||
if (fixedPlatformsList != null) {
|
if (fixedPlatformsList != null) {
|
||||||
for (String userPlatform : fixedPlatformsList.getItems()) {
|
for (String userPlatform : fixedPlatformsList.getItems()) {
|
||||||
File userPlatformConfig = new File(userPlatform + File.separatorChar
|
|
||||||
+ GUI.PLATFORM_CONFIG_FILENAME);
|
|
||||||
try {
|
try {
|
||||||
config.appendConfig(userPlatformConfig);
|
config.appendUserPlatform(new File(userPlatform));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Error when merging configurations: " + ex);
|
logger.fatal("Error when merging configurations: " + ex);
|
||||||
return;
|
return;
|
||||||
|
@ -258,10 +248,8 @@ public class UserPlatformsDialog extends JDialog {
|
||||||
|
|
||||||
// Add the user platform configurations
|
// Add the user platform configurations
|
||||||
for (String userPlatform : changablePlatformsList.getItems()) {
|
for (String userPlatform : changablePlatformsList.getItems()) {
|
||||||
File userPlatformConfig = new File(userPlatform + File.separatorChar
|
|
||||||
+ GUI.PLATFORM_CONFIG_FILENAME);
|
|
||||||
try {
|
try {
|
||||||
config.appendConfig(userPlatformConfig);
|
config.appendUserPlatform(new File(userPlatform));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Error when merging configurations: " + ex);
|
logger.fatal("Error when merging configurations: " + ex);
|
||||||
return;
|
return;
|
||||||
|
@ -422,6 +410,9 @@ class ConfigViewer extends JDialog {
|
||||||
String propertyName = allPropertyNames.nextElement();
|
String propertyName = allPropertyNames.nextElement();
|
||||||
|
|
||||||
keyPane.add(new JLabel(propertyName));
|
keyPane.add(new JLabel(propertyName));
|
||||||
|
if (config.getStringValue(propertyName).equals(""))
|
||||||
|
valuePane.add(new JLabel(" "));
|
||||||
|
else
|
||||||
valuePane.add(new JLabel(config.getStringValue(propertyName)));
|
valuePane.add(new JLabel(config.getStringValue(propertyName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue