From 2f705ad240ba7731a105f9b438240fa7cd3c52a1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 14 Mar 2011 09:06:16 -0700 Subject: [PATCH] FS: Overload detect() with no arguments This allows callers to perform the logic that constructed the current FS.DETECTED value. Change-Id: Id8517d131dcc3f675c60b2d935730872695ed1b0 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/util/FS.java | 26 +++++++++++-------- .../org/eclipse/jgit/util/FS_POSIX_Java6.java | 2 +- .../src/org/eclipse/jgit/util/FS_Win32.java | 2 +- .../eclipse/jgit/util/FS_Win32_Cygwin.java | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 8faefede1..857b980a3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -53,7 +53,16 @@ import java.security.PrivilegedAction; /** Abstraction to support various file system operations not in Java. */ public abstract class FS { /** The auto-detected implementation selected for this operating system and JRE. */ - public static final FS DETECTED; + public static final FS DETECTED = detect(); + + /** + * Auto-detect the appropriate file system abstraction. + * + * @return detected file system abstraction + */ + public static FS detect() { + return detect(null); + } /** * Auto-detect the appropriate file system abstraction, taking into account @@ -77,24 +86,19 @@ public abstract class FS { * @return detected file system abstraction */ public static FS detect(Boolean cygwinUsed) { - if (FS_Win32.detect()) { - boolean useCygwin = (cygwinUsed == null && FS_Win32_Cygwin.detect()) - || Boolean.TRUE.equals(cygwinUsed); - - if (useCygwin) + if (FS_Win32.isWin32()) { + if (cygwinUsed == null) + cygwinUsed = Boolean.valueOf(FS_Win32_Cygwin.isCygwin()); + if (cygwinUsed.booleanValue()) return new FS_Win32_Cygwin(); else return new FS_Win32(); - } else if (FS_POSIX_Java6.detect()) + } else if (FS_POSIX_Java6.hasExecute()) return new FS_POSIX_Java6(); else return new FS_POSIX_Java5(); } - static { - DETECTED = detect(null); - } - private final File userHome; /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java index dfc03c451..2417ae735 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java @@ -59,7 +59,7 @@ class FS_POSIX_Java6 extends FS_POSIX { setExecute = needMethod(File.class, "setExecutable", Boolean.TYPE); } - static boolean detect() { + static boolean hasExecute() { return canExecute != null && setExecute != null; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java index bde633c58..7e1b6434c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java @@ -53,7 +53,7 @@ import java.util.Arrays; import java.util.List; class FS_Win32 extends FS { - static boolean detect() { + static boolean isWin32() { final String osDotName = AccessController .doPrivileged(new PrivilegedAction() { public String run() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java index 4e8841c99..0cc937d59 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java @@ -53,7 +53,7 @@ import java.util.List; class FS_Win32_Cygwin extends FS_Win32 { private static String cygpath; - static boolean detect() { + static boolean isCygwin() { final String path = AccessController .doPrivileged(new PrivilegedAction() { public String run() {