diff --git a/.classpath b/.classpath index 48811b68a..4fde3ef69 100644 --- a/.classpath +++ b/.classpath @@ -13,5 +13,6 @@ + diff --git a/build.xml b/build.xml index 51d4b57bf..d9a49fd17 100644 --- a/build.xml +++ b/build.xml @@ -96,10 +96,10 @@ dontWrapJar="true" icon="${graphics.dir}/icon/gridworks.ico"> - ${lib.dir}/*.jar + lib/*.jar - - ${java.version} + + -Djava.library.path=lib/native/windows + + + + + diff --git a/gridworks b/gridworks index d16583314..eb99cfc86 100755 --- a/gridworks +++ b/gridworks @@ -32,10 +32,13 @@ where [options] include: -w path to the webapp default: src/main/webapp - - -d enable JVM debugging (on port 8000) + + -d path to the data directory + default: OS dependent + + --debug enable JVM debugging (on port 8000) - -x enable JMX monitoring (for jconsole) + --jmx enable JMX monitoring (for jconsole) and is one of @@ -89,7 +92,8 @@ ant_prepare() { } ant() { - ant_prepare + ant_prepare + echo $NUM_VERSION $ANT -f build.xml -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Djava.options="$JAVA_OPTIONS" $1 || exit 1 } @@ -114,7 +118,7 @@ get_version() { fail "Must specify a version number" fi - NUM_VERSION=`echo $VERSION | sed 's/\a//g'` + NUM_VERSION=`echo $VERSION | sed 's/[a-zA-Z]//g'` } make_exe() { @@ -182,10 +186,18 @@ run() { ant build echo "" fi + + if [ "$SYSTEM" == 'Darwin' ] ; then + OPTS="-Xdock:name=Gridworks -Xdock:icon=src/graphics/icon/gridworks.icns $OPTS" + fi + + if [ "$GRIDWORKS_DATA_DIR" != "" ] ; then + OPTS="-Dgridworks.data_dir=$GRIDWORKS_DATA_DIR $OPTS" + fi CLASSPATH="$GRIDWORKS_BUILD_DIR/classes:$GRIDWORKS_LIB_DIR/*" - RUN_CMD="$JAVA -cp $CLASSPATH $OPTS -Xdock:name=Gridworks -Xdock:icon=src/graphics/icon/gridworks.icns com.metaweb.gridworks.Gridworks" + RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks" echo "Starting Gridworks at 'http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/'" echo "" @@ -230,8 +242,9 @@ while [ $# -ne 0 ] ; do -p) shift; GRIDWORKS_PORT="$1"; shift; continue;; -i) shift; GRIDWORKS_HOST="$1"; shift; continue;; -w) shift; GRIDWORKS_WEBAPP="$1"; shift; continue;; - -d) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;; - -x) shift; add_option '-Dcom.sun.management.jmxremote'; continue;; + -d) shift; GRIDWORKS_DATA_DIR="$1"; shift; continue;; + --debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;; + --jmx) shift; add_option '-Dcom.sun.management.jmxremote'; continue;; -*) fail "Invalid option: $1";; *) break;; esac diff --git a/gridworks.bat b/gridworks.bat index 55b123bba..988e89587 100644 --- a/gridworks.bat +++ b/gridworks.bat @@ -140,7 +140,7 @@ goto usage :doRun set CLASSPATH="%GRIDWORKS_BUILD_DIR%\classes;%GRIDWORKS_LIB_DIR%\*" -"%JAVA_HOME%\bin\java.exe" -cp %CLASSPATH% %OPTS% com.metaweb.gridworks.Gridworks +"%JAVA_HOME%\bin\java.exe" -cp %CLASSPATH% %OPTS% -Djava.library.path=lib/native/windows com.metaweb.gridworks.Gridworks goto end :doAnt diff --git a/lib-src/jdatapath-alpha2-sources.jar b/lib-src/jdatapath-alpha2-sources.jar new file mode 100644 index 000000000..d4264d843 Binary files /dev/null and b/lib-src/jdatapath-alpha2-sources.jar differ diff --git a/lib/jdatapath-alpha2.jar b/lib/jdatapath-alpha2.jar new file mode 100644 index 000000000..0dce7e2e6 Binary files /dev/null and b/lib/jdatapath-alpha2.jar differ diff --git a/lib/native/windows/jdatapath.dll b/lib/native/windows/jdatapath.dll new file mode 100755 index 000000000..894dbe477 Binary files /dev/null and b/lib/native/windows/jdatapath.dll differ diff --git a/src/main/java/com/metaweb/gridworks/Gridworks.java b/src/main/java/com/metaweb/gridworks/Gridworks.java index a9cec0105..ac5349703 100644 --- a/src/main/java/com/metaweb/gridworks/Gridworks.java +++ b/src/main/java/com/metaweb/gridworks/Gridworks.java @@ -28,6 +28,9 @@ import com.metaweb.util.threads.ThreadPoolExecutorAdapter; public class Gridworks extends Server { + private static Logger root = Logger.getRootLogger(); + private static Logger logger = Logger.getLogger("com.metaweb.gridworks"); + public static void main(String[] args) throws Exception { // tell jetty to use SLF4J for logging instead of its own stuff @@ -36,14 +39,12 @@ public class Gridworks extends Server { // initialize the log4j system Appender console = new ConsoleAppender(new IndentingLayout()); - - Logger root = Logger.getRootLogger(); root.setLevel(Level.ALL); root.addAppender(console); Logger jetty_logger = Logger.getLogger("org.mortbay.log"); - jetty_logger.setLevel(Level.INFO); - + jetty_logger.setLevel(Level.WARN); + // get main configurations int port = Configurations.getInteger("gridworks.port",3333); String host = Configurations.get("gridworks.host","127.0.0.1"); @@ -65,6 +66,10 @@ public class Gridworks extends Server { server.join(); } + public static void log(String message) { + logger.info(message); + } + /* -------------- Gridworks HTTP server ----------------- */ private ThreadPoolExecutor threadPool; @@ -80,15 +85,6 @@ public class Gridworks extends Server { threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue); this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool)); - - // NOTE(SM): we use a BIO connector instead of the NIO connector - // because NIO can't deal with thread deaths: if the execution - // of a script is taking too long and acre kills it, that automatically - // shuts down the I/O channel to the user and we can't communicate - // that error back to the user (which also causes the I/O channel - // to be abruptly terminated and causes all sorts of proxy errors - // down the line). This is a performance penalty, but not severe - // enough to compensate for this problem. Connector connector = new SocketConnector(); connector.setPort(port); diff --git a/src/main/java/com/metaweb/gridworks/GridworksServlet.java b/src/main/java/com/metaweb/gridworks/GridworksServlet.java index d22480330..263fcc5af 100644 --- a/src/main/java/com/metaweb/gridworks/GridworksServlet.java +++ b/src/main/java/com/metaweb/gridworks/GridworksServlet.java @@ -1,6 +1,5 @@ package com.metaweb.gridworks; -import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -10,10 +9,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; - import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.commands.edit.AddColumnCommand; import com.metaweb.gridworks.commands.edit.AnnotateOneRowCommand; @@ -30,17 +25,17 @@ import com.metaweb.gridworks.commands.edit.UndoRedoCommand; import com.metaweb.gridworks.commands.info.ComputeFacetsCommand; import com.metaweb.gridworks.commands.info.ExportRowsCommand; import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand; -import com.metaweb.gridworks.commands.info.GetModelsCommand; import com.metaweb.gridworks.commands.info.GetHistoryCommand; +import com.metaweb.gridworks.commands.info.GetModelsCommand; import com.metaweb.gridworks.commands.info.GetOperationsCommand; import com.metaweb.gridworks.commands.info.GetProcessesCommand; import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand; import com.metaweb.gridworks.commands.info.GetRowsCommand; -import com.metaweb.gridworks.commands.recon.ReconMarkNewTopicsCommand; -import com.metaweb.gridworks.commands.recon.ReconMatchBestCandidatesCommand; import com.metaweb.gridworks.commands.recon.ReconDiscardJudgmentsCommand; import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand; import com.metaweb.gridworks.commands.recon.ReconJudgeSimilarCellsCommand; +import com.metaweb.gridworks.commands.recon.ReconMarkNewTopicsCommand; +import com.metaweb.gridworks.commands.recon.ReconMatchBestCandidatesCommand; import com.metaweb.gridworks.commands.recon.ReconMatchSpecificTopicCommand; import com.metaweb.gridworks.commands.recon.ReconcileCommand; import com.metaweb.gridworks.commands.util.CancelProcessesCommand; @@ -50,6 +45,7 @@ import com.metaweb.gridworks.commands.util.PreviewExpressionCommand; import com.metaweb.gridworks.commands.util.PreviewProtographCommand; public class GridworksServlet extends HttpServlet { + private static final long serialVersionUID = 2386057901503517403L; static protected Map _commands = new HashMap(); @@ -116,7 +112,7 @@ public class GridworksServlet extends HttpServlet { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ProjectManager.initialize(new File("./data")); + ProjectManager.initialize(); String commandName = request.getPathInfo().substring(1); Command command = _commands.get(commandName); @@ -126,7 +122,7 @@ public class GridworksServlet extends HttpServlet { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ProjectManager.initialize(new File("./data")); + ProjectManager.initialize(); String commandName = request.getPathInfo().substring(1); Command command = _commands.get(commandName); @@ -135,13 +131,4 @@ public class GridworksServlet extends HttpServlet { } } - static public JSONObject evaluateJsonStringToObject(String s) throws JSONException { - JSONTokener t = new JSONTokener(s); - JSONObject o = (JSONObject) t.nextValue(); - return o; - } - - protected String encodeString(String s) { - return s.replace("\"", "\\\""); - } } diff --git a/src/main/java/com/metaweb/gridworks/ProjectManager.java b/src/main/java/com/metaweb/gridworks/ProjectManager.java index 2c5dcc03a..0e6980ffa 100644 --- a/src/main/java/com/metaweb/gridworks/ProjectManager.java +++ b/src/main/java/com/metaweb/gridworks/ProjectManager.java @@ -10,10 +10,13 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import com.codeberry.jdatapath.DataPath; +import com.codeberry.jdatapath.JDataPathSystem; import com.metaweb.gridworks.model.Project; public class ProjectManager implements Serializable { - private static final long serialVersionUID = -2967415873336723962L; + + private static final long serialVersionUID = -2967415873336723962L; protected File _dir; protected Map _projectsMetadata; @@ -22,18 +25,57 @@ public class ProjectManager implements Serializable { static public ProjectManager singleton; - static public void initialize(File dir) { + static public void initialize() { if (singleton == null) { + File dir = getProjectLocation(); + Gridworks.log("Using data directory: " + dir.getAbsolutePath()); File file = new File(dir, "projects"); if (file.exists()) { singleton = load(file); - } - if (singleton == null) { + } else { singleton = new ProjectManager(dir); } } } + 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")) { + // 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, + // it's not elegant but it's the safest bet + DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks"); + File data = new File(localDataPath.getPath()); + data.mkdirs(); + return data; + } else if (os.contains("mac os x")) { + // on macosx, use "~/Library/Application Support" + String home = System.getProperty("user.home"); + String data_home = (home != null) ? home + "/Library/Application Support/Gridworks" : ".gridworks"; + File data = new File(data_home); + data.mkdirs(); + return data; + } else { // most likely a UNIX flavor + // start with the XDG environment + // see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + 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; + } + } + static protected ProjectManager load(File file) { ProjectManager pm = null; FileInputStream fis = null; diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/AnnotateOneRowCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/AnnotateOneRowCommand.java index b454a029f..97cb0e7eb 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/AnnotateOneRowCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/AnnotateOneRowCommand.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.commands.edit; -import java.io.IOException; +import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java index d9c9e834e..7f39dcb3d 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java @@ -15,10 +15,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; - import com.ibm.icu.text.CharsetDetector; import com.ibm.icu.text.CharsetMatch; +import com.metaweb.gridworks.Gridworks; import com.metaweb.gridworks.ProjectManager; import com.metaweb.gridworks.ProjectMetadata; import com.metaweb.gridworks.commands.Command; @@ -34,8 +33,6 @@ import com.oreilly.servlet.multipart.Part; public class CreateProjectCommand extends Command { - private final static Logger logger = Logger.getLogger("gridworks"); - @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -131,7 +128,7 @@ public class CreateProjectCommand extends Command { CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect(); options.setProperty("encoding", charsetMatch.getName()); options.setProperty("encoding_confidence", Integer.toString(charsetMatch.getConfidence())); - logger.info("Best encoding guess: " + charsetMatch.getName() + " [confidence: " + charsetMatch.getConfidence() + "]"); + Gridworks.log("Best encoding guess: " + charsetMatch.getName() + " [confidence: " + charsetMatch.getConfidence() + "]"); Reader reader = charsetMatch.getReader(); try { importer.read(charsetMatch.getReader(), project, options, skip, limit); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java index cbef0c650..321df800c 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java @@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest; import org.json.JSONObject; - import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.operations.TextTransformOperation; diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/FacetBasedEditCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/FacetBasedEditCommand.java index ffe236f19..6dae079fd 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/FacetBasedEditCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/FacetBasedEditCommand.java @@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest; import org.json.JSONObject; - import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.operations.FacetBasedEditOperation; diff --git a/src/main/java/com/metaweb/gridworks/commands/util/GuessTypesOfColumnCommand.java b/src/main/java/com/metaweb/gridworks/commands/util/GuessTypesOfColumnCommand.java index a71a5740c..aaecfd495 100644 --- a/src/main/java/com/metaweb/gridworks/commands/util/GuessTypesOfColumnCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/util/GuessTypesOfColumnCommand.java @@ -22,7 +22,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONWriter; - import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.model.Column; diff --git a/src/main/java/com/metaweb/gridworks/commands/util/PreviewExpressionCommand.java b/src/main/java/com/metaweb/gridworks/commands/util/PreviewExpressionCommand.java index 1d588c2ec..fdd599b58 100644 --- a/src/main/java/com/metaweb/gridworks/commands/util/PreviewExpressionCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/util/PreviewExpressionCommand.java @@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.json.JSONWriter; - import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.expr.EvalError; import com.metaweb.gridworks.expr.Evaluable; diff --git a/src/main/java/com/metaweb/gridworks/expr/ExpressionUtils.java b/src/main/java/com/metaweb/gridworks/expr/ExpressionUtils.java index 9bcfef8b7..9aed29b30 100644 --- a/src/main/java/com/metaweb/gridworks/expr/ExpressionUtils.java +++ b/src/main/java/com/metaweb/gridworks/expr/ExpressionUtils.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.expr; -import java.util.Properties; +import java.util.Properties; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Project; diff --git a/src/main/java/com/metaweb/gridworks/gel/controls/IsTest.java b/src/main/java/com/metaweb/gridworks/gel/controls/IsTest.java index e02afa8b0..1a9e568ba 100644 --- a/src/main/java/com/metaweb/gridworks/gel/controls/IsTest.java +++ b/src/main/java/com/metaweb/gridworks/gel/controls/IsTest.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.gel.controls; -import java.util.Properties; +import java.util.Properties; import org.json.JSONException; import org.json.JSONWriter; diff --git a/src/main/java/com/metaweb/gridworks/gel/controls/With.java b/src/main/java/com/metaweb/gridworks/gel/controls/With.java index 8eafd1319..08ab60f3a 100644 --- a/src/main/java/com/metaweb/gridworks/gel/controls/With.java +++ b/src/main/java/com/metaweb/gridworks/gel/controls/With.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.gel.controls; -import java.util.Properties; +import java.util.Properties; import org.json.JSONException; import org.json.JSONWriter; diff --git a/src/main/java/com/metaweb/gridworks/model/recon/ReconConfig.java b/src/main/java/com/metaweb/gridworks/model/recon/ReconConfig.java index 1659b2dbd..c36bb45e4 100644 --- a/src/main/java/com/metaweb/gridworks/model/recon/ReconConfig.java +++ b/src/main/java/com/metaweb/gridworks/model/recon/ReconConfig.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.model.recon; -import java.io.Serializable; +import java.io.Serializable; import java.util.List; import org.json.JSONObject; diff --git a/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellJoinOperation.java b/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellJoinOperation.java index a983f5431..a220fd745 100644 --- a/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellJoinOperation.java +++ b/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellJoinOperation.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.operations; -import java.util.ArrayList; +import java.util.ArrayList; import java.util.List; import java.util.Properties; diff --git a/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellSplitOperation.java b/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellSplitOperation.java index 132d300d2..f25f5408d 100644 --- a/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellSplitOperation.java +++ b/src/main/java/com/metaweb/gridworks/operations/MultiValuedCellSplitOperation.java @@ -1,6 +1,6 @@ package com.metaweb.gridworks.operations; - import java.util.ArrayList; + import java.util.ArrayList; import java.util.List; import java.util.Properties;