1 /*******************************************************************************
2 * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
3 * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License 2.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-2.0/
10 * SPDX-License-Identifier: EPL-2.0
11 *******************************************************************************/
12 package org
.eclipse
.egit
.ui
.internal
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
20 import org
.eclipse
.egit
.ui
.Activator
;
21 import org
.eclipse
.egit
.ui
.UIPreferences
;
22 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
23 import org
.eclipse
.jgit
.lib
.ConfigConstants
;
24 import org
.eclipse
.jgit
.lib
.StoredConfig
;
25 import org
.eclipse
.jgit
.util
.FS
;
26 import org
.eclipse
.jgit
.util
.LfsFactory
;
27 import org
.eclipse
.jgit
.util
.LfsFactory
.LfsInstallCommand
;
28 import org
.eclipse
.jgit
.util
.SystemReader
;
29 import org
.eclipse
.osgi
.util
.NLS
;
30 import org
.eclipse
.ui
.PlatformUI
;
33 * Checks the system configuration
36 public class ConfigurationChecker
{
39 * Checks the system configuration.
41 public static void checkConfiguration() {
43 // This avoids that the check is executed too early
44 // because in startup phase the JobManager is suspended
45 // and scheduled Jobs are executed later
46 Job job
= new Job(UIText
.ConfigurationChecker_checkConfiguration
) {
48 protected IStatus
run(IProgressMonitor monitor
) {
49 if (PlatformUI
.isWorkbenchRunning()) {
50 PlatformUI
.getWorkbench().getDisplay()
51 .asyncExec(new Runnable() {
60 return Status
.OK_STATUS
;
66 private static void check() {
71 private static void checkLfs() {
72 IPreferenceStore store
= Activator
.getDefault().getPreferenceStore();
73 boolean auto
= store
.getBoolean(UIPreferences
.LFS_AUTO_CONFIGURATION
);
74 if (auto
&& !isLfsConfigured()) {
76 LfsInstallCommand cmd
= LfsFactory
.getInstance()
81 } catch (Exception e
) {
82 Activator
.handleIssue(IStatus
.WARNING
,
83 UIText
.ConfigurationChecker_installLfsCannotInstall
, e
,
89 private static boolean isLfsConfigured() {
91 StoredConfig cfg
= SystemReader
.getInstance().openUserConfig(null,
94 return cfg
.getSubsections(ConfigConstants
.CONFIG_FILTER_SECTION
)
95 .contains("lfs"); //$NON-NLS-1$
96 } catch (Exception e
) {
97 Activator
.handleIssue(IStatus
.WARNING
,
98 UIText
.ConfigurationChecker_installLfsCannotLoadConfig
, e
, false);
103 private static void checkHome() {
104 String home
= System
.getenv("HOME"); //$NON-NLS-1$
106 return; // home is set => ok
107 home
= calcHomeDir();
108 String message
= NLS
.bind(UIText
.ConfigurationChecker_homeNotSet
, home
);
109 IPreferenceStore store
= Activator
.getDefault().getPreferenceStore();
110 boolean hidden
= !store
.getBoolean(UIPreferences
.SHOW_HOME_DIR_WARNING
);
112 Activator
.handleIssue(IStatus
.WARNING
, message
, null, false);
115 private static String
calcHomeDir() {
116 if (runsOnWindows()) {
117 String homeDrive
= System
.getenv("HOMEDRIVE"); //$NON-NLS-1$
118 if (homeDrive
!= null) {
119 String homePath
= SystemReader
.getInstance().getenv("HOMEPATH"); //$NON-NLS-1$
120 return new File(homeDrive
, homePath
).getAbsolutePath();
122 return System
.getenv("HOMESHARE"); //$NON-NLS-1$
124 // The user.home property is not compatible with Git for Windows
125 return System
.getProperty("user.home"); //$NON-NLS-1$
129 private static boolean runsOnWindows() {
132 os
= System
.getProperty("os.name"); //$NON-NLS-1$
133 } catch (RuntimeException e
) {
136 return os
.indexOf("Windows") != -1; //$NON-NLS-1$