Use environment variables for default workspace location on Windows, (#3840)
* Use environment variables for default workspace location on Windows, for #2961. * Mention possibility of using System.getProperty instead * Migrate to user.profile java property for Windows workspace dir fallback
This commit is contained in:
parent
5c891e6ad7
commit
1654cd31b1
@ -172,11 +172,6 @@
|
|||||||
<artifactId>jetty-webapp</artifactId>
|
<artifactId>jetty-webapp</artifactId>
|
||||||
<version>${jetty.version}</version>
|
<version>${jetty.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.openrefine.dependencies</groupId>
|
|
||||||
<artifactId>jdatapath</artifactId>
|
|
||||||
<version>alpha2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openrefine.dependencies</groupId>
|
<groupId>org.openrefine.dependencies</groupId>
|
||||||
<artifactId>butterfly</artifactId>
|
<artifactId>butterfly</artifactId>
|
||||||
|
@ -64,9 +64,6 @@ import com.google.util.threads.ThreadPoolExecutorAdapter;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.codeberry.jdatapath.DataPath;
|
|
||||||
import com.codeberry.jdatapath.JDataPathSystem;
|
|
||||||
|
|
||||||
import com.google.refine.Configurations;
|
import com.google.refine.Configurations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -356,37 +353,14 @@ class RefineServer extends Server {
|
|||||||
|
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
if (os.contains("windows")) {
|
if (os.contains("windows")) {
|
||||||
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,
|
|
||||||
// it's not elegant but it's the safest bet.
|
|
||||||
|
|
||||||
dataDir = new File(fixWindowsUnicodePath(JDataPathSystem.getLocalSystem()
|
|
||||||
.getLocalDataPath("OpenRefine").getPath()));
|
|
||||||
|
|
||||||
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Google");
|
|
||||||
|
|
||||||
// new: ./Google/Refine old: ./Gridworks
|
|
||||||
grefineDir = new File(new File(fixWindowsUnicodePath(localDataPath.getPath())), "Refine");
|
|
||||||
gridworksDir = new File(fixWindowsUnicodePath(JDataPathSystem.getLocalSystem()
|
|
||||||
.getLocalDataPath("Gridworks").getPath()));
|
|
||||||
} catch (Error e) {
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
logger.warn("Failed to use jdatapath to detect user data path: resorting to environment variables");
|
|
||||||
|
|
||||||
File parentDir = null;
|
File parentDir = null;
|
||||||
String appData = System.getenv("APPDATA");
|
String appData = System.getenv("APPDATA");
|
||||||
if (appData != null && appData.length() > 0) {
|
if (appData != null && appData.length() > 0) {
|
||||||
// e.g., C:\Users\[userid]\AppData\Roaming
|
// e.g., C:\Users\[userid]\AppData\Roaming
|
||||||
parentDir = new File(appData);
|
parentDir = new File(appData);
|
||||||
} else {
|
} else {
|
||||||
String userProfile = System.getenv("USERPROFILE");
|
// TODO migrate to System.getProperty("user.home")?
|
||||||
|
String userProfile = System.getProperty("user.home");
|
||||||
if (userProfile != null && userProfile.length() > 0) {
|
if (userProfile != null && userProfile.length() > 0) {
|
||||||
// e.g., C:\Users\[userid]
|
// e.g., C:\Users\[userid]
|
||||||
parentDir = new File(userProfile);
|
parentDir = new File(userProfile);
|
||||||
@ -400,7 +374,6 @@ class RefineServer extends Server {
|
|||||||
dataDir = new File(parentDir, "OpenRefine");
|
dataDir = new File(parentDir, "OpenRefine");
|
||||||
grefineDir = new File(new File(parentDir, "Google"), "Refine");
|
grefineDir = new File(new File(parentDir, "Google"), "Refine");
|
||||||
gridworksDir = new File(parentDir, "Gridworks");
|
gridworksDir = new File(parentDir, "Gridworks");
|
||||||
}
|
|
||||||
} else if (os.contains("os x")) {
|
} else if (os.contains("os x")) {
|
||||||
// on macosx, use "~/Library/Application Support"
|
// on macosx, use "~/Library/Application Support"
|
||||||
String home = System.getProperty("user.home");
|
String home = System.getProperty("user.home");
|
||||||
|
Loading…
Reference in New Issue
Block a user