adding OS-specific data paths

git-svn-id: http://google-refine.googlecode.com/svn/trunk@173 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-03-03 02:53:07 +00:00
parent 52eef30177
commit 2691ee50d7
22 changed files with 101 additions and 64 deletions

View File

@ -13,5 +13,6 @@
<classpathentry kind="lib" path="lib/cos-20081226.jar" sourcepath="lib-src/cos-20081226-sources.jar"/> <classpathentry kind="lib" path="lib/cos-20081226.jar" sourcepath="lib-src/cos-20081226-sources.jar"/>
<classpathentry kind="lib" path="lib/poi-3.6.jar"/> <classpathentry kind="lib" path="lib/poi-3.6.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-3.6.jar"/> <classpathentry kind="lib" path="lib/poi-ooxml-3.6.jar"/>
<classpathentry kind="lib" path="lib/jdatapath-alpha2.jar" sourcepath="lib-src/jdatapath-alpha2-sources.jar"/>
<classpathentry kind="output" path="build/classes"/> <classpathentry kind="output" path="build/classes"/>
</classpath> </classpath>

View File

@ -96,10 +96,10 @@
dontWrapJar="true" dontWrapJar="true"
icon="${graphics.dir}/icon/gridworks.ico"> icon="${graphics.dir}/icon/gridworks.ico">
<classPath mainClass="com.metaweb.gridworks.Gridworks"> <classPath mainClass="com.metaweb.gridworks.Gridworks">
<cp>${lib.dir}/*.jar</cp> <cp>lib/*.jar</cp>
</classPath> </classPath>
<jre minVersion="1.6.0" jdkPreference="preferJre"> <jre minVersion="1.6.0" jdkPreference="preferJre" initialHeapPercent="10" maxHeapPercent="80">
<opt>${java.version}</opt> <opt>-Djava.library.path=lib/native/windows</opt>
</jre> </jre>
<versionInfo <versionInfo
fileVersion="${num_version}.0.0" fileVersion="${num_version}.0.0"
@ -120,6 +120,11 @@
<include name="**/*.jar"/> <include name="**/*.jar"/>
</fileset> </fileset>
</copy> </copy>
<copy todir="${exe.dir}/lib/native/windows">
<fileset dir="${lib.dir}/native/windows">
<include name="*.dll"/>
</fileset>
</copy>
<copy file="${build.dir}/gridworks.jar" tofile="${exe.dir}/lib/gridworks-${version}.jar"/> <copy file="${build.dir}/gridworks.jar" tofile="${exe.dir}/lib/gridworks-${version}.jar"/>
<copy todir="${exe.dir}/webapp"> <copy todir="${exe.dir}/webapp">
<fileset dir="${basedir}/src/main/webapp"> <fileset dir="${basedir}/src/main/webapp">

View File

@ -33,9 +33,12 @@ where [options] include:
-w <path> path to the webapp -w <path> path to the webapp
default: src/main/webapp default: src/main/webapp
-d enable JVM debugging (on port 8000) -d <path> path to the data directory
default: OS dependent
-x enable JMX monitoring (for jconsole) --debug enable JVM debugging (on port 8000)
--jmx enable JMX monitoring (for jconsole)
and <action> is one of and <action> is one of
@ -90,6 +93,7 @@ ant_prepare() {
ant() { 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 $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" fail "Must specify a version number"
fi fi
NUM_VERSION=`echo $VERSION | sed 's/\a//g'` NUM_VERSION=`echo $VERSION | sed 's/[a-zA-Z]//g'`
} }
make_exe() { make_exe() {
@ -183,9 +187,17 @@ run() {
echo "" echo ""
fi 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/*" 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 "Starting Gridworks at 'http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/'"
echo "" echo ""
@ -230,8 +242,9 @@ while [ $# -ne 0 ] ; do
-p) shift; GRIDWORKS_PORT="$1"; shift; continue;; -p) shift; GRIDWORKS_PORT="$1"; shift; continue;;
-i) shift; GRIDWORKS_HOST="$1"; shift; continue;; -i) shift; GRIDWORKS_HOST="$1"; shift; continue;;
-w) shift; GRIDWORKS_WEBAPP="$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;; -d) shift; GRIDWORKS_DATA_DIR="$1"; shift; continue;;
-x) shift; add_option '-Dcom.sun.management.jmxremote'; 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";; -*) fail "Invalid option: $1";;
*) break;; *) break;;
esac esac

View File

@ -140,7 +140,7 @@ goto usage
:doRun :doRun
set CLASSPATH="%GRIDWORKS_BUILD_DIR%\classes;%GRIDWORKS_LIB_DIR%\*" 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 goto end
:doAnt :doAnt

Binary file not shown.

BIN
lib/jdatapath-alpha2.jar Normal file

Binary file not shown.

BIN
lib/native/windows/jdatapath.dll Executable file

Binary file not shown.

View File

@ -28,6 +28,9 @@ import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
public class Gridworks extends Server { 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 { public static void main(String[] args) throws Exception {
// tell jetty to use SLF4J for logging instead of its own stuff // tell jetty to use SLF4J for logging instead of its own stuff
@ -36,13 +39,11 @@ public class Gridworks extends Server {
// initialize the log4j system // initialize the log4j system
Appender console = new ConsoleAppender(new IndentingLayout()); Appender console = new ConsoleAppender(new IndentingLayout());
Logger root = Logger.getRootLogger();
root.setLevel(Level.ALL); root.setLevel(Level.ALL);
root.addAppender(console); root.addAppender(console);
Logger jetty_logger = Logger.getLogger("org.mortbay.log"); Logger jetty_logger = Logger.getLogger("org.mortbay.log");
jetty_logger.setLevel(Level.INFO); jetty_logger.setLevel(Level.WARN);
// get main configurations // get main configurations
int port = Configurations.getInteger("gridworks.port",3333); int port = Configurations.getInteger("gridworks.port",3333);
@ -65,6 +66,10 @@ public class Gridworks extends Server {
server.join(); server.join();
} }
public static void log(String message) {
logger.info(message);
}
/* -------------- Gridworks HTTP server ----------------- */ /* -------------- Gridworks HTTP server ----------------- */
private ThreadPoolExecutor threadPool; private ThreadPoolExecutor threadPool;
@ -81,15 +86,6 @@ public class Gridworks extends Server {
this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool)); 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 connector = new SocketConnector();
connector.setPort(port); connector.setPort(port);
connector.setHost(host); connector.setHost(host);

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks; package com.metaweb.gridworks;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -10,10 +9,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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.Command;
import com.metaweb.gridworks.commands.edit.AddColumnCommand; import com.metaweb.gridworks.commands.edit.AddColumnCommand;
import com.metaweb.gridworks.commands.edit.AnnotateOneRowCommand; 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.ComputeFacetsCommand;
import com.metaweb.gridworks.commands.info.ExportRowsCommand; import com.metaweb.gridworks.commands.info.ExportRowsCommand;
import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand; 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.GetHistoryCommand;
import com.metaweb.gridworks.commands.info.GetModelsCommand;
import com.metaweb.gridworks.commands.info.GetOperationsCommand; import com.metaweb.gridworks.commands.info.GetOperationsCommand;
import com.metaweb.gridworks.commands.info.GetProcessesCommand; import com.metaweb.gridworks.commands.info.GetProcessesCommand;
import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand; import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand;
import com.metaweb.gridworks.commands.info.GetRowsCommand; 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.ReconDiscardJudgmentsCommand;
import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand; import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand;
import com.metaweb.gridworks.commands.recon.ReconJudgeSimilarCellsCommand; 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.ReconMatchSpecificTopicCommand;
import com.metaweb.gridworks.commands.recon.ReconcileCommand; import com.metaweb.gridworks.commands.recon.ReconcileCommand;
import com.metaweb.gridworks.commands.util.CancelProcessesCommand; 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; import com.metaweb.gridworks.commands.util.PreviewProtographCommand;
public class GridworksServlet extends HttpServlet { public class GridworksServlet extends HttpServlet {
private static final long serialVersionUID = 2386057901503517403L; private static final long serialVersionUID = 2386057901503517403L;
static protected Map<String, Command> _commands = new HashMap<String, Command>(); static protected Map<String, Command> _commands = new HashMap<String, Command>();
@ -116,7 +112,7 @@ public class GridworksServlet extends HttpServlet {
} }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ProjectManager.initialize(new File("./data")); ProjectManager.initialize();
String commandName = request.getPathInfo().substring(1); String commandName = request.getPathInfo().substring(1);
Command command = _commands.get(commandName); Command command = _commands.get(commandName);
@ -126,7 +122,7 @@ public class GridworksServlet extends HttpServlet {
} }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ProjectManager.initialize(new File("./data")); ProjectManager.initialize();
String commandName = request.getPathInfo().substring(1); String commandName = request.getPathInfo().substring(1);
Command command = _commands.get(commandName); 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("\"", "\\\"");
}
} }

