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,51 +353,27 @@ 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 {
|
File parentDir = null;
|
||||||
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
|
String appData = System.getenv("APPDATA");
|
||||||
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
|
if (appData != null && appData.length() > 0) {
|
||||||
// so we're using a library that uses JNI to ask directly the win32 APIs,
|
// e.g., C:\Users\[userid]\AppData\Roaming
|
||||||
// it's not elegant but it's the safest bet.
|
parentDir = new File(appData);
|
||||||
|
} else {
|
||||||
dataDir = new File(fixWindowsUnicodePath(JDataPathSystem.getLocalSystem()
|
// TODO migrate to System.getProperty("user.home")?
|
||||||
.getLocalDataPath("OpenRefine").getPath()));
|
String userProfile = System.getProperty("user.home");
|
||||||
|
if (userProfile != null && userProfile.length() > 0) {
|
||||||
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Google");
|
// e.g., C:\Users\[userid]
|
||||||
|
parentDir = new File(userProfile);
|
||||||
// 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;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentDir == null) {
|
|
||||||
parentDir = new File(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
dataDir = new File(parentDir, "OpenRefine");
|
|
||||||
grefineDir = new File(new File(parentDir, "Google"), "Refine");
|
|
||||||
gridworksDir = new File(parentDir, "Gridworks");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parentDir == null) {
|
||||||
|
parentDir = new File(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataDir = new File(parentDir, "OpenRefine");
|
||||||
|
grefineDir = new File(new File(parentDir, "Google"), "Refine");
|
||||||
|
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