diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsCacheFileNodeFile.java similarity index 88% rename from designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java rename to designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsCacheFileNodeFile.java index 9ddc411d4..9933fc0e7 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsCacheFileNodeFile.java @@ -1,7 +1,6 @@ -package com.fr.design.mainframe.vcs.proxy; +package com.fr.design.mainframe.vcs.common; import com.fr.base.io.XMLEncryptUtils; -import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; @@ -30,7 +29,7 @@ public class VcsCacheFileNodeFile extends FileNodeFILE { * @throws Exception */ @Override - public InputStream asInputStream() throws Exception { + public InputStream asInputStream() { if (node == null) { return null; } @@ -56,13 +55,13 @@ public class VcsCacheFileNodeFile extends FileNodeFILE { * @throws Exception */ @Override - public OutputStream asOutputStream() throws Exception { + public OutputStream asOutputStream() { if (ComparatorUtils.equals(node, null)) { return null; } String envPath = node.getEnvPath(); - // envPath必须以reportlets开头 + // envPath必须以reportLets开头 if (!envPath.startsWith(VcsHelper.VCS_CACHE_DIR)) { return null; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java index 4e1809d6d..ee6135718 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java @@ -1,11 +1,13 @@ package com.fr.design.mainframe.vcs.common; import com.fr.base.BaseUtils; +import com.fr.design.DesignerEnvManager; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JTemplate; +import com.fr.report.entity.VcsEntity; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; @@ -13,14 +15,19 @@ import com.fr.workspace.WorkContext; import javax.swing.Icon; import javax.swing.border.EmptyBorder; import java.awt.Color; +import java.util.Date; import static com.fr.stable.StableUtils.pathJoin; - +/** + * Created by XiaXiang on 2019/4/17. + */ public class VcsHelper { - public final static String VCS_DIR = "vcs"; + private final static String VCS_DIR = "vcs"; public final static String VCS_CACHE_DIR = pathJoin(VCS_DIR, "cache"); + private static final int MINUTE = 60 * 1000; + public final static String CURRENT_USERNAME = WorkContext.getCurrent().isLocal() ? Toolkit.i18nText("Fine-Design_Vcs_Local_User") @@ -51,7 +58,7 @@ public class VcsHelper { if (fileTree.getSelectionPaths().length == 0) { return 0; } - //所有的num减去模板的num,得到文件夹的num + //所有的num减去模板的count,得到文件夹的count return fileTree.getSelectionPaths().length - fileTree.getSelectedTemplatePaths().length; } @@ -82,5 +89,12 @@ public class VcsHelper { return editingFilePath; } + public static boolean needSaveVersion(VcsEntity entity) { + if (entity == null) { + return true; + } + return new Date().getTime() - entity.getTime().getTime() > DesignerEnvManager.getEnvManager().getSaveInterval() * MINUTE || StringUtils.isNotBlank(entity.getCommitMsg()); + } + } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java index b8bf36356..ccb6fa93f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java @@ -6,9 +6,8 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.vcs.common.VcsHelper; -import com.fr.design.mainframe.vcs.proxy.VcsCacheFileNodeFile; +import com.fr.design.mainframe.vcs.common.VcsCacheFileNodeFile; import com.fr.file.filetree.FileNode; -import com.fr.log.FineLoggerFactory; import com.fr.report.entity.VcsEntity; import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; diff --git a/designer-realize/src/main/java/com/fr/start/Designer.java b/designer-realize/src/main/java/com/fr/start/Designer.java index 3f194ca2a..fc38b989d 100644 --- a/designer-realize/src/main/java/com/fr/start/Designer.java +++ b/designer-realize/src/main/java/com/fr/start/Designer.java @@ -32,7 +32,7 @@ import com.fr.design.mainframe.bbs.UserInfoLabel; import com.fr.design.mainframe.bbs.UserInfoPane; import com.fr.design.mainframe.template.info.TemplateInfoCollector; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; -import com.fr.design.mainframe.vcs.proxy.VcsCacheFileNodeFile; +import com.fr.design.mainframe.vcs.common.VcsCacheFileNodeFile; import com.fr.design.mainframe.vcs.ui.FileVersionTable; import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.MenuDef; @@ -295,14 +295,20 @@ public class Designer extends BaseDesigner { private void dealWithVcs(JTemplate jt) { String fileName = VcsHelper.getEditingFilename(); VcsEntity entity = WorkContext.getCurrent().get(VcsOperator.class).getLatestFileVersion(fileName); - int latestFileVersion = entity == null ? 0 : entity.getVersion(); - if (jt.getEditingFILE() instanceof VcsCacheFileNodeFile) { - WorkContext.getCurrent().get(VcsOperator.class).saveVersionFromCache(VcsHelper.CURRENT_USERNAME, fileName, StringUtils.EMPTY, latestFileVersion + 1); - String path = DesignerFrameFileDealerPane.getInstance().getSelectedOperation().getFilePath(); - FileVersionTable.getInstance().updateModel(1, WorkContext.getCurrent().get(VcsOperator.class).getVersions(path.replaceFirst("/", ""))); - } else { - WorkContext.getCurrent().get(VcsOperator.class).saveVersion(VcsHelper.CURRENT_USERNAME, fileName, StringUtils.EMPTY, latestFileVersion + 1); + int latestFileVersion = 0; + if (entity != null) { + latestFileVersion = entity.getVersion(); } + if (VcsHelper.needSaveVersion(entity)) { + if (jt.getEditingFILE() instanceof VcsCacheFileNodeFile) { + WorkContext.getCurrent().get(VcsOperator.class).saveVersionFromCache(VcsHelper.CURRENT_USERNAME, fileName, StringUtils.EMPTY, latestFileVersion + 1); + String path = DesignerFrameFileDealerPane.getInstance().getSelectedOperation().getFilePath(); + FileVersionTable.getInstance().updateModel(1, WorkContext.getCurrent().get(VcsOperator.class).getVersions(path.replaceFirst("/", ""))); + } else { + WorkContext.getCurrent().get(VcsOperator.class).saveVersion(VcsHelper.CURRENT_USERNAME, fileName, StringUtils.EMPTY, latestFileVersion + 1); + } + } + } private UIButton createUndoButton() {