View File

@ -10,9 +10,12 @@ import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.codeberry.jdatapath.DataPath;
import com.codeberry.jdatapath.JDataPathSystem;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class ProjectManager implements Serializable { public class ProjectManager implements Serializable {
private static final long serialVersionUID = -2967415873336723962L; private static final long serialVersionUID = -2967415873336723962L;
protected File _dir; protected File _dir;
@ -22,18 +25,57 @@ public class ProjectManager implements Serializable {
static public ProjectManager singleton; static public ProjectManager singleton;
static public void initialize(File dir) { static public void initialize() {
if (singleton == null) { if (singleton == null) {
File dir = getProjectLocation();
Gridworks.log("Using data directory: " + dir.getAbsolutePath());
File file = new File(dir, "projects"); File file = new File(dir, "projects");
if (file.exists()) { if (file.exists()) {
singleton = load(file); singleton = load(file);
} } else {
if (singleton == null) {
singleton = new ProjectManager(dir); 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) { static protected ProjectManager load(File file) {
ProjectManager pm = null; ProjectManager pm = null;
FileInputStream fis = null; FileInputStream fis = null;

View File

@ -15,10 +15,9 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.ibm.icu.text.CharsetDetector; import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch; import com.ibm.icu.text.CharsetMatch;
import com.metaweb.gridworks.Gridworks;
import com.metaweb.gridworks.ProjectManager; import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.ProjectMetadata; import com.metaweb.gridworks.ProjectMetadata;
import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.commands.Command;
@ -34,8 +33,6 @@ import com.oreilly.servlet.multipart.Part;
public class CreateProjectCommand extends Command { public class CreateProjectCommand extends Command {
private final static Logger logger = Logger.getLogger("gridworks");
@Override @Override
public void doPost(HttpServletRequest request, HttpServletResponse response) public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
@ -131,7 +128,7 @@ public class CreateProjectCommand extends Command {
CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect(); CharsetMatch charsetMatch = detector.setText(enforceMarking(filePart.getInputStream())).detect();
options.setProperty("encoding", charsetMatch.getName()); options.setProperty("encoding", charsetMatch.getName());
options.setProperty("encoding_confidence", Integer.toString(charsetMatch.getConfidence())); 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(); Reader reader = charsetMatch.getReader();
try { try {
importer.read(charsetMatch.getReader(), project, options, skip, limit); importer.read(charsetMatch.getReader(), project, options, skip, limit);

View File

@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject; import org.json.JSONObject;
import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.commands.EngineDependentCommand;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.TextTransformOperation; import com.metaweb.gridworks.operations.TextTransformOperation;

View File

@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject; import org.json.JSONObject;
import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.commands.EngineDependentCommand;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.operations.FacetBasedEditOperation; import com.metaweb.gridworks.operations.FacetBasedEditOperation;

View File

@ -22,7 +22,6 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Column;

View File

@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.expr.EvalError; import com.metaweb.gridworks.expr.EvalError;
import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.Evaluable;