mirror of https://github.com/Rekoe/rk_svnadmin
del path field
parent
ace8f8ee1d
commit
11982eccca
|
@ -21,11 +21,6 @@ public class Pj implements Serializable{
|
|||
*/
|
||||
@Name
|
||||
private String pj;
|
||||
/**
|
||||
* 仓库位置
|
||||
*/
|
||||
@Comment
|
||||
private String path;
|
||||
/**
|
||||
* 访问项目的svn地址
|
||||
*/
|
||||
|
@ -63,21 +58,6 @@ public class Pj implements Serializable{
|
|||
this.pj = pj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 仓库位置
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* 仓库位置
|
||||
*/
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 描述
|
||||
*/
|
||||
|
|
|
@ -56,13 +56,11 @@ public class ProjectService extends BaseService<Pj> {
|
|||
return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("pj", "=", name)));
|
||||
}
|
||||
|
||||
public int getCount(String path, String url) {
|
||||
int num = dao().count(getEntityClass(), Cnd.where("path", "=", path).or("url", "=", url));
|
||||
return num;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Inject
|
||||
private RepositoryService repositoryService;
|
||||
@Inject
|
||||
private ProjectConfigService projectConfigService;
|
||||
|
||||
/**
|
||||
* 保存。<br>
|
||||
* 数据库里已经存在相同的路径或url的项目,不可以保存。<br>
|
||||
|
@ -73,30 +71,14 @@ public class ProjectService extends BaseService<Pj> {
|
|||
* 项目
|
||||
*/
|
||||
public void save(Pj pj) {
|
||||
// 路径 把\替换为/
|
||||
if (StringUtils.isNotBlank(pj.getPath())) {
|
||||
pj.setPath(StringUtils.replace(pj.getPath(), "\\", "/"));
|
||||
}
|
||||
// url 把\替换为/
|
||||
if (StringUtils.isNotBlank(pj.getUrl())) {
|
||||
pj.setUrl(StringUtils.replace(pj.getUrl(), "\\", "/"));
|
||||
}
|
||||
|
||||
// 是否可以增加项目
|
||||
boolean insert = nameOk(pj.getPj());
|
||||
if (insert) {
|
||||
// 数据库里已经存在相同的路径或url的项目
|
||||
if (this.getCount(pj.getPath(), pj.getUrl()) > 0) {
|
||||
throw new RuntimeException("数据库里已经存在相同的路径或url的仓库项目,请检查路径或url");
|
||||
}
|
||||
} else {
|
||||
// 数据库里已经存在相同的路径或url的项目
|
||||
if (this.getCount(pj.getPath(), pj.getUrl()) > 1) {
|
||||
throw new RuntimeException("数据库里已经存在多个相同的路径或url的仓库项目,请检查路径或url");
|
||||
}
|
||||
}
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
// 创建仓库
|
||||
File respository = new File(pj.getPath());
|
||||
File respository = new File(path);
|
||||
if (!respository.exists() || !respository.isDirectory()) {// 不存在仓库
|
||||
RepositoryService.createLocalRepository(respository);
|
||||
}
|
||||
|
@ -134,10 +116,10 @@ public class ProjectService extends BaseService<Pj> {
|
|||
*/
|
||||
public String getRelateRootPath(String pj) {
|
||||
Pj p = this.get(pj);
|
||||
if (p == null || StringUtils.isBlank(p.getPath())) {
|
||||
if (p == null) {
|
||||
return pj;
|
||||
}
|
||||
return getRelateRootPath(pj);
|
||||
return projectConfigService.getRepoPath(p);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,15 +131,7 @@ public class ProjectService extends BaseService<Pj> {
|
|||
* @since 3.0.3
|
||||
*/
|
||||
public String getRelateRootPath(Pj pj) {
|
||||
String path = pj.getPath();
|
||||
if (StringUtils.isBlank(path)) {
|
||||
return pj.getPj();
|
||||
}
|
||||
path = StringUtils.replace(path, "\\", "/");
|
||||
while (path.endsWith("/")) {
|
||||
path = path.substring(0, path.length() - 1);
|
||||
}
|
||||
return StringUtils.substringAfterLast(path, "/");
|
||||
return projectConfigService.getRepoPath(pj);
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
|
|
@ -79,16 +79,15 @@ public class SvnService {
|
|||
if (pj == null) {
|
||||
return;
|
||||
}
|
||||
String path = projectConfigService.get().getRepositoryPath() + pj.getPj();
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File parent = new File(path);
|
||||
if (!parent.exists() || !parent.isDirectory()) {
|
||||
throw new RuntimeException(String.format("找不到仓库 路径 %s", pj.getPath()));
|
||||
throw new RuntimeException(String.format("找不到仓库 路径 %s", path));
|
||||
}
|
||||
if (Constants.HTTP.equalsIgnoreCase(pj.getType())) {// HTTP(单库) SVNPath
|
||||
this.exportHTTP(pj);
|
||||
} else if (Constants.HTTP_MUTIL.equalsIgnoreCase(pj.getType())) {// HTTP(多库)
|
||||
// SVNParentPath
|
||||
File root = new File(pj.getPath()).getParentFile();
|
||||
File root = new File(path).getParentFile();
|
||||
this.exportHTTPMutil(root);
|
||||
} else if (Constants.SVN.equalsIgnoreCase(pj.getType())) {// SVN
|
||||
this.exportSVN(pj);
|
||||
|
@ -277,7 +276,8 @@ public class SvnService {
|
|||
* 项目用户列表
|
||||
*/
|
||||
private void exportPasswdHTTP(Pj pj, List<Usr> usrList) {
|
||||
File outFile = new File(pj.getPath(), "/conf/passwd.http");
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File outFile = new File(path, "/conf/passwd.http");
|
||||
StringBuffer contents = new StringBuffer();
|
||||
for (Usr usr : usrList) {
|
||||
// 采用SHA加密
|
||||
|
@ -297,7 +297,8 @@ public class SvnService {
|
|||
* 项目用户列表
|
||||
*/
|
||||
private void exportPasswdSVN(Pj pj, List<Usr> usrList) {
|
||||
File outFile = new File(pj.getPath(), "/conf/passwd");
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File outFile = new File(path, "/conf/passwd");
|
||||
StringBuffer contents = new StringBuffer();
|
||||
contents.append("[users]").append(SEP);
|
||||
for (Usr usr : usrList) {
|
||||
|
@ -376,7 +377,8 @@ public class SvnService {
|
|||
* if(pjGrList == null || pjGrList.size() == 0){ return; } if(pjAuthMap
|
||||
* == null || pjAuthMap.size() == 0){ return; }
|
||||
*/
|
||||
File outFile = new File(pj.getPath(), "/conf/authz");
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File outFile = new File(path, "/conf/authz");
|
||||
StringBuffer contents = new StringBuffer();
|
||||
contents.append("[aliases]").append(SEP);
|
||||
contents.append("[groups]").append(SEP);
|
||||
|
@ -423,7 +425,8 @@ public class SvnService {
|
|||
if (pj == null || StringUtils.isBlank(pj.getPj())) {
|
||||
return;
|
||||
}
|
||||
File outFile = new File(pj.getPath(), "/conf/svnserve.conf");
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File outFile = new File(path, "/conf/svnserve.conf");
|
||||
StringBuffer contents = new StringBuffer();
|
||||
contents.append("[general]").append(SEP);
|
||||
contents.append("anon-access = none").append(SEP);
|
||||
|
@ -444,9 +447,10 @@ public class SvnService {
|
|||
if (pj == null || StringUtils.isBlank(pj.getPj())) {
|
||||
return;
|
||||
}
|
||||
File outFile = new File(pj.getPath(), "/conf/httpd.conf");
|
||||
String path = projectConfigService.getRepoPath(pj);
|
||||
File outFile = new File(path, "/conf/httpd.conf");
|
||||
StringBuffer contents = new StringBuffer();
|
||||
contents.append("#Include ").append(pj.getPath()).append("/conf/httpd.conf").append(SEP);
|
||||
contents.append("#Include ").append(path).append("/conf/httpd.conf").append(SEP);
|
||||
String location = pj.getPj();
|
||||
// 例如 http://192.168.1.100/svn/projar/trunk
|
||||
if (StringUtils.isNotBlank(pj.getUrl()) && pj.getUrl().indexOf("//") != -1) {
|
||||
|
@ -457,11 +461,11 @@ public class SvnService {
|
|||
}
|
||||
contents.append("<Location /").append(location).append(">").append(SEP);
|
||||
contents.append("DAV svn").append(SEP);
|
||||
contents.append("SVNPath ").append(pj.getPath()).append(SEP);
|
||||
contents.append("SVNPath ").append(path).append(SEP);
|
||||
contents.append("AuthType Basic").append(SEP);
|
||||
contents.append("AuthName ").append("\"").append(pj.getPj()).append("\"").append(SEP);
|
||||
contents.append("AuthUserFile ").append(pj.getPath()).append("/conf/passwd.http").append(SEP);
|
||||
contents.append("AuthzSVNAccessFile ").append(pj.getPath()).append("/conf/authz").append(SEP);
|
||||
contents.append("AuthName ").append("\"").append(path).append("\"").append(SEP);
|
||||
contents.append("AuthUserFile ").append(path).append("/conf/passwd.http").append(SEP);
|
||||
contents.append("AuthzSVNAccessFile ").append(path).append("/conf/authz").append(SEP);
|
||||
contents.append("Require valid-user").append(SEP);
|
||||
contents.append("</Location>").append(SEP);
|
||||
this.write(outFile, contents.toString());
|
||||
|
|
Loading…
Reference in New Issue