优化自动打包工具
parent
64ed73b319
commit
c2f67e8c1f
|
@ -16,8 +16,8 @@ import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
public class BuilderPackageEcology extends Application {
|
public class BuilderPackageEcology extends Application {
|
||||||
|
|
||||||
|
@ -68,17 +68,33 @@ public class BuilderPackageEcology extends Application {
|
||||||
buttonBox.setSpacing(10);
|
buttonBox.setSpacing(10);
|
||||||
buttonBox.setPadding(new Insets(10));
|
buttonBox.setPadding(new Insets(10));
|
||||||
buttonBox.setAlignment(Pos.CENTER_RIGHT);
|
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 button = new Button("生成升级包");
|
||||||
button.setOnAction(event -> {
|
button.setOnAction(event -> {
|
||||||
|
// 输出包编号和功能名称的值
|
||||||
|
String packageNumber = packageNumberTextField.getText();
|
||||||
|
String functionName = functionNameTextField.getText();
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
String defaultName = FileTreeBuilder.zipDefaultName;
|
String defaultName = FileTreeBuilder.zipDefaultName;
|
||||||
if (StrUtil.isBlank(defaultName)) {
|
if (StrUtil.isBlank(defaultName)) {
|
||||||
defaultName = "sh_ebu_dev_1_ecology.zip";
|
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.setInitialFileName(defaultName);
|
||||||
// fileChooser.setInitialDirectory();
|
|
||||||
File outputFile = fileChooser.showSaveDialog(primaryStage);
|
File outputFile = fileChooser.showSaveDialog(primaryStage);
|
||||||
if (outputFile != null) {
|
if (outputFile != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -97,14 +113,11 @@ public class BuilderPackageEcology extends Application {
|
||||||
});
|
});
|
||||||
clearSelections();
|
clearSelections();
|
||||||
updateTreeView();
|
updateTreeView();
|
||||||
|
packageNumberTextField.setText("");
|
||||||
|
functionNameTextField.setText("");
|
||||||
showSuccessAlert("升级包制作成功!");
|
showSuccessAlert("升级包制作成功!");
|
||||||
System.out.println("压缩包位置: " + outputFile.getPath());
|
System.out.println("压缩包位置: " + outputFile.getPath());
|
||||||
|
|
||||||
// 输出包编号和功能名称的值
|
|
||||||
String packageNumber = packageNumberTextField.getText();
|
|
||||||
String functionName = functionNameTextField.getText();
|
|
||||||
System.out.println("包编号: " + packageNumber);
|
|
||||||
System.out.println("功能名称: " + functionName);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -154,6 +167,7 @@ public class BuilderPackageEcology extends Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filePaths.clear();
|
filePaths.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTreeView() {
|
private void updateTreeView() {
|
||||||
|
@ -217,6 +231,25 @@ public class BuilderPackageEcology extends Application {
|
||||||
alert.showAndWait();
|
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) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package builderpackage;
|
package builderpackage;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class FileTreeBuilder {
|
public class FileTreeBuilder {
|
||||||
|
@ -27,7 +27,11 @@ public class FileTreeBuilder {
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try (InputStream inputStream = FileTreeBuilder.class.getClassLoader().getResourceAsStream("application.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");
|
String value = properties.getProperty("packageBlackPaths");
|
||||||
if (StrUtil.isNotBlank(value)) {
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
|
Loading…
Reference in New Issue