From 4b6954313b514cd5936e1abcf7a28739a8ed6c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 14 Oct 2023 18:23:47 +0800 Subject: [PATCH 01/15] =?UTF-8?q?+=20=E6=8F=90=E7=A4=BA=E6=A1=86=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=AE=BD=E5=BA=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../light/component/AuthenticationPane.java | 19 ++- .../component/CustomProgressMonitor.java | 40 ++++++ .../com/light/component/DownloadHBox.java | 131 ++++++++++++++++++ .../com/light/component/DownloadPane.java | 20 +++ .../com/light/exception/CustomException.java | 24 ++++ src/main/java/com/light/layout/MenuPane.java | 6 + .../light/util/FxApplicationContextUtils.java | 7 +- src/main/java/com/light/util/H2PoolUtils.java | 5 +- src/main/java/com/light/util/JGitUtils.java | 41 ++---- src/main/java/com/light/view/HomeView.java | 28 ++-- 10 files changed, 264 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/light/component/CustomProgressMonitor.java create mode 100644 src/main/java/com/light/component/DownloadHBox.java create mode 100644 src/main/java/com/light/component/DownloadPane.java create mode 100644 src/main/java/com/light/exception/CustomException.java diff --git a/src/main/java/com/light/component/AuthenticationPane.java b/src/main/java/com/light/component/AuthenticationPane.java index 3117093..7a98ccf 100644 --- a/src/main/java/com/light/component/AuthenticationPane.java +++ b/src/main/java/com/light/component/AuthenticationPane.java @@ -1,9 +1,11 @@ package com.light.component; import com.light.enums.Level; +import com.light.exception.CustomException; import com.light.layout.ModalDialog; import com.light.model.GitAuthInfo; import com.light.thread.AsyncTask; +import com.light.util.FxApplicationContextUtils; import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; import com.light.util.NoticeUtils; @@ -47,15 +49,20 @@ public class AuthenticationPane extends ModalDialog { } GitAuthInfo authInfo = new GitAuthInfo(0, repoType, username, username, ""); // 入库 - int num = H2PoolUtils.insertAuthInfo(authInfo); + int num = 0; + try { + num = H2PoolUtils.insertAuthInfo(authInfo); + } catch (CustomException e) { + NoticeUtils.show(null, e.getMessage(), Level.WARN); + return; + } if (num > 0) { - AsyncTask.runOnce("克隆项目", () -> { - JGitUtils.AUTH_INFO_MAP.put(repoType, authInfo); - JGitUtils.cloneRepo(remoteUrl, file, authInfo); - }); + JGitUtils.AUTH_INFO_MAP.put(repoType, authInfo); + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + // 关闭界面 + close(); } }); - return root; } } diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java new file mode 100644 index 0000000..0c1758b --- /dev/null +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -0,0 +1,40 @@ +package com.light.component; + +import javafx.scene.control.ProgressBar; +import org.eclipse.jgit.lib.BatchingProgressMonitor; + +import java.time.Duration; +import java.util.concurrent.atomic.AtomicInteger; + +public class CustomProgressMonitor extends BatchingProgressMonitor { + + private final ProgressBar progressBar; + + private final AtomicInteger progress; + + public CustomProgressMonitor(ProgressBar progressBar) { + this.progressBar = progressBar; + progress = new AtomicInteger(0); + } + + @Override + protected void onUpdate(String taskName, int workCurr, Duration duration) { + + } + + @Override + protected void onEndTask(String taskName, int workCurr, Duration duration) { + + } + + @Override + protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { + System.out.println(percentDone); + progressBar.setProgress((double) progress.incrementAndGet() / 600); + } + + @Override + protected void onEndTask(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { +// progressBar.setProgress(1.0); + } +} diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownloadHBox.java new file mode 100644 index 0000000..c2ae5c8 --- /dev/null +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -0,0 +1,131 @@ +package com.light.component; + +import atlantafx.base.theme.Styles; +import com.light.model.GitAuthInfo; +import com.light.model.GitProject; +import com.light.thread.AsyncTask; +import com.light.util.DateUtils; +import com.light.util.FxApplicationContextUtils; +import com.light.util.H2PoolUtils; +import com.light.util.JGitUtils; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressBar; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; +import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; +import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; +import org.kordamp.ikonli.javafx.FontIcon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.sql.SQLOutput; +import java.util.Date; + +import static com.light.util.JGitUtils.getAuthor; +import static com.light.util.JGitUtils.getRepoName; + +public class DownloadHBox extends HBox { + public static final Logger LOGGER = LoggerFactory.getLogger(DownloadHBox.class); + + private final String remoteUrl; + private final File localRepoFile; + private final GitAuthInfo authInfo; + + private final Button retryButton; + + public DownloadHBox(String remoteUrl, File localRepoFile, GitAuthInfo authInfo) { + super(10); + setAlignment(Pos.CENTER); + + this.remoteUrl = remoteUrl; + this.localRepoFile = localRepoFile; + this.authInfo = authInfo; + + var label = new Label(getRepoName(remoteUrl)); + var progressBar = new ProgressBar(0.0); + progressBar.setMaxWidth(300); + var vbox = new VBox(10, label, progressBar); + + retryButton = new Button(null, new FontIcon(BootstrapIcons.PLAY)); + retryButton.getStyleClass().addAll(Styles.BUTTON_ICON, Styles.FLAT, Styles.ACCENT); + retryButton.setVisible(false); + getChildren().addAll(vbox, retryButton); + HBox.setHgrow(vbox, Priority.ALWAYS); + + retryButton.setOnMouseClicked(event -> { + cloneRepo(progressBar, true); + }); + + cloneRepo(progressBar, false); + } + + public void cloneRepo(ProgressBar progressBar, boolean retry) { + // 更新下载数量+1 + FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.incrementAndGet())); + + AsyncTask.runOnce("克隆项目", () -> { + try { + if (retry) { + deleteFiles(localRepoFile); + retryButton.setVisible(false); + } + // 开始下载 + String branch = JGitUtils.cloneRepo(remoteUrl, localRepoFile, authInfo, progressBar); + // 下载完成入库 + String name = getRepoName(remoteUrl); + String author = getAuthor(remoteUrl); + String local = localRepoFile.getAbsolutePath(); + GitProject newProject = new GitProject(new SimpleIntegerProperty(0), + new SimpleStringProperty(name), + new SimpleStringProperty(author), + new SimpleStringProperty(branch), + DateUtils.formatDateTime(new Date()), + new SimpleStringProperty(DateUtils.formatDateTime(new Date())), + remoteUrl, + new SimpleStringProperty(local), + new SimpleStringProperty(), + new SimpleStringProperty(), + new SimpleIntegerProperty(0), + new SimpleDoubleProperty(0.0), + new SimpleBooleanProperty(false) + ); + newProject.addSelectedListener(); + H2PoolUtils.insertProjectInfo(newProject); + FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); + } catch (Exception e) { + retryButton.setVisible(true); + LOGGER.error("项目 {} 克隆失败:{}", remoteUrl, e.getMessage()); + } + }); + // 更新下载数量-1 + FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); + } + + private void deleteFiles(File folder) { + if (folder.exists()) { + // 获取文件夹中的所有文件和子文件夹 + File[] files = folder.listFiles(); + + if (files != null) { + for (File file : files) { + // 如果是文件,则直接删除 + if (file.isFile()) { + file.delete(); + } + // 如果是文件夹,则递归调用deleteFiles方法删除文件夹下的文件 + else if (file.isDirectory()) { + deleteFiles(file); + } + } + } + } + } +} diff --git a/src/main/java/com/light/component/DownloadPane.java b/src/main/java/com/light/component/DownloadPane.java new file mode 100644 index 0000000..2d3b93f --- /dev/null +++ b/src/main/java/com/light/component/DownloadPane.java @@ -0,0 +1,20 @@ +package com.light.component; + +import com.light.layout.ModalDialog; +import com.light.util.FxApplicationContextUtils; +import javafx.scene.control.ListView; +import javafx.scene.layout.HBox; + +public class DownloadPane extends ModalDialog { + + public DownloadPane() { + super(); + header.setTitle("下载"); + content.setBody(createContent()); + content.setFooter(null); + } + + private HBox createContent() { + return new HBox(new ListView<>(FxApplicationContextUtils.DOWNLOAD_LIST)); + } +} diff --git a/src/main/java/com/light/exception/CustomException.java b/src/main/java/com/light/exception/CustomException.java new file mode 100644 index 0000000..4febef6 --- /dev/null +++ b/src/main/java/com/light/exception/CustomException.java @@ -0,0 +1,24 @@ +package com.light.exception; + +public class CustomException extends Exception{ + + public CustomException() { + super(); + } + + public CustomException(String message) { + super(message); + } + + public CustomException(String message, Throwable cause) { + super(message, cause); + } + + public CustomException(Throwable cause) { + super(cause); + } + + protected CustomException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 512fb33..f41dfae 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -1,6 +1,7 @@ package com.light.layout; import atlantafx.base.theme.Styles; +import com.light.component.DownloadPane; import com.light.theme.ThemeDialog; import com.light.util.FxApplicationContextUtils; import com.light.util.FxUtil; @@ -107,5 +108,10 @@ public class MenuPane extends StackPane { ThemeDialog themeDialog = (ThemeDialog) setting.getContent().get(); themeDialog.show(getScene()); }); + + downloadLabel.setOnMouseClicked(event -> { + DownloadPane downloadPane = new DownloadPane(); + downloadPane.show(getScene()); + }); } } diff --git a/src/main/java/com/light/util/FxApplicationContextUtils.java b/src/main/java/com/light/util/FxApplicationContextUtils.java index 7afdffa..771e7a4 100644 --- a/src/main/java/com/light/util/FxApplicationContextUtils.java +++ b/src/main/java/com/light/util/FxApplicationContextUtils.java @@ -1,10 +1,12 @@ package com.light.util; -import atlantafx.base.theme.*; +import atlantafx.base.theme.Theme; import com.light.model.GitProject; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; import java.util.ArrayList; import java.util.List; @@ -20,11 +22,14 @@ public final class FxApplicationContextUtils { */ public static final AtomicInteger DOWNLOAD_NUMBER = new AtomicInteger(0); public static final SimpleStringProperty DOWNLOAD_PROPERTY = new SimpleStringProperty(DOWNLOAD_NUMBER.toString()); + public static final ObservableList DOWNLOAD_LIST = FXCollections.observableArrayList(); + /** * 正在更新数量 */ public static final AtomicInteger UPDATE_NUMBER = new AtomicInteger(0); public static final SimpleStringProperty UPDATE_PROPERTY = new SimpleStringProperty(UPDATE_NUMBER.toString()); + public static final ObservableList UPDATE_LIST = FXCollections.observableArrayList(); /** * git项目集合 diff --git a/src/main/java/com/light/util/H2PoolUtils.java b/src/main/java/com/light/util/H2PoolUtils.java index 2ee4791..24f73cc 100644 --- a/src/main/java/com/light/util/H2PoolUtils.java +++ b/src/main/java/com/light/util/H2PoolUtils.java @@ -1,5 +1,6 @@ package com.light.util; +import com.light.exception.CustomException; import com.light.model.GitAuthInfo; import com.light.model.GitNotice; import com.light.model.GitProject; @@ -202,7 +203,7 @@ public class H2PoolUtils { return list; } - public static int insertAuthInfo(GitAuthInfo authInfo) { + public static int insertAuthInfo(GitAuthInfo authInfo) throws CustomException { try (Connection conn = getConnection()) { String sql = "INSERT INTO git_auth_info(type, username, password, createtime) values(?,?,?,?)"; PreparedStatement statement = conn.prepareStatement(sql); @@ -213,8 +214,8 @@ public class H2PoolUtils { return statement.executeUpdate(); } catch (SQLException e) { LOGGER.error("记录权限信息异常:{}", e.getMessage()); + throw new CustomException("记录权限信息异常"); } - return 0; } public static int updateAuthInfo(String type, String username, String password) { diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index 10fdc14..ddd553a 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -1,11 +1,13 @@ package com.light.util; +import com.light.component.CustomProgressMonitor; import com.light.model.GitAuthInfo; import com.light.model.GitProject; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; +import javafx.scene.control.ProgressBar; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.CredentialsProvider; @@ -84,7 +86,7 @@ public class JGitUtils { */ public static String getAuthor(String remoteUrl) { String author = remoteUrl.substring(0, remoteUrl.lastIndexOf("/")); - return author = author.substring(author.lastIndexOf("/") + 1); + return author.substring(author.lastIndexOf("/") + 1); } /** @@ -172,39 +174,12 @@ public class JGitUtils { PROJECT_FILE.clear(); } - public static void cloneRepo(String remoteUrl, File localRepoFile, GitAuthInfo authInfo) { - // 更新下载数量 - FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.incrementAndGet())); - - String name = getRepoName(remoteUrl); - String author = getAuthor(remoteUrl); - String local = localRepoFile.getAbsolutePath(); - - try (Git git = Git.cloneRepository() + public static String cloneRepo(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, ProgressBar progressBar) throws Exception { + Git git = Git.cloneRepository() .setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())) - .setURI(remoteUrl).setDirectory(localRepoFile).call()) { - String branch = git.getRepository().getBranch(); - GitProject newProject = new GitProject(new SimpleIntegerProperty(0), - new SimpleStringProperty(name), - new SimpleStringProperty(author), - new SimpleStringProperty(branch), - DateUtils.formatDateTime(new Date()), - new SimpleStringProperty(DateUtils.formatDateTime(new Date())), - remoteUrl, - new SimpleStringProperty(local), - new SimpleStringProperty(), - new SimpleStringProperty(), - new SimpleIntegerProperty(0), - new SimpleDoubleProperty(0.0), - new SimpleBooleanProperty(false) - ); - newProject.addSelectedListener(); - H2PoolUtils.insertProjectInfo(newProject); - FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); - } catch (Exception e) { - LOGGER.error("项目 {},作者 {} 克隆失败:{}", name, author, e.getMessage()); - } - FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); + .setURI(remoteUrl).setDirectory(localRepoFile).setProgressMonitor(new CustomProgressMonitor(progressBar)).call(); + + return git.getRepository().getBranch(); } /*private static void pull(String localDirPath, String remoteUrl) { diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index 8ac4400..732861a 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -2,9 +2,10 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; import com.light.component.AuthenticationPane; +import com.light.component.DownloadHBox; import com.light.enums.Level; import com.light.model.GitAuthInfo; -import com.light.thread.AsyncTask; +import com.light.util.FxApplicationContextUtils; import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; import javafx.beans.property.SimpleStringProperty; @@ -70,21 +71,18 @@ public class HomeView extends BorderPane { show(null, "项目已经存在", Level.WARN); return; } - // 项目保存地址不存在则创建 - boolean newFolder = file.exists(); - if (!newFolder) { - newFolder = file.mkdirs(); - } - if (newFolder) { - // 判断权限信息是否存在 - GitAuthInfo authInfo = JGitUtils.isExistsAuthInfo(remoteUrl); - if (authInfo != null) { - AsyncTask.runOnce("克隆项目", () -> JGitUtils.cloneRepo(remoteUrl, file, authInfo)); - } else { - AuthenticationPane authPane = new AuthenticationPane(JGitUtils.getType(remoteUrl), remoteUrl, file); - authPane.show(getScene()); - } + // 判断权限信息是否存在 + GitAuthInfo authInfo = JGitUtils.isExistsAuthInfo(remoteUrl); + if (authInfo != null) { + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + } else { + AuthenticationPane authPane = new AuthenticationPane(JGitUtils.getType(remoteUrl), remoteUrl, file); + authPane.show(getScene()); } + // 清空信息 + downloadPath.setText(""); + targetPath.setText(""); + downloadButton.setDisable(true); } } catch (Exception e) { show(null, "下载失败,请稍后重试", Level.DANGER); -- Gitee From 3b0c5c2211fb4eca1b2fc755a1275750a7486ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 14 Oct 2023 21:27:42 +0800 Subject: [PATCH 02/15] =?UTF-8?q?+=20=E6=9B=B4=E6=96=B0=E5=92=8C=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...wnloadPane.java => DownAndUpdatePane.java} | 16 ++++--- .../java/com/light/component/UpdateHBox.java | 6 +++ .../java/com/light/component/UpdatePane.java | 6 +++ src/main/java/com/light/layout/MenuPane.java | 9 ++-- src/main/resources/css/menu.css | 43 ------------------- src/main/resources/css/root.css | 43 +++++++++++++++++++ 6 files changed, 70 insertions(+), 53 deletions(-) rename src/main/java/com/light/component/{DownloadPane.java => DownAndUpdatePane.java} (31%) create mode 100644 src/main/java/com/light/component/UpdateHBox.java create mode 100644 src/main/java/com/light/component/UpdatePane.java diff --git a/src/main/java/com/light/component/DownloadPane.java b/src/main/java/com/light/component/DownAndUpdatePane.java similarity index 31% rename from src/main/java/com/light/component/DownloadPane.java rename to src/main/java/com/light/component/DownAndUpdatePane.java index 2d3b93f..d10a56c 100644 --- a/src/main/java/com/light/component/DownloadPane.java +++ b/src/main/java/com/light/component/DownAndUpdatePane.java @@ -1,20 +1,22 @@ package com.light.component; import com.light.layout.ModalDialog; -import com.light.util.FxApplicationContextUtils; +import javafx.collections.ObservableList; import javafx.scene.control.ListView; import javafx.scene.layout.HBox; -public class DownloadPane extends ModalDialog { +public class DownAndUpdatePane extends ModalDialog { - public DownloadPane() { + public DownAndUpdatePane(String title, ObservableList list) { super(); - header.setTitle("下载"); - content.setBody(createContent()); + header.setTitle(title); + content.setBody(createContent(list)); content.setFooter(null); } - private HBox createContent() { - return new HBox(new ListView<>(FxApplicationContextUtils.DOWNLOAD_LIST)); + private HBox createContent(ObservableList list) { + ListView listView = new ListView<>(list); + listView.getStyleClass().add("menu"); + return new HBox(listView); } } diff --git a/src/main/java/com/light/component/UpdateHBox.java b/src/main/java/com/light/component/UpdateHBox.java new file mode 100644 index 0000000..fd95f98 --- /dev/null +++ b/src/main/java/com/light/component/UpdateHBox.java @@ -0,0 +1,6 @@ +package com.light.component; + +import javafx.scene.layout.HBox; + +public class UpdateHBox extends HBox { +} diff --git a/src/main/java/com/light/component/UpdatePane.java b/src/main/java/com/light/component/UpdatePane.java new file mode 100644 index 0000000..447595e --- /dev/null +++ b/src/main/java/com/light/component/UpdatePane.java @@ -0,0 +1,6 @@ +package com.light.component; + +import com.light.layout.ModalDialog; + +public class UpdatePane extends ModalDialog { +} diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index f41dfae..b6f5a4c 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -1,7 +1,7 @@ package com.light.layout; import atlantafx.base.theme.Styles; -import com.light.component.DownloadPane; +import com.light.component.DownAndUpdatePane; import com.light.theme.ThemeDialog; import com.light.util.FxApplicationContextUtils; import com.light.util.FxUtil; @@ -108,10 +108,13 @@ public class MenuPane extends StackPane { ThemeDialog themeDialog = (ThemeDialog) setting.getContent().get(); themeDialog.show(getScene()); }); - + DownAndUpdatePane downloadPane = new DownAndUpdatePane("下载", FxApplicationContextUtils.DOWNLOAD_LIST); downloadLabel.setOnMouseClicked(event -> { - DownloadPane downloadPane = new DownloadPane(); downloadPane.show(getScene()); }); + DownAndUpdatePane updatePane = new DownAndUpdatePane("更新", FxApplicationContextUtils.UPDATE_LIST); + updateLabel.setOnMouseClicked(event -> { + updatePane.show(getScene()); + }); } } diff --git a/src/main/resources/css/menu.css b/src/main/resources/css/menu.css index fca6cca..1ec3e9b 100644 --- a/src/main/resources/css/menu.css +++ b/src/main/resources/css/menu.css @@ -53,49 +53,6 @@ -fx-icon-color: -cf-primary-color; } -/*动态导航栏*/ -.menu { - -fx-background-insets: 0px; - -fx-background-color: transparent; - -fx-padding: 0 0 5px 0; - -fx-border-width: 0; -} - -.menu .scroll-bar { - -fx-opacity: 0; -} - -.menu:hover .scroll-bar { - -fx-opacity: 1; -} - -.menu .cell.indexed-cell.list-cell { - -fx-background-color: transparent; - -fx-padding: 0px; -} - -.menu .cell.indexed-cell.list-cell:empty:hover { - -fx-background-color: transparent; -} - -.menu .cell.indexed-cell.list-cell:hover { -} - -.menu .cell.indexed-cell.list-cell:selected { -} - -.menu .cell.indexed-cell.list-cell:selected .nav-item { - -fx-background-color: rgba(0, 0, 0, 0.1); -} - -.menu .cell.indexed-cell.list-cell:selected .name-label { - -fx-text-fill: -cf-primary-color; -} - -.menu .cell.indexed-cell.list-cell:selected .icon-label > .ikonli-font-icon { - -fx-icon-color: -cf-primary-color; -} - /*正在下载,正在更新box*/ .down-update { -fx-alignment: center-left; diff --git a/src/main/resources/css/root.css b/src/main/resources/css/root.css index 1e94ac2..80608eb 100644 --- a/src/main/resources/css/root.css +++ b/src/main/resources/css/root.css @@ -51,4 +51,47 @@ .theme-thumbnail > .label { -fx-underline: true; +} + +/*动态菜单导航栏*/ +.menu { + -fx-background-insets: 0px; + -fx-background-color: transparent; + -fx-padding: 0 0 5px 0; + -fx-border-width: 0; +} + +.menu .scroll-bar { + -fx-opacity: 0; +} + +.menu:hover .scroll-bar { + -fx-opacity: 1; +} + +.menu .cell.indexed-cell.list-cell { + -fx-background-color: transparent; + -fx-padding: 0px; +} + +.menu .cell.indexed-cell.list-cell:empty:hover { + -fx-background-color: transparent; +} + +.menu .cell.indexed-cell.list-cell:hover { +} + +.menu .cell.indexed-cell.list-cell:selected { +} + +.menu .cell.indexed-cell.list-cell:selected .nav-item { + -fx-background-color: rgba(0, 0, 0, 0.1); +} + +.menu .cell.indexed-cell.list-cell:selected .name-label { + -fx-text-fill: -cf-primary-color; +} + +.menu .cell.indexed-cell.list-cell:selected .icon-label > .ikonli-font-icon { + -fx-icon-color: -cf-primary-color; } \ No newline at end of file -- Gitee From 57a8f21c73e3f8a0005f14d373cb171a63951547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Sat, 14 Oct 2023 23:04:48 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/layout/MenuPane.java | 48 ++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index b6f5a4c..3821c0e 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -11,9 +11,7 @@ import com.light.view.ManagerView; import com.light.view.NotificationView; import javafx.geometry.Orientation; import javafx.geometry.Pos; -import javafx.scene.control.Label; -import javafx.scene.control.ListView; -import javafx.scene.control.Separator; +import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; @@ -24,6 +22,8 @@ import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; public class MenuPane extends StackPane { @@ -108,6 +108,7 @@ public class MenuPane extends StackPane { ThemeDialog themeDialog = (ThemeDialog) setting.getContent().get(); themeDialog.show(getScene()); }); + DownAndUpdatePane downloadPane = new DownAndUpdatePane("下载", FxApplicationContextUtils.DOWNLOAD_LIST); downloadLabel.setOnMouseClicked(event -> { downloadPane.show(getScene()); @@ -116,5 +117,46 @@ public class MenuPane extends StackPane { updateLabel.setOnMouseClicked(event -> { updatePane.show(getScene()); }); + + /** + * 正在下载视图 + * 项目名 进度条 暂停按钮 取消按钮 + */ + downloadLabel.setOnMouseClicked(event -> { + //纵向布局 + VBox vBox = new VBox(10); + List hBoxList = new ArrayList<>(); + for(int i=1; i<=10; i++){ + //横向布局 + HBox hBox = new HBox(15); + hBox.setAlignment(Pos.CENTER); + hBox.getStyleClass().add("menu"); + + //项目名 + Label projectName = new Label("项目" + i); + projectName.setAlignment(Pos.CENTER_LEFT); + //进度条 + ProgressBar bar = new ProgressBar(0); + bar.setProgress(0.8); + + //暂停按钮 + Button stopBtn = new Button("暂停"); + stopBtn.setAlignment(Pos.CENTER_RIGHT); + stopBtn.setOnAction(ss -> { + if("暂停".equals(stopBtn.getText())){ + stopBtn.setText("开始"); + }else if("开始".equals(stopBtn.getText())){ + stopBtn.setText("暂停"); + } + }); + //取消按钮 + Button cannel = new Button("取消"); + cannel.setAlignment(Pos.CENTER_RIGHT); + hBox.getChildren().addAll(projectName,bar,stopBtn,cannel); + hBoxList.add(hBox); + } + vBox.getChildren().addAll(hBoxList); + contentPane.setContent(vBox); + }); } } -- Gitee From 7bc306b8de188ceadbe0f4b250c9c63ab794aa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 14 Oct 2023 23:21:08 +0800 Subject: [PATCH 04/15] =?UTF-8?q?+=20=E6=9C=89=E6=9B=B4=E6=96=B0=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E7=9A=84=E7=89=88=E6=9C=AC=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 2 +- .../light/component/AuthenticationPane.java | 17 ++++-- .../component/CustomProgressMonitor.java | 9 ++- ...wnloadHBox.java => DownAndUpdateHBox.java} | 60 ++++++++++++++++--- .../light/component/DownAndUpdatePane.java | 2 +- .../light/component/OperationTableCell.java | 17 ++++-- .../java/com/light/component/UpdateHBox.java | 6 -- .../java/com/light/component/UpdatePane.java | 6 -- src/main/java/com/light/layout/MenuPane.java | 4 +- src/main/java/com/light/util/H2PoolUtils.java | 1 + src/main/java/com/light/util/JGitUtils.java | 43 ++++--------- src/main/java/com/light/view/HomeView.java | 6 +- src/main/resources/css/menu.css | 43 +++++++++++++ src/main/resources/css/root.css | 34 +---------- 14 files changed, 147 insertions(+), 103 deletions(-) rename src/main/java/com/light/component/{DownloadHBox.java => DownAndUpdateHBox.java} (68%) delete mode 100644 src/main/java/com/light/component/UpdateHBox.java delete mode 100644 src/main/java/com/light/component/UpdatePane.java diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index b341d43..88b632c 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -37,7 +37,7 @@ public class GitManagerApp extends Application { super.init(); AsyncTask.runOnce("初始化数据库和主题数据", () -> { String gitDbInit = H2PoolUtils.queryDictByLabel("GIT_DB_INIT", "0"); - if ("0".equals(gitDbInit)) { + if ("1".equals(gitDbInit)) { H2PoolUtils.createTable(); H2PoolUtils.initGitProjectDictData(); } diff --git a/src/main/java/com/light/component/AuthenticationPane.java b/src/main/java/com/light/component/AuthenticationPane.java index 7a98ccf..4fc7c8b 100644 --- a/src/main/java/com/light/component/AuthenticationPane.java +++ b/src/main/java/com/light/component/AuthenticationPane.java @@ -4,11 +4,12 @@ import com.light.enums.Level; import com.light.exception.CustomException; import com.light.layout.ModalDialog; import com.light.model.GitAuthInfo; -import com.light.thread.AsyncTask; +import com.light.model.GitProject; import com.light.util.FxApplicationContextUtils; import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; import com.light.util.NoticeUtils; +import javafx.beans.property.SimpleDoubleProperty; import javafx.geometry.Insets; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; @@ -20,14 +21,14 @@ import java.io.File; public class AuthenticationPane extends ModalDialog { - public AuthenticationPane(String repoType, String remoteUrl, File file) { + public AuthenticationPane(boolean download, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { super(); header.setTitle(repoType); - content.setBody(createContent(repoType, remoteUrl, file)); + content.setBody(createContent(download, repoType, remoteUrl, file, rate, project, updateButton)); content.setFooter(null); } - private VBox createContent(String repoType, String remoteUrl, File file) { + private VBox createContent(boolean download, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { var usernameField = new TextField(); usernameField.setPromptText("手机/邮箱/用户名"); usernameField.setMaxWidth(300); @@ -47,7 +48,7 @@ public class AuthenticationPane extends ModalDialog { NoticeUtils.show(null, "用户名密码不能为空", Level.WARN); return; } - GitAuthInfo authInfo = new GitAuthInfo(0, repoType, username, username, ""); + GitAuthInfo authInfo = new GitAuthInfo(0, repoType, username, password, ""); // 入库 int num = 0; try { @@ -58,7 +59,11 @@ public class AuthenticationPane extends ModalDialog { } if (num > 0) { JGitUtils.AUTH_INFO_MAP.put(repoType, authInfo); - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + if (download) { + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownAndUpdateHBox(download, remoteUrl, file, authInfo, null, null, null)); + } else { + FxApplicationContextUtils.UPDATE_LIST.add(new DownAndUpdateHBox(download, remoteUrl, file, authInfo, rate, project, updateButton)); + } // 关闭界面 close(); } diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index 0c1758b..d5d9b45 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -1,5 +1,6 @@ package com.light.component; +import javafx.beans.property.SimpleDoubleProperty; import javafx.scene.control.ProgressBar; import org.eclipse.jgit.lib.BatchingProgressMonitor; @@ -12,8 +13,11 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { private final AtomicInteger progress; - public CustomProgressMonitor(ProgressBar progressBar) { + private final SimpleDoubleProperty rate; + + public CustomProgressMonitor(ProgressBar progressBar, SimpleDoubleProperty rate) { this.progressBar = progressBar; + this.rate = rate; progress = new AtomicInteger(0); } @@ -31,6 +35,9 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { System.out.println(percentDone); progressBar.setProgress((double) progress.incrementAndGet() / 600); + if (null != rate) { + rate.set((double) percentDone / 100); + } } @Override diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownAndUpdateHBox.java similarity index 68% rename from src/main/java/com/light/component/DownloadHBox.java rename to src/main/java/com/light/component/DownAndUpdateHBox.java index c2ae5c8..3fa6d65 100644 --- a/src/main/java/com/light/component/DownloadHBox.java +++ b/src/main/java/com/light/component/DownAndUpdateHBox.java @@ -19,21 +19,19 @@ import javafx.scene.control.ProgressBar; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; -import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.sql.SQLOutput; import java.util.Date; import static com.light.util.JGitUtils.getAuthor; import static com.light.util.JGitUtils.getRepoName; -public class DownloadHBox extends HBox { - public static final Logger LOGGER = LoggerFactory.getLogger(DownloadHBox.class); +public class DownAndUpdateHBox extends HBox { + public static final Logger LOGGER = LoggerFactory.getLogger(DownAndUpdateHBox.class); private final String remoteUrl; private final File localRepoFile; @@ -41,13 +39,22 @@ public class DownloadHBox extends HBox { private final Button retryButton; - public DownloadHBox(String remoteUrl, File localRepoFile, GitAuthInfo authInfo) { + private final SimpleDoubleProperty rate; + + private final GitProject gitProject; + + private final Button updateButton; + + public DownAndUpdateHBox(boolean download, String remoteUrl, File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate, GitProject project, Button updateButton) { super(10); setAlignment(Pos.CENTER); this.remoteUrl = remoteUrl; this.localRepoFile = localRepoFile; this.authInfo = authInfo; + this.rate = rate; + this.gitProject = project; + this.updateButton = updateButton; var label = new Label(getRepoName(remoteUrl)); var progressBar = new ProgressBar(0.0); @@ -61,10 +68,45 @@ public class DownloadHBox extends HBox { HBox.setHgrow(vbox, Priority.ALWAYS); retryButton.setOnMouseClicked(event -> { - cloneRepo(progressBar, true); + if (download) { + cloneRepo(progressBar, true); + } else { + updateRepo(progressBar, true); + } + }); + + if (download) { + cloneRepo(progressBar, false); + } else { + updateRepo(progressBar, false); + } + } + + public void updateRepo(ProgressBar progressBar, boolean retry) { + // 更新更新数量+1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); + + AsyncTask.runOnce("更新项目", () -> { + try { + if (retry) { + retryButton.setVisible(false); + } + // 开始更新 + boolean success = JGitUtils.pull(localRepoFile, authInfo, progressBar, rate); + // 更新完成更新数据库 + if (success) { + gitProject.updateTime().set(DateUtils.formatDateTime(new Date())); + H2PoolUtils.updateGitProject(gitProject); + } + } catch (Exception e) { + retryButton.setVisible(true); + LOGGER.error("项目 {} 更新失败:{}", remoteUrl, e.getMessage()); + } + updateButton.setDisable(false); }); - cloneRepo(progressBar, false); + // 更新更新数量-1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); } public void cloneRepo(ProgressBar progressBar, boolean retry) { @@ -100,13 +142,13 @@ public class DownloadHBox extends HBox { newProject.addSelectedListener(); H2PoolUtils.insertProjectInfo(newProject); FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); + // 更新下载数量-1 + FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); } catch (Exception e) { retryButton.setVisible(true); LOGGER.error("项目 {} 克隆失败:{}", remoteUrl, e.getMessage()); } }); - // 更新下载数量-1 - FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); } private void deleteFiles(File folder) { diff --git a/src/main/java/com/light/component/DownAndUpdatePane.java b/src/main/java/com/light/component/DownAndUpdatePane.java index d10a56c..54672bf 100644 --- a/src/main/java/com/light/component/DownAndUpdatePane.java +++ b/src/main/java/com/light/component/DownAndUpdatePane.java @@ -16,7 +16,7 @@ public class DownAndUpdatePane extends ModalDialog { private HBox createContent(ObservableList list) { ListView listView = new ListView<>(list); - listView.getStyleClass().add("menu"); + listView.getStyleClass().add("du-list"); return new HBox(listView); } } diff --git a/src/main/java/com/light/component/OperationTableCell.java b/src/main/java/com/light/component/OperationTableCell.java index 7b5e7fa..9815994 100644 --- a/src/main/java/com/light/component/OperationTableCell.java +++ b/src/main/java/com/light/component/OperationTableCell.java @@ -1,8 +1,10 @@ package com.light.component; import atlantafx.base.theme.Styles; +import com.light.model.GitAuthInfo; import com.light.model.GitProject; import com.light.util.FxApplicationContextUtils; +import com.light.util.JGitUtils; import javafx.beans.property.SimpleDoubleProperty; import javafx.geometry.Pos; import javafx.scene.control.Button; @@ -11,6 +13,8 @@ import javafx.scene.control.TableColumn; import javafx.scene.layout.HBox; import javafx.util.Callback; +import java.io.File; + /** * 操作列 - 按钮 */ @@ -51,11 +55,14 @@ public class OperationTableCell extends TableCell { private void initEvent() { // TODO Auto-generated method stub updateButton.setOnMouseClicked(event -> { - rate.set(0.0); - FxApplicationContextUtils.UPDATE_PROPERTY.set(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet() + ""); - for (int i = 0; i <= 100; i++) { - double dRate = (double) i / 100; - rate.set(dRate); + updateButton.setDisable(true); + GitProject project = getTableRow().getItem(); + GitAuthInfo existsAuthInfo = JGitUtils.isExistsAuthInfo(project.remote()); + if (existsAuthInfo == null) { + AuthenticationPane authPane = new AuthenticationPane(false, JGitUtils.getType(project.remote()), project.remote(), new File(project.local().get()), rate, project, updateButton); + authPane.show(getScene()); + } else { + FxApplicationContextUtils.UPDATE_LIST.add(new DownAndUpdateHBox(false, project.remote(), new File(project.local().get()), existsAuthInfo, rate, project, updateButton)); } }); } diff --git a/src/main/java/com/light/component/UpdateHBox.java b/src/main/java/com/light/component/UpdateHBox.java deleted file mode 100644 index fd95f98..0000000 --- a/src/main/java/com/light/component/UpdateHBox.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.light.component; - -import javafx.scene.layout.HBox; - -public class UpdateHBox extends HBox { -} diff --git a/src/main/java/com/light/component/UpdatePane.java b/src/main/java/com/light/component/UpdatePane.java deleted file mode 100644 index 447595e..0000000 --- a/src/main/java/com/light/component/UpdatePane.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.light.component; - -import com.light.layout.ModalDialog; - -public class UpdatePane extends ModalDialog { -} diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 3821c0e..9326e70 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -122,7 +122,7 @@ public class MenuPane extends StackPane { * 正在下载视图 * 项目名 进度条 暂停按钮 取消按钮 */ - downloadLabel.setOnMouseClicked(event -> { + /*downloadLabel.setOnMouseClicked(event -> { //纵向布局 VBox vBox = new VBox(10); List hBoxList = new ArrayList<>(); @@ -157,6 +157,6 @@ public class MenuPane extends StackPane { } vBox.getChildren().addAll(hBoxList); contentPane.setContent(vBox); - }); + });*/ } } diff --git a/src/main/java/com/light/util/H2PoolUtils.java b/src/main/java/com/light/util/H2PoolUtils.java index 24f73cc..ae20d7a 100644 --- a/src/main/java/com/light/util/H2PoolUtils.java +++ b/src/main/java/com/light/util/H2PoolUtils.java @@ -99,6 +99,7 @@ public class H2PoolUtils { stmt.executeUpdate("drop table git_project_info if exists"); stmt.executeUpdate("drop table git_project_dict if exists"); stmt.executeUpdate("drop table git_project_notice_history if exists"); + stmt.executeUpdate("drop table git_auth_info if exists"); // 初始化项目信息表 String createGitProjectInfoTable = """ create table git_project_info diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index ddd553a..cd5ec3f 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -9,14 +9,14 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.scene.control.ProgressBar; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.PullCommand; +import org.eclipse.jgit.api.PullResult; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.IOException; import java.util.*; public class JGitUtils { @@ -177,39 +177,18 @@ public class JGitUtils { public static String cloneRepo(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, ProgressBar progressBar) throws Exception { Git git = Git.cloneRepository() .setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())) - .setURI(remoteUrl).setDirectory(localRepoFile).setProgressMonitor(new CustomProgressMonitor(progressBar)).call(); + .setURI(remoteUrl).setDirectory(localRepoFile).setProgressMonitor(new CustomProgressMonitor(progressBar, null)).call(); return git.getRepository().getBranch(); } - /*private static void pull(String localDirPath, String remoteUrl) { - Git git = null; - try { - System.out.println("remoteUrl: " + remoteUrl + " --- localPath: " + localDirPath + " --- 开始拉取数据"); - File localPath = new File(localDirPath); - git = Git.open(localPath); - PullCommand pullCommand = git.pull(); - pullCommand.setTimeout(5); - pullCommand.setCredentialsProvider(usernamePasswordCredentialsProvider); - PullResult call = pullCommand.call(); - if (call.isSuccessful()) { - System.out.println("remoteUrl: " + remoteUrl + " --- localPath: " + localDirPath + " --- 拉取成功 --- 合并数据: " + call.getMergeResult()); - } - } catch (IOException e) { - githubMaxNum++; - System.out.println("IO pull : " + e.getMessage()); - } catch (GitAPIException e) { - githubMaxNum++; - System.out.println("Git pull : " + e.getMessage()); - } finally { - if (Objects.nonNull(git)) { - git.close(); - } - } - }*/ - - private static String getRemoteUrl(File localPath) throws IOException, GitAPIException { - Git git = Git.open(localPath); - return git.remoteList().call().get(0).getURIs().get(0).toString(); + public static boolean pull(File localRepoFile, GitAuthInfo authInfo, ProgressBar progressBar, SimpleDoubleProperty rate) throws Exception { + Git git = Git.open(localRepoFile); + PullCommand pullCommand = git.pull(); + pullCommand.setTimeout(10); + pullCommand.setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())); + pullCommand.setProgressMonitor(new CustomProgressMonitor(progressBar, rate)); + PullResult call = pullCommand.call(); + return call.isSuccessful(); } } diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index 732861a..e2af7ff 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -2,7 +2,7 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; import com.light.component.AuthenticationPane; -import com.light.component.DownloadHBox; +import com.light.component.DownAndUpdateHBox; import com.light.enums.Level; import com.light.model.GitAuthInfo; import com.light.util.FxApplicationContextUtils; @@ -74,9 +74,9 @@ public class HomeView extends BorderPane { // 判断权限信息是否存在 GitAuthInfo authInfo = JGitUtils.isExistsAuthInfo(remoteUrl); if (authInfo != null) { - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownAndUpdateHBox(true, remoteUrl, file, authInfo, null, null, null)); } else { - AuthenticationPane authPane = new AuthenticationPane(JGitUtils.getType(remoteUrl), remoteUrl, file); + AuthenticationPane authPane = new AuthenticationPane(true, JGitUtils.getType(remoteUrl), remoteUrl, file, null, null, null); authPane.show(getScene()); } // 清空信息 diff --git a/src/main/resources/css/menu.css b/src/main/resources/css/menu.css index 1ec3e9b..f2a1ba5 100644 --- a/src/main/resources/css/menu.css +++ b/src/main/resources/css/menu.css @@ -53,6 +53,49 @@ -fx-icon-color: -cf-primary-color; } +/*动态菜单导航栏*/ +.menu { + -fx-background-insets: 0px; + -fx-background-color: transparent; + -fx-padding: 0 0 5px 0; + -fx-border-width: 0; +} + +.menu .scroll-bar { + -fx-opacity: 0; +} + +.menu:hover .scroll-bar { + -fx-opacity: 1; +} + +.menu .cell.indexed-cell.list-cell { + -fx-background-color: transparent; + -fx-padding: 0px; +} + +.menu .cell.indexed-cell.list-cell:empty:hover { + -fx-background-color: transparent; +} + +.menu .cell.indexed-cell.list-cell:hover { +} + +.menu .cell.indexed-cell.list-cell:selected { +} + +.menu .cell.indexed-cell.list-cell:selected .nav-item { + -fx-background-color: rgba(0, 0, 0, 0.1); +} + +.menu .cell.indexed-cell.list-cell:selected .name-label { + -fx-text-fill: -cf-primary-color; +} + +.menu .cell.indexed-cell.list-cell:selected .icon-label > .ikonli-font-icon { + -fx-icon-color: -cf-primary-color; +} + /*正在下载,正在更新box*/ .down-update { -fx-alignment: center-left; diff --git a/src/main/resources/css/root.css b/src/main/resources/css/root.css index 80608eb..b2b9a79 100644 --- a/src/main/resources/css/root.css +++ b/src/main/resources/css/root.css @@ -53,45 +53,17 @@ -fx-underline: true; } -/*动态菜单导航栏*/ -.menu { +.du-list { -fx-background-insets: 0px; -fx-background-color: transparent; -fx-padding: 0 0 5px 0; -fx-border-width: 0; } -.menu .scroll-bar { +.du-list .scroll-bar { -fx-opacity: 0; } -.menu:hover .scroll-bar { +.du-list:hover .scroll-bar { -fx-opacity: 1; -} - -.menu .cell.indexed-cell.list-cell { - -fx-background-color: transparent; - -fx-padding: 0px; -} - -.menu .cell.indexed-cell.list-cell:empty:hover { - -fx-background-color: transparent; -} - -.menu .cell.indexed-cell.list-cell:hover { -} - -.menu .cell.indexed-cell.list-cell:selected { -} - -.menu .cell.indexed-cell.list-cell:selected .nav-item { - -fx-background-color: rgba(0, 0, 0, 0.1); -} - -.menu .cell.indexed-cell.list-cell:selected .name-label { - -fx-text-fill: -cf-primary-color; -} - -.menu .cell.indexed-cell.list-cell:selected .icon-label > .ikonli-font-icon { - -fx-icon-color: -cf-primary-color; } \ No newline at end of file -- Gitee From 54cebcaac9b7e3e17ab7aced625f33e41df9b903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 14 Oct 2023 23:41:53 +0800 Subject: [PATCH 05/15] =?UTF-8?q?+=20=E7=A7=BB=E9=99=A4=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=EF=BC=88=E5=9C=A8=E7=AE=A1=E7=90=86=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=B1=95=E7=A4=BA=EF=BC=8C=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=B1=95=E7=A4=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../light/component/AuthenticationPane.java | 9 +++-- .../component/CustomProgressMonitor.java | 4 ++- ...wnAndUpdateHBox.java => DownloadHBox.java} | 34 ++++--------------- .../light/component/OperationTableCell.java | 6 +++- src/main/java/com/light/layout/MenuPane.java | 4 +-- src/main/java/com/light/util/JGitUtils.java | 4 +-- src/main/java/com/light/view/HomeView.java | 4 +-- 7 files changed, 28 insertions(+), 37 deletions(-) rename src/main/java/com/light/component/{DownAndUpdateHBox.java => DownloadHBox.java} (86%) diff --git a/src/main/java/com/light/component/AuthenticationPane.java b/src/main/java/com/light/component/AuthenticationPane.java index 4fc7c8b..0705818 100644 --- a/src/main/java/com/light/component/AuthenticationPane.java +++ b/src/main/java/com/light/component/AuthenticationPane.java @@ -60,9 +60,14 @@ public class AuthenticationPane extends ModalDialog { if (num > 0) { JGitUtils.AUTH_INFO_MAP.put(repoType, authInfo); if (download) { - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownAndUpdateHBox(download, remoteUrl, file, authInfo, null, null, null)); + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); } else { - FxApplicationContextUtils.UPDATE_LIST.add(new DownAndUpdateHBox(download, remoteUrl, file, authInfo, rate, project, updateButton)); + // 更新 + try { + JGitUtils.pull(file, authInfo, rate); + } catch (Exception e) { + throw new RuntimeException(e); + } } // 关闭界面 close(); diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index d5d9b45..b9f2a21 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -34,7 +34,9 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { @Override protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { System.out.println(percentDone); - progressBar.setProgress((double) progress.incrementAndGet() / 600); + if (progressBar != null) { + progressBar.setProgress((double) progress.incrementAndGet() / 600); + } if (null != rate) { rate.set((double) percentDone / 100); } diff --git a/src/main/java/com/light/component/DownAndUpdateHBox.java b/src/main/java/com/light/component/DownloadHBox.java similarity index 86% rename from src/main/java/com/light/component/DownAndUpdateHBox.java rename to src/main/java/com/light/component/DownloadHBox.java index 3fa6d65..7bf4223 100644 --- a/src/main/java/com/light/component/DownAndUpdateHBox.java +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -30,8 +30,8 @@ import java.util.Date; import static com.light.util.JGitUtils.getAuthor; import static com.light.util.JGitUtils.getRepoName; -public class DownAndUpdateHBox extends HBox { - public static final Logger LOGGER = LoggerFactory.getLogger(DownAndUpdateHBox.class); +public class DownloadHBox extends HBox { + public static final Logger LOGGER = LoggerFactory.getLogger(DownloadHBox.class); private final String remoteUrl; private final File localRepoFile; @@ -39,22 +39,13 @@ public class DownAndUpdateHBox extends HBox { private final Button retryButton; - private final SimpleDoubleProperty rate; - - private final GitProject gitProject; - - private final Button updateButton; - - public DownAndUpdateHBox(boolean download, String remoteUrl, File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate, GitProject project, Button updateButton) { + public DownloadHBox(String remoteUrl, File localRepoFile, GitAuthInfo authInfo) { super(10); setAlignment(Pos.CENTER); this.remoteUrl = remoteUrl; this.localRepoFile = localRepoFile; this.authInfo = authInfo; - this.rate = rate; - this.gitProject = project; - this.updateButton = updateButton; var label = new Label(getRepoName(remoteUrl)); var progressBar = new ProgressBar(0.0); @@ -67,22 +58,11 @@ public class DownAndUpdateHBox extends HBox { getChildren().addAll(vbox, retryButton); HBox.setHgrow(vbox, Priority.ALWAYS); - retryButton.setOnMouseClicked(event -> { - if (download) { - cloneRepo(progressBar, true); - } else { - updateRepo(progressBar, true); - } - }); - - if (download) { - cloneRepo(progressBar, false); - } else { - updateRepo(progressBar, false); - } + retryButton.setOnMouseClicked(event -> cloneRepo(progressBar, true)); + cloneRepo(progressBar, false); } - public void updateRepo(ProgressBar progressBar, boolean retry) { + /*public void updateRepo(ProgressBar progressBar, boolean retry) { // 更新更新数量+1 FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); @@ -107,7 +87,7 @@ public class DownAndUpdateHBox extends HBox { // 更新更新数量-1 FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); - } + }*/ public void cloneRepo(ProgressBar progressBar, boolean retry) { // 更新下载数量+1 diff --git a/src/main/java/com/light/component/OperationTableCell.java b/src/main/java/com/light/component/OperationTableCell.java index 9815994..ec7beb9 100644 --- a/src/main/java/com/light/component/OperationTableCell.java +++ b/src/main/java/com/light/component/OperationTableCell.java @@ -62,7 +62,11 @@ public class OperationTableCell extends TableCell { AuthenticationPane authPane = new AuthenticationPane(false, JGitUtils.getType(project.remote()), project.remote(), new File(project.local().get()), rate, project, updateButton); authPane.show(getScene()); } else { - FxApplicationContextUtils.UPDATE_LIST.add(new DownAndUpdateHBox(false, project.remote(), new File(project.local().get()), existsAuthInfo, rate, project, updateButton)); + try { + JGitUtils.pull(new File(project.local().get()), existsAuthInfo, rate); + } catch (Exception e) { + throw new RuntimeException(e); + } } }); } diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 9326e70..c0b5adc 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -113,10 +113,10 @@ public class MenuPane extends StackPane { downloadLabel.setOnMouseClicked(event -> { downloadPane.show(getScene()); }); - DownAndUpdatePane updatePane = new DownAndUpdatePane("更新", FxApplicationContextUtils.UPDATE_LIST); + /*DownAndUpdatePane updatePane = new DownAndUpdatePane("更新", FxApplicationContextUtils.UPDATE_LIST); updateLabel.setOnMouseClicked(event -> { updatePane.show(getScene()); - }); + });*/ /** * 正在下载视图 diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index cd5ec3f..bf47f95 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -182,12 +182,12 @@ public class JGitUtils { return git.getRepository().getBranch(); } - public static boolean pull(File localRepoFile, GitAuthInfo authInfo, ProgressBar progressBar, SimpleDoubleProperty rate) throws Exception { + public static boolean pull(File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate) throws Exception { Git git = Git.open(localRepoFile); PullCommand pullCommand = git.pull(); pullCommand.setTimeout(10); pullCommand.setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())); - pullCommand.setProgressMonitor(new CustomProgressMonitor(progressBar, rate)); + pullCommand.setProgressMonitor(new CustomProgressMonitor(null, rate)); PullResult call = pullCommand.call(); return call.isSuccessful(); } diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index e2af7ff..1e3df79 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -2,7 +2,7 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; import com.light.component.AuthenticationPane; -import com.light.component.DownAndUpdateHBox; +import com.light.component.DownloadHBox; import com.light.enums.Level; import com.light.model.GitAuthInfo; import com.light.util.FxApplicationContextUtils; @@ -74,7 +74,7 @@ public class HomeView extends BorderPane { // 判断权限信息是否存在 GitAuthInfo authInfo = JGitUtils.isExistsAuthInfo(remoteUrl); if (authInfo != null) { - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownAndUpdateHBox(true, remoteUrl, file, authInfo, null, null, null)); + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); } else { AuthenticationPane authPane = new AuthenticationPane(true, JGitUtils.getType(remoteUrl), remoteUrl, file, null, null, null); authPane.show(getScene()); -- Gitee From b5096459035d11b06249c99eed727d3cf6fa5121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 00:20:36 +0800 Subject: [PATCH 06/15] =?UTF-8?q?+=20=E8=B0=83=E6=95=B4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=BF=9B=E5=BA=A6=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/component/CustomProgressMonitor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index b9f2a21..33ef467 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -35,7 +35,7 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { System.out.println(percentDone); if (progressBar != null) { - progressBar.setProgress((double) progress.incrementAndGet() / 600); + progressBar.setProgress((double) (progress.get() + percentDone) / 500); } if (null != rate) { rate.set((double) percentDone / 100); @@ -44,6 +44,6 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { @Override protected void onEndTask(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { -// progressBar.setProgress(1.0); + progress.addAndGet(percentDone); } } -- Gitee From d964ebf91f86599473c478894c13b01625ba614c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 00:40:47 +0800 Subject: [PATCH 07/15] =?UTF-8?q?+=20=E8=B0=83=E6=95=B4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=BF=9B=E5=BA=A6=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 5 +++- .../component/CustomProgressMonitor.java | 4 +++ .../com/light/component/DownloadHBox.java | 27 ------------------- src/main/java/com/light/view/ManagerView.java | 8 ------ 4 files changed, 8 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index 88b632c..c439612 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -37,7 +37,7 @@ public class GitManagerApp extends Application { super.init(); AsyncTask.runOnce("初始化数据库和主题数据", () -> { String gitDbInit = H2PoolUtils.queryDictByLabel("GIT_DB_INIT", "0"); - if ("1".equals(gitDbInit)) { + if ("0".equals(gitDbInit)) { H2PoolUtils.createTable(); H2PoolUtils.initGitProjectDictData(); } @@ -58,6 +58,9 @@ public class GitManagerApp extends Application { .ifPresentOrElse(theme -> Application.setUserAgentStylesheet(theme.getUserAgentStylesheet()), () -> Application.setUserAgentStylesheet(THEME_LIST.getFirst().getUserAgentStylesheet()) ); + + // 查询所有项目数据 + H2PoolUtils.queryGitProjects(); }); } diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index 33ef467..c1565eb 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -12,6 +12,7 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { private final ProgressBar progressBar; private final AtomicInteger progress; + private final AtomicInteger total; private final SimpleDoubleProperty rate; @@ -19,6 +20,7 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { this.progressBar = progressBar; this.rate = rate; progress = new AtomicInteger(0); + total = new AtomicInteger(100); } @Override @@ -45,5 +47,7 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { @Override protected void onEndTask(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { progress.addAndGet(percentDone); + total.addAndGet(percentDone); + System.out.println("taskName: " + taskName + " workCurr: " + workCurr + " workTotal: " + workTotal + " percentDone: " + percentDone); } } diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownloadHBox.java index 7bf4223..a78f324 100644 --- a/src/main/java/com/light/component/DownloadHBox.java +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -62,33 +62,6 @@ public class DownloadHBox extends HBox { cloneRepo(progressBar, false); } - /*public void updateRepo(ProgressBar progressBar, boolean retry) { - // 更新更新数量+1 - FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); - - AsyncTask.runOnce("更新项目", () -> { - try { - if (retry) { - retryButton.setVisible(false); - } - // 开始更新 - boolean success = JGitUtils.pull(localRepoFile, authInfo, progressBar, rate); - // 更新完成更新数据库 - if (success) { - gitProject.updateTime().set(DateUtils.formatDateTime(new Date())); - H2PoolUtils.updateGitProject(gitProject); - } - } catch (Exception e) { - retryButton.setVisible(true); - LOGGER.error("项目 {} 更新失败:{}", remoteUrl, e.getMessage()); - } - updateButton.setDisable(false); - }); - - // 更新更新数量-1 - FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); - }*/ - public void cloneRepo(ProgressBar progressBar, boolean retry) { // 更新下载数量+1 FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.incrementAndGet())); diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index b81404e..d811c44 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -9,7 +9,6 @@ import com.light.component.TooltipTableRow; import com.light.model.GitProject; import com.light.thread.AsyncTask; import com.light.util.FxApplicationContextUtils; -import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; import javafx.collections.FXCollections; import javafx.geometry.Insets; @@ -52,8 +51,6 @@ public class ManagerView extends StackPane { this.getChildren().add(vBox); initialize(); initEvent(); - // 异步初始化数据 - AsyncTask.runOnce("初始化项目数据", this::initData); } public void initialize() { @@ -127,11 +124,6 @@ public class ManagerView extends StackPane { tableView.setEditable(true); } - public void initData() { - // 查H2数据库获取数据 - H2PoolUtils.queryGitProjects(); - } - public void initEvent() { // 全选按钮事件 selectAll.setOnAction(event -> { -- Gitee From 7410a184aa8a7b21564587e6c7a50c69fd346b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 00:43:02 +0800 Subject: [PATCH 08/15] =?UTF-8?q?+=20=E8=B0=83=E6=95=B4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=BF=9B=E5=BA=A6=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/component/CustomProgressMonitor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index c1565eb..818aa5e 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -37,10 +37,10 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { System.out.println(percentDone); if (progressBar != null) { - progressBar.setProgress((double) (progress.get() + percentDone) / 500); + progressBar.setProgress((double) (progress.get() + percentDone) / total.get()); } if (null != rate) { - rate.set((double) percentDone / 100); + rate.set((double) (progress.get() + percentDone) / total.get()); } } -- Gitee From 7c1b214b42ee9c4ac35fe72ad214f8c2564fe00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 00:44:43 +0800 Subject: [PATCH 09/15] =?UTF-8?q?+=20=E9=87=8C=E7=A8=8B=E7=A2=91=E7=89=88?= =?UTF-8?q?=E6=9C=AC1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/light/component/CustomProgressMonitor.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a28c40d..f8e4177 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.light GitManagerClientFx - 1.0-SNAPSHOT + 1.0 21 diff --git a/src/main/java/com/light/component/CustomProgressMonitor.java b/src/main/java/com/light/component/CustomProgressMonitor.java index 818aa5e..e403099 100644 --- a/src/main/java/com/light/component/CustomProgressMonitor.java +++ b/src/main/java/com/light/component/CustomProgressMonitor.java @@ -35,7 +35,6 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { @Override protected void onUpdate(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { - System.out.println(percentDone); if (progressBar != null) { progressBar.setProgress((double) (progress.get() + percentDone) / total.get()); } @@ -48,6 +47,6 @@ public class CustomProgressMonitor extends BatchingProgressMonitor { protected void onEndTask(String taskName, int workCurr, int workTotal, int percentDone, Duration duration) { progress.addAndGet(percentDone); total.addAndGet(percentDone); - System.out.println("taskName: " + taskName + " workCurr: " + workCurr + " workTotal: " + workTotal + " percentDone: " + percentDone); +// System.out.println("taskName: " + taskName + " workCurr: " + workCurr + " workTotal: " + workTotal + " percentDone: " + percentDone); } } -- Gitee From 7b4ee33a25613eddbc39f0769fce34c9f91d5554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 02:22:25 +0800 Subject: [PATCH 10/15] =?UTF-8?q?+=20=E4=B8=8B=E8=BD=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 1 + .../light/component/AuthenticationPane.java | 42 +++++-- .../com/light/component/DownloadHBox.java | 116 +++++++++++------- .../light/component/OperationTableCell.java | 4 +- .../com/light/exception/AuthException.java | 23 ++++ .../java/com/light/exception/H2Exception.java | 23 ++++ .../com/light/exception/JGitException.java | 23 ++++ .../com/light/exception/TimeOutException.java | 23 ++++ .../light/util/FxApplicationContextUtils.java | 8 +- src/main/java/com/light/util/H2PoolUtils.java | 10 +- src/main/java/com/light/util/JGitUtils.java | 55 ++++++--- src/main/java/com/light/view/HomeView.java | 4 +- 12 files changed, 256 insertions(+), 76 deletions(-) create mode 100644 src/main/java/com/light/exception/AuthException.java create mode 100644 src/main/java/com/light/exception/H2Exception.java create mode 100644 src/main/java/com/light/exception/JGitException.java create mode 100644 src/main/java/com/light/exception/TimeOutException.java diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index c439612..6a75c62 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -95,6 +95,7 @@ public class GitManagerApp extends Application { stage.setScene(scene); stage.show(); scene.getStylesheets().add(STYLE_SHEET); + FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.put("scene", scene); LOGGER.info("项目启动完成,耗时 {} ms", System.currentTimeMillis() - startTime); } diff --git a/src/main/java/com/light/component/AuthenticationPane.java b/src/main/java/com/light/component/AuthenticationPane.java index 0705818..d7dd8ca 100644 --- a/src/main/java/com/light/component/AuthenticationPane.java +++ b/src/main/java/com/light/component/AuthenticationPane.java @@ -2,6 +2,7 @@ package com.light.component; import com.light.enums.Level; import com.light.exception.CustomException; +import com.light.exception.H2Exception; import com.light.layout.ModalDialog; import com.light.model.GitAuthInfo; import com.light.model.GitProject; @@ -21,14 +22,27 @@ import java.io.File; public class AuthenticationPane extends ModalDialog { - public AuthenticationPane(boolean download, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { + /** + * 没有权限 + * + * @param clone + * @param index + * @param remoteUrl + * @param file + */ + public AuthenticationPane(boolean clone, int index, String remoteUrl, File file) { + this(clone, index, remoteUrl, file, null, null, null); + } + + public AuthenticationPane(boolean clone, int index, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { super(); + String repoType = JGitUtils.getType(remoteUrl); header.setTitle(repoType); - content.setBody(createContent(download, repoType, remoteUrl, file, rate, project, updateButton)); + content.setBody(createContent(clone, index, repoType, remoteUrl, file, rate, project, updateButton)); content.setFooter(null); } - private VBox createContent(boolean download, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { + private VBox createContent(boolean clone, int index, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { var usernameField = new TextField(); usernameField.setPromptText("手机/邮箱/用户名"); usernameField.setMaxWidth(300); @@ -52,19 +66,31 @@ public class AuthenticationPane extends ModalDialog { // 入库 int num = 0; try { - num = H2PoolUtils.insertAuthInfo(authInfo); - } catch (CustomException e) { + if (-1 != index) { + // 克隆或者下载时权限异常会执行这段代码 + num = H2PoolUtils.updateAuthInfo(repoType, username, password); + } else { + num = H2PoolUtils.insertAuthInfo(authInfo); + } + } catch (H2Exception e) { NoticeUtils.show(null, e.getMessage(), Level.WARN); return; } if (num > 0) { JGitUtils.AUTH_INFO_MAP.put(repoType, authInfo); - if (download) { - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + if (clone) { + if (-1 != index) { + // 克隆项目时没有权限会执行这段代码 + DownloadHBox downloadHBox = (DownloadHBox) FxApplicationContextUtils.DOWNLOAD_LIST.get(index); + downloadHBox.cloneRepo(JGitUtils.createCredential(username, password), false); + } else { + // 第一次克隆 + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo, FxApplicationContextUtils.DOWNLOAD_LIST.size())); + } } else { // 更新 try { - JGitUtils.pull(file, authInfo, rate); + JGitUtils.pull(null, file, authInfo, rate); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownloadHBox.java index a78f324..cc4e21d 100644 --- a/src/main/java/com/light/component/DownloadHBox.java +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -1,6 +1,9 @@ package com.light.component; import atlantafx.base.theme.Styles; +import com.light.exception.AuthException; +import com.light.exception.JGitException; +import com.light.exception.TimeOutException; import com.light.model.GitAuthInfo; import com.light.model.GitProject; import com.light.thread.AsyncTask; @@ -8,21 +11,22 @@ import com.light.util.DateUtils; import com.light.util.FxApplicationContextUtils; import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; +import javafx.application.Platform; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.geometry.Pos; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; +import org.eclipse.jgit.transport.CredentialsProvider; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.util.Date; @@ -31,24 +35,33 @@ import static com.light.util.JGitUtils.getAuthor; import static com.light.util.JGitUtils.getRepoName; public class DownloadHBox extends HBox { - public static final Logger LOGGER = LoggerFactory.getLogger(DownloadHBox.class); - private final String remoteUrl; private final File localRepoFile; - private final GitAuthInfo authInfo; - private final Button retryButton; + private final ProgressBar progressBar = new ProgressBar(0.0); + private final CustomProgressMonitor customProgressMonitor = new CustomProgressMonitor(progressBar, null); + private final int index; + + private CredentialsProvider provider; - public DownloadHBox(String remoteUrl, File localRepoFile, GitAuthInfo authInfo) { + /** + * 构造方法 + * + * @param remoteUrl 远程仓库路径 + * @param localRepoFile 本地克隆地址 + * @param authInfo 权限 + * @param index 在下载列表中的位置 + */ + public DownloadHBox(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, int index) { super(10); setAlignment(Pos.CENTER); this.remoteUrl = remoteUrl; this.localRepoFile = localRepoFile; - this.authInfo = authInfo; + this.index = index; var label = new Label(getRepoName(remoteUrl)); - var progressBar = new ProgressBar(0.0); + progressBar.setMaxWidth(300); var vbox = new VBox(10, label, progressBar); @@ -58,49 +71,66 @@ public class DownloadHBox extends HBox { getChildren().addAll(vbox, retryButton); HBox.setHgrow(vbox, Priority.ALWAYS); - retryButton.setOnMouseClicked(event -> cloneRepo(progressBar, true)); - cloneRepo(progressBar, false); - } + // 监控器和权限 + provider = JGitUtils.createCredential(authInfo.username(), authInfo.password()); - public void cloneRepo(ProgressBar progressBar, boolean retry) { + retryButton.setOnMouseClicked(event -> cloneRepo(provider, true)); // 更新下载数量+1 FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.incrementAndGet())); + cloneRepo(provider, false); + } + /** + * 克隆项目 + * + * @param provider 权限 + * @param retry 重试标识 + */ + public void cloneRepo(CredentialsProvider provider, boolean retry) { + this.provider = provider; AsyncTask.runOnce("克隆项目", () -> { + if (retry) { + deleteFiles(localRepoFile); + retryButton.setVisible(false); + } + + String branch = ""; try { - if (retry) { - deleteFiles(localRepoFile); - retryButton.setVisible(false); - } // 开始下载 - String branch = JGitUtils.cloneRepo(remoteUrl, localRepoFile, authInfo, progressBar); - // 下载完成入库 - String name = getRepoName(remoteUrl); - String author = getAuthor(remoteUrl); - String local = localRepoFile.getAbsolutePath(); - GitProject newProject = new GitProject(new SimpleIntegerProperty(0), - new SimpleStringProperty(name), - new SimpleStringProperty(author), - new SimpleStringProperty(branch), - DateUtils.formatDateTime(new Date()), - new SimpleStringProperty(DateUtils.formatDateTime(new Date())), - remoteUrl, - new SimpleStringProperty(local), - new SimpleStringProperty(), - new SimpleStringProperty(), - new SimpleIntegerProperty(0), - new SimpleDoubleProperty(0.0), - new SimpleBooleanProperty(false) - ); - newProject.addSelectedListener(); - H2PoolUtils.insertProjectInfo(newProject); - FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); - // 更新下载数量-1 - FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); - } catch (Exception e) { + branch = JGitUtils.cloneRepo(remoteUrl, localRepoFile, provider, customProgressMonitor); + } catch (AuthException e) { + // 弹出输入权限界面 + AuthenticationPane authPane = new AuthenticationPane(true, index, remoteUrl, localRepoFile); + Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + return; + } catch (TimeOutException | JGitException e) { retryButton.setVisible(true); - LOGGER.error("项目 {} 克隆失败:{}", remoteUrl, e.getMessage()); + return; } + + // 下载完成入库 + String name = getRepoName(remoteUrl); + String author = getAuthor(remoteUrl); + String local = localRepoFile.getAbsolutePath(); + GitProject newProject = new GitProject(new SimpleIntegerProperty(0), + new SimpleStringProperty(name), + new SimpleStringProperty(author), + new SimpleStringProperty(branch), + DateUtils.formatDateTime(new Date()), + new SimpleStringProperty(DateUtils.formatDateTime(new Date())), + remoteUrl, + new SimpleStringProperty(local), + new SimpleStringProperty(), + new SimpleStringProperty(), + new SimpleIntegerProperty(0), + new SimpleDoubleProperty(0.0), + new SimpleBooleanProperty(false) + ); + newProject.addSelectedListener(); + H2PoolUtils.insertProjectInfo(newProject); + FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); + // 更新下载数量-1 + FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.decrementAndGet())); }); } diff --git a/src/main/java/com/light/component/OperationTableCell.java b/src/main/java/com/light/component/OperationTableCell.java index ec7beb9..6982d96 100644 --- a/src/main/java/com/light/component/OperationTableCell.java +++ b/src/main/java/com/light/component/OperationTableCell.java @@ -59,11 +59,11 @@ public class OperationTableCell extends TableCell { GitProject project = getTableRow().getItem(); GitAuthInfo existsAuthInfo = JGitUtils.isExistsAuthInfo(project.remote()); if (existsAuthInfo == null) { - AuthenticationPane authPane = new AuthenticationPane(false, JGitUtils.getType(project.remote()), project.remote(), new File(project.local().get()), rate, project, updateButton); + AuthenticationPane authPane = new AuthenticationPane(false,-1, project.remote(), new File(project.local().get()), rate, project, updateButton); authPane.show(getScene()); } else { try { - JGitUtils.pull(new File(project.local().get()), existsAuthInfo, rate); + JGitUtils.pull(null, new File(project.local().get()), existsAuthInfo, rate); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/light/exception/AuthException.java b/src/main/java/com/light/exception/AuthException.java new file mode 100644 index 0000000..f8365b1 --- /dev/null +++ b/src/main/java/com/light/exception/AuthException.java @@ -0,0 +1,23 @@ +package com.light.exception; + +public class AuthException extends RuntimeException{ + public AuthException() { + super(); + } + + public AuthException(String message) { + super(message); + } + + public AuthException(String message, Throwable cause) { + super(message, cause); + } + + public AuthException(Throwable cause) { + super(cause); + } + + protected AuthException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/light/exception/H2Exception.java b/src/main/java/com/light/exception/H2Exception.java new file mode 100644 index 0000000..72ab1ac --- /dev/null +++ b/src/main/java/com/light/exception/H2Exception.java @@ -0,0 +1,23 @@ +package com.light.exception; + +public class H2Exception extends RuntimeException { + public H2Exception() { + super(); + } + + public H2Exception(String message) { + super(message); + } + + public H2Exception(String message, Throwable cause) { + super(message, cause); + } + + public H2Exception(Throwable cause) { + super(cause); + } + + protected H2Exception(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/light/exception/JGitException.java b/src/main/java/com/light/exception/JGitException.java new file mode 100644 index 0000000..1a1d4e7 --- /dev/null +++ b/src/main/java/com/light/exception/JGitException.java @@ -0,0 +1,23 @@ +package com.light.exception; + +public class JGitException extends RuntimeException{ + public JGitException() { + super(); + } + + public JGitException(String message) { + super(message); + } + + public JGitException(String message, Throwable cause) { + super(message, cause); + } + + public JGitException(Throwable cause) { + super(cause); + } + + protected JGitException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/light/exception/TimeOutException.java b/src/main/java/com/light/exception/TimeOutException.java new file mode 100644 index 0000000..426c37b --- /dev/null +++ b/src/main/java/com/light/exception/TimeOutException.java @@ -0,0 +1,23 @@ +package com.light.exception; + +public class TimeOutException extends RuntimeException{ + public TimeOutException() { + super(); + } + + public TimeOutException(String message) { + super(message); + } + + public TimeOutException(String message, Throwable cause) { + super(message, cause); + } + + public TimeOutException(Throwable cause) { + super(cause); + } + + protected TimeOutException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/light/util/FxApplicationContextUtils.java b/src/main/java/com/light/util/FxApplicationContextUtils.java index 771e7a4..c525cac 100644 --- a/src/main/java/com/light/util/FxApplicationContextUtils.java +++ b/src/main/java/com/light/util/FxApplicationContextUtils.java @@ -6,10 +6,11 @@ import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; /** @@ -17,6 +18,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public final class FxApplicationContextUtils { + /** + * 全局容器 + */ + public static final Map GLOBAL_CONTEXT_MAP = new ConcurrentHashMap<>(); + /** * 正在下载数量 */ diff --git a/src/main/java/com/light/util/H2PoolUtils.java b/src/main/java/com/light/util/H2PoolUtils.java index ae20d7a..ef9fa43 100644 --- a/src/main/java/com/light/util/H2PoolUtils.java +++ b/src/main/java/com/light/util/H2PoolUtils.java @@ -1,6 +1,6 @@ package com.light.util; -import com.light.exception.CustomException; +import com.light.exception.H2Exception; import com.light.model.GitAuthInfo; import com.light.model.GitNotice; import com.light.model.GitProject; @@ -204,7 +204,7 @@ public class H2PoolUtils { return list; } - public static int insertAuthInfo(GitAuthInfo authInfo) throws CustomException { + public static int insertAuthInfo(GitAuthInfo authInfo) throws H2Exception { try (Connection conn = getConnection()) { String sql = "INSERT INTO git_auth_info(type, username, password, createtime) values(?,?,?,?)"; PreparedStatement statement = conn.prepareStatement(sql); @@ -215,11 +215,11 @@ public class H2PoolUtils { return statement.executeUpdate(); } catch (SQLException e) { LOGGER.error("记录权限信息异常:{}", e.getMessage()); - throw new CustomException("记录权限信息异常"); + throw new H2Exception("记录权限信息异常"); } } - public static int updateAuthInfo(String type, String username, String password) { + public static int updateAuthInfo(String type, String username, String password) throws H2Exception { try (Connection conn = getConnection()) { String sql = "update git_auth_info set username = ?, password = ? where type = ?"; PreparedStatement statement = conn.prepareStatement(sql); @@ -229,8 +229,8 @@ public class H2PoolUtils { return statement.executeUpdate(); } catch (SQLException e) { LOGGER.error("通过 {} 更新权限信息为 {} 失败:{}", type, username, e.getMessage()); + throw new H2Exception("更新权限信息异常"); } - return 0; } public static int deleteAuthInfo(String type) { diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index bf47f95..e750e52 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -1,13 +1,15 @@ package com.light.util; import com.light.component.CustomProgressMonitor; +import com.light.exception.AuthException; +import com.light.exception.JGitException; +import com.light.exception.TimeOutException; import com.light.model.GitAuthInfo; import com.light.model.GitProject; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; -import javafx.scene.control.ProgressBar; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.PullCommand; import org.eclipse.jgit.api.PullResult; @@ -174,21 +176,44 @@ public class JGitUtils { PROJECT_FILE.clear(); } - public static String cloneRepo(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, ProgressBar progressBar) throws Exception { - Git git = Git.cloneRepository() - .setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())) - .setURI(remoteUrl).setDirectory(localRepoFile).setProgressMonitor(new CustomProgressMonitor(progressBar, null)).call(); - - return git.getRepository().getBranch(); + public static String cloneRepo(String remoteUrl, File localRepoFile, CredentialsProvider provider, CustomProgressMonitor monitor) throws JGitException, AuthException, TimeOutException { + try (Git git = Git.cloneRepository() + .setCredentialsProvider(provider) + .setURI(remoteUrl).setDirectory(localRepoFile).setProgressMonitor(monitor).call()) { + return git.getRepository().getBranch(); + } catch (Exception e) { + String message = e.getMessage(); + LOGGER.error("项目 {} 克隆异常:{}", remoteUrl, message); + if (message.contains("authorized")) { + // 权限异常 + throw new AuthException(); + } else if (message.contains("time out") || message.contains("timeout")) { + // 超时异常 + throw new TimeOutException(); + } + throw new JGitException(); + } } - public static boolean pull(File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate) throws Exception { - Git git = Git.open(localRepoFile); - PullCommand pullCommand = git.pull(); - pullCommand.setTimeout(10); - pullCommand.setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())); - pullCommand.setProgressMonitor(new CustomProgressMonitor(null, rate)); - PullResult call = pullCommand.call(); - return call.isSuccessful(); + public static boolean pull(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate) throws JGitException, AuthException, TimeOutException { + try (Git git = Git.open(localRepoFile)) { + PullCommand pullCommand = git.pull(); + pullCommand.setTimeout(10); + pullCommand.setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())); + pullCommand.setProgressMonitor(new CustomProgressMonitor(null, rate)); + PullResult call = pullCommand.call(); + return call.isSuccessful(); + } catch (Exception e) { + String message = e.getMessage(); + LOGGER.error("项目 {} 更新异常:{}", remoteUrl, message); + if (message.contains("authorized")) { + // 权限异常 + throw new AuthException(); + } else if (message.contains("time out") || message.contains("timeout")) { + // 超时异常 + throw new TimeOutException(); + } + throw new JGitException(); + } } } diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index 1e3df79..168f9cb 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -74,9 +74,9 @@ public class HomeView extends BorderPane { // 判断权限信息是否存在 GitAuthInfo authInfo = JGitUtils.isExistsAuthInfo(remoteUrl); if (authInfo != null) { - FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo)); + FxApplicationContextUtils.DOWNLOAD_LIST.add(new DownloadHBox(remoteUrl, file, authInfo, FxApplicationContextUtils.DOWNLOAD_LIST.size())); } else { - AuthenticationPane authPane = new AuthenticationPane(true, JGitUtils.getType(remoteUrl), remoteUrl, file, null, null, null); + AuthenticationPane authPane = new AuthenticationPane(true, -1, remoteUrl, file); authPane.show(getScene()); } // 清空信息 -- Gitee From afa8397b9c91ca07967cf55ee7cfbb90efccfb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 04:35:37 +0800 Subject: [PATCH 11/15] =?UTF-8?q?+=20=E5=8F=B2=E8=AF=97=E7=BA=A7=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../light/component/AuthenticationPane.java | 50 +++++++++++++---- .../com/light/component/DownloadHBox.java | 8 +-- .../light/component/OperationTableCell.java | 51 ++++++++++++++---- src/main/java/com/light/model/GitProject.java | 9 ---- .../light/util/FxApplicationContextUtils.java | 4 +- src/main/java/com/light/util/H2PoolUtils.java | 16 ++++-- src/main/java/com/light/util/JGitUtils.java | 7 +-- src/main/java/com/light/view/HomeView.java | 53 ++++++++++++------- src/main/java/com/light/view/ManagerView.java | 6 +-- 9 files changed, 137 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/light/component/AuthenticationPane.java b/src/main/java/com/light/component/AuthenticationPane.java index d7dd8ca..b1372b0 100644 --- a/src/main/java/com/light/component/AuthenticationPane.java +++ b/src/main/java/com/light/component/AuthenticationPane.java @@ -1,24 +1,28 @@ package com.light.component; import com.light.enums.Level; -import com.light.exception.CustomException; +import com.light.exception.AuthException; import com.light.exception.H2Exception; +import com.light.exception.JGitException; +import com.light.exception.TimeOutException; import com.light.layout.ModalDialog; import com.light.model.GitAuthInfo; import com.light.model.GitProject; -import com.light.util.FxApplicationContextUtils; -import com.light.util.H2PoolUtils; -import com.light.util.JGitUtils; -import com.light.util.NoticeUtils; +import com.light.thread.AsyncTask; +import com.light.util.*; +import javafx.application.Platform; import javafx.beans.property.SimpleDoubleProperty; import javafx.geometry.Insets; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jgit.transport.CredentialsProvider; import java.io.File; +import java.util.Date; public class AuthenticationPane extends ModalDialog { @@ -26,7 +30,7 @@ public class AuthenticationPane extends ModalDialog { * 没有权限 * * @param clone - * @param index + * @param index 只有克隆时使用 * @param remoteUrl * @param file */ @@ -40,6 +44,7 @@ public class AuthenticationPane extends ModalDialog { header.setTitle(repoType); content.setBody(createContent(clone, index, repoType, remoteUrl, file, rate, project, updateButton)); content.setFooter(null); +// FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.put("authDialogShowing", true); } private VBox createContent(boolean clone, int index, String repoType, String remoteUrl, File file, SimpleDoubleProperty rate, GitProject project, Button updateButton) { @@ -66,7 +71,8 @@ public class AuthenticationPane extends ModalDialog { // 入库 int num = 0; try { - if (-1 != index) { + GitAuthInfo existsAuthInfo = H2PoolUtils.queryAuthInfo(repoType); + if (existsAuthInfo != null) { // 克隆或者下载时权限异常会执行这段代码 num = H2PoolUtils.updateAuthInfo(repoType, username, password); } else { @@ -89,14 +95,36 @@ public class AuthenticationPane extends ModalDialog { } } else { // 更新 - try { - JGitUtils.pull(null, file, authInfo, rate); - } catch (Exception e) { - throw new RuntimeException(e); + if (null != project) { + // 更新更新数量+1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); + AsyncTask.runOnce("更新项目", () -> { + try { + CredentialsProvider provider = JGitUtils.createCredential(username, password); + boolean pull = JGitUtils.pull(remoteUrl, file, provider, rate); + if (pull) { + project.updateTime().set(DateUtils.formatDateTime(new Date())); + H2PoolUtils.updateGitProject(project); + project.selected().set(false); + } + } catch (AuthException e) { + // 弹出输入权限界面 + if (!(Boolean) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("authDialogShowing")) { + AuthenticationPane authPane = new AuthenticationPane(false, -1, remoteUrl, file, rate, project, updateButton); + Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + } + } catch (TimeOutException | JGitException e) { + + } + // 更新更新数量-1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.decrementAndGet())); + updateButton.setDisable(false); + }); } } // 关闭界面 close(); + FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.put("authDialogShowing", false); } }); return root; diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownloadHBox.java index cc4e21d..3d047c5 100644 --- a/src/main/java/com/light/component/DownloadHBox.java +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -100,8 +100,11 @@ public class DownloadHBox extends HBox { branch = JGitUtils.cloneRepo(remoteUrl, localRepoFile, provider, customProgressMonitor); } catch (AuthException e) { // 弹出输入权限界面 - AuthenticationPane authPane = new AuthenticationPane(true, index, remoteUrl, localRepoFile); - Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + if (!(Boolean) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("authDialogShowing")) { + AuthenticationPane authPane = new AuthenticationPane(true, index, remoteUrl, localRepoFile); + Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + } + retryButton.setVisible(true); return; } catch (TimeOutException | JGitException e) { retryButton.setVisible(true); @@ -126,7 +129,6 @@ public class DownloadHBox extends HBox { new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(false) ); - newProject.addSelectedListener(); H2PoolUtils.insertProjectInfo(newProject); FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); // 更新下载数量-1 diff --git a/src/main/java/com/light/component/OperationTableCell.java b/src/main/java/com/light/component/OperationTableCell.java index 6982d96..a383e44 100644 --- a/src/main/java/com/light/component/OperationTableCell.java +++ b/src/main/java/com/light/component/OperationTableCell.java @@ -1,19 +1,29 @@ package com.light.component; import atlantafx.base.theme.Styles; +import com.light.exception.AuthException; +import com.light.exception.JGitException; +import com.light.exception.TimeOutException; import com.light.model.GitAuthInfo; import com.light.model.GitProject; +import com.light.thread.AsyncTask; +import com.light.util.DateUtils; import com.light.util.FxApplicationContextUtils; +import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; +import javafx.application.Platform; import javafx.beans.property.SimpleDoubleProperty; import javafx.geometry.Pos; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.layout.HBox; import javafx.util.Callback; +import org.eclipse.jgit.transport.CredentialsProvider; import java.io.File; +import java.util.Date; /** * 操作列 - 按钮 @@ -57,16 +67,37 @@ public class OperationTableCell extends TableCell { updateButton.setOnMouseClicked(event -> { updateButton.setDisable(true); GitProject project = getTableRow().getItem(); - GitAuthInfo existsAuthInfo = JGitUtils.isExistsAuthInfo(project.remote()); - if (existsAuthInfo == null) { - AuthenticationPane authPane = new AuthenticationPane(false,-1, project.remote(), new File(project.local().get()), rate, project, updateButton); - authPane.show(getScene()); - } else { - try { - JGitUtils.pull(null, new File(project.local().get()), existsAuthInfo, rate); - } catch (Exception e) { - throw new RuntimeException(e); - } + if (null != project) { + // 更新更新数量+1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); + AsyncTask.runOnce("更新项目", () -> { + File localRepoFile = new File(project.local().get()); + String remoteUrl = project.remote(); + try { + GitAuthInfo existsAuthInfo = JGitUtils.isExistsAuthInfo(project.remote()); + CredentialsProvider provider = null; + if (existsAuthInfo != null) { + provider = JGitUtils.createCredential(existsAuthInfo.username(), existsAuthInfo.password()); + } + boolean pull = JGitUtils.pull(remoteUrl, localRepoFile, provider, rate); + if (pull) { + project.updateTime().set(DateUtils.formatDateTime(new Date())); + H2PoolUtils.updateGitProject(project); + project.selected().set(false); + } + } catch (AuthException e) { + // 弹出输入权限界面 + if (!(Boolean) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("authDialogShowing")) { + AuthenticationPane authPane = new AuthenticationPane(false, -1, remoteUrl, localRepoFile, rate, project, updateButton); + Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + } + } catch (TimeOutException | JGitException e) { + + } + // 更新更新数量-1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.decrementAndGet())); + updateButton.setDisable(false); + }); } }); } diff --git a/src/main/java/com/light/model/GitProject.java b/src/main/java/com/light/model/GitProject.java index a5af28b..169a15d 100644 --- a/src/main/java/com/light/model/GitProject.java +++ b/src/main/java/com/light/model/GitProject.java @@ -19,13 +19,4 @@ public record GitProject(SimpleIntegerProperty id, SimpleIntegerProperty level, SimpleDoubleProperty downloadRate, SimpleBooleanProperty selected) { - - public void addSelectedListener() { - downloadRate.addListener((observable, oldValue, newValue) -> { - if (newValue != null && newValue.doubleValue() >= 1.0) { - selected.set(false); - FxApplicationContextUtils.UPDATE_PROPERTY.set(FxApplicationContextUtils.UPDATE_NUMBER.decrementAndGet() + ""); - } - }); - } } diff --git a/src/main/java/com/light/util/FxApplicationContextUtils.java b/src/main/java/com/light/util/FxApplicationContextUtils.java index c525cac..fa14f66 100644 --- a/src/main/java/com/light/util/FxApplicationContextUtils.java +++ b/src/main/java/com/light/util/FxApplicationContextUtils.java @@ -35,15 +35,13 @@ public final class FxApplicationContextUtils { */ public static final AtomicInteger UPDATE_NUMBER = new AtomicInteger(0); public static final SimpleStringProperty UPDATE_PROPERTY = new SimpleStringProperty(UPDATE_NUMBER.toString()); - public static final ObservableList UPDATE_LIST = FXCollections.observableArrayList(); - /** * git项目集合 */ public static final ObservableList GIT_PROJECT_OBSERVABLE_LIST = FXCollections.observableArrayList(); /** - * 当前主题民初 + * 当前主题名称 */ public static final SimpleStringProperty CURRENT_THEME_NAME = new SimpleStringProperty(); diff --git a/src/main/java/com/light/util/H2PoolUtils.java b/src/main/java/com/light/util/H2PoolUtils.java index ef9fa43..7f7485e 100644 --- a/src/main/java/com/light/util/H2PoolUtils.java +++ b/src/main/java/com/light/util/H2PoolUtils.java @@ -254,12 +254,19 @@ public class H2PoolUtils { Date currentDate = new Date(); Connection conn = getConnection(); Statement stmt = conn.createStatement(); + String dateTime = DateUtils.formatDateTime(currentDate); String sql = "insert into git_project_dict(label, label_value, description, createtime, updatetime) values('GIT_DB_INIT','1','项目数据库初始化标识:0 未初始化,1 初始化', " + - "'" + DateUtils.formatDateTime(currentDate) + "', '" + DateUtils.formatDateTime(currentDate) + "')"; + "'" + dateTime + "', '" + dateTime + "')"; stmt.addBatch(sql); String sql2 = "insert into git_project_dict(label, label_value, description, createtime, updatetime) values('GIT_CURRENT_THEME','Primer Light','项目当前主题', " + - "'" + DateUtils.formatDateTime(currentDate) + "', '" + DateUtils.formatDateTime(currentDate) + "')"; + "'" + dateTime + "', '" + dateTime + "')"; stmt.addBatch(sql2); + String sql3 = "insert into git_project_dict(label, label_value, description, createtime, updatetime) values('GIT_CURRENT_CLONE_DIR','D:','项目克隆路径', " + + "'" + dateTime + "', '" + dateTime + "')"; + stmt.addBatch(sql3); + String sql4 = "insert into git_project_dict(label, label_value, description, createtime, updatetime) values('GIT_CURRENT_LOCAL_DIR','D:','本地项目路径', " + + "'" + dateTime + "', '" + dateTime + "')"; + stmt.addBatch(sql4); stmt.executeBatch(); LOGGER.info("h2 字典表数据初始化成功"); } @@ -288,8 +295,8 @@ public class H2PoolUtils { statement.setString(1, value); statement.setString(2, label); statement.executeUpdate(); - } catch (SQLException ignored) { - LOGGER.error("通过 {} 更新数据为 {} 失败:{}", label, value, ignored.getMessage()); + } catch (SQLException e) { + LOGGER.error("通过 {} 更新数据为 {} 失败:{}", label, value, e.getMessage()); } LOGGER.info("通过 {} 更新数据为 {} 成功", label, value); } @@ -385,7 +392,6 @@ public class H2PoolUtils { new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(false) ); - gitProject.addSelectedListener(); FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(gitProject); } } catch (SQLException e) { diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index e750e52..945bfbd 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -163,7 +163,6 @@ public class JGitUtils { newProject = null; } else { // 不存在则继续新增,并设置id - newProject.addSelectedListener(); H2PoolUtils.insertProjectInfo(newProject); FxApplicationContextUtils.GIT_PROJECT_OBSERVABLE_LIST.add(newProject); } @@ -195,11 +194,13 @@ public class JGitUtils { } } - public static boolean pull(String remoteUrl, File localRepoFile, GitAuthInfo authInfo, SimpleDoubleProperty rate) throws JGitException, AuthException, TimeOutException { + public static boolean pull(String remoteUrl, File localRepoFile, CredentialsProvider provider, SimpleDoubleProperty rate) throws JGitException, AuthException, TimeOutException { try (Git git = Git.open(localRepoFile)) { PullCommand pullCommand = git.pull(); pullCommand.setTimeout(10); - pullCommand.setCredentialsProvider(createCredential(authInfo.username(), authInfo.password())); + if (provider != null) { + pullCommand.setCredentialsProvider(provider); + } pullCommand.setProgressMonitor(new CustomProgressMonitor(null, rate)); PullResult call = pullCommand.call(); return call.isSuccessful(); diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index 168f9cb..8e62089 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -22,14 +22,13 @@ import org.kordamp.ikonli.javafx.FontIcon; import java.io.File; import static com.light.util.NoticeUtils.show; -import static com.light.view.ManagerView.INIT_DIR; public class HomeView extends BorderPane { private final DirectoryChooser dirChooser = new DirectoryChooser(); private final SimpleStringProperty targetFolderPath = new SimpleStringProperty(); - private final TextField downloadPath = new TextField(); - private final CustomTextField targetPath = new CustomTextField(targetFolderPath.get()); + private final TextField clonePathField = new TextField(); + private final CustomTextField targetPathField = new CustomTextField(targetFolderPath.get()); private final FontIcon right = new FontIcon(AntDesignIconsOutlined.FOLDER); private final Button downloadButton = new Button("下载"); @@ -38,30 +37,31 @@ public class HomeView extends BorderPane { VBox downloadVBox = new VBox(10); downloadVBox.setAlignment(Pos.CENTER); // 下载框 - downloadPath.setPromptText("请输入远程项目地址"); - downloadPath.setMaxWidth(600); + clonePathField.setPromptText("请输入远程项目地址"); + clonePathField.setMaxWidth(600); // 目的地框 - targetPath.setPromptText("请输入本地仓库地址"); - targetPath.setRight(right); - targetPath.setMaxWidth(600); + targetPathField.setPromptText("请输入本地仓库地址"); + targetPathField.setRight(right); + targetPathField.setMaxWidth(600); // 下载按钮 downloadButton.setDisable(true); - downloadVBox.getChildren().addAll(downloadPath, targetPath, downloadButton); + downloadVBox.getChildren().addAll(clonePathField, targetPathField, downloadButton); this.setCenter(downloadVBox); initEvent(); + FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.put("authDialogShowing", false); } private void initEvent() { downloadButton.setOnAction(btn -> { try { - String remoteUrl = downloadPath.getText(); - String localRepoFile = targetPath.getText(); + String remoteUrl = clonePathField.getText(); + String localRepoFile = targetPathField.getText(); if (StringUtils.isAnyBlank(remoteUrl, localRepoFile)) { show(null, "请检查项目地址和仓库地址不能为空", Level.WARN); } else { // 检查仓库地址是不是为空 - File file = new File(targetPath.getText()); + File file = new File(targetPathField.getText()); if (file.isFile() || (file.isDirectory() && file.listFiles().length > 0)) { show(null, "仓库地址不为空", Level.WARN); return; @@ -80,8 +80,8 @@ public class HomeView extends BorderPane { authPane.show(getScene()); } // 清空信息 - downloadPath.setText(""); - targetPath.setText(""); + clonePathField.setText(""); + targetPathField.setText(""); downloadButton.setDisable(true); } } catch (Exception e) { @@ -90,27 +90,40 @@ public class HomeView extends BorderPane { }); right.setOnMouseClicked(event -> { - dirChooser.setInitialDirectory(new File(INIT_DIR + File.separator)); + dirChooser.setInitialDirectory(new File(H2PoolUtils.queryDictByLabel("GIT_CURRENT_CLONE_DIR", "D:") + File.separator)); File file = dirChooser.showDialog(getScene().getWindow()); if (null != file) { - targetPath.setText(file.getPath()); targetFolderPath.set(file.getPath()); + H2PoolUtils.updateDictData("GIT_CURRENT_CLONE_DIR", file.getPath()); + + String downloadPathText = clonePathField.getText(); + if (StringUtils.isNotBlank(downloadPathText)) { + if (downloadPathText.contains("/") && !downloadPathText.startsWith("/")) { + String downloadPathFolder = downloadPathText.substring(downloadPathText.lastIndexOf("/") + 1); + String actPath = downloadPathFolder.endsWith(".git") ? downloadPathFolder.substring(0, downloadPathFolder.lastIndexOf(".")) : downloadPathFolder; + targetPathField.setText(file.getPath() + File.separator + actPath); + } else { + targetPathField.setText(file.getPath()); + } + } else { + targetPathField.setText(file.getPath()); + } } event.consume(); }); - downloadPath.setOnKeyReleased(event -> { + clonePathField.setOnKeyReleased(event -> { String targetPathText = StringUtils.isBlank(targetFolderPath.get()) ? "" : targetFolderPath.get() + File.separator; - String downloadPathText = downloadPath.getText(); + String downloadPathText = clonePathField.getText(); if (downloadPathText.contains("/") && !downloadPathText.startsWith("/")) { String downloadPathFolder = downloadPathText.substring(downloadPathText.lastIndexOf("/") + 1); String actPath = downloadPathFolder.endsWith(".git") ? downloadPathFolder.substring(0, downloadPathFolder.lastIndexOf(".")) : downloadPathFolder; if (StringUtils.isNotBlank(targetPathText)) { - targetPath.setText(targetPathText + actPath); + targetPathField.setText(targetPathText + actPath); } downloadButton.setDisable(!downloadPathText.endsWith(".git")); } else { - targetPath.setText(targetPathText); + targetPathField.setText(targetPathText); downloadButton.setDisable(true); } }); diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index d811c44..c0e2d55 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -9,6 +9,7 @@ import com.light.component.TooltipTableRow; import com.light.model.GitProject; import com.light.thread.AsyncTask; import com.light.util.FxApplicationContextUtils; +import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; import javafx.collections.FXCollections; import javafx.geometry.Insets; @@ -36,7 +37,6 @@ public class ManagerView extends StackPane { private CustomTextField searchField; private final Button updateButton = new Button("更新"); private final Button addLocalButton = new Button("添加本地项目"); - public static final String INIT_DIR = "D:"; private final DirectoryChooser dirChooser = new DirectoryChooser(); private final HBox hBox = new HBox(5); @@ -133,13 +133,13 @@ public class ManagerView extends StackPane { event.consume(); }); - /** + /* * 添加本地项目按钮事件 * 输入框 让用户键入代码存放路径 * 按钮 加载 */ addLocalButton.setOnAction(btn -> { - dirChooser.setInitialDirectory(new File(INIT_DIR + File.separator)); + dirChooser.setInitialDirectory(new File(H2PoolUtils.queryDictByLabel("GIT_CURRENT_LOCAL_DIR", "D:") + File.separator)); File file = dirChooser.showDialog(getScene().getWindow()); if (null != file) { AsyncTask.runOnce("加载本地项目", () -> { -- Gitee From 9ddd102f11cb36028157cab8f143881d6f92187f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 04:39:40 +0800 Subject: [PATCH 12/15] =?UTF-8?q?+=20=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/util/JGitUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index 945bfbd..ed6f63b 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -183,7 +183,7 @@ public class JGitUtils { } catch (Exception e) { String message = e.getMessage(); LOGGER.error("项目 {} 克隆异常:{}", remoteUrl, message); - if (message.contains("authorized")) { + if (message.contains("authorized") || message.contains("Authentication")) { // 权限异常 throw new AuthException(); } else if (message.contains("time out") || message.contains("timeout")) { @@ -207,7 +207,7 @@ public class JGitUtils { } catch (Exception e) { String message = e.getMessage(); LOGGER.error("项目 {} 更新异常:{}", remoteUrl, message); - if (message.contains("authorized")) { + if (message.contains("authorized") || message.contains("Authentication")) { // 权限异常 throw new AuthException(); } else if (message.contains("time out") || message.contains("timeout")) { -- Gitee From 4fe31f6bfb0a8b1b1e87f7d74ebc0f2e72d82030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 04:48:27 +0800 Subject: [PATCH 13/15] =?UTF-8?q?+=20=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index c0e2d55..2ac8bc0 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -3,16 +3,25 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; +import com.light.component.AuthenticationPane; import com.light.component.LevelTableCell; import com.light.component.OperationTableCell; import com.light.component.TooltipTableRow; +import com.light.exception.AuthException; +import com.light.exception.JGitException; +import com.light.exception.TimeOutException; +import com.light.model.GitAuthInfo; import com.light.model.GitProject; import com.light.thread.AsyncTask; +import com.light.util.DateUtils; import com.light.util.FxApplicationContextUtils; import com.light.util.H2PoolUtils; import com.light.util.JGitUtils; +import javafx.application.Platform; +import javafx.beans.property.SimpleDoubleProperty; import javafx.collections.FXCollections; import javafx.geometry.Insets; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; @@ -25,10 +34,12 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jgit.transport.CredentialsProvider; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; import java.io.File; +import java.util.Date; import java.util.List; public class ManagerView extends StackPane { @@ -172,14 +183,40 @@ public class ManagerView extends StackPane { List list = tableView.getItems().stream().filter(param -> param.selected().get()).toList(); if (!list.isEmpty()) { updateButton.setDisable(true); - FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.addAndGet(list.size()))); } list.forEach(param -> { - param.downloadRate().set(0.0); - for (int i = 0; i <= 100; i++) { - double dRate = (double) i / 100; - param.downloadRate().set(dRate); - } + SimpleDoubleProperty rate = param.downloadRate(); + rate.set(0.0); + // 更新更新数量+1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.incrementAndGet())); + AsyncTask.runOnce("更新项目", () -> { + File localRepoFile = new File(param.local().get()); + String remoteUrl = param.remote(); + try { + GitAuthInfo existsAuthInfo = JGitUtils.isExistsAuthInfo(param.remote()); + CredentialsProvider provider = null; + if (existsAuthInfo != null) { + provider = JGitUtils.createCredential(existsAuthInfo.username(), existsAuthInfo.password()); + } + boolean pull = JGitUtils.pull(remoteUrl, localRepoFile, provider, rate); + if (pull) { + param.updateTime().set(DateUtils.formatDateTime(new Date())); + H2PoolUtils.updateGitProject(param); + param.selected().set(false); + } + } catch (AuthException e) { + // 弹出输入权限界面 + if (!(Boolean) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("authDialogShowing")) { + AuthenticationPane authPane = new AuthenticationPane(false, -1, remoteUrl, localRepoFile, rate, param, updateButton); + Platform.runLater(() -> authPane.show((Scene) FxApplicationContextUtils.GLOBAL_CONTEXT_MAP.get("scene"))); + } + } catch (TimeOutException | JGitException e) { + + } + // 更新更新数量-1 + FxApplicationContextUtils.UPDATE_PROPERTY.set(String.valueOf(FxApplicationContextUtils.UPDATE_NUMBER.decrementAndGet())); + updateButton.setDisable(false); + }); }); }); } -- Gitee From ef2a61e0565346ab42d48681d9b0228e48cc024d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 05:08:46 +0800 Subject: [PATCH 14/15] =?UTF-8?q?+=20=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/component/DownloadHBox.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/light/component/DownloadHBox.java b/src/main/java/com/light/component/DownloadHBox.java index 3d047c5..4d58311 100644 --- a/src/main/java/com/light/component/DownloadHBox.java +++ b/src/main/java/com/light/component/DownloadHBox.java @@ -68,13 +68,17 @@ public class DownloadHBox extends HBox { retryButton = new Button(null, new FontIcon(BootstrapIcons.PLAY)); retryButton.getStyleClass().addAll(Styles.BUTTON_ICON, Styles.FLAT, Styles.ACCENT); retryButton.setVisible(false); - getChildren().addAll(vbox, retryButton); + + Button removeButton = new Button(null, new FontIcon(BootstrapIcons.X)); + removeButton.getStyleClass().addAll(Styles.BUTTON_ICON, Styles.FLAT, Styles.ACCENT); + getChildren().addAll(vbox, retryButton, removeButton); HBox.setHgrow(vbox, Priority.ALWAYS); // 监控器和权限 provider = JGitUtils.createCredential(authInfo.username(), authInfo.password()); retryButton.setOnMouseClicked(event -> cloneRepo(provider, true)); + removeButton.setOnMouseClicked(event -> FxApplicationContextUtils.DOWNLOAD_LIST.remove(this)); // 更新下载数量+1 FxApplicationContextUtils.DOWNLOAD_PROPERTY.set(String.valueOf(FxApplicationContextUtils.DOWNLOAD_NUMBER.incrementAndGet())); cloneRepo(provider, false); -- Gitee From caae5efa567d36ba4c99daf3520690ab0ae245eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 15 Oct 2023 05:53:52 +0800 Subject: [PATCH 15/15] =?UTF-8?q?+=20=E9=80=9A=E7=9F=A5=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/light/component/NoticePane.java | 26 +++++++++++++++++++ src/main/java/com/light/layout/MenuPane.java | 22 +++++++++------- .../light/util/FxApplicationContextUtils.java | 1 + src/main/java/com/light/util/JGitUtils.java | 1 + .../java/com/light/view/NotificationView.java | 7 ++--- 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/light/component/NoticePane.java diff --git a/src/main/java/com/light/component/NoticePane.java b/src/main/java/com/light/component/NoticePane.java new file mode 100644 index 0000000..25bfa3a --- /dev/null +++ b/src/main/java/com/light/component/NoticePane.java @@ -0,0 +1,26 @@ +package com.light.component; + +import com.light.layout.ModalDialog; +import javafx.collections.ObservableList; +import javafx.scene.control.ListView; +import javafx.scene.layout.HBox; + +public class NoticePane extends ModalDialog { + + public NoticePane(String title, ObservableList list) { + super(); + header.setTitle(title); + content.setBody(createContent(list)); + content.setFooter(null); + } + + private HBox createContent(ObservableList list) { + ListView listView = new ListView<>(list); + listView.getStyleClass().add("du-list"); + listView.setMaxWidth(800); + listView.setMinWidth(550); + return new HBox(listView); + } + + +} diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index c0b5adc..0bd572f 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -2,6 +2,7 @@ package com.light.layout; import atlantafx.base.theme.Styles; import com.light.component.DownAndUpdatePane; +import com.light.component.NoticePane; import com.light.theme.ThemeDialog; import com.light.util.FxApplicationContextUtils; import com.light.util.FxUtil; @@ -9,9 +10,12 @@ import com.light.util.Lazy; import com.light.view.HomeView; import com.light.view.ManagerView; import com.light.view.NotificationView; +import javafx.collections.ListChangeListener; import javafx.geometry.Orientation; import javafx.geometry.Pos; -import javafx.scene.control.*; +import javafx.scene.control.Label; +import javafx.scene.control.ListView; +import javafx.scene.control.Separator; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; @@ -22,8 +26,6 @@ import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; public class MenuPane extends StackPane { @@ -40,10 +42,10 @@ public class MenuPane extends StackPane { // 底部导航栏 private final Label downloadLabel = new Label("正在下载", new FontIcon(BootstrapIcons.ARROW_DOWN)); - private final Text downloadLabelText = new Text(FxApplicationContextUtils.DOWNLOAD_PROPERTY.getValue().toString()); + private final Text downloadLabelText = new Text(FxApplicationContextUtils.DOWNLOAD_PROPERTY.getValue()); private final HBox downloadBox = new HBox(10, downloadLabel, downloadLabelText); private final Label updateLabel = new Label("正在更新", new FontIcon(BootstrapIcons.ARROW_DOWN)); - private final Text updateLabelText = new Text(FxApplicationContextUtils.UPDATE_PROPERTY.getValue().toString()); + private final Text updateLabelText = new Text(FxApplicationContextUtils.UPDATE_PROPERTY.getValue()); private final HBox updateBox = new HBox(10, updateLabel, updateLabelText); private final VBox bottomMenu = new VBox(downloadBox, updateBox); @@ -109,14 +111,16 @@ public class MenuPane extends StackPane { themeDialog.show(getScene()); }); + // 通知 + NoticePane noticePane = new NoticePane("消息", FxApplicationContextUtils.HISTORY_NOTICE_LIST); + notification.setOnMouseClicked(event -> { + noticePane.show(getScene()); + }); + DownAndUpdatePane downloadPane = new DownAndUpdatePane("下载", FxApplicationContextUtils.DOWNLOAD_LIST); downloadLabel.setOnMouseClicked(event -> { downloadPane.show(getScene()); }); - /*DownAndUpdatePane updatePane = new DownAndUpdatePane("更新", FxApplicationContextUtils.UPDATE_LIST); - updateLabel.setOnMouseClicked(event -> { - updatePane.show(getScene()); - });*/ /** * 正在下载视图 diff --git a/src/main/java/com/light/util/FxApplicationContextUtils.java b/src/main/java/com/light/util/FxApplicationContextUtils.java index fa14f66..0ff48b6 100644 --- a/src/main/java/com/light/util/FxApplicationContextUtils.java +++ b/src/main/java/com/light/util/FxApplicationContextUtils.java @@ -6,6 +6,7 @@ import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.layout.HBox; +import javafx.scene.text.Text; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/light/util/JGitUtils.java b/src/main/java/com/light/util/JGitUtils.java index ed6f63b..8bd8502 100644 --- a/src/main/java/com/light/util/JGitUtils.java +++ b/src/main/java/com/light/util/JGitUtils.java @@ -207,6 +207,7 @@ public class JGitUtils { } catch (Exception e) { String message = e.getMessage(); LOGGER.error("项目 {} 更新异常:{}", remoteUrl, message); + FxApplicationContextUtils.HISTORY_NOTICE_LIST.add(e.getMessage()); if (message.contains("authorized") || message.contains("Authentication")) { // 权限异常 throw new AuthException(); diff --git a/src/main/java/com/light/view/NotificationView.java b/src/main/java/com/light/view/NotificationView.java index a7870d4..af09622 100644 --- a/src/main/java/com/light/view/NotificationView.java +++ b/src/main/java/com/light/view/NotificationView.java @@ -1,13 +1,14 @@ package com.light.view; +import atlantafx.base.theme.Styles; import com.light.util.FxApplicationContextUtils; import javafx.collections.ListChangeListener; -import javafx.scene.control.Label; +import javafx.scene.text.Text; -public class NotificationView extends Label { +public class NotificationView extends Text { public NotificationView() { super(FxApplicationContextUtils.HISTORY_NOTICE_LIST.size() + ""); - this.getStyleClass().add("notice-label"); + getStyleClass().addAll(Styles.TEXT, Styles.WARNING); FxApplicationContextUtils.HISTORY_NOTICE_LIST.addListener((ListChangeListener) c -> setText(FxApplicationContextUtils.HISTORY_NOTICE_LIST.size() + "")); } } -- Gitee