del path field

pull/3/head
rekoe 2016-03-25 13:50:41 +08:00
parent ace8f8ee1d
commit 11982eccca
3 changed files with 27 additions and 69 deletions

View File

@ -21,11 +21,6 @@ public class Pj implements Serializable{
*/ */
@Name @Name
private String pj; private String pj;
/**
*
*/
@Comment
private String path;
/** /**
* 访svn * 访svn
*/ */
@ -63,21 +58,6 @@ public class Pj implements Serializable{
this.pj = pj; this.pj = pj;
} }
/**
* @return
*/
public String getPath() {
return path;
}
/**
* @param path
*
*/
public void setPath(String path) {
this.path = path;
}
/** /**
* @return * @return
*/ */

View File

@ -56,13 +56,11 @@ public class ProjectService extends BaseService<Pj> {
return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("pj", "=", name))); return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("pj", "=", name)));
} }
public int getCount(String path, String url) { @Inject
int num = dao().count(getEntityClass(), Cnd.where("path", "=", path).or("url", "=", url));
return num;
}
@Inject
private RepositoryService repositoryService; private RepositoryService repositoryService;
@Inject
private ProjectConfigService projectConfigService;
/** /**
* <br> * <br>
* url<br> * url<br>
@ -73,30 +71,14 @@ public class ProjectService extends BaseService<Pj> {
* *
*/ */
public void save(Pj pj) { public void save(Pj pj) {
// 路径 把\替换为/
if (StringUtils.isNotBlank(pj.getPath())) {
pj.setPath(StringUtils.replace(pj.getPath(), "\\", "/"));
}
// url 把\替换为/
if (StringUtils.isNotBlank(pj.getUrl())) { if (StringUtils.isNotBlank(pj.getUrl())) {
pj.setUrl(StringUtils.replace(pj.getUrl(), "\\", "/")); pj.setUrl(StringUtils.replace(pj.getUrl(), "\\", "/"));
} }
// 是否可以增加项目 // 是否可以增加项目
boolean insert = nameOk(pj.getPj()); boolean insert = nameOk(pj.getPj());
if (insert) { String path = projectConfigService.getRepoPath(pj);
// 数据库里已经存在相同的路径或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");
}
}
// 创建仓库 // 创建仓库
File respository = new File(pj.getPath()); File respository = new File(path);
if (!respository.exists() || !respository.isDirectory()) {// 不存在仓库 if (!respository.exists() || !respository.isDirectory()) {// 不存在仓库
RepositoryService.createLocalRepository(respository); RepositoryService.createLocalRepository(respository);
} }
@ -134,10 +116,10 @@ public class ProjectService extends BaseService<Pj> {
*/ */
public String getRelateRootPath(String pj) { public String getRelateRootPath(String pj) {
Pj p = this.get(pj); Pj p = this.get(pj);
if (p == null || StringUtils.isBlank(p.getPath())) { if (p == null) {
return pj; return pj;
} }
return getRelateRootPath(pj); return projectConfigService.getRepoPath(p);
} }
/** /**
@ -149,15 +131,7 @@ public class ProjectService extends BaseService<Pj> {
* @since 3.0.3 * @since 3.0.3
*/ */
public String getRelateRootPath(Pj pj) { public String getRelateRootPath(Pj pj) {
String path = pj.getPath(); return projectConfigService.getRepoPath(pj);
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, "/");
} }
@Inject @Inject

View File

@ -79,16 +79,15 @@ public class SvnService {
if (pj == null) { if (pj == null) {
return; return;
} }
String path = projectConfigService.get().getRepositoryPath() + pj.getPj(); String path = projectConfigService.getRepoPath(pj);
File parent = new File(path); File parent = new File(path);
if (!parent.exists() || !parent.isDirectory()) { 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 if (Constants.HTTP.equalsIgnoreCase(pj.getType())) {// HTTP(单库) SVNPath
this.exportHTTP(pj); this.exportHTTP(pj);
} else if (Constants.HTTP_MUTIL.equalsIgnoreCase(pj.getType())) {// HTTP(多库) } else if (Constants.HTTP_MUTIL.equalsIgnoreCase(pj.getType())) {// HTTP(多库)
// SVNParentPath File root = new File(path).getParentFile();
File root = new File(pj.getPath()).getParentFile();
this.exportHTTPMutil(root); this.exportHTTPMutil(root);
} else if (Constants.SVN.equalsIgnoreCase(pj.getType())) {// SVN } else if (Constants.SVN.equalsIgnoreCase(pj.getType())) {// SVN
this.exportSVN(pj); this.exportSVN(pj);
@ -277,7 +276,8 @@ public class SvnService {
* *
*/ */
private void exportPasswdHTTP(Pj pj, List<Usr> usrList) { 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(); StringBuffer contents = new StringBuffer();
for (Usr usr : usrList) { for (Usr usr : usrList) {
// 采用SHA加密 // 采用SHA加密
@ -297,7 +297,8 @@ public class SvnService {
* *
*/ */
private void exportPasswdSVN(Pj pj, List<Usr> usrList) { 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(); StringBuffer contents = new StringBuffer();
contents.append("[users]").append(SEP); contents.append("[users]").append(SEP);
for (Usr usr : usrList) { for (Usr usr : usrList) {
@ -376,7 +377,8 @@ public class SvnService {
* if(pjGrList == null || pjGrList.size() == 0){ return; } if(pjAuthMap * if(pjGrList == null || pjGrList.size() == 0){ return; } if(pjAuthMap
* == null || pjAuthMap.size() == 0){ return; } * == 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(); StringBuffer contents = new StringBuffer();
contents.append("[aliases]").append(SEP); contents.append("[aliases]").append(SEP);
contents.append("[groups]").append(SEP); contents.append("[groups]").append(SEP);
@ -423,7 +425,8 @@ public class SvnService {
if (pj == null || StringUtils.isBlank(pj.getPj())) { if (pj == null || StringUtils.isBlank(pj.getPj())) {
return; 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(); StringBuffer contents = new StringBuffer();
contents.append("[general]").append(SEP); contents.append("[general]").append(SEP);
contents.append("anon-access = none").append(SEP); contents.append("anon-access = none").append(SEP);
@ -444,9 +447,10 @@ public class SvnService {
if (pj == null || StringUtils.isBlank(pj.getPj())) { if (pj == null || StringUtils.isBlank(pj.getPj())) {
return; 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(); 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(); String location = pj.getPj();
// 例如 http://192.168.1.100/svn/projar/trunk // 例如 http://192.168.1.100/svn/projar/trunk
if (StringUtils.isNotBlank(pj.getUrl()) && pj.getUrl().indexOf("//") != -1) { 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("<Location /").append(location).append(">").append(SEP);
contents.append("DAV svn").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("AuthType Basic").append(SEP);
contents.append("AuthName ").append("\"").append(pj.getPj()).append("\"").append(SEP); contents.append("AuthName ").append("\"").append(path).append("\"").append(SEP);
contents.append("AuthUserFile ").append(pj.getPath()).append("/conf/passwd.http").append(SEP); contents.append("AuthUserFile ").append(path).append("/conf/passwd.http").append(SEP);
contents.append("AuthzSVNAccessFile ").append(pj.getPath()).append("/conf/authz").append(SEP); contents.append("AuthzSVNAccessFile ").append(path).append("/conf/authz").append(SEP);
contents.append("Require valid-user").append(SEP); contents.append("Require valid-user").append(SEP);
contents.append("</Location>").append(SEP); contents.append("</Location>").append(SEP);
this.write(outFile, contents.toString()); this.write(outFile, contents.toString());