Browse Source

Merge pull request #1027 in DESIGN/design from ~ZACK/design:feature/10.0 to feature/10.0

* commit 'a5bb0bf8cd3693e0e9bfd4cae579ba01f9b4c625':
  删掉sdk
  冲突
research/10.0
zack 5 years ago
parent
commit
c3ecab7af4
  1. 23
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  2. 4
      designer-base/src/main/java/com/fr/design/utils/DesignUtils.java
  3. 29
      designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java
  4. 153
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  5. 5
      designer-sdk/pom.xml
  6. 80
      designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java
  7. 7
      designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java

23
designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java

@ -35,6 +35,7 @@ import com.fr.json.JSONArray;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.EncodeConstants;
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;
@ -362,10 +363,10 @@ public class UpdateMainDialog extends UIDialog {
add(jarVersionInfoPane, BorderLayout.NORTH); add(jarVersionInfoPane, BorderLayout.NORTH);
//海外版本不显示更新信息 //海外版本不显示更新信息
if (GeneralContext.getLocale().equals(Locale.CHINA) || GeneralContext.getLocale().equals(Locale.TAIWAN)){ if (GeneralContext.getLocale().equals(Locale.CHINA) || GeneralContext.getLocale().equals(Locale.TAIWAN)) {
add(jarUpdateInfoPane, BorderLayout.CENTER); add(jarUpdateInfoPane, BorderLayout.CENTER);
add(updateActionPane, BorderLayout.SOUTH); add(updateActionPane, BorderLayout.SOUTH);
}else { } else {
add(updateActionPane, BorderLayout.CENTER); add(updateActionPane, BorderLayout.CENTER);
} }
@ -513,16 +514,15 @@ public class UpdateMainDialog extends UIDialog {
if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) { if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) {
return; return;
} }
OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), "UTF-8"); try (OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), EncodeConstants.ENCODING_UTF_8);
BufferedWriter bufferWriter = new BufferedWriter(writerStream); BufferedWriter bufferWriter = new BufferedWriter(writerStream)) {
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = (JSONObject) jsonArray.get(i); JSONObject jo = (JSONObject) jsonArray.get(i);
bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title")); bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title"));
bufferWriter.newLine(); bufferWriter.newLine();
bufferWriter.flush(); bufferWriter.flush();
}
} }
bufferWriter.close();
writerStream.close();
lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS; lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS;
lastUpdateCacheTime = endTime; lastUpdateCacheTime = endTime;
cacheProperty.updateProperty("updateTime", lastUpdateCacheTime); cacheProperty.updateProperty("updateTime", lastUpdateCacheTime);
@ -634,6 +634,7 @@ public class UpdateMainDialog extends UIDialog {
/** /**
* 获取当前jar的md5 * 获取当前jar的md5
*
* @param currentJAR * @param currentJAR
* @return * @return
*/ */

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

@ -67,8 +67,7 @@ public class DesignUtils {
* @return 启动了返回true * @return 启动了返回true
*/ */
public static boolean isStarted() { public static boolean isStarted() {
try { try (Socket socket = new Socket("localhost", port)) {
new Socket("localhost", port);
return true; return true;
} catch (Exception ignored) { } catch (Exception ignored) {
} }
@ -116,6 +115,7 @@ public class DesignUtils {
* @param startPort 端口 * @param startPort 端口
* @param suffixs 文件后缀 * @param suffixs 文件后缀
*/ */
@SuppressWarnings("squid:S2095")
public static void createListeningServer(final int startPort, final String[] suffixs) { public static void createListeningServer(final int startPort, final String[] suffixs) {
ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("DesignClientListener")); ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("DesignClientListener"));
service.execute(new Runnable() { service.execute(new Runnable() {

29
designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java

@ -86,12 +86,14 @@ public class DownloadOnlineSourcesHelper implements DownloadSourcesEvent {
initDialog(); initDialog();
dialog.addWindowListener(new WindowAdapter() { dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
//取消下载 //取消下载
result = false; result = false;
exitDialog(); exitDialog();
} }
@Override
public void windowOpened(WindowEvent e) { public void windowOpened(WindowEvent e) {
downloadAndInstallPluginDependenceFile(); downloadAndInstallPluginDependenceFile();
exitDialog(); exitDialog();
@ -119,25 +121,22 @@ public class DownloadOnlineSourcesHelper implements DownloadSourcesEvent {
httpClient = new HttpClient(CloudCenter.getInstance().acquireUrlByKind(siteInfo.siteKind)); httpClient = new HttpClient(CloudCenter.getInstance().acquireUrlByKind(siteInfo.siteKind));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
File file = new File(temp); File file = new File(temp);
StableUtils.makesureFileExist(file); StableUtils.makesureFileExist(file);
FileOutputStream writer = new FileOutputStream(temp); try (InputStream reader = httpClient.getResponseStream();
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; FileOutputStream writer = new FileOutputStream(temp)) {
int bytesRead; byte[] buffer = new byte[PluginConstants.BYTES_NUM];
while ((bytesRead = reader.read(buffer)) > 0 && result) { int bytesRead;
writer.write(buffer, 0, bytesRead); while ((bytesRead = reader.read(buffer)) > 0 && result) {
buffer = new byte[PluginConstants.BYTES_NUM]; writer.write(buffer, 0, bytesRead);
buffer = new byte[PluginConstants.BYTES_NUM];
currentBytesRead += bytesRead;
setProgress(currentBytesRead); currentBytesRead += bytesRead;
setProgress(currentBytesRead);
}
writer.flush();
} }
reader.close();
writer.flush();
writer.close();
if (result) { if (result) {
//安装文件 //安装文件
IOUtils.unZipFilesGBK(temp, StableUtils.pathJoin(WorkContext.getCurrent().getPath(), siteInfo.localDir)); IOUtils.unZipFilesGBK(temp, StableUtils.pathJoin(WorkContext.getCurrent().getPath(), siteInfo.localDir));

153
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -54,7 +54,6 @@ import java.util.concurrent.TimeUnit;
/** /**
* @author neil * @author neil
*
* @date: 2015-4-8-下午5:11:46 * @date: 2015-4-8-下午5:11:46
*/ */
public class InformationCollector implements XMLReadable, XMLWriter { public class InformationCollector implements XMLReadable, XMLWriter {
@ -83,17 +82,17 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private String lastTime; private String lastTime;
private StartStopTime current = new StartStopTime(); private StartStopTime current = new StartStopTime();
public static InformationCollector getInstance(){ public static InformationCollector getInstance() {
if (collector == null) { if (collector == null) {
collector = new InformationCollector(); collector = new InformationCollector();
readEncodeXMLFile(collector, collector.getInfoFile()); readEncodeXMLFile(collector, collector.getInfoFile());
} }
return collector; return collector;
} }
private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile){ private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) {
if (xmlFile == null || !xmlFile.exists()) { if (xmlFile == null || !xmlFile.exists()) {
return; return;
} }
@ -110,22 +109,22 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} }
xmlInputStream.close(); xmlInputStream.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (XMLStreamException e) { } catch (XMLStreamException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException{ private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException {
InputStream encodeInputStream = new FileInputStream(xmlFile); InputStream encodeInputStream = new FileInputStream(xmlFile);
String encodeContent = IOUtils.inputStream2String(encodeInputStream); String encodeContent = IOUtils.inputStream2String(encodeInputStream);
return DesUtils.getDecString(encodeContent); return DesUtils.getDecString(encodeContent);
} }
private long getLastTimeMillis(){ private long getLastTimeMillis() {
if (StringUtils.isEmpty(this.lastTime)) { if (StringUtils.isEmpty(this.lastTime)) {
return 0; return 0;
} }
@ -138,7 +137,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} }
private JSONObject getJSONContentAsByte(){ private JSONObject getJSONContentAsByte() {
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
JSONArray startStopArray = new JSONArray(); JSONArray startStopArray = new JSONArray();
@ -159,7 +158,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
return content; return content;
} }
private void sendUserInfo(){ private void sendUserInfo() {
long currentTime = new Date().getTime(); long currentTime = new Date().getTime();
long lastTime = getLastTimeMillis(); long lastTime = getLastTimeMillis();
@ -178,7 +177,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
if (success){ if (success) {
this.reset(); this.reset();
} }
} }
@ -186,13 +185,13 @@ public class InformationCollector implements XMLReadable, XMLWriter {
/** /**
* 收集开始使用时间发送信息 * 收集开始使用时间发送信息
*/ */
public void collectStartTime(){ public void collectStartTime() {
this.current.setStartDate(dateToString()); this.current.setStartDate(dateToString());
sendUserInfoInOtherThread(); sendUserInfoInOtherThread();
} }
private void sendUserInfoInOtherThread(){ private void sendUserInfoInOtherThread() {
if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) { if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) {
return; return;
} }
@ -209,67 +208,57 @@ public class InformationCollector implements XMLReadable, XMLWriter {
}, SEND_DELAY, TimeUnit.MILLISECONDS); }, SEND_DELAY, TimeUnit.MILLISECONDS);
} }
/** /**
* 收集结束使用时间 * 收集结束使用时间
*/ */
public void collectStopTime(){ public void collectStopTime() {
this.current.setStopDate(dateToString()); this.current.setStopDate(dateToString());
} }
private String dateToString(){ private String dateToString() {
DateFormat df = FRContext.getDefaultValues().getDateTimeFormat(); DateFormat df = FRContext.getDefaultValues().getDateTimeFormat();
return df.format(new Date()); return df.format(new Date());
} }
private void reset(){ private void reset() {
this.startStop.clear(); this.startStop.clear();
this.lastTime = dateToString(); this.lastTime = dateToString();
} }
private File getInfoFile() { private File getInfoFile() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
} }
/** /**
* 保存xml文件 * 保存xml文件
*/ */
public void saveXMLFile() { public void saveXMLFile() {
File xmlFile = this.getInfoFile(); File xmlFile = this.getInfoFile();
try{ try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLTools.writeOutputStreamXML(this, out); XMLTools.writeOutputStreamXML(this, out);
out.flush(); out.flush();
out.close(); out.close();
String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8);
String encodeCotent = DesUtils.getEncString(fileContent); String encodeCotent = DesUtils.getEncString(fileContent);
writeEncodeContentToFile(encodeCotent, xmlFile); writeEncodeContentToFile(encodeCotent, xmlFile);
}catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
/** /**
* 将文件内容写到输出流中 * 将文件内容写到输出流中
*/ */
private static void writeEncodeContentToFile(String fileContent, File file){ private static void writeEncodeContentToFile(String fileContent, File file) {
BufferedWriter bw = null; try (FileOutputStream fos = new FileOutputStream(file);
try { OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8);
FileOutputStream fos = new FileOutputStream(file); BufferedWriter bw = new BufferedWriter(osw)) {
OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8);
bw = new BufferedWriter(osw);
bw.write(fileContent); bw.write(fileContent);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if(bw != null){
try {
bw.close();
} catch (IOException e) {
}
}
} }
} }
@Override @Override
@ -284,56 +273,56 @@ public class InformationCollector implements XMLReadable, XMLWriter {
writer.end(); writer.end();
} }
private void writeStartStopList(XMLPrintWriter writer){ private void writeStartStopList(XMLPrintWriter writer) {
//启停 //启停
writer.startTAG(XML_START_STOP_LIST); writer.startTAG(XML_START_STOP_LIST);
for (int i = 0; i < startStop.size(); i++) { for (int i = 0; i < startStop.size(); i++) {
startStop.get(i).writeXML(writer); startStop.get(i).writeXML(writer);
} }
writer.end(); writer.end();
} }
private void writeTag(String tag, String content, XMLPrintWriter writer){ private void writeTag(String tag, String content, XMLPrintWriter writer) {
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
return; return;
} }
writer.startTAG(tag); writer.startTAG(tag);
writer.textNode(content); writer.textNode(content);
writer.end(); writer.end();
} }
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
if (reader.isChildNode()) { if (reader.isChildNode()) {
String name = reader.getTagName(); String name = reader.getTagName();
if (XML_START_STOP_LIST.equals(name)) { if (XML_START_STOP_LIST.equals(name)) {
readStartStopList(reader); readStartStopList(reader);
} else if(XML_LAST_TIME.equals(name)){ } else if (XML_LAST_TIME.equals(name)) {
readLastTime(reader); readLastTime(reader);
} }
} }
} }
private void readLastTime(XMLableReader reader){ private void readLastTime(XMLableReader reader) {
String tmpVal; String tmpVal;
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) { if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) {
this.lastTime = tmpVal; this.lastTime = tmpVal;
} }
} }
private void readStartStopList(XMLableReader reader){ private void readStartStopList(XMLableReader reader) {
startStop.clear(); startStop.clear();
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
if (XML_START_STOP.equals(reader.getTagName())) { if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime(); StartStopTime startStopTime = new StartStopTime();
reader.readXMLObject(startStopTime); reader.readXMLObject(startStopTime);
startStop.add(startStopTime); startStop.add(startStopTime);
} }
} }
}); });
} }
private class StartStopTime implements XMLReadable, XMLWriter { private class StartStopTime implements XMLReadable, XMLWriter {
@ -358,14 +347,14 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} }
public void writeXML(XMLPrintWriter writer) { public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP); writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) { if (StringUtils.isNotEmpty(startDate)) {
writer.attr(ATTR_START, this.startDate); writer.attr(ATTR_START, this.startDate);
} }
if (StringUtils.isNotEmpty(stopDate)) { if (StringUtils.isNotEmpty(stopDate)) {
writer.attr(ATTR_STOP, this.stopDate); writer.attr(ATTR_STOP, this.stopDate);
} }
writer.end(); writer.end();
} }
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {

5
designer-sdk/pom.xml

@ -17,10 +17,5 @@
<artifactId>designer-realize</artifactId> <artifactId>designer-realize</artifactId>
<version>10.0</version> <version>10.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.fr.report</groupId>
<artifactId>sdk-base</artifactId>
<version>10.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

80
designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java

@ -1,80 +0,0 @@
//package com.fr.sdk.designer;
//
//import com.fr.config.activator.ConfigurationActivator;
//import com.fr.design.env.DesignerWorkspaceGenerator;
//import com.fr.design.env.RemoteDesignerWorkspaceInfo;
//import com.fr.log.FineLoggerFactory;
//import com.fr.module.Activator;
//import com.fr.module.Module;
//import com.fr.module.tool.ActivatorToolBox;
//import com.fr.report.ReportActivator;
//import com.fr.report.RestrictionActivator;
//import com.fr.report.module.ReportBaseActivator;
//import com.fr.scheduler.SchedulerActivator;
//import com.fr.sdk.server.shell.ModuleShell;
//import com.fr.serialization.SerializationActivator;
//import com.fr.stable.StringUtils;
//import com.fr.startup.WorkspaceRegister;
//import com.fr.store.StateServerActivator;
//import com.fr.workspace.WorkContext;
//import com.fr.workspace.connect.WorkspaceConnectionInfo;
//import com.fr.workspace.engine.WorkspaceActivator;
//import com.fr.workspace.server.ServerWorkspaceRegister;
//
///**
// * 设计器SDK模块工具类,用来放一些设计器相关插件开发过程中常用的工具函数
// */
//public class FineDesignUtils {
//
// /**
// * 创建一个连接远程服务器的模块
// * @param remoteUrl 远程服务器地址
// * @param username 用户名
// * @param password 密码
// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停
// */
// public static ModuleShell createRemoteServerModule(String remoteUrl, String username, String password) {
// return createRemoteServerModule(remoteUrl, username, password, StringUtils.EMPTY, StringUtils.EMPTY);
// }
//
// /**
// * 创建一个连接远程服务器的模块
// * @param remoteUrl 远程服务器地址
// * @param username 用户名
// * @param password 密码
// * @param certPath https证书路径
// * @param certSecretKey 证书秘钥
// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停
// */
// public static ModuleShell createRemoteServerModule(final String remoteUrl, final String username, final String password, final String certPath, final String certSecretKey) {
// Module module = ActivatorToolBox.simpleLink(
// new WorkspaceActivator(),
// new SerializationActivator(),
// new Activator() {
// @Override
// public void start() {
// WorkspaceConnectionInfo connectionInfo = new WorkspaceConnectionInfo(remoteUrl, username, password, certPath, certSecretKey);
// try {
// WorkContext.switchTo(DesignerWorkspaceGenerator.generate(RemoteDesignerWorkspaceInfo.create(connectionInfo)));
// } catch (Exception e) {
// FineLoggerFactory.getLogger().error(e.getMessage(),e);
// }
// }
//
// @Override
// public void stop() {
//
// }
// },
// new ConfigurationActivator(),
// new StateServerActivator(),
// new SchedulerActivator(),
// new ReportBaseActivator(),
// new RestrictionActivator(),
// new ReportActivator(),
// new WorkspaceRegister(),
// new ServerWorkspaceRegister()
// );
// return new ModuleShell(module);
// }
//}

7
designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java

@ -1,7 +0,0 @@
package com.fr.sdk;
import junit.framework.TestCase;
public class FineDesignUtilsTest extends TestCase {
}
Loading…
Cancel
Save