summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-09-10 00:04:38 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2015-09-27 02:04:57 +0200
commit41a972cd1efe22ba65b4dfdd2fcaad8af18a522c (patch)
treef8c8c8baf0a17e5589d84d14cf247adbef3a08fe /org.eclipse.jgit.junit/src
parent1abd51d95373fcf7450463478b45aa7da8012cef (diff)
downloadjgit-41a972cd1efe22ba65b4dfdd2fcaad8af18a522c.tar.gz
jgit-41a972cd1efe22ba65b4dfdd2fcaad8af18a522c.zip
[performance] Cache platform name in SystemReader
SystemReader.isMacOs() and SystemReader.isWindows() return values are unlikely to change during the JVM lifetime (except tests). Don't read system properties each time the methods are called, just use previously calculated value. Change-Id: I495521f67a8b544e7b7247d99bbd05a42ea16d20 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
index 65551d6579..d24dd44fff 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
@@ -47,6 +47,7 @@ package org.eclipse.jgit.junit;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
@@ -170,6 +171,7 @@ public class MockSystemReader extends SystemReader {
* Assign some properties for the currently executing platform
*/
public void setCurrentPlatform() {
+ resetOsNames();
setProperty("os.name", System.getProperty("os.name"));
setProperty("file.separator", System.getProperty("file.separator"));
setProperty("path.separator", System.getProperty("path.separator"));
@@ -180,6 +182,7 @@ public class MockSystemReader extends SystemReader {
* Emulate Windows
*/
public void setWindows() {
+ resetOsNames();
setProperty("os.name", "Windows");
setProperty("file.separator", "\\");
setProperty("path.separator", ";");
@@ -191,10 +194,25 @@ public class MockSystemReader extends SystemReader {
* Emulate Unix
*/
public void setUnix() {
+ resetOsNames();
setProperty("os.name", "*nix"); // Essentially anything but Windows
setProperty("file.separator", "/");
setProperty("path.separator", ":");
setProperty("line.separator", "\n");
setPlatformChecker();
}
+
+ private void resetOsNames() {
+ Field field;
+ try {
+ field = SystemReader.class.getDeclaredField("isWindows");
+ field.setAccessible(true);
+ field.set(null, null);
+ field = SystemReader.class.getDeclaredField("isMacOS");
+ field.setAccessible(true);
+ field.set(null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}