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:
Antonin Delpeuch 2021-06-10 08:09:09 +02:00 committed by GitHub
parent 5c891e6ad7
commit 1654cd31b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 51 deletions

View File

@ -172,11 +172,6 @@
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.openrefine.dependencies</groupId>
<artifactId>jdatapath</artifactId>
<version>alpha2</version>
</dependency>
<dependency>
<groupId>org.openrefine.dependencies</groupId>
<artifactId>butterfly</artifactId>

View File

@ -64,9 +64,6 @@ import com.google.util.threads.ThreadPoolExecutorAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codeberry.jdatapath.DataPath;
import com.codeberry.jdatapath.JDataPathSystem;
import com.google.refine.Configurations;
/**
@ -356,37 +353,14 @@ class RefineServer extends Server {
String os = System.getProperty("os.name").toLowerCase();
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;
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");
// TODO migrate to System.getProperty("user.home")?
String userProfile = System.getProperty("user.home");
if (userProfile != null && userProfile.length() > 0) {
// e.g., C:\Users\[userid]
parentDir = new File(userProfile);
@ -400,7 +374,6 @@ class RefineServer extends Server {
dataDir = new File(parentDir, "OpenRefine");
grefineDir = new File(new File(parentDir, "Google"), "Refine");
gridworksDir = new File(parentDir, "Gridworks");
}
} else if (os.contains("os x")) {
// on macosx, use "~/Library/Application Support"
String home = System.getProperty("user.home");