Cooja: Allow setting a folder to search for projects

This commit is contained in:
Moritz 'Morty' Strübe 2012-10-30 11:42:00 +01:00
parent 142fa4a9a5
commit 32aa70e5cf
2 changed files with 58 additions and 2 deletions

View file

@ -29,21 +29,62 @@
package se.sics.cooja; package se.sics.cooja;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* COOJA Project. * COOJA Project.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
* @author Moritz Strübe
*/ */
public class COOJAProject { public class COOJAProject {
private static Logger logger = Logger.getLogger(COOJAProject.class); 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<File> dirs = new ArrayList<File>();
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 dir = null;
public File configFile = null; public File configFile = null;
public ProjectConfig config = null; public ProjectConfig config = null;
public COOJAProject(File dir) { public COOJAProject(File dir) {
try { try {

View file

@ -247,7 +247,8 @@ public class GUI extends Observable {
public static Properties currentExternalToolsSettings; public static Properties currentExternalToolsSettings;
private static final String externalToolsSettingNames[] = new String[] { 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_MAKE",
"PATH_SHELL", "PATH_SHELL",
@ -426,6 +427,20 @@ public class GUI extends Observable {
currentProjects.add(new COOJAProject(projectDir)); 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 */ /* Parse current extension configuration */
try { try {