Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
begin inlining bagit to fix lib incompat around commons-io
- Loading branch information
Showing
297 changed files
with
10,538 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package gov.loc.cygwin; | ||
|
||
import static java.text.MessageFormat.format; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.apache.commons.exec.CommandLine; | ||
import org.apache.commons.exec.DefaultExecutor; | ||
import org.apache.commons.exec.ExecuteException; | ||
import org.apache.commons.exec.OS; | ||
import org.apache.commons.exec.PumpStreamHandler; | ||
|
||
public class Cygpath | ||
{ | ||
// Private constructor to prevent instantiation | ||
private Cygpath() {} | ||
|
||
/** | ||
* Returns a given path as a unix-style path by calling | ||
* out to the <c>cygpath --unix</c> command line. If the | ||
* current environment is not a Windows machine, then the | ||
* given path is returned unchanged. | ||
* | ||
* @param path The path to be converted. | ||
* @return The converted path. If not on Windows, the same path given. | ||
* @throws CygwinException If an error occurs during execution of the | ||
* Cygwin command. | ||
* | ||
* @see OS#isFamilyWindows() | ||
*/ | ||
public static String toUnix(String path) throws CygwinException | ||
{ | ||
String finalPath; | ||
|
||
if (OS.isFamilyWindows()) | ||
{ | ||
ByteArrayOutputStream cygpathOut = new ByteArrayOutputStream(); | ||
|
||
CommandLine cygPath = new CommandLine("cygpath"); | ||
cygPath.addArgument("--unix"); | ||
cygPath.addArgument(path); | ||
|
||
try | ||
{ | ||
DefaultExecutor executor = new DefaultExecutor(); | ||
executor.setStreamHandler(new PumpStreamHandler(cygpathOut)); | ||
|
||
executor.execute(cygPath); | ||
finalPath = cygpathOut.toString().trim(); | ||
} | ||
catch (ExecuteException e) | ||
{ | ||
int exitValue = e.getExitValue(); | ||
throw new CygwinException(format("Error when executing \"{0}\" (exit value {2}: {1}", cygPath, cygpathOut.toString().trim(), exitValue), e); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new CygwinException(format("Error when executing \"{0}\": {1}", cygPath, cygpathOut.toString().trim()), e); | ||
} | ||
} | ||
else | ||
{ | ||
finalPath = path; | ||
} | ||
|
||
return finalPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gov.loc.cygwin; | ||
|
||
public class CygwinException extends Exception | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public CygwinException() | ||
{ | ||
super(); | ||
} | ||
|
||
public CygwinException(String message, Throwable cause) | ||
{ | ||
super(message, cause); | ||
} | ||
|
||
public CygwinException(String message) | ||
{ | ||
super(message); | ||
} | ||
|
||
public CygwinException(Throwable cause) | ||
{ | ||
super(cause); | ||
} | ||
} |
Oops, something went wrong.