Merge remote-tracking branch 'origin/dev' into dev

dev
weilin.zhu 2023-07-07 18:33:31 +08:00
commit fbb7322d11
2 changed files with 57 additions and 18 deletions

View File

@ -16,8 +16,8 @@ import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
public class BuilderPackageEcology extends Application {
@ -68,17 +68,33 @@ public class BuilderPackageEcology extends Application {
buttonBox.setSpacing(10);
buttonBox.setPadding(new Insets(10));
buttonBox.setAlignment(Pos.CENTER_RIGHT);
Map<String, String> param = new HashMap<>(8);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
param.put("date", simpleDateFormat.format(date));
Button button = new Button("生成升级包");
button.setOnAction(event -> {
// 输出包编号和功能名称的值
String packageNumber = packageNumberTextField.getText();
String functionName = functionNameTextField.getText();
FileChooser fileChooser = new FileChooser();
String defaultName = FileTreeBuilder.zipDefaultName;
if (StrUtil.isBlank(defaultName)) {
defaultName = "sh_ebu_dev_1_ecology.zip";
}
param.put("name", functionName);
param.put("no", packageNumber);
defaultName = replacePlaceholders(defaultName, param);
replacePlaceholders(defaultName, param);
String defaultDir = FileTreeBuilder.defaultDir;
if (StrUtil.isNotBlank(defaultDir)) {
try {
fileChooser.setInitialDirectory(new File(defaultDir));
} catch (Exception ignore) {
System.out.println(defaultDir);
}
}
fileChooser.setInitialFileName(defaultName);
// fileChooser.setInitialDirectory();
File outputFile = fileChooser.showSaveDialog(primaryStage);
if (outputFile != null) {
try {
@ -97,14 +113,11 @@ public class BuilderPackageEcology extends Application {
});
clearSelections();
updateTreeView();
packageNumberTextField.setText("");
functionNameTextField.setText("");
showSuccessAlert("升级包制作成功!");
System.out.println("压缩包位置: " + outputFile.getPath());
// 输出包编号和功能名称的值
String packageNumber = packageNumberTextField.getText();
String functionName = functionNameTextField.getText();
System.out.println("包编号: " + packageNumber);
System.out.println("功能名称: " + functionName);
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -154,6 +167,7 @@ public class BuilderPackageEcology extends Application {
}
}
filePaths.clear();
}
private void updateTreeView() {
@ -217,6 +231,25 @@ public class BuilderPackageEcology extends Application {
alert.showAndWait();
}
public static String replacePlaceholders(String inputString, Map<String, String> placeholderMap) {
StringBuilder outputString = new StringBuilder(inputString);
for (Map.Entry<String, String> entry : placeholderMap.entrySet()) {
String placeholder = "${" + entry.getKey() + "}";
String value = entry.getValue();
// 检查占位符是否存在于字符串中
if (outputString.indexOf(placeholder) != -1) {
// 使用 String 类的 replace 方法进行占位符的替换
outputString.replace(outputString.indexOf(placeholder),
outputString.indexOf(placeholder) + placeholder.length(),
value);
}
}
return outputString.toString();
}
public static void main(String[] args) {
launch(args);
}

View File

@ -1,10 +1,10 @@
package builderpackage;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class FileTreeBuilder {
@ -27,7 +27,11 @@ public class FileTreeBuilder {
Properties properties = new Properties();
try (InputStream inputStream = FileTreeBuilder.class.getClassLoader().getResourceAsStream("application.properties")) {
properties.load(inputStream);
if (inputStream == null) {
throw new CustomerException("测试包的resources中不存在application.properties!");
}
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
properties.load(bf);
// 通过键获取属性值
String value = properties.getProperty("packageBlackPaths");
if (StrUtil.isNotBlank(value)) {
@ -65,6 +69,7 @@ public class FileTreeBuilder {
System.out.println("Invalid directory path: " + directoryPath);
return null;
}
System.out.println(blackList);
return buildFileTreeRecursively(root, blackList);
}
@ -92,7 +97,7 @@ public class FileTreeBuilder {
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
if (!isBlacklisted(file.getAbsolutePath(), blacklistPrefixes)) {
if (!isBlacklisted(file.getPath(), blacklistPrefixes)) {
FileInfo child = buildFileTreeRecursively(file, blacklistPrefixes);
fileInfo.addChild(child);
}
@ -121,10 +126,11 @@ public class FileTreeBuilder {
if (filePath.endsWith(".DS_Store") || filePath.endsWith(".DSStore")) {
return true;
}
System.out.println("黑名单过滤文件:" + filePath);
for (String prefix : blacklistPrefixes) {
String path = FileTreeBuilder.class.getResource("").getPath();
String prefixPath = path.substring(0, path.indexOf(File.separator + "target" + File.separator)) + File.separator;
if (filePath.startsWith(prefixPath + prefix)) {
// // String path = FileTreeBuilder.class.getResource("").getPath();
// String prefixPath = path.substring(0, path.indexOf(File.separator + "target" + File.separator)) + File.separator;
if (filePath.startsWith(prefix)) {
return true;
}
}