- add username/password fields to project dialog and model - pass optional auth to SVN info/status/log/diff/update/commit services - centralize SVN CLI auth flags in SvnService and fix header text Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
3.3 KiB
Java
90 lines
3.3 KiB
Java
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, String username, String password)
|
|
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;
|
|
}
|
|
|
|
public SvnInfo getInfo(String workingDirectory)
|
|
throws IOException, InterruptedException, TimeoutException {
|
|
return getInfo(workingDirectory, null, null);
|
|
}
|
|
|
|
/**
|
|
* 解析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());
|
|
}
|
|
}
|
|
}
|
|
}
|