增加目录初始化功能

pull/3/head
rekoe 2016-03-28 11:19:05 +08:00
parent 32626bb414
commit a12751e424
6 changed files with 173 additions and 33 deletions

View File

@ -14,6 +14,13 @@ import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig; import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup; import org.nutz.mvc.Setup;
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer; 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.Pj;
import com.rekoe.domain.ProjectConfig; import com.rekoe.domain.ProjectConfig;
@ -69,6 +76,20 @@ public class MvcSetup implements Setup {
ioc.get(ProjectConfigService.class).init(); 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 @Override
public void destroy(NutConfig config) { public void destroy(NutConfig config) {

View File

@ -2,7 +2,9 @@ package com.rekoe.domain;
import java.io.Serializable; import java.io.Serializable;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment; 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.Name;
import org.nutz.dao.entity.annotation.Readonly; import org.nutz.dao.entity.annotation.Readonly;
import org.nutz.dao.entity.annotation.Table; import org.nutz.dao.entity.annotation.Table;
@ -24,12 +26,12 @@ public class Pj implements Serializable {
/** /**
* *
*/ */
@Comment @Column
private String des; private String des;
/** /**
* *
*/ */
@Comment @Column
private String type; private String type;
/** /**
@ -38,6 +40,19 @@ public class Pj implements Serializable {
@Readonly @Readonly
private boolean manager; 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 * @return ID
*/ */

View File

@ -84,7 +84,6 @@ public class AdminProjectAct extends BaseAction {
@RequiresPermissions({ "svn.project:view" }) @RequiresPermissions({ "svn.project:view" })
public String rep(@Param("pj") String pj, HttpServletRequest req) { public String rep(@Param("pj") String pj, HttpServletRequest req) {
Pj project = projectService.get(pj); Pj project = projectService.get(pj);
repositoryService.createDir(project);
String root = repositoryService.getRepositoryRoot(project); String root = repositoryService.getRepositoryRoot(project);
String svnUrl = RepositoryService.parseURL(projectConfigService.getProjectUrl(pj)); String svnUrl = RepositoryService.parseURL(projectConfigService.getProjectUrl(pj));
String path = "/"; String path = "/";
@ -122,8 +121,11 @@ public class AdminProjectAct extends BaseAction {
@RequiresPermissions({ "svn.project:edit" }) @RequiresPermissions({ "svn.project:edit" })
public Message init(@Param("pj") String pj, HttpServletRequest req) { public Message init(@Param("pj") String pj, HttpServletRequest req) {
Pj project = projectService.get(pj); Pj project = projectService.get(pj);
repositoryService.createDir(project); boolean isRight = repositoryService.createDir(project);
return Message.success("ok", req); if (isRight) {
return Message.success("ok", req);
}
return Message.error("error", req);
} }
@At @At

View File

@ -5,9 +5,9 @@ package com.rekoe.service;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd; import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean; 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.PjUsr;
import com.rekoe.domain.ProjectConfig; import com.rekoe.domain.ProjectConfig;
import com.rekoe.domain.Usr; import com.rekoe.domain.Usr;
import com.rekoe.utils.DoCommit;
import com.rekoe.utils.EncryptUtil; import com.rekoe.utils.EncryptUtil;
import com.rekoe.utils.UsrProvider; import com.rekoe.utils.UsrProvider;
@ -48,6 +49,9 @@ public class RepositoryService {
*/ */
private final Log log = Logs.get(); private final Log log = Logs.get();
@Inject
private DoCommit doCommit;
@Inject @Inject
private ProjectService projectService; private ProjectService projectService;
@ -147,36 +151,17 @@ public class RepositoryService {
* @param pj * @param pj
* @throws SVNException * @throws SVNException
*/ */
public synchronized boolean createDir(Pj pj) { public synchronized boolean createDir(Pj pj) {
Usr usr = UsrProvider.getCurrentUsr(); if (pj.isInitTempl()) {
String svnUrl = getProjectSVNUrl(pj); return true;
if (StringUtils.isBlank(svnUrl)) {
throw new RuntimeException("URL不可以为空");
} }
String svnUserName = usr.getUsr(); boolean isRight = doCommit.mkdirs(pj.getPj());
String svnPassword = usr.getPsw(); if (isRight) {
if (!com.rekoe.utils.Constants.HTTP_MUTIL.equals(pj.getType())) { pj.setInitTempl(true);
// pj_usr覆盖用户的密码 projectService.update(Chain.make("is_init_templ", true), Cnd.where("pj", "=", pj.getPj()));
PjUsr pjUsr = projectUserService.get(pj.getPj(), svnUserName);
if (pjUsr != null) {
svnPassword = pjUsr.getPsw();
}
} }
svnPassword = EncryptUtil.decrypt(svnPassword);// 解密 return isRight;
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);
} }
public boolean svnMkDirs(SVNURL[] urls) { public boolean svnMkDirs(SVNURL[] urls) {
@ -193,6 +178,7 @@ public class RepositoryService {
else else
log.debug("no commits performed (commit operation returned new revision < 0)"); log.debug("no commits performed (commit operation returned new revision < 0)");
} }
System.out.println(newRevision);
} catch (SVNException e) { } catch (SVNException e) {
log.error(e); log.error(e);
return false; return false;

View File

@ -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();
}
}

View File

@ -8,6 +8,31 @@
function getTableForm() { function getTableForm() {
return document.getElementById('tableForm'); 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> </script>
</head> </head>
<body> <body>