removing strict dependency on project platform configuration files (cooja.config).

files are still used if existing.
This commit is contained in:
fros4943 2008-10-03 10:23:05 +00:00
parent 4cc56a741d
commit 70a74f624a
5 changed files with 51 additions and 57 deletions

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.81 2008/09/29 13:02:15 fros4943 Exp $ * $Id: GUI.java,v 1.82 2008/10/03 10:23:05 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -910,18 +910,6 @@ public class GUI extends Observable {
logger.info("> Reparsing project directories and creating config"); logger.info("> Reparsing project directories and creating config");
for (String projectDir : projectDirs) { for (String projectDir : projectDirs) {
logger.info(">> Adding: " + projectDir); logger.info(">> Adding: " + projectDir);
// Check if config file exists
File configFile = new File(projectDir + File.separatorChar + PROJECT_CONFIG_FILENAME);
if (!configFile.exists()) {
logger.debug(">>> Creating empty cooja.config file");
try {
configFile.createNewFile();
} catch (IOException e) {
logger.fatal(">> Error when creating cooja.config file, aborting");
return false;
}
}
gui.currentProjectDirs.add(new File(projectDir)); gui.currentProjectDirs.add(new File(projectDir));
} }
try { try {

View File

@ -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: ProjectConfig.java,v 1.2 2008/02/18 08:18:18 fros4943 Exp $ * $Id: ProjectConfig.java,v 1.3 2008/10/03 10:23:33 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -135,10 +135,15 @@ public class ProjectConfig {
*/ */
public boolean appendProjectDir(File projectDir) public boolean appendProjectDir(File projectDir)
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {
myProjectDirHistory.add(projectDir);
File projectConfig = new File(projectDir.getPath(), File projectConfig = new File(projectDir.getPath(),
GUI.PROJECT_CONFIG_FILENAME); GUI.PROJECT_CONFIG_FILENAME);
myProjectDirHistory.add(projectDir); if (projectConfig.exists()) {
return appendConfigFile(projectConfig); return appendConfigFile(projectConfig);
}
return true;
} }
@ -227,6 +232,11 @@ public class ProjectConfig {
*/ */
public boolean appendConfigFile(File propertyFile) public boolean appendConfigFile(File propertyFile)
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {
if (!propertyFile.exists()) {
logger.warn("Trying to import non-existant project configuration");
return true;
}
FileInputStream in = new FileInputStream(propertyFile); FileInputStream in = new FileInputStream(propertyFile);
return appendConfigStream(myConfig, in); return appendConfigStream(myConfig, in);
} }

View File

@ -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.42 2008/03/19 09:41:03 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.43 2008/10/03 10:25:56 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -2132,9 +2132,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Check that all project directories are valid // Check that all project directories are valid
for (File projectDir : moteTypeProjectDirs) { for (File projectDir : moteTypeProjectDirs) {
File userProjectConfig = new File(projectDir.getPath(), if (!projectDir.exists()) {
GUI.PROJECT_CONFIG_FILENAME);
if (!userProjectConfig.exists()) {
textProjectDirs.setBackground(Color.RED); textProjectDirs.setBackground(Color.RED);
textProjectDirs.setToolTipText("Invalid project directory: " textProjectDirs.setToolTipText("Invalid project directory: "
+ projectDir); + projectDir);

View File

@ -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: ProjectDirectoriesDialog.java,v 1.7 2008/05/02 05:47:53 fros4943 Exp $ * $Id: ProjectDirectoriesDialog.java,v 1.8 2008/10/03 10:26:16 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -383,7 +383,7 @@ public class ProjectDirectoriesDialog extends JDialog {
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new java.io.File(".")); fc.setCurrentDirectory(new java.io.File(GUI.getExternalToolsSetting("PATH_CONTIKI")));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle("Select project directory"); fc.setDialogTitle("Select project directory");
@ -446,34 +446,34 @@ public class ProjectDirectoriesDialog extends JDialog {
return; return;
} }
File projectConfigFile = new File(projectDir.getPath(), // File projectConfigFile = new File(projectDir.getPath(),
GUI.PROJECT_CONFIG_FILENAME); // GUI.PROJECT_CONFIG_FILENAME);
if (!projectConfigFile.exists()) { // if (!projectConfigFile.exists()) {
//
Object[] options = {"Create", // Object[] options = {"Create",
"Cancel"}; // "Cancel"};
//
int n = JOptionPane.showOptionDialog( // int n = JOptionPane.showOptionDialog(
this, // this,
"No " + GUI.PROJECT_CONFIG_FILENAME + " file exists in specified directory!" // "No " + GUI.PROJECT_CONFIG_FILENAME + " file exists in specified directory!"
+ "\nCreate an empty " + GUI.PROJECT_CONFIG_FILENAME + " file?", // + "\nCreate an empty " + GUI.PROJECT_CONFIG_FILENAME + " file?",
"Create project directory configuration?", // "Create project directory configuration?",
JOptionPane.YES_NO_OPTION, // JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, // JOptionPane.QUESTION_MESSAGE,
null, options, options[1]); // null, options, options[1]);
//
if (n == JOptionPane.NO_OPTION) { // if (n == JOptionPane.NO_OPTION) {
return; // return;
} // }
//
try { // try {
projectConfigFile.createNewFile(); // projectConfigFile.createNewFile();
} catch (IOException e) { // } catch (IOException e) {
logger.fatal("Could not create project directory configuration file: " // logger.fatal("Could not create project directory configuration file: "
+ projectConfigFile); // + projectConfigFile);
return; // return;
} // }
} // }
changeableProjectsList.add(projectDir.getPath(), index); changeableProjectsList.add(projectDir.getPath(), index);
} }

View File

@ -8,8 +8,6 @@ import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.GUI;
class ProjectDirectoryInputDialog extends JDialog implements ActionListener, PropertyChangeListener { class ProjectDirectoryInputDialog extends JDialog implements ActionListener, PropertyChangeListener {
private static Logger logger = Logger.getLogger(ProjectDirectoryInputDialog.class); private static Logger logger = Logger.getLogger(ProjectDirectoryInputDialog.class);
@ -105,11 +103,11 @@ class ProjectDirectoryInputDialog extends JDialog implements ActionListener, Pro
return; return;
} }
if (!new File(projectDir, GUI.PROJECT_CONFIG_FILENAME).exists()) { // if (!new File(projectDir, GUI.PROJECT_CONFIG_FILENAME).exists()) {
textField.setBackground(Color.LIGHT_GRAY); // textField.setBackground(Color.LIGHT_GRAY);
textField.setToolTipText("No configuration file found"); // textField.setToolTipText("No configuration file found");
return; // return;
} // }
textField.setBackground(Color.WHITE); textField.setBackground(Color.WHITE);
textField.setToolTipText(""); textField.setToolTipText("");