From 32aa70e5cf527f02e017121d705bfbbdd1bf2ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Tue, 30 Oct 2012 11:42:00 +0100 Subject: [PATCH] Cooja: Allow setting a folder to search for projects --- .../java/se/sics/cooja/COOJAProject.java | 43 ++++++++++++++++++- tools/cooja/java/se/sics/cooja/GUI.java | 17 +++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/COOJAProject.java b/tools/cooja/java/se/sics/cooja/COOJAProject.java index 5e303c5a4..685e333d5 100644 --- a/tools/cooja/java/se/sics/cooja/COOJAProject.java +++ b/tools/cooja/java/se/sics/cooja/COOJAProject.java @@ -29,21 +29,62 @@ package se.sics.cooja; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; - +import java.util.Collections; import org.apache.log4j.Logger; /** * COOJA Project. * * @author Fredrik Osterlind + * @author Moritz StrĂ¼be */ public class COOJAProject { private static Logger logger = Logger.getLogger(COOJAProject.class); + + + public static File[] sarchProjects(File folder){ + return sarchProjects(folder, 3); + } + + public static File[] sarchProjects(File folder, int depth){ + if(depth == 0){ + return null; + } + depth--; + ArrayList dirs = new ArrayList(); + + if(!folder.isDirectory()){ + logger.warn("Project directorys: " + folder.getPath() + "is not a Folder" ); + return null; + } + File[] files = folder.listFiles(); + for(File subf : files){ + if(subf.getName().charAt(0) == '.') continue; + if(subf.isDirectory()){ + File[] newf = sarchProjects(subf, depth); + if(newf != null){ + Collections.addAll(dirs, newf); + } + } + if(subf.getName().equals(GUI.PROJECT_CONFIG_FILENAME)){ + try{ + dirs.add(folder); + } catch(Exception e){ + logger.error("Somthing odd happend", e); + } + } + } + return dirs.toArray(new File[0]); + + } + public File dir = null; public File configFile = null; public ProjectConfig config = null; + public COOJAProject(File dir) { try { diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index 6434d6fd4..a0e7a7826 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -247,7 +247,8 @@ public class GUI extends Observable { public static Properties currentExternalToolsSettings; private static final String externalToolsSettingNames[] = new String[] { - "PATH_CONTIKI", "PATH_COOJA_CORE_RELATIVE", "PATH_COOJA", "PATH_APPS", + "PATH_CONTIKI", "PATH_COOJA_CORE_RELATIVE","PATH_COOJA","PATH_APPS", + "PATH_APPSEARCH", "PATH_MAKE", "PATH_SHELL", @@ -426,6 +427,20 @@ public class GUI extends Observable { currentProjects.add(new COOJAProject(projectDir)); } } + + //Scan for projects + String searchProjectDirs = getExternalToolsSetting("PATH_APPSEARCH", null); + if (searchProjectDirs != null && searchProjectDirs.length() > 0) { + String[] arr = searchProjectDirs.split(";"); + for (String d : arr) { + File searchDir = restorePortablePath(new File(d)); + File[] projects = COOJAProject.sarchProjects(searchDir, 3); + if(projects == null) continue; + for(File p : projects){ + currentProjects.add(new COOJAProject(p)); + } + } + } /* Parse current extension configuration */ try {