blob: 0674e2af7196c3995c61f1c1c7eca5ab772538a2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*******************************************************************************
* Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
* Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.ui.internal;
import java.io.File;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.PlatformUI;
/**
* Checks the system configuration
*
*/
public class ConfigurationChecker {
/**
* Checks the system configuration. Currently only the HOME variable on
* Windows is checked
*/
public static void checkConfiguration() {
// Schedule a job
// This avoids that the check is executed too early
// because in startup phase the JobManager is suspended
// and scheduled Jobs are executed later
Job job = new Job(UIText.ConfigurationChecker_checkConfiguration) {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (PlatformUI.isWorkbenchRunning()) {
PlatformUI.getWorkbench().getDisplay()
.asyncExec(new Runnable() {
@Override
public void run() {
check();
}
});
} else {
schedule(1000L);
}
return Status.OK_STATUS;
}
};
job.schedule();
}
private static void check() {
checkHome();
}
private static void checkHome() {
String home = System.getenv("HOME"); //$NON-NLS-1$
if (home != null)
return; // home is set => ok
home = calcHomeDir();
String message = NLS.bind(UIText.ConfigurationChecker_homeNotSet, home);
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
boolean hidden = !store.getBoolean(UIPreferences.SHOW_HOME_DIR_WARNING);
if (!hidden)
Activator.handleIssue(IStatus.WARNING, message, null, false);
}
private static String calcHomeDir() {
if (runsOnWindows()) {
String homeDrive = System.getenv("HOMEDRIVE"); //$NON-NLS-1$
if (homeDrive != null) {
String homePath = SystemReader.getInstance().getenv("HOMEPATH"); //$NON-NLS-1$
return new File(homeDrive, homePath).getAbsolutePath();
}
return System.getenv("HOMESHARE"); //$NON-NLS-1$
} else {
// The user.home property is not compatible with Git for Windows
return System.getProperty("user.home"); //$NON-NLS-1$
}
}
private static boolean runsOnWindows() {
String os;
try {
os = System.getProperty("os.name"); //$NON-NLS-1$
} catch (RuntimeException e) {
return false;
}
return os.indexOf("Windows") != -1; //$NON-NLS-1$
}
}
|