Move resolveGrandparentFile() to the base class for wider use

Change-Id: I67ec732ea2e5345a6946783f0c5ef60c07ce254e
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Sebastian Schuberth 2015-05-19 09:30:02 +02:00 committed by Matthias Sohn
parent 686124bec3
commit 8025443db4
3 changed files with 17 additions and 14 deletions

View File

@ -507,6 +507,21 @@ public File gitPrefix() {
/** @return the $prefix directory C Git would use. */
protected abstract File discoverGitPrefix();
/**
* @param grandchild
* @return the parent directory of this file's parent directory or
* {@code null} in case there's no grandparent directory
* @since 4.0
*/
protected static File resolveGrandparentFile(File grandchild) {
if (grandchild != null) {
File parent = grandchild.getParentFile();
if (parent != null)
return parent.getParentFile();
}
return null;
}
/**
* Set the $prefix directory C Git uses.
*

View File

@ -138,7 +138,7 @@ protected File discoverGitPrefix() {
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git"); //$NON-NLS-1$
if (gitExe != null)
return gitExe.getParentFile().getParentFile();
return resolveGrandparentFile(gitExe);
if (SystemReader.getInstance().isMacOS()) {
// On MacOSX, PATH is shorter when Eclipse is launched from the
@ -150,10 +150,7 @@ protected File discoverGitPrefix() {
Charset.defaultCharset().name());
if (w == null || w.length() == 0)
return null;
File parentFile = new File(w).getParentFile();
if (parentFile == null)
return null;
return parentFile.getParentFile();
return resolveGrandparentFile(new File(w));
}
return null;

View File

@ -128,15 +128,6 @@ protected File discoverGitPrefix() {
return null;
}
private static File resolveGrandparentFile(File grandchild) {
if (grandchild != null) {
File parent = grandchild.getParentFile();
if (parent != null)
return parent.getParentFile();
}
return null;
}
@Override
protected File userHomeImpl() {
String home = SystemReader.getInstance().getenv("HOME"); //$NON-NLS-1$