From 9570e0d4a9783df132cc117827275eb5724d41d6 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 3 Aug 2012 01:33:34 +0200 Subject: [PATCH] Refactor detection of Windows platform to SystemReader Change-Id: Id0b8aef92f10572d4f1ec198e0281162fcd7ed4e --- .../eclipse/jgit/dircache/DirCacheCheckout.java | 3 +-- .../org/eclipse/jgit/dircache/DirCacheEntry.java | 3 +-- org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 2 +- .../src/org/eclipse/jgit/util/FS_Win32.java | 14 -------------- .../src/org/eclipse/jgit/util/SystemReader.java | 13 +++++++++++++ 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index 1d8c0d01b..d43fef847 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -1022,8 +1022,7 @@ public class DirCacheCheckout { } private static boolean isValidPathSegment(CanonicalTreeParser t) { - String osName = SystemReader.getInstance().getProperty("os.name"); - boolean isWindows = "Windows".equals(osName); + boolean isWindows = SystemReader.getInstance().isWindows(); boolean isOSX = SystemReader.getInstance().isMacOS(); boolean ignCase = isOSX || isWindows; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index aec12e316..00af0657d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -724,8 +724,7 @@ public class DirCacheEntry { case ':': // Tree's never have a backslash in them, not even on Windows // but even there we regard it as an invalid path - if ("Windows".equals(SystemReader.getInstance().getProperty( - "os.name"))) + if (SystemReader.getInstance().isWindows()) return false; //$FALL-THROUGH$ default: 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 535d1cd26..6eb020e52 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -89,7 +89,7 @@ public abstract class FS { * @return detected file system abstraction */ public static FS detect(Boolean cygwinUsed) { - if (FS_Win32.isWin32()) { + if (SystemReader.getInstance().isWindows()) { if (cygwinUsed == null) cygwinUsed = Boolean.valueOf(FS_Win32_Cygwin.isCygwin()); if (cygwinUsed.booleanValue()) 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 3b6704497..eebaa65d0 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 @@ -46,25 +46,11 @@ package org.eclipse.jgit.util; import java.io.File; import java.nio.charset.Charset; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.List; class FS_Win32 extends FS { - - static boolean isWin32() { - final String osDotName = AccessController - .doPrivileged(new PrivilegedAction() { - public String run() { - return System.getProperty("os.name"); - } - }); - return osDotName != null - && StringUtils.toLowerCase(osDotName).indexOf("windows") != -1; - } - FS_Win32() { super(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index 4298fbcf7..7cddccc29 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -239,6 +239,19 @@ public abstract class SystemReader { return DateFormat.getDateTimeInstance(dateStyle, timeStyle); } + /** + * @return true if we are running on a Windows. + */ + public boolean isWindows() { + String osDotName = AccessController + .doPrivileged(new PrivilegedAction() { + public String run() { + return getProperty("os.name"); + } + }); + return osDotName.startsWith("Windows"); + } + /** * @return true if we are running on Mac OS X */