chore: initial project setup
This commit is contained in:
64
src/main/java/com/svnmanager/service/DiffService.java
Normal file
64
src/main/java/com/svnmanager/service/DiffService.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.svnmanager.service;
|
||||
|
||||
import com.svnmanager.util.ProcessUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Diff服务
|
||||
*/
|
||||
public class DiffService extends SvnService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DiffService.class);
|
||||
|
||||
/**
|
||||
* 获取差异
|
||||
*
|
||||
* @param workingDirectory 工作目录
|
||||
* @param filePath 文件路径(null表示所有文件)
|
||||
* @return 差异内容
|
||||
* @throws IOException IO异常
|
||||
* @throws InterruptedException 中断异常
|
||||
* @throws TimeoutException 超时异常
|
||||
*/
|
||||
public String getDiff(String workingDirectory, String filePath)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
logger.debug("获取差异: {}", workingDirectory);
|
||||
|
||||
if (!isValidWorkingCopy(workingDirectory)) {
|
||||
throw new IllegalArgumentException("无效的SVN工作副本: " + workingDirectory);
|
||||
}
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
if (filePath != null && !filePath.isEmpty()) {
|
||||
args.add(filePath);
|
||||
}
|
||||
|
||||
ProcessUtil.ProcessResult result = executeSvnCommand("diff", args, workingDirectory);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
return result.getOutputAsString();
|
||||
} else {
|
||||
logger.warn("获取差异失败: {}", result.getErrorAsString());
|
||||
return result.getErrorAsString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有文件的差异
|
||||
*
|
||||
* @param workingDirectory 工作目录
|
||||
* @return 差异内容
|
||||
* @throws IOException IO异常
|
||||
* @throws InterruptedException 中断异常
|
||||
* @throws TimeoutException 超时异常
|
||||
*/
|
||||
public String getDiff(String workingDirectory)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
return getDiff(workingDirectory, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user