Browse Source

Merge pull request #808 in DESIGN/design from ~YAOH.WU/design:bugfix to release/10.0

* commit '643ad5230c1352f147f1f17d86b523a60b1a68ad':
  REPORT-15700 设计器端口启动问题
  REPORT-15862 设计器预览经登录跳转后400
bugfix/10.0
yaoh.wu 6 years ago
parent
commit
7c5656cfd7
  1. 203
      designer-base/src/main/java/com/fr/design/utils/DesignUtils.java
  2. 10
      designer-base/src/main/java/com/fr/design/utils/DesignerPort.java
  3. 57
      designer-realize/src/main/java/com/fr/start/Designer.java
  4. 108
      designer-realize/src/main/java/com/fr/start/module/PreStartActivator.java
  5. 21
      designer-realize/src/main/java/com/fr/start/module/StartFinishActivator.java

203
designer-base/src/main/java/com/fr/design/utils/DesignUtils.java

@ -1,6 +1,5 @@
package com.fr.design.utils; package com.fr.design.utils;
import com.fr.base.BaseUtils;
import com.fr.base.FeedBackInfo; import com.fr.base.FeedBackInfo;
import com.fr.base.ServerConfig; import com.fr.base.ServerConfig;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
@ -14,8 +13,7 @@ import com.fr.general.FRFont;
import com.fr.general.GeneralContext; import com.fr.general.GeneralContext;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.CodeUtils; import com.fr.stable.CommonCodeUtils;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.ServerStarter; import com.fr.start.ServerStarter;
@ -33,32 +31,33 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.URI; import java.net.URI;
import java.net.URLEncoder; import java.nio.charset.StandardCharsets;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* Some util method of Designer * Some util method of Designer
*/ */
public class DesignUtils { public class DesignUtils {
private static final int MESSAGEPORT = 51462; private static int port = DesignerPort.MESSAGE_PORT;
private static final int TIME_OUT = 20 * 1000;
public synchronized static void setPort(int port) { private DesignUtils() {
DesignUtils.port = port;
} }
private static int port = MESSAGEPORT;
private DesignUtils() {
public synchronized static void setPort(int port) {
DesignUtils.port = port;
} }
public static int getPort() {
return port;
}
/** /**
* 通过端口是否被占用判断设计器有没有启动 * 通过端口是否被占用判断设计器有没有启动
@ -70,8 +69,7 @@ public class DesignUtils {
try { try {
new Socket("localhost", port); new Socket("localhost", port);
return true; return true;
} catch (Exception exp) { } catch (Exception ignored) {
} }
return false; return false;
} }
@ -82,7 +80,7 @@ public class DesignUtils {
* @param lines 命令行 * @param lines 命令行
*/ */
public static void clientSend(String[] lines) { public static void clientSend(String[] lines) {
if (lines != null && lines.length <= 0) { if (lines == null || lines.length == 0) {
return; return;
} }
Socket socket = null; Socket socket = null;
@ -90,18 +88,21 @@ public class DesignUtils {
try { try {
socket = new Socket("localhost", port); socket = new Socket("localhost", port);
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), EncodeConstants.ENCODING_UTF_8))); writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)));
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
writer.println(lines[i]); writer.println(lines[i]);
} }
writer.flush(); writer.flush();
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally { } finally {
try { try {
writer.close(); if (writer != null) {
socket.close(); writer.close();
}
if (socket != null) {
socket.close();
}
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@ -114,47 +115,52 @@ public class DesignUtils {
* @param startPort 端口 * @param startPort 端口
* @param suffixs 文件后缀 * @param suffixs 文件后缀
*/ */
public static void creatListeningServer(final int startPort, final String[] suffixs) { public static void createListeningServer(final int startPort, final String[] suffixs) {
Thread serverSocketThread = new Thread() { ExecutorService service = Executors.newSingleThreadExecutor();
service.execute(new Runnable() {
@Override
public void run() { public void run() {
ServerSocket serverSocket = null; ServerSocket serverSocket = null;
try { try {
serverSocket = new ServerSocket(startPort); serverSocket = new ServerSocket(startPort);
} catch (IOException e1) { } catch (IOException e1) {
FineLoggerFactory.getLogger().error("Cannot create server socket on" + port); FineLoggerFactory.getLogger().error("Cannot create server socket on " + port);
} }
while (true) { while (true) {
try { try {
Socket socket = serverSocket.accept(); // 接收客户连接 if (serverSocket != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), EncodeConstants.ENCODING_UTF_8)); Socket socket = serverSocket.accept(); // 接收客户连接
String line = null; BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
while ((line = reader.readLine()) != null) { String line;
if (line.startsWith("demo")) { while ((line = reader.readLine()) != null) {
DesignerEnvManager.getEnvManager().setCurrentEnv2Default(); if (line.startsWith("demo")) {
ServerStarter.browserDemoURL(); DesignerEnvManager.getEnvManager().setCurrentEnv2Default();
} else if (StringUtils.isNotEmpty(line)) { ServerStarter.browserDemoURL();
File f = new File(line); } else if (StringUtils.isNotEmpty(line)) {
String path = f.getAbsolutePath(); File f = new File(line);
String path = f.getAbsolutePath();
boolean isMatch = false;
for (int i = 0; i < suffixs.length; i++) { boolean isMatch = false;
isMatch = isMatch || path.endsWith(suffixs[i]); for (int i = 0; i < suffixs.length; i++) {
} isMatch = isMatch || path.endsWith(suffixs[i]);
if (isMatch) { }
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f)); if (isMatch) {
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f));
}
} }
} }
reader.close();
socket.close();
} else {
FineLoggerFactory.getLogger().error("Cannot create server socket on " + port);
break;
} }
} catch (IOException ignored) {
reader.close();
socket.close();
} catch (IOException e) {
} }
} }
} }
}; });
serverSocketThread.start();
} }
/** /**
@ -278,19 +284,18 @@ public class DesignUtils {
*/ */
public static void visitEnvServerByParameters(String baseRoute, String[] names, String[] values) { public static void visitEnvServerByParameters(String baseRoute, String[] names, String[] values) {
int len = Math.min(ArrayUtils.getLength(names), ArrayUtils.getLength(values)); int len = Math.min(ArrayUtils.getLength(names), ArrayUtils.getLength(values));
String[] segs = new String[len]; String[] nameValuePairs = new String[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
try { //设计器里面据说为了改什么界面统一, 把分隔符统一用File.separator, 意味着在windows里面报表路径变成了\
//设计器里面据说为了改什么界面统一, 把分隔符统一用File.separator, 意味着在windows里面报表路径变成了\ //以前的超链, 以及预览url什么的都是/, 产品组的意思就是用到的地方替换下, 真恶心.
//以前的超链, 以及预览url什么的都是/, 产品组的意思就是用到的地方替换下, 真恶心. String value = values[i].replaceAll("\\\\", "/");
String value = values[i].replaceAll("\\\\", "/"); // 两次 encode 支持中文和特殊符号,避免跳转登录后预览400报错
segs[i] = URLEncoder.encode(CodeUtils.cjkEncode(names[i]), EncodeConstants.ENCODING_UTF_8) + "=" + URLEncoder.encode(CodeUtils.cjkEncode(value), "UTF-8"); nameValuePairs[i] =
} catch (UnsupportedEncodingException e) { CommonCodeUtils.encodeURIComponent(CommonCodeUtils.encodeURIComponent(names[i])) +
FineLoggerFactory.getLogger().error(e.getMessage(), e); "=" + CommonCodeUtils.encodeURIComponent(CommonCodeUtils.encodeURIComponent(value));
}
} }
String postfixOfUri = (segs.length > 0 ? "?" + StableUtils.join(segs, "&") : StringUtils.EMPTY); String postfixOfUri = (nameValuePairs.length > 0 ? "?" + StableUtils.join(nameValuePairs, "&") : StringUtils.EMPTY);
if (!WorkContext.getCurrent().isLocal()) { if (!WorkContext.getCurrent().isLocal()) {
try { try {
String urlPath = getWebBrowserPath(); String urlPath = getWebBrowserPath();
@ -305,8 +310,7 @@ public class DesignUtils {
+ "/" + web + "/" + ServerConfig.getInstance().getServletName() + baseRoute + "/" + web + "/" + ServerConfig.getInstance().getServletName() + baseRoute
+ postfixOfUri; + postfixOfUri;
ServerStarter.browserURLWithLocalEnv(url); ServerStarter.browserURLWithLocalEnv(url);
} catch (Throwable e) { } catch (Throwable ignored) {
//
} }
} }
} }
@ -321,87 +325,6 @@ public class DesignUtils {
return urlPath; return urlPath;
} }
//TODO:august:下个版本,要把下面的图片都放在一个preload文件夹下,表示可以预先加载。然后遍历一下就可以了,不用这么一个一个的写了
/**
* 预加载
*/
public static void preLoadingImages() {
BaseUtils.readIcon("com/fr/design/images/custombtn/baobiaozhuti.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/baobiaozhuti_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/baobiaozhuti_click.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/canshujiemian.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/canshujiemian_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/canshujiemian_click.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/setting.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/setting_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/setting_click.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/page.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/page_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/page_click.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/form.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/form_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/form_click.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/edit.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/edit_hover.png");
BaseUtils.readIcon("com/fr/design/images/custombtn/edit_click.png");
BaseUtils.readIcon("com/fr/base/images/oem/addworksheet.png");
BaseUtils.readIcon("com/fr/design/images/sheet/addpolysheet.png");
BaseUtils.readIcon("com/fr/base/images/oem/worksheet.png");
BaseUtils.readIcon("com/fr/design/images/sheet/polysheet.png");
BaseUtils.readIcon("com/fr/design/images/sheet/left_right_btn.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/cellPop.png");
BaseUtils.readIcon("/com/fr/design/images/docking/right.gif");
BaseUtils.readIcon("/com/fr/design/images/docking/left.gif");
BaseUtils.readIcon("/com/fr/design/images/m_file/save.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/excel.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/pdf.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/word.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/svg.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/csv.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/text.png");
BaseUtils.readIcon("/com/fr/design/images/m_web/datasource.png");
BaseUtils.readIcon("/com/fr/design/images/m_report/webreportattribute.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/pageSetup.png");
BaseUtils.readIcon("/com/fr/design/images/m_report/header.png");
BaseUtils.readIcon("/com/fr/design/images/m_report/footer.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/saveAs.png");
BaseUtils.readIcon("/com/fr/design/images/m_report/background.png");
loadOtherImages();
}
private static void loadOtherImages() {
BaseUtils.readIcon("/com/fr/design/images/m_report/reportWriteAttr.png");
BaseUtils.readIcon("/com/fr/design/images/m_report/linearAttr.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/bindColumn.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/text.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/chart.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/image.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/bias.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/subReport.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/insertRow.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/insertColumn.png");
BaseUtils.readIcon("/com/fr/design/images/m_format/highlight.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/hyperLink.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/merge.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/unmerge.png");
BaseUtils.readIcon("/com/fr/design/images/m_file/export.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/cell.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/float.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/undo.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/redo.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/cut.png");
BaseUtils.readIcon("/com/fr/design/images/m_edit/paste.png");
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/leftAlignment.png");
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/centerAlignment.png");
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/rightAlignment.png");
BaseUtils.readIcon("/com/fr/design/images/m_format/noboder.png");
BaseUtils.readIcon("/com/fr/design/images/gui/color/background.png");
BaseUtils.readIcon("/com/fr/design/images/m_insert/floatPop.png");
}
/** /**
* 将用户反馈发送至服务器 * 将用户反馈发送至服务器
* *

10
designer-base/src/main/java/com/fr/design/utils/DesignerPort.java

@ -0,0 +1,10 @@
package com.fr.design.utils;
public class DesignerPort {
private DesignerPort() {
}
public static final int MESSAGE_PORT = 51462;
public static final int DEBUG_MESSAGE_PORT = 51463;
}

57
designer-realize/src/main/java/com/fr/start/Designer.java

@ -3,7 +3,6 @@ package com.fr.start;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.vcs.DesignerMode; import com.fr.base.vcs.DesignerMode;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.file.WebPreviewUtils; import com.fr.design.actions.file.WebPreviewUtils;
import com.fr.design.actions.file.newReport.NewPolyReportAction; import com.fr.design.actions.file.newReport.NewPolyReportAction;
@ -28,14 +27,12 @@ import com.fr.design.mainframe.JWorkBook;
import com.fr.design.mainframe.alphafine.component.AlphaFinePane; import com.fr.design.mainframe.alphafine.component.AlphaFinePane;
import com.fr.design.mainframe.bbs.UserInfoLabel; import com.fr.design.mainframe.bbs.UserInfoLabel;
import com.fr.design.mainframe.bbs.UserInfoPane; import com.fr.design.mainframe.bbs.UserInfoPane;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.KeySetUtils;
import com.fr.design.menu.MenuDef; import com.fr.design.menu.MenuDef;
import com.fr.design.menu.SeparatorDef; import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.concurrent.ThreadFactoryBuilder; import com.fr.design.utils.concurrent.ThreadFactoryBuilder;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -43,17 +40,12 @@ import com.fr.log.FineLoggerFactory;
import com.fr.module.Module; import com.fr.module.Module;
import com.fr.module.ModuleContext; import com.fr.module.ModuleContext;
import com.fr.runtime.FineRuntime; import com.fr.runtime.FineRuntime;
import com.fr.stable.BuildContext;
import com.fr.stable.OperatingSystem;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.lifecycle.LifecycleFatalError; import com.fr.stable.lifecycle.LifecycleFatalError;
import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLTools;
import com.fr.start.fx.SplashFx;
import com.fr.start.jni.SplashMac;
import com.fr.start.module.StartupArgs; import com.fr.start.module.StartupArgs;
import com.fr.start.preload.ImagePreLoader;
import com.fr.start.server.ServerTray; import com.fr.start.server.ServerTray;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
@ -69,8 +61,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -96,25 +86,9 @@ public class Designer extends BaseDesigner {
* @param args 参数 * @param args 参数
*/ */
public static void main(String[] args) { public static void main(String[] args) {
//启动运行时 //启动运行时
FineRuntime.start(); FineRuntime.start();
BuildContext.setBuildFilePath("/com/fr/stable/build.properties");
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
if (DesignUtils.isStarted()) {
DesignUtils.clientSend(args);
FineLoggerFactory.getLogger().error("Designer port not available.");
System.exit(0);
return;
}
RestartHelper.deleteRecordFilesWhenStart();
preloadResource();
SplashContext.getInstance().registerSplash(createSplash());
SplashContext.getInstance().show();
Module designerRoot = ModuleContext.parseRoot("designer-startup.xml"); Module designerRoot = ModuleContext.parseRoot("designer-startup.xml");
//传递启动参数 //传递启动参数
designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args)); designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args));
@ -134,35 +108,6 @@ public class Designer extends BaseDesigner {
} }
private static void preloadResource() {
ExecutorService service = Executors.newCachedThreadPool();
service.submit(new Runnable() {
@Override
public void run() {
new ImagePreLoader();
}
});
service.submit(new Runnable() {
@Override
public void run() {
TemplateInfoCollector.getInstance();
}
});
service.shutdown();
}
private static SplashStrategy createSplash() {
// 这里可以开接口加载自定义启动画面
if (OperatingSystem.isWindows()) {
return new SplashFx();
} else if (OperatingSystem.isMacOS()) {
return new SplashMac();
}
return new SplashFx();
}
public Designer(String[] args) { public Designer(String[] args) {
super(args); super(args);
} }

108
designer-realize/src/main/java/com/fr/start/module/PreStartActivator.java

@ -2,63 +2,99 @@ package com.fr.start.module;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper; import com.fr.design.RestartHelper;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.DesignerPort;
import com.fr.general.CloudCenter; import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext; import com.fr.general.GeneralContext;
import com.fr.log.FineLoggerFactory;
import com.fr.module.Activator; import com.fr.module.Activator;
import com.fr.stable.BuildContext;
import com.fr.stable.OperatingSystem;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.start.SplashContext;
import com.fr.start.SplashStrategy;
import com.fr.start.fx.SplashFx;
import com.fr.start.jni.SplashMac;
import com.fr.start.preload.ImagePreLoader;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* Created by juhaoyu on 2018/1/8. * Created by juhaoyu on 2018/1/8.
*/ */
public class PreStartActivator extends Activator { public class PreStartActivator extends Activator {
private static final int MESSAGE_PORT = 51462;
private static final int DEBUG_PORT = 51463;
@Override @Override
public void start() { public void start() {
CloudCenter.getInstance(); BuildContext.setBuildFilePath("/com/fr/stable/build.properties");
if (checkMultiStart()) { // 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
final String[] args = getModule().upFindSingleton(StartupArgs.class).get();
// 检查是否是-Ddebug = true 启动 并切换对应的端口以及环境配置文件
checkDebugStart();
if (DesignUtils.isStarted()) {
DesignUtils.clientSend(args);
FineLoggerFactory.getLogger().info("The Designer Has Been Started");
System.exit(0);
return; return;
} }
RestartHelper.deleteRecordFilesWhenStart();
preloadResource();
SplashContext.getInstance().registerSplash(createSplash());
SplashContext.getInstance().show();
// 完成初始化
//noinspection ResultOfMethodCallIgnored
CloudCenter.getInstance();
// 创建监听服务
DesignUtils.createListeningServer(DesignUtils.getPort(), startFileSuffix());
initLanguage(); initLanguage();
} }
private boolean checkMultiStart() { @Override
public void stop() {
}
private void checkDebugStart() {
if (isDebug()) { if (isDebug()) {
setDebugEnv(); setDebugEnv();
} else { } else {
DesignUtils.setPort(getStartPort()); DesignUtils.setPort(DesignUtils.getPort());
} }
return false;
} }
private int getStartPort() {
return MESSAGE_PORT;
}
/**
//在VM options里加入-Ddebug=true激活 * 在VM options里加入-Ddebug=true激活
*
* @return isDebug
*/
private boolean isDebug() { private boolean isDebug() {
return ComparatorUtils.equals("true", System.getProperty("debug")); return ComparatorUtils.equals("true", System.getProperty("debug"));
} }
//端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试 //端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试
private void setDebugEnv() { private void setDebugEnv() {
DesignUtils.setPort(DesignerPort.DEBUG_MESSAGE_PORT);
DesignUtils.setPort(DEBUG_PORT); String debugXMlFilePath = StableUtils.pathJoin(
DesignerEnvManager.setEnvFile(new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_debug.xml")); ProductConstants.getEnvHome(),
ProductConstants.APP_NAME + "Env_debug.xml"
);
DesignerEnvManager.setEnvFile(
new File(debugXMlFilePath));
} }
private void initLanguage() { private void initLanguage() {
@ -66,8 +102,36 @@ public class PreStartActivator extends Activator {
GeneralContext.setLocale(DesignerEnvManager.getEnvManager(false).getLanguage()); GeneralContext.setLocale(DesignerEnvManager.getEnvManager(false).getLanguage());
} }
@Override private String[] startFileSuffix() {
public void stop() { return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"};
}
private static void preloadResource() {
ExecutorService service = Executors.newCachedThreadPool();
service.submit(new Runnable() {
@Override
public void run() {
new ImagePreLoader();
}
});
service.submit(new Runnable() {
@Override
public void run() {
TemplateInfoCollector.getInstance();
}
});
service.shutdown();
}
private static SplashStrategy createSplash() {
// 这里可以开接口加载自定义启动画面
if (OperatingSystem.isWindows()) {
return new SplashFx();
} else if (OperatingSystem.isMacOS()) {
return new SplashMac();
}
return new SplashFx();
} }
} }

21
designer-realize/src/main/java/com/fr/start/module/StartFinishActivator.java

@ -1,36 +1,19 @@
package com.fr.start.module; package com.fr.start.module;
import com.fr.design.fun.impl.GlobalListenerProviderManager; import com.fr.design.fun.impl.GlobalListenerProviderManager;
import com.fr.design.utils.DesignUtils;
import com.fr.module.Activator; import com.fr.module.Activator;
/** /**
* Created by juhaoyu on 2018/1/8. * Created by juhaoyu on 2018/1/8.
*/ */
public class StartFinishActivator extends Activator { public class StartFinishActivator extends Activator {
private static final int MESSAGE_PORT = 51462;
@Override @Override
public void start() { public void start() {
DesignUtils.creatListeningServer(getStartPort(), startFileSuffix());
GlobalListenerProviderManager.getInstance().init(); GlobalListenerProviderManager.getInstance().init();
} }
private int getStartPort() {
return MESSAGE_PORT;
}
private String[] startFileSuffix() {
return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"};
}
@Override @Override
public void stop() { public void stop() {
} }
} }

Loading…
Cancel
Save