Skip to content

Commit

Permalink
begin inlining bagit to fix lib incompat around commons-io
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Apr 18, 2013
1 parent 7ac04a4 commit 236d054
Show file tree
Hide file tree
Showing 297 changed files with 10,538 additions and 19 deletions.
30 changes: 15 additions & 15 deletions pom.xml
Expand Up @@ -21,21 +21,6 @@
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>gov.loc</groupId>
<artifactId>bagit</artifactId>
<version>4.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
Expand Down Expand Up @@ -81,6 +66,21 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>com.martiansoftware</groupId>
<artifactId>jsap</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/gov/loc/cygwin/Cygpath.java
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/gov/loc/cygwin/CygwinException.java
@@ -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);
}
}

0 comments on commit 236d054

Please sign in to comment.