`
收藏列表
标题 标签 来源
svn编程 svn
API文档:  
http://svnkit.com/javadoc/org/tmatesoft/svn/core/package-summary.html  
  
例子路径:  
https://wiki.svnkit.com/Managing_A_Working_Copy  
  
别人写的例子:  
http://eatsalt.blog.163.com/blog/static/879402662009102402949523/  
  
public class DefaultSVNResourceGenerator extends AbstractLogEnabled implements SVNResourceGenerator {  
    private SVNClientManager svnClientManager;  
     
    private SVNURL           repositoryURL;  
     
    private void init(String svnUrl, String svnUser, String svnPassword) throws SVNException {  
        DAVRepositoryFactory.setup();  
        repositoryURL = SVNURL.parseURIEncoded(svnUrl);  
  
        ISVNOptions options = SVNWCUtil.createDefaultOptions(true);  
  
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(  
            svnUser, svnPassword);  
  
        svnClientManager = SVNClientManager.newInstance(options, authManager);  
  
    }  
    public boolean resourceCheckout(String svnUrl, String projectPath, String svnUser,  
                                    String svnPassword) throws Exception {  
        File projectDir = new File(projectPath);  
        if (projectDir.exists())  
            deleteDir(projectDir);  
         
        if (!projectDir.exists())  
            projectDir.mkdirs();  
         
        init(svnUrl, svnUser, svnPassword);  
         
        SVNUpdateClient updateClient = svnClientManager.getUpdateClient();  
        updateClient.setIgnoreExternals(false);  
  
        updateClient.doCheckout(repositoryURL, projectDir, SVNRevision.HEAD, SVNRevision.HEAD,  
            SVNDepth.INFINITY, true);  
        deleteSvnDir(projectDir);  
        return true;  
    }  
     
    public void deleteSvnDir(File file) {  
        if (file.isDirectory()) {  
            File svnDir = new File(file, ".svn");  
            if (svnDir.exists() && svnDir.isDirectory())  
                deleteDir(svnDir);  
            File[] fileArray = file.listFiles();  
            for (File f : fileArray)  
                deleteSvnDir(f);  
        }  
    }  
  
    public void deleteDir(File file) {  
        if (file.isDirectory()) {  
            File[] files = file.listFiles();  
            for (File f : files)  
                deleteDir(f);  
        }  
        file.delete();  
    }  
}  
svn下载工程 svn
import java.io.File; 
import java.util.ArrayList; 
import java.util.List; 

import org.tmatesoft.svn.core.SVNDepth; 
import org.tmatesoft.svn.core.SVNException; 
import org.tmatesoft.svn.core.SVNURL; 
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; 
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; 
import org.tmatesoft.svn.core.wc.ISVNOptions; 
import org.tmatesoft.svn.core.wc.SVNClientManager; 
import org.tmatesoft.svn.core.wc.SVNRevision; 
import org.tmatesoft.svn.core.wc.SVNUpdateClient; 
import org.tmatesoft.svn.core.wc.SVNWCUtil; 




public class CheckOutProject implements IDownload { 
private static final String NATIVE = "native"; 
private static ISVNOptions options = SVNWCUtil.createDefaultOptions(true); 

private List<String> gProFolderList = new ArrayList<String>(); 

public List<String> getGProFolderList() { 
return gProFolderList; 
} 

public boolean checkout() { 
ProjectService projectService = new ProjectService(); 
List<Project> listProject = projectService.findAllList(); 
if (listProject == null) { 
Log.errorToDataBase("数据库配置工程信息为空"); 
return false; 
} 
for (Project project : listProject) { 
if (project == null) { 
continue; 
} 
String t3docRootName = project.getT3docRootName(); 
String svnUrl = project.getSvn(); 
String svnUserName = project.getUserName(); 
String svnPassword = project.getPassword(); 
gProFolderList.add(t3docRootName);// 全局工程文件夹名称 
String checkOutPath = ConstString.DOWNLOAD_SRC_PATH + t3docRootName; 
if (checkOutPath == null || t3docRootName == null || svnUrl == null 
|| svnUserName == null || svnPassword == null) { 
continue; 
} 
mkdirs(checkOutPath); 
try { 
DAVRepositoryFactory.setup(); // 对于通过使用 http:// 和 https:// 访问 
SVNURL repositoryURL = SVNURL.parseURIEncoded(svnUrl); 
SVNClientManager svnClientManager = SVNClientManager 
.newInstance((DefaultSVNOptions) options, svnUserName, 
svnPassword); 
SVNUpdateClient updateClient = svnClientManager 
.getUpdateClient(); 
updateClient.setIgnoreExternals(false); 
updateClient.doExport(repositoryURL, new File(checkOutPath), 
SVNRevision.HEAD, SVNRevision.HEAD, NATIVE, true, 
SVNDepth.INFINITY); 
} catch (SVNException e) { 
e.printStackTrace(); 
Log.errorToDataBase("下载更新工程"+checkOutPath+"失败"); 
} 
} 
return true; 

} 

/** 
* 创建文件夹 
* 
* @param path 
*            需要创建文件夹路径 
* @return boolean 
*/ 
public boolean mkdirs(String path) { 
if (path == null) { 
return false; 
} 
File file = new File(path); 
if (!file.exists()) { 
return new File(path).mkdirs(); 
} 
return true; 
} 


} 
Global site tag (gtag.js) - Google Analytics