Skip to content

Instantly share code, notes, and snippets.

@pasviegas
Created April 9, 2013 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasviegas/5345410 to your computer and use it in GitHub Desktop.
Save pasviegas/5345410 to your computer and use it in GitHub Desktop.
svn bindings
package br.org.pav.svp.old;
import java.io.File;
import java.io.IOException;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.io.ISVNEditor;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import com.google.common.io.Files;
public class SVP {
private SVNRepository repo;
private SVP() {
}
public static SVP build(String url) throws SVNException {
SVP svp = new SVP();
SVNURL svnurl = SVNURL.parseURIEncoded(url);
svp.repo = SVNRepositoryFactory.create(svnurl);
return svp;
}
public boolean checkPath(String path) throws SVNException {
return repo.checkPath(path, -1) != SVNNodeKind.NONE;
}
public boolean sendFile(String fileRoot, String localFilePath) throws SVNException, IOException {
String filePath = localFilePath.replace(fileRoot, "");
String[] dirs = filePath.split("/");
for (int i = 0; i < dirs.length-1; i++) {
if(!dirs[i].isEmpty()){
String toReplace = filePath.substring(filePath.indexOf(dirs[i+1])-1, filePath.length());
sendDir(filePath.replace(toReplace, "").replaceFirst("/", ""));
}
}
ISVNEditor editor = repo.getCommitEditor("commit " + filePath, null);
SVPHelper.addFile(editor, filePath, Files.toByteArray(new File(localFilePath)));
return true;
}
public boolean sendDir(String dirPath) throws SVNException, IOException {
if(checkPath(dirPath)){
return true;
}
ISVNEditor editor = repo.getCommitEditor("commit dir " + dirPath, null);
SVPHelper.addDir(editor, dirPath);
return true;
}
public Object modifyFile(String absolutePath, String path) {
// TODO Auto-generated method stub
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment