Util.deleteContentsRecursive(new File(ws, location.getLocalDir()));
// buffer the output by a separate thread so that the update operation
// won't be blocked by the remoting of the data
PipedOutputStream pos = new PipedOutputStream();
StreamCopyThread sct = new StreamCopyThread("svn log copier", new PipedInputStream(pos), listener.getLogger());
sct.start();
try {
SVNRevision r = getRevision(location);
String revisionName = r.getDate() != null ?
fmt.format(r.getDate()) : r.toString();
listener.getLogger().println("Checking out " + location.remote + " at revision " + revisionName);
File local = new File(ws, location.getLocalDir());
SubversionUpdateEventHandler eventHandler = new SubversionUpdateEventHandler(new PrintStream(pos), externals, local, location.getLocalDir());
svnuc.setEventHandler(eventHandler);
svnuc.setExternalsHandler(eventHandler);
svnuc.setIgnoreExternals(location.isIgnoreExternalsOption());
SVNDepth svnDepth = getSvnDepth(location.getDepthOption());
SvnCheckout checkout = svnuc.getOperationsFactory().createCheckout();
checkout.setSource(SvnTarget.fromURL(location.getSVNURL(), SVNRevision.HEAD));
checkout.setSingleTarget(SvnTarget.fromFile(local.getCanonicalFile()));
checkout.setDepth(svnDepth);
checkout.setRevision(r);
checkout.setAllowUnversionedObstructions(true);
checkout.setIgnoreExternals(location.isIgnoreExternalsOption());
checkout.setExternalsHandler(SvnCodec.externalsHandler(svnuc.getExternalsHandler()));
// Workaround for SVNKIT-430 is to set the working copy format when
// a checkout is performed.
checkout.setTargetWorkingCopyFormat(SubversionWorkspaceSelector.workspaceFormat);
checkout.run();
} catch (SVNCancelException e) {
if (isAuthenticationFailedError(e)) {
e.printStackTrace(listener.error("Failed to check out " + location.remote));
return null;
} else {
listener.error("Subversion checkout has been canceled");
throw (InterruptedException)new InterruptedException().initCause(e);
}
} catch (SVNException e) {
e.printStackTrace(listener.error("Failed to check out " + location.remote));
throw new IOException("Failed to check out " + location.remote, e) ;
} finally {
try {
pos.close();
} finally {
try {
sct.join(); // wait for all data to be piped.
} catch (InterruptedException e) {
throw new IOException2("interrupted", e);
}
}
}