diff --git a/designer-base/src/main/java/com/fr/design/RestartHelper.java b/designer-base/src/main/java/com/fr/design/RestartHelper.java index 8a6d02823f..cdb4fc532e 100644 --- a/designer-base/src/main/java/com/fr/design/RestartHelper.java +++ b/designer-base/src/main/java/com/fr/design/RestartHelper.java @@ -8,11 +8,10 @@ import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.stable.os.OperatingSystem; import com.fr.stable.os.support.OSBasedAction; -import com.fr.stable.os.support.OSSupportCenter; import com.fr.workspace.WorkContext; +import javax.swing.*; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -20,8 +19,6 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Properties; @@ -34,7 +31,7 @@ public class RestartHelper { public static final String RECORD_FILE = StableUtils.pathJoin(StableUtils.getInstallHome(), "delete.properties"); public static final String MOVE_FILE = StableUtils.pathJoin(StableUtils.getInstallHome(), "move.properties"); - private static OSBasedAction restartAction; + private static final OSBasedAction restartAction = new RestartAction(); /** * 把要删除的文件都记录到delete.properties中 @@ -147,58 +144,19 @@ public class RestartHelper { restart(ArrayUtils.EMPTY_STRING_ARRAY); } - public static void restartForUpdate(String installHome) { + public static void restartForUpdate(JFrame frame) { try { - if (OperatingSystem.isMacos()) { - restartInMacOS(installHome, ArrayUtils.EMPTY_STRING_ARRAY); - } else if (OperatingSystem.isLinux()){ - restartInLinux(installHome, ArrayUtils.EMPTY_STRING_ARRAY); - } else { - restartInWindows(installHome,ArrayUtils.EMPTY_STRING_ARRAY); - } + restartAction.execute(ArrayUtils.EMPTY_STRING_ARRAY); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage()); } finally { WorkContext.getCurrent().close(); + frame.dispose(); System.exit(0); } } - private static void restartInMacOS(String installHome, String[] filesToBeDelete) throws Exception { - ProcessBuilder builder = new ProcessBuilder(); - List commands = new ArrayList<>(); - commands.add("open"); - commands.add(installHome + File.separator + "bin" + File.separator + "restart.app"); - if (ArrayUtils.isNotEmpty(filesToBeDelete)) { - commands.add("--args"); - commands.add(StableUtils.join(filesToBeDelete, "+")); - } - builder.command(commands); - builder.start(); - } - private static void restartInWindows(String installHome, String[] filesToBeDelete) throws Exception { - ProcessBuilder builder = new ProcessBuilder(); - List commands = new ArrayList<>(); - commands.add(installHome + File.separator + "bin" + File.separator + "restart.exe"); - if (ArrayUtils.isNotEmpty(filesToBeDelete)) { - commands.add(StableUtils.join(filesToBeDelete, "+")); - } - builder.command(commands); - builder.start(); - } - - private static void restartInLinux(String installHome, String[] filesToBeDelete) throws Exception { - ProcessBuilder builder = new ProcessBuilder(); - List commands = new ArrayList<>(); - //现在先写的是restart.sh - commands.add(installHome + File.separator + "bin" + File.separator + "restart.sh"); - if (ArrayUtils.isNotEmpty(filesToBeDelete)) { - commands.add(StableUtils.join(filesToBeDelete, "+")); - } - builder.command(commands); - builder.start(); - } /** * 重启设计器并删除某些特定的文件 @@ -239,12 +197,4 @@ public class RestartHelper { DesignerContext.getDesignerFrame().exit(); } } - - /** - * 提前初始化重启动作 - */ - public static void initRestartAction(){ - restartAction = OSSupportCenter.getAction(RestartAction.class); - } - } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java b/designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java index b18254c113..47a7ae43bf 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java @@ -10,10 +10,19 @@ import java.util.ArrayList; import java.util.List; public class RestartAction implements OSBasedAction { + + private static String installHome; + + public RestartAction() { + installHome = StableUtils.getInstallHome(); + } + @Override public void execute(Object... objects) { String[] filesToBeDelete = (String[])objects; - String installHome = StableUtils.getInstallHome(); + if (installHome == null) { + installHome = StableUtils.getInstallHome(); + } try{ if (OperatingSystem.isMacos()) { restartInMacOS(installHome, filesToBeDelete); diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java index 8633c0616d..c736b6383b 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java @@ -30,7 +30,6 @@ import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.*; -import com.fr.stable.project.ProjectConstants; import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; import com.fr.third.org.apache.http.client.methods.HttpGet; import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; @@ -594,20 +593,21 @@ public class UpdateMainDialog extends UIDialog { updateButton.setEnabled(false); updateLabel.setVisible(false); RestoreResultDialog.deletePreviousPropertyFile(); - final String installHome = StableUtils.getInstallHome(); + final JFrame frame = DesignerContext.getDesignerFrame(); + final RestartHelper helper = new RestartHelper(); new FileProcess(callBack) { @Override public void onDownloadSuccess() { progressBar.setVisible(false); deleteForDesignerUpdate(); - RestartHelper.restartForUpdate(installHome); + helper.restartForUpdate(frame); } @Override public void onDownloadFailed() { progressBar.setVisible(false); deleteForDesignerUpdate(); JOptionPane.showMessageDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Failed_Message")); - RestartHelper.restartForUpdate(installHome); + helper.restartForUpdate(frame); } }.execute(); } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java index 051857c330..1727906fb0 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java @@ -11,7 +11,6 @@ import com.fr.config.MarketConfig; import com.fr.decision.update.backup.RecoverManager; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; -import com.fr.design.RestartHelper; import com.fr.design.actions.NewFormAction; import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.insert.cell.BiasCellAction; @@ -140,7 +139,6 @@ public class DesignerActivator extends Activator { storePassport(); AlphaFineHelper.switchConfig4Locale(); RecoverManager.register(new RecoverForDesigner()); - RestartHelper.initRestartAction(); } @Override