chore: initial project setup
This commit is contained in:
84
src/main/java/com/svnmanager/service/InfoService.java
Normal file
84
src/main/java/com/svnmanager/service/InfoService.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.svnmanager.service;
|
||||
|
||||
import com.svnmanager.model.SvnInfo;
|
||||
import com.svnmanager.util.ProcessUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Info服务
|
||||
*/
|
||||
public class InfoService extends SvnService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(InfoService.class);
|
||||
|
||||
/**
|
||||
* 获取SVN信息
|
||||
*
|
||||
* @param workingDirectory 工作目录
|
||||
* @return SVN信息
|
||||
* @throws IOException IO异常
|
||||
* @throws InterruptedException 中断异常
|
||||
* @throws TimeoutException 超时异常
|
||||
*/
|
||||
public SvnInfo getInfo(String workingDirectory)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
logger.debug("获取信息: {}", workingDirectory);
|
||||
|
||||
if (!isValidWorkingCopy(workingDirectory)) {
|
||||
throw new IllegalArgumentException("无效的SVN工作副本: " + workingDirectory);
|
||||
}
|
||||
|
||||
ProcessUtil.ProcessResult result = executeSvnCommand("info", workingDirectory);
|
||||
|
||||
SvnInfo info = new SvnInfo();
|
||||
if (result.isSuccess()) {
|
||||
// 将输出行合并为一个字符串,便于解析
|
||||
String output = String.join("\n", result.getOutput());
|
||||
parseInfoOutput(output, info);
|
||||
} else {
|
||||
logger.warn("获取信息失败: {}", result.getErrorAsString());
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析svn info输出
|
||||
*
|
||||
* @param output 命令输出
|
||||
* @param info 信息对象
|
||||
*/
|
||||
private void parseInfoOutput(String output, SvnInfo info) {
|
||||
for (String line : output.split("\n")) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("Path: ")) {
|
||||
info.setPath(line.substring(6).trim());
|
||||
} else if (line.startsWith("URL: ")) {
|
||||
info.setUrl(line.substring(5).trim());
|
||||
} else if (line.startsWith("Repository Root: ")) {
|
||||
info.setRepositoryRoot(line.substring(17).trim());
|
||||
} else if (line.startsWith("Repository UUID: ")) {
|
||||
info.setRepositoryUuid(line.substring(18).trim());
|
||||
} else if (line.startsWith("Revision: ")) {
|
||||
info.setRevision(line.substring(11).trim());
|
||||
} else if (line.startsWith("Node Kind: ")) {
|
||||
info.setNodeKind(line.substring(11).trim());
|
||||
} else if (line.startsWith("Schedule: ")) {
|
||||
info.setSchedule(line.substring(11).trim());
|
||||
} else if (line.startsWith("Last Changed Author: ")) {
|
||||
info.setLastChangedAuthor(line.substring(22).trim());
|
||||
} else if (line.startsWith("Last Changed Rev: ")) {
|
||||
info.setLastChangedRev(line.substring(19).trim());
|
||||
} else if (line.startsWith("Last Changed Date: ")) {
|
||||
info.setLastChangedDate(line.substring(20).trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user