mirror of https://github.com/Rekoe/rk_svnadmin
增加目录初始化功能
parent
32626bb414
commit
a12751e424
|
@ -14,6 +14,13 @@ import org.nutz.ioc.Ioc;
|
|||
import org.nutz.mvc.NutConfig;
|
||||
import org.nutz.mvc.Setup;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
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.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.SVNCommitClient;
|
||||
import org.tmatesoft.svn.core.wc.SVNWCUtil;
|
||||
|
||||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.ProjectConfig;
|
||||
|
@ -69,6 +76,20 @@ public class MvcSetup implements Setup {
|
|||
ioc.get(ProjectConfigService.class).init();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("admin", "john");
|
||||
SVNClientManager manager = SVNClientManager.newInstance();
|
||||
manager.setAuthenticationManager(authManager);
|
||||
SVNCommitClient commitClient = SVNClientManager.newInstance().getCommitClient();
|
||||
try {
|
||||
SVNCommitInfo info = commitClient.doMkDir(new SVNURL[] { SVNURL.parseURIEncoded("http://192.168.3.127/repository/koux/trunk") }, "commitMessage", null, true);
|
||||
long newRevision = info.getNewRevision();
|
||||
System.out.println(newRevision);
|
||||
} catch (SVNException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(NutConfig config) {
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.rekoe.domain;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Readonly;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
@ -24,12 +26,12 @@ public class Pj implements Serializable {
|
|||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Comment
|
||||
@Column
|
||||
private String des;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Comment
|
||||
@Column
|
||||
private String type;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +40,19 @@ public class Pj implements Serializable {
|
|||
@Readonly
|
||||
private boolean manager;
|
||||
|
||||
@Column("is_init_templ")
|
||||
@Default("0")
|
||||
@Comment("是否初始化模板")
|
||||
private boolean initTempl;
|
||||
|
||||
public boolean isInitTempl() {
|
||||
return initTempl;
|
||||
}
|
||||
|
||||
public void setInitTempl(boolean initTempl) {
|
||||
this.initTempl = initTempl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 项目ID
|
||||
*/
|
||||
|
|
|
@ -84,7 +84,6 @@ public class AdminProjectAct extends BaseAction {
|
|||
@RequiresPermissions({ "svn.project:view" })
|
||||
public String rep(@Param("pj") String pj, HttpServletRequest req) {
|
||||
Pj project = projectService.get(pj);
|
||||
repositoryService.createDir(project);
|
||||
String root = repositoryService.getRepositoryRoot(project);
|
||||
String svnUrl = RepositoryService.parseURL(projectConfigService.getProjectUrl(pj));
|
||||
String path = "/";
|
||||
|
@ -122,8 +121,11 @@ public class AdminProjectAct extends BaseAction {
|
|||
@RequiresPermissions({ "svn.project:edit" })
|
||||
public Message init(@Param("pj") String pj, HttpServletRequest req) {
|
||||
Pj project = projectService.get(pj);
|
||||
repositoryService.createDir(project);
|
||||
return Message.success("ok", req);
|
||||
boolean isRight = repositoryService.createDir(project);
|
||||
if (isRight) {
|
||||
return Message.success("ok", req);
|
||||
}
|
||||
return Message.error("error", req);
|
||||
}
|
||||
|
||||
@At
|
||||
|
|
|
@ -5,9 +5,9 @@ package com.rekoe.service;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
@ -34,6 +34,7 @@ import com.rekoe.domain.Pj;
|
|||
import com.rekoe.domain.PjUsr;
|
||||
import com.rekoe.domain.ProjectConfig;
|
||||
import com.rekoe.domain.Usr;
|
||||
import com.rekoe.utils.DoCommit;
|
||||
import com.rekoe.utils.EncryptUtil;
|
||||
import com.rekoe.utils.UsrProvider;
|
||||
|
||||
|
@ -48,6 +49,9 @@ public class RepositoryService {
|
|||
*/
|
||||
private final Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private DoCommit doCommit;
|
||||
|
||||
@Inject
|
||||
private ProjectService projectService;
|
||||
|
||||
|
@ -147,36 +151,17 @@ public class RepositoryService {
|
|||
* @param pj
|
||||
* @throws SVNException
|
||||
*/
|
||||
|
||||
public synchronized boolean createDir(Pj pj) {
|
||||
Usr usr = UsrProvider.getCurrentUsr();
|
||||
String svnUrl = getProjectSVNUrl(pj);
|
||||
if (StringUtils.isBlank(svnUrl)) {
|
||||
throw new RuntimeException("URL不可以为空");
|
||||
if (pj.isInitTempl()) {
|
||||
return true;
|
||||
}
|
||||
String svnUserName = usr.getUsr();
|
||||
String svnPassword = usr.getPsw();
|
||||
if (!com.rekoe.utils.Constants.HTTP_MUTIL.equals(pj.getType())) {
|
||||
// pj_usr覆盖用户的密码
|
||||
PjUsr pjUsr = projectUserService.get(pj.getPj(), svnUserName);
|
||||
if (pjUsr != null) {
|
||||
svnPassword = pjUsr.getPsw();
|
||||
}
|
||||
boolean isRight = doCommit.mkdirs(pj.getPj());
|
||||
if (isRight) {
|
||||
pj.setInitTempl(true);
|
||||
projectService.update(Chain.make("is_init_templ", true), Cnd.where("pj", "=", pj.getPj()));
|
||||
}
|
||||
svnPassword = EncryptUtil.decrypt(svnPassword);// 解密
|
||||
ProjectConfig conf = projectConfigService.get();
|
||||
List<String> dirs = conf.getDirs();
|
||||
SVNURL[] urlAr = new SVNURL[dirs.size()];
|
||||
int i = 0;
|
||||
for (String url : dirs) {
|
||||
try {
|
||||
String tempUrl = getProjectSVNUrl(pj) + "/" + url;
|
||||
urlAr[i] = SVNURL.parseURIEncoded(tempUrl);
|
||||
} catch (SVNException e) {
|
||||
log.error(e);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return svnMkDirs(urlAr);
|
||||
return isRight;
|
||||
}
|
||||
|
||||
public boolean svnMkDirs(SVNURL[] urls) {
|
||||
|
@ -193,6 +178,7 @@ public class RepositoryService {
|
|||
else
|
||||
log.debug("no commits performed (commit operation returned new revision < 0)");
|
||||
}
|
||||
System.out.println(newRevision);
|
||||
} catch (SVNException e) {
|
||||
log.error(e);
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package com.rekoe.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
|
||||
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.SVNWCUtil;
|
||||
|
||||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.PjUsr;
|
||||
import com.rekoe.domain.ProjectConfig;
|
||||
import com.rekoe.domain.Usr;
|
||||
import com.rekoe.service.ProjectConfigService;
|
||||
import com.rekoe.service.ProjectService;
|
||||
import com.rekoe.service.ProjectUserService;
|
||||
import com.rekoe.service.RepositoryService;
|
||||
|
||||
@IocBean(create = "init")
|
||||
public class DoCommit {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private ProjectService projectService;
|
||||
@Inject
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Inject
|
||||
private ProjectUserService projectUserService;
|
||||
|
||||
@Inject
|
||||
private ProjectConfigService projectConfigService;
|
||||
|
||||
public boolean mkdirs(String pj) {
|
||||
Pj project =projectService.get(pj);
|
||||
Usr usr = UsrProvider.getCurrentUsr();
|
||||
String svnUrl = repositoryService.getProjectSVNUrl(project);
|
||||
if (StringUtils.isBlank(svnUrl)) {
|
||||
throw new RuntimeException("URL不可以为空");
|
||||
}
|
||||
String svnUserName = usr.getUsr();
|
||||
String svnPassword = usr.getPsw();
|
||||
if (!com.rekoe.utils.Constants.HTTP_MUTIL.equals(project.getType())) {
|
||||
// pj_usr覆盖用户的密码
|
||||
PjUsr pjUsr = projectUserService.get(project.getPj(), svnUserName);
|
||||
if (pjUsr != null) {
|
||||
svnPassword = pjUsr.getPsw();
|
||||
}
|
||||
}
|
||||
svnPassword = EncryptUtil.decrypt(svnPassword);// 解密
|
||||
ProjectConfig conf = projectConfigService.get();
|
||||
List<String> dirs = conf.getDirs();
|
||||
SVNURL[] urlAr = new SVNURL[dirs.size()];
|
||||
int i = 0;
|
||||
for (String url : dirs) {
|
||||
try {
|
||||
String tempUrl = repositoryService.getProjectSVNUrl(project) + "/" + url;
|
||||
urlAr[i] = SVNURL.parseURIEncoded(tempUrl);
|
||||
} catch (SVNException e) {
|
||||
log.error(e);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
String name = svnUserName;
|
||||
String password = svnPassword;
|
||||
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
|
||||
// 实例化客户端管理类
|
||||
SVNClientManager ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, name, password);
|
||||
// 要提交的文件
|
||||
try {
|
||||
ourClientManager.getCommitClient().doMkDir(urlAr, "commitMessage");
|
||||
} catch (SVNException e) {
|
||||
log.error(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
SVNRepositoryFactoryImpl.setup();
|
||||
}
|
||||
}
|
|
@ -8,6 +8,31 @@
|
|||
function getTableForm() {
|
||||
return document.getElementById('tableForm');
|
||||
}
|
||||
function init(pj){
|
||||
$.dialog({
|
||||
type: "warn",
|
||||
content: '确定要创建模板目录?',
|
||||
ok: 'Ok',
|
||||
cancel: 'Cancel',
|
||||
onOk: function() {
|
||||
$.ajax({
|
||||
url: "init.rk",
|
||||
type: "POST",
|
||||
data: {"pj":pj},
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
success: function(message) {
|
||||
$.message(message);
|
||||
if (message.type == "success")
|
||||
{
|
||||
window.location.href = "list.rk"
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in New Issue