java读取svn目录_Java 利用 svnKit 操作SVN 【获取所有文件夹、添加文件、文件下载】...

e3ec9e04f22051ec193e9848e9e0f506.png

又遇到了一个功能点,网上的参考内容挺少的,终于把功能实现了,记一下,方便以后遇到坑的时候看看

主要功能点

获取一个SVN目录中的所有子文件夹以及文件

可以利用参数控制是否进行递归获取所有的文件夹中的子类

可以利用参数控制获取的是文件还是文件夹

通过输出流下载SVN中的文件

为SVN中添加目录

将不同级别的目录中的文件目录(内含子类)copy到一个指定的文件夹中

功能实现

获取一个SVN目录中的所有子文件夹以及文件

请不要在意代码中的dto类

* @Author: winterchen

* @Description: 获取SVN目录下下一层所有文件信息

* @Date: 2018/2/6

* @param dirPath 需要查找的目录名

* @param fileNameSearch 名称模糊搜索

* @param typeEnum 文件的类型枚举 -- 这个就是三个参数 ‘dir’,‘file’,‘all’

*/

public List getNextLvFileList2(String dirPath, String fileNameSearch, SvnGetFileTypeEnum typeEnum){

if (dirPath.startsWith("/")){

dirPath = dirPath.replaceFirst("/", "");

}

try {

//获取SVNRepository

SVNRepository svnRepository = SVNUtil.getSVNRepository();

//获取路径下的所有文件夹或文件

List svnList = SvnOption.getSvnFileBaseInfoDto(svnRepository,dirPath, fileNameSearch, typeEnum,

false);

//这个方法只是做对象转换的,忽略

return parsePmcFileInfoDtos(svnList);

} catch (SVNException e) {

throw BusinessException.withErrorCode(ErrorsWepm.JiraAndSvnIntf.GET_FILE_LIST_FAIL)

.withErrorMessageArguments(e.getMessage());

}

}

SVNUtil.java

public class SVNUtil {

//svn连接地址

public static String storeUrl=null;

private static final String USERNAME = "你的账号";

private static final String PASSWD = "你的密码";

static{

storeUrl = “https://ip:port/svn/...”

}

/**

* @Author: winterchen

* @Description: 获取SVNRepository

* @Date: 2018/2/6

* @param url

*/

public static SVNRepository getSVNRepository(String url) throws SVNException{

SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));

ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( USERNAME , PASSWD );

repository.setAuthenticationManager( authManager );

return repository;

}

/**

* @Author: winterchen

* @Description: 获取SVNRepository

* @Date: 2018/2/7

* @param

*/

public static SVNRepository getSVNRepository() throws SVNException{

return SVNUtil.getSVNRepository(storeUrl);

}

}

/**

* @Author: winterchen

* @Description: 获取 SVNUpdateClient

* @Date: 2018/2/9

* @param

*/

public static SVNUpdateClient getSVNUpdateClient(){

//声明SVN客户端管理类

SVNClientManager ourClientManager = null;

//初始化库。 必须先执行此操作。具体操作封装在setupLibrary方法中。

setupLibrary();

ISVNOptions options = SVNWCUtil.createDefaultOptions(true);

//实例化客户端管理类

ourClientManager = SVNClientManager.newInstance(

(DefaultSVNOptions) options, USERNAME, PASSWD);

//通过客户端管理类获得updateClient类的实例。

SVNUpdateClient updateClient = ourClientManager.getUpdateCli

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中,可以使用SVNKit库来实现创建SVN目录SVNKit是一个开源的Java库,提供了与Subversion版本控制系统进行交互的API。 以下是使用SVNKit库创建SVN目录的示例代码: ```java import org.tmatesoft.svn.core.SVNCommitInfo; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.*; public class SVNCreateDirectoryExample { public static void main(String[] args) { // 初始化SVN库 DAVRepositoryFactory.setup(); // 定义SVN仓库的URL String url = "http://svn.example.com/svn/repository"; // 定义SVN仓库的认证信息 String username = "your_username"; String password = "your_password"; // 创建SVN目录的路径 String directoryPath = "/path/to/new_directory"; try { // 创建SVN仓库的连接 SVNURL svnUrl = SVNURL.parseURIEncoded(url); SVNRepository repository = SVNRepositoryFactory.create(svnUrl); // 设置SVN仓库的认证信息 ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); repository.setAuthenticationManager(authManager); // 创建SVN目录 SVNClientManager clientManager = SVNClientManager.newInstance(); SVNWCClient wcClient = clientManager.getWCClient(); SVNCommitInfo commitInfo = wcClient.doMkDir(new SVNURL[]{svnUrl.appendPath(directoryPath, false)}, "Create new directory"); // 输出创建目录的结果 System.out.println("Directory created: " + commitInfo.getNewRevision()); } catch (SVNException e) { e.printStackTrace(); } } } ``` 请注意,上述示例代码中的`url`、`username`、`password`和`directoryPath`需要根据实际情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值