2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-04-09 02:14:11 +02:00
|
|
|
import java.io.File;
|
2010-03-04 20:15:46 +01:00
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.IOException;
|
2010-03-08 01:37:06 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Date;
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.util.HashMap;
|
2010-03-03 22:21:38 +01:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.util.Map;
|
2010-04-06 07:35:48 +02:00
|
|
|
import java.util.Map.Entry;
|
2010-03-04 20:15:46 +01:00
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONTokener;
|
|
|
|
import org.json.JSONWriter;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-03-03 03:53:07 +01:00
|
|
|
import com.codeberry.jdatapath.DataPath;
|
|
|
|
import com.codeberry.jdatapath.JDataPathSystem;
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.model.Project;
|
2010-03-04 20:15:46 +01:00
|
|
|
import com.metaweb.gridworks.util.JSONUtilities;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
public class ProjectManager {
|
2010-03-03 05:19:58 +01:00
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
// last n expressions used across all projects
|
|
|
|
static protected final int s_expressionHistoryMax = 100;
|
2010-03-03 05:19:58 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
protected File _workspaceDir;
|
2010-03-03 05:19:58 +01:00
|
|
|
protected Map<Long, ProjectMetadata> _projectsMetadata;
|
2010-03-03 22:21:38 +01:00
|
|
|
protected List<String> _expressions;
|
2010-03-03 05:19:58 +01:00
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
/**
|
|
|
|
* While each project's metadata is loaded completely at start-up, each project's raw data
|
|
|
|
* is loaded only when the project is accessed by the user. This is because project
|
|
|
|
* metadata is tiny compared to raw project data. This hash map from project ID to project
|
|
|
|
* is more like a last accessed-last out cache.
|
|
|
|
*/
|
|
|
|
transient protected Map<Long, Project> _projects;
|
2010-03-03 05:19:58 +01:00
|
|
|
|
2010-04-06 07:35:48 +02:00
|
|
|
/**
|
|
|
|
* What caches the joins between projects.
|
|
|
|
*/
|
|
|
|
transient protected InterProjectModel _interProjectModel = new InterProjectModel();
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
static public ProjectManager singleton;
|
|
|
|
|
2010-04-05 09:15:16 +02:00
|
|
|
static public synchronized void initialize() {
|
2010-03-03 05:19:58 +01:00
|
|
|
if (singleton == null) {
|
|
|
|
File dir = getProjectLocation();
|
2010-03-08 01:37:06 +01:00
|
|
|
Gridworks.log("Using workspace directory: " + dir.getAbsolutePath());
|
2010-03-04 20:15:46 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
singleton = new ProjectManager(dir);
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static protected File getProjectLocation() {
|
|
|
|
String data_dir = Configurations.get("gridworks.data_dir");
|
|
|
|
if (data_dir != null) {
|
|
|
|
return new File(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
String os = Configurations.get("os.name").toLowerCase();
|
|
|
|
if (os.contains("windows")) {
|
2010-03-17 04:51:58 +01:00
|
|
|
try {
|
|
|
|
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
|
|
|
|
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
|
|
|
|
// so we're using a library that uses JNI to ask directly the win32 APIs,
|
2010-03-21 00:56:28 +01:00
|
|
|
// it's not elegant but it's the safest bet.
|
|
|
|
|
2010-03-17 04:51:58 +01:00
|
|
|
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
|
|
|
|
File data = new File(localDataPath.getPath());
|
|
|
|
data.mkdirs();
|
|
|
|
return data;
|
|
|
|
} catch (Error e) {
|
2010-03-21 00:56:28 +01:00
|
|
|
/*
|
|
|
|
* The above trick can fail, particularly on a 64-bit OS as the jdatapath.dll
|
|
|
|
* we include is compiled for 32-bit. In this case, we just have to dig up
|
|
|
|
* environment variables and try our best to find a user-specific path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gridworks.log(
|
|
|
|
"Failed to use jdatapath to detect user data path. " +
|
|
|
|
"Resorting to environment variables.");
|
2010-03-17 04:51:58 +01:00
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
File parentDir = null;
|
|
|
|
{
|
|
|
|
String appData = System.getenv("APPDATA");
|
|
|
|
if (appData != null && appData.length() > 0) {
|
|
|
|
// e.g., C:\Users\[userid]\AppData\Roaming
|
|
|
|
parentDir = new File(appData);
|
|
|
|
} else {
|
|
|
|
String userProfile = System.getenv("USERPROFILE");
|
|
|
|
if (userProfile != null && userProfile.length() > 0) {
|
|
|
|
// e.g., C:\Users\[userid]
|
|
|
|
parentDir = new File(userProfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 04:51:58 +01:00
|
|
|
if (parentDir == null) {
|
|
|
|
parentDir = new File(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
File data = new File(parentDir, "Gridworks");
|
|
|
|
data.mkdirs();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2010-03-03 05:19:58 +01:00
|
|
|
} else if (os.contains("mac os x")) {
|
|
|
|
// on macosx, use "~/Library/Application Support"
|
|
|
|
String home = System.getProperty("user.home");
|
2010-03-03 03:53:07 +01:00
|
|
|
String data_home = (home != null) ? home + "/Library/Application Support/Gridworks" : ".gridworks";
|
|
|
|
File data = new File(data_home);
|
|
|
|
data.mkdirs();
|
|
|
|
return data;
|
2010-03-03 05:19:58 +01:00
|
|
|
} else { // most likely a UNIX flavor
|
|
|
|
// start with the XDG environment
|
|
|
|
// see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
2010-03-03 03:53:07 +01:00
|
|
|
String data_home = System.getenv("XDG_DATA_HOME");
|
|
|
|
if (data_home == null) { // if not found, default back to ~/.local/share
|
|
|
|
String home = System.getProperty("user.home");
|
|
|
|
if (home == null) home = ".";
|
|
|
|
data_home = home + "/.local/share";
|
|
|
|
}
|
|
|
|
File data = new File(data_home + "/gridworks");
|
|
|
|
data.mkdirs();
|
|
|
|
return data;
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ProjectManager(File dir) {
|
2010-03-06 08:43:45 +01:00
|
|
|
_workspaceDir = dir;
|
|
|
|
_workspaceDir.mkdirs();
|
2010-03-03 05:19:58 +01:00
|
|
|
|
|
|
|
_projectsMetadata = new HashMap<Long, ProjectMetadata>();
|
2010-03-03 22:21:38 +01:00
|
|
|
_expressions = new LinkedList<String>();
|
2010-03-03 05:19:58 +01:00
|
|
|
_projects = new HashMap<Long, Project>();
|
2010-03-07 23:37:26 +01:00
|
|
|
|
|
|
|
load();
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
|
2010-04-06 07:35:48 +02:00
|
|
|
public InterProjectModel getInterProjectModel() {
|
|
|
|
return _interProjectModel;
|
|
|
|
}
|
|
|
|
|
2010-03-06 08:43:45 +01:00
|
|
|
public File getWorkspaceDir() {
|
|
|
|
return _workspaceDir;
|
|
|
|
}
|
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
static public File getProjectDir(File workspaceDir, long projectID) {
|
|
|
|
File dir = new File(workspaceDir, projectID + ".project");
|
2010-03-06 08:43:45 +01:00
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdir();
|
|
|
|
}
|
|
|
|
return dir;
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
public File getProjectDir(long projectID) {
|
|
|
|
return getProjectDir(_workspaceDir, projectID);
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
2010-03-08 01:37:06 +01:00
|
|
|
synchronized (this) {
|
|
|
|
_projects.put(project.id, project);
|
|
|
|
_projectsMetadata.put(project.id, projectMetadata);
|
|
|
|
}
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
/**
|
|
|
|
* Import an external project that has been received as a .tar file, expanded, and
|
|
|
|
* copied into our workspace directory.
|
|
|
|
*
|
|
|
|
* @param projectID
|
|
|
|
*/
|
2010-04-09 06:52:32 +02:00
|
|
|
public boolean importProject(long projectID) {
|
2010-03-08 03:34:25 +01:00
|
|
|
synchronized (this) {
|
|
|
|
ProjectMetadata metadata = ProjectMetadata.load(getProjectDir(projectID));
|
2010-04-09 06:52:32 +02:00
|
|
|
if (metadata != null) {
|
|
|
|
_projectsMetadata.put(projectID, metadata);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-08 03:34:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
/**
|
|
|
|
* Make sure that a project's metadata and data are saved to file. For example,
|
|
|
|
* this method is called before the project is exported to a .tar file.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
*/
|
2010-03-08 03:34:25 +01:00
|
|
|
public void ensureProjectSaved(long id) {
|
|
|
|
synchronized (this) {
|
|
|
|
File projectDir = getProjectDir(id);
|
|
|
|
|
|
|
|
ProjectMetadata metadata = _projectsMetadata.get(id);
|
|
|
|
if (metadata != null) {
|
|
|
|
try {
|
|
|
|
metadata.save(projectDir);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Project project = _projects.get(id);
|
|
|
|
if (project != null && metadata.getModified().after(project.lastSave)) {
|
|
|
|
try {
|
|
|
|
project.save();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public ProjectMetadata getProjectMetadata(long id) {
|
|
|
|
return _projectsMetadata.get(id);
|
|
|
|
}
|
|
|
|
|
2010-04-06 07:35:48 +02:00
|
|
|
public ProjectMetadata getProjectMetadata(String name) {
|
|
|
|
for (ProjectMetadata pm : _projectsMetadata.values()) {
|
|
|
|
if (pm.getName().equals(name)) {
|
|
|
|
return pm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getProjectID(String name) {
|
|
|
|
for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
|
|
|
|
if (entry.getValue().getName().equals(name)) {
|
|
|
|
return entry.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public Map<Long, ProjectMetadata> getAllProjectMetadata() {
|
|
|
|
return _projectsMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Project getProject(long id) {
|
2010-03-21 00:56:28 +01:00
|
|
|
synchronized (this) {
|
|
|
|
if (_projects.containsKey(id)) {
|
|
|
|
return _projects.get(id);
|
|
|
|
} else {
|
|
|
|
Project project = Project.load(getProjectDir(id), id);
|
|
|
|
|
|
|
|
_projects.put(id, project);
|
|
|
|
|
|
|
|
return project;
|
|
|
|
}
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-03 22:21:38 +01:00
|
|
|
public void addLatestExpression(String s) {
|
2010-03-21 00:56:28 +01:00
|
|
|
synchronized (this) {
|
|
|
|
_expressions.remove(s);
|
|
|
|
_expressions.add(0, s);
|
|
|
|
while (_expressions.size() > s_expressionHistoryMax) {
|
|
|
|
_expressions.remove(_expressions.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
2010-03-03 22:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getExpressions() {
|
|
|
|
return _expressions;
|
|
|
|
}
|
|
|
|
|
2010-03-08 01:37:06 +01:00
|
|
|
public void save(boolean allModified) {
|
|
|
|
saveProjects(allModified);
|
|
|
|
saveWorkspace();
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
/**
|
|
|
|
* Save the workspace's data out to file in a safe way: save to a temporary file first
|
|
|
|
* and rename it to the real file.
|
|
|
|
*/
|
2010-03-08 01:37:06 +01:00
|
|
|
protected void saveWorkspace() {
|
|
|
|
synchronized (this) {
|
|
|
|
File tempFile = new File(_workspaceDir, "workspace.temp.json");
|
|
|
|
try {
|
|
|
|
saveToFile(tempFile);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
Gridworks.log("Failed to save workspace.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
File file = new File(_workspaceDir, "workspace.json");
|
|
|
|
File oldFile = new File(_workspaceDir, "workspace.old.json");
|
2010-03-04 20:15:46 +01:00
|
|
|
|
2010-03-08 01:37:06 +01:00
|
|
|
if (file.exists()) {
|
|
|
|
file.renameTo(oldFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
tempFile.renameTo(file);
|
|
|
|
if (oldFile.exists()) {
|
|
|
|
oldFile.delete();
|
|
|
|
}
|
|
|
|
|
2010-03-08 07:30:47 +01:00
|
|
|
//Gridworks.log("Saved workspace.");
|
2010-03-04 20:15:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
protected void saveToFile(File file) throws IOException, JSONException {
|
2010-03-04 20:15:46 +01:00
|
|
|
FileWriter writer = new FileWriter(file);
|
2010-03-03 05:19:58 +01:00
|
|
|
try {
|
2010-03-04 20:15:46 +01:00
|
|
|
JSONWriter jsonWriter = new JSONWriter(writer);
|
|
|
|
jsonWriter.object();
|
2010-03-07 23:37:26 +01:00
|
|
|
jsonWriter.key("projectIDs");
|
2010-03-04 20:15:46 +01:00
|
|
|
jsonWriter.array();
|
|
|
|
for (Long id : _projectsMetadata.keySet()) {
|
2010-03-07 23:37:26 +01:00
|
|
|
ProjectMetadata metadata = _projectsMetadata.get(id);
|
2010-04-09 06:52:32 +02:00
|
|
|
if (metadata != null) {
|
|
|
|
jsonWriter.value(id);
|
|
|
|
|
|
|
|
try {
|
|
|
|
metadata.save(getProjectDir(id));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2010-03-07 23:37:26 +01:00
|
|
|
}
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
2010-03-04 20:15:46 +01:00
|
|
|
jsonWriter.endArray();
|
|
|
|
writer.write('\n');
|
|
|
|
|
|
|
|
jsonWriter.key("expressions"); JSONUtilities.writeStringList(jsonWriter, _expressions);
|
|
|
|
jsonWriter.endObject();
|
|
|
|
} finally {
|
|
|
|
writer.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
/**
|
|
|
|
* A utility class to prioritize projects for saving, depending on how long ago
|
|
|
|
* they have been changed but have not been saved.
|
|
|
|
*/
|
2010-03-08 01:37:06 +01:00
|
|
|
static protected class SaveRecord {
|
|
|
|
final Project project;
|
|
|
|
final long overdue;
|
|
|
|
|
|
|
|
SaveRecord(Project project, long overdue) {
|
|
|
|
this.project = project;
|
|
|
|
this.overdue = overdue;
|
2010-03-07 23:37:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
static protected final int s_projectFlushDelay = 1000 * 60 * 60; // 1 hour
|
|
|
|
static protected final int s_quickSaveTimeout = 1000 * 30; // 30 secs
|
|
|
|
|
2010-03-08 01:37:06 +01:00
|
|
|
protected void saveProjects(boolean allModified) {
|
|
|
|
List<SaveRecord> records = new ArrayList<SaveRecord>();
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
for (long id : _projectsMetadata.keySet()) {
|
|
|
|
ProjectMetadata metadata = _projectsMetadata.get(id);
|
|
|
|
Project project = _projects.get(id);
|
|
|
|
|
|
|
|
if (project != null) {
|
2010-03-21 00:56:28 +01:00
|
|
|
boolean hasUnsavedChanges =
|
|
|
|
metadata.getModified().getTime() > project.lastSave.getTime();
|
2010-03-08 01:37:06 +01:00
|
|
|
|
|
|
|
if (hasUnsavedChanges) {
|
|
|
|
long msecsOverdue = now.getTime() - project.lastSave.getTime();
|
|
|
|
|
|
|
|
records.add(new SaveRecord(project, msecsOverdue));
|
|
|
|
|
2010-03-21 00:56:28 +01:00
|
|
|
} else if (now.getTime() - project.lastSave.getTime() > s_projectFlushDelay) {
|
2010-03-08 01:37:06 +01:00
|
|
|
/*
|
2010-03-21 00:56:28 +01:00
|
|
|
* It's been a while since the project was last saved and it hasn't been
|
|
|
|
* modified. We can safely remove it from the cache to save some memory.
|
2010-03-08 01:37:06 +01:00
|
|
|
*/
|
|
|
|
_projects.remove(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-07 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
2010-03-08 01:37:06 +01:00
|
|
|
if (records.size() > 0) {
|
|
|
|
Collections.sort(records, new Comparator<SaveRecord>() {
|
|
|
|
public int compare(SaveRecord o1, SaveRecord o2) {
|
|
|
|
if (o1.overdue < o2.overdue) {
|
|
|
|
return 1;
|
|
|
|
} else if (o1.overdue > o2.overdue) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Gridworks.log(allModified ?
|
|
|
|
"Saving all modified projects ..." :
|
|
|
|
"Saving some modified projects ..."
|
|
|
|
);
|
|
|
|
|
|
|
|
for (int i = 0;
|
|
|
|
i < records.size() &&
|
2010-03-21 00:56:28 +01:00
|
|
|
(allModified || (new Date().getTime() - now.getTime() < s_quickSaveTimeout));
|
|
|
|
i++) {
|
2010-03-08 01:37:06 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
records.get(i).project.save();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteProject(Project project) {
|
|
|
|
synchronized (this) {
|
|
|
|
if (_projectsMetadata.containsKey(project.id)) {
|
|
|
|
_projectsMetadata.remove(project.id);
|
|
|
|
}
|
|
|
|
if (_projects.containsKey(project.id)) {
|
|
|
|
_projects.remove(project.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
File dir = getProjectDir(project.id);
|
|
|
|
if (dir.exists()) {
|
|
|
|
dir.delete();
|
|
|
|
}
|
2010-03-07 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
2010-03-08 01:37:06 +01:00
|
|
|
saveWorkspace();
|
2010-03-07 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void load() {
|
2010-04-09 02:14:11 +02:00
|
|
|
if (loadFromFile(new File(_workspaceDir, "workspace.json"))) return;
|
|
|
|
if (loadFromFile(new File(_workspaceDir, "workspace.temp.json"))) return;
|
|
|
|
if (loadFromFile(new File(_workspaceDir, "workspace.old.json"))) return;
|
2010-03-04 20:15:46 +01:00
|
|
|
}
|
|
|
|
|
2010-04-09 02:14:11 +02:00
|
|
|
protected boolean loadFromFile(File file) {
|
2010-03-08 01:37:06 +01:00
|
|
|
Gridworks.log("Loading workspace from " + file.getAbsolutePath());
|
2010-03-04 20:15:46 +01:00
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
_projectsMetadata.clear();
|
|
|
|
_expressions.clear();
|
|
|
|
|
2010-04-09 02:14:11 +02:00
|
|
|
if (file.exists() || file.canRead()) {
|
|
|
|
FileReader reader = null;
|
|
|
|
try {
|
|
|
|
reader = new FileReader(file);
|
|
|
|
JSONTokener tokener = new JSONTokener(reader);
|
|
|
|
JSONObject obj = (JSONObject) tokener.nextValue();
|
2010-03-07 23:37:26 +01:00
|
|
|
|
2010-04-09 02:14:11 +02:00
|
|
|
JSONArray a = obj.getJSONArray("projectIDs");
|
|
|
|
int count = a.length();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
long id = a.getLong(i);
|
|
|
|
|
|
|
|
File projectDir = getProjectDir(id);
|
|
|
|
ProjectMetadata metadata = ProjectMetadata.load(projectDir);
|
|
|
|
|
|
|
|
_projectsMetadata.put(id, metadata);
|
|
|
|
}
|
2010-03-04 20:15:46 +01:00
|
|
|
|
2010-04-09 02:14:11 +02:00
|
|
|
JSONUtilities.getStringList(obj, "expressions", _expressions);
|
|
|
|
return true;
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Gridworks.warn("Error reading " + file, e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Gridworks.warn("Error reading " + file, e);
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
reader.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
Gridworks.warn("Exception closing file",e);
|
|
|
|
}
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
}
|
2010-04-09 02:14:11 +02:00
|
|
|
|
|
|
|
return false;
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|