FS: Allow cloning an FS instance
This permits an application to create its own copy of FS.DETECTED before manually setting the userHome or gitPrefix. Bug: 337101 Change-Id: Ieea33c8d0ebdc801a4656b829d2a4b398559fd45 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
a4a00ea8f1
commit
ae1f7947de
|
@ -110,6 +110,20 @@ protected FS() {
|
||||||
// Do nothing by default.
|
// Do nothing by default.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize this FS using another's current settings.
|
||||||
|
*
|
||||||
|
* @param src
|
||||||
|
* the source FS to copy from.
|
||||||
|
*/
|
||||||
|
protected FS(FS src) {
|
||||||
|
userHome = src.userHome;
|
||||||
|
gitPrefix = src.gitPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return a new instance of the same type of FS. */
|
||||||
|
public abstract FS newInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this operating system and JRE support the execute flag on files?
|
* Does this operating system and JRE support the execute flag on files?
|
||||||
*
|
*
|
||||||
|
|
|
@ -77,6 +77,14 @@ protected File discoverGitPrefix() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_POSIX() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_POSIX(FS src) {
|
||||||
|
super(src);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProcessBuilder runInShell(String cmd, String[] args) {
|
public ProcessBuilder runInShell(String cmd, String[] args) {
|
||||||
List<String> argv = new ArrayList<String>(4 + args.length);
|
List<String> argv = new ArrayList<String>(4 + args.length);
|
||||||
|
|
|
@ -46,6 +46,19 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
class FS_POSIX_Java5 extends FS_POSIX {
|
class FS_POSIX_Java5 extends FS_POSIX {
|
||||||
|
FS_POSIX_Java5() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_POSIX_Java5(FS src) {
|
||||||
|
super(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FS newInstance() {
|
||||||
|
return new FS_POSIX_Java5(this);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean supportsExecute() {
|
public boolean supportsExecute() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,19 @@ private static Method needMethod(final Class<?> on, final String name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_POSIX_Java6() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_POSIX_Java6(FS src) {
|
||||||
|
super(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FS newInstance() {
|
||||||
|
return new FS_POSIX_Java6(this);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean supportsExecute() {
|
public boolean supportsExecute() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,18 @@ public String run() {
|
||||||
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
|
&& StringUtils.toLowerCase(osDotName).indexOf("windows") != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_Win32() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_Win32(FS src) {
|
||||||
|
super(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FS newInstance() {
|
||||||
|
return new FS_Win32(this);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean supportsExecute() {
|
public boolean supportsExecute() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,18 @@ public String run() {
|
||||||
return cygpath != null;
|
return cygpath != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_Win32_Cygwin() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_Win32_Cygwin(FS src) {
|
||||||
|
super(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FS newInstance() {
|
||||||
|
return new FS_Win32_Cygwin(this);
|
||||||
|
}
|
||||||
|
|
||||||
public File resolve(final File dir, final String pn) {
|
public File resolve(final File dir, final String pn) {
|
||||||
String w = readPipe(dir, //
|
String w = readPipe(dir, //
|
||||||
new String[] { cygpath, "--windows", "--absolute", pn }, //
|
new String[] { cygpath, "--windows", "--absolute", pn }, //
|
||||||
|
|
Loading…
Reference in New Issue