mirror of https://github.com/Rekoe/rk_svnadmin
添加初始化文件夹功能
parent
ca7eb105a3
commit
d37e0e50e9
|
@ -84,6 +84,7 @@ 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 = "/";
|
||||||
|
@ -116,6 +117,15 @@ public class AdminProjectAct extends BaseAction {
|
||||||
@Inject
|
@Inject
|
||||||
private UsrService usrService;
|
private UsrService usrService;
|
||||||
|
|
||||||
|
@At
|
||||||
|
@Ok("json")
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
@At
|
@At
|
||||||
@Ok("fm:template.admin.project.pjauth")
|
@Ok("fm:template.admin.project.pjauth")
|
||||||
@RequiresPermissions({ "svn.project:view" })
|
@RequiresPermissions({ "svn.project:view" })
|
||||||
|
|
|
@ -109,6 +109,11 @@ public class ProjectService extends BaseService<Pj> {
|
||||||
dao().update(pj);
|
dao().update(pj);
|
||||||
}
|
}
|
||||||
svnService.exportConfig(pj.getPj());
|
svnService.exportConfig(pj.getPj());
|
||||||
|
// createDefatutDirs(pj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Async
|
||||||
|
public void createDefatutDirs(Pj pj) {
|
||||||
repositoryService.createDir(pj);
|
repositoryService.createDir(pj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,8 @@ public class RepositoryService {
|
||||||
/**
|
/**
|
||||||
* 日志
|
* 日志
|
||||||
*/
|
*/
|
||||||
private final Log LOG = Logs.get();
|
private final Log log = Logs.get();
|
||||||
|
|
||||||
private SVNClientManager manager;
|
|
||||||
@Inject
|
@Inject
|
||||||
private ProjectService projectService;
|
private ProjectService projectService;
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ public class RepositoryService {
|
||||||
public SVNRepository getRepository(String pjId) throws SVNException {
|
public SVNRepository getRepository(String pjId) throws SVNException {
|
||||||
Pj pj = projectService.fetch(Cnd.where("pj", "=", pjId));
|
Pj pj = projectService.fetch(Cnd.where("pj", "=", pjId));
|
||||||
if (pj == null) {
|
if (pj == null) {
|
||||||
LOG.warn("Not found project: " + pjId);
|
log.warn("Not found project: " + pjId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.getRepository(pj);
|
return this.getRepository(pj);
|
||||||
|
@ -148,7 +147,7 @@ public class RepositoryService {
|
||||||
* @param pj
|
* @param pj
|
||||||
* @throws SVNException
|
* @throws SVNException
|
||||||
*/
|
*/
|
||||||
public synchronized void createDir(Pj pj) {
|
public synchronized boolean createDir(Pj pj) {
|
||||||
Usr usr = UsrProvider.getCurrentUsr();
|
Usr usr = UsrProvider.getCurrentUsr();
|
||||||
String svnUrl = getProjectSVNUrl(pj);
|
String svnUrl = getProjectSVNUrl(pj);
|
||||||
if (StringUtils.isBlank(svnUrl)) {
|
if (StringUtils.isBlank(svnUrl)) {
|
||||||
|
@ -164,34 +163,55 @@ public class RepositoryService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
svnPassword = EncryptUtil.decrypt(svnPassword);// 解密
|
svnPassword = EncryptUtil.decrypt(svnPassword);// 解密
|
||||||
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(svnUserName, svnPassword);
|
|
||||||
this.manager.setAuthenticationManager(authManager);
|
|
||||||
boolean makeParents = true;
|
|
||||||
String commitMessage = "mkdir by Rekoe";
|
|
||||||
ProjectConfig conf = projectConfigService.get();
|
ProjectConfig conf = projectConfigService.get();
|
||||||
List<String> dirs = conf.getDirs();
|
List<String> dirs = conf.getDirs();
|
||||||
SVNURL[] urlAr = new SVNURL[dirs.size()];
|
SVNURL[] urlAr = new SVNURL[dirs.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String url : dirs) {
|
for (String url : dirs) {
|
||||||
try {
|
try {
|
||||||
urlAr[i] = SVNURL.parseURIEncoded(getProjectSVNUrl(pj) + "/" + url);
|
String tempUrl = getProjectSVNUrl(pj) + "/" + url;
|
||||||
|
urlAr[i] = SVNURL.parseURIEncoded(tempUrl);
|
||||||
} catch (SVNException e) {
|
} catch (SVNException e) {
|
||||||
LOG.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
return svnMkDirs(urlAr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean svnMkDirs(SVNURL[] urls) {
|
||||||
|
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("admin", "john");
|
||||||
|
SVNClientManager manager = SVNClientManager.newInstance();
|
||||||
|
manager.setAuthenticationManager(authManager);
|
||||||
SVNCommitClient commitClient = SVNClientManager.newInstance().getCommitClient();
|
SVNCommitClient commitClient = SVNClientManager.newInstance().getCommitClient();
|
||||||
try {
|
try {
|
||||||
SVNCommitInfo info = commitClient.doMkDir(urlAr, commitMessage, null, makeParents);
|
SVNCommitInfo info = commitClient.doMkDir(urls, "commitMessage", null, true);
|
||||||
if (LOG.isDebugEnabled()) {
|
|
||||||
long newRevision = info.getNewRevision();
|
long newRevision = info.getNewRevision();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
if (newRevision >= 0)
|
if (newRevision >= 0)
|
||||||
LOG.debug("commit successful: new revision = " + newRevision);
|
log.debug("commit successful: new revision = " + newRevision);
|
||||||
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 true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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/branches") }, "commitMessage", null, true);
|
||||||
|
long newRevision = info.getNewRevision();
|
||||||
|
System.out.println(newRevision);
|
||||||
|
} catch (SVNException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +228,10 @@ public class RepositoryService {
|
||||||
repository = this.getRepository(pj);
|
repository = this.getRepository(pj);
|
||||||
return repository.getRepositoryRoot(true).toString();
|
return repository.getRepositoryRoot(true).toString();
|
||||||
} catch (SVNAuthenticationException e) {
|
} catch (SVNAuthenticationException e) {
|
||||||
LOG.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch (SVNException e) {
|
} catch (SVNException e) {
|
||||||
LOG.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (repository != null) {
|
if (repository != null) {
|
||||||
|
@ -243,10 +263,10 @@ public class RepositoryService {
|
||||||
SVNProperties properties = new SVNProperties();
|
SVNProperties properties = new SVNProperties();
|
||||||
return repository.getDir(path, SVNRevision.HEAD.getNumber(), properties, (Collection) null);
|
return repository.getDir(path, SVNRevision.HEAD.getNumber(), properties, (Collection) null);
|
||||||
} catch (SVNAuthenticationException e) {
|
} catch (SVNAuthenticationException e) {
|
||||||
LOG.error(e);
|
log.error(e);
|
||||||
throw new RuntimeException("认证失败");
|
throw new RuntimeException("认证失败");
|
||||||
} catch (SVNException e) {
|
} catch (SVNException e) {
|
||||||
LOG.error(e);
|
log.error(e);
|
||||||
throw new RuntimeException(e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (repository != null) {
|
if (repository != null) {
|
||||||
|
@ -288,7 +308,6 @@ public class RepositoryService {
|
||||||
*/
|
*/
|
||||||
FSRepositoryFactory.setup();
|
FSRepositoryFactory.setup();
|
||||||
|
|
||||||
this.manager = SVNClientManager.newInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ function getTableForm() {
|
||||||
<@p.column title="设置用户组" align="center"><a href="${base}/admin/project/group/list?pj=${project.pj}">设置用户组</a></@p.column><#t/>
|
<@p.column title="设置用户组" align="center"><a href="${base}/admin/project/group/list?pj=${project.pj}">设置用户组</a></@p.column><#t/>
|
||||||
</@shiro.hasPermission>
|
</@shiro.hasPermission>
|
||||||
<@p.column title="设置权限" align="center"><a href="rep?pj=${project.pj}">设置权限</a></@p.column><#t/>
|
<@p.column title="设置权限" align="center"><a href="rep?pj=${project.pj}">设置权限</a></@p.column><#t/>
|
||||||
|
<@p.column title="初始化" align="center"><a href="init?pj=${project.pj}">初始化</a></@p.column><#t/>
|
||||||
<@shiro.hasPermission name="svn.project:auth.manager">
|
<@shiro.hasPermission name="svn.project:auth.manager">
|
||||||
<@p.column title="编辑" align="center">
|
<@p.column title="编辑" align="center">
|
||||||
<a href="javascript:void(0);" onclick="Cms.deleted('${project.pj}')" class="pn-opt">删除</a><#rt/>
|
<a href="javascript:void(0);" onclick="Cms.deleted('${project.pj}')" class="pn-opt">删除</a><#rt/>
|
||||||
|
|
Loading…
Reference in New Issue