Browse Source

REPORT-51958 远程环境检测及同步

feature/10.0
pengda 3 years ago
parent
commit
8fe4ad250f
  1. 67
      designer-base/src/main/java/com/fr/design/VersionCheckUtils.java
  2. 8
      designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java
  3. 50
      designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java
  4. 7
      designer-base/src/main/java/com/fr/env/CheckServiceDialog.java

67
designer-base/src/main/java/com/fr/design/VersionCheckUtils.java

@ -1,10 +1,9 @@
package com.fr.design;
import com.fr.base.FRContext;
import com.fr.decision.update.data.UpdateConstants;
import com.fr.decision.update.exception.UpdateException;
import com.fr.decision.update.info.UpdateCallBack;
import com.fr.decision.update.info.UpdateProcessBean;
import com.fr.decision.update.util.UpdateFileUtils;
import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceType;
import com.fr.design.env.RemoteWorkspace;
@ -83,9 +82,9 @@ public class VersionCheckUtils {
return checkLocalAndRemoteJartime(selectedEnv) && checkLocalAndRemotePlugin().size() == 0;
}
public static void showVersionCheckDialog(String envName){
if(!VersionCheckUtils.versionCheck(envName)){
VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(),Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"),envName);
public static void showVersionCheckDialog(String envName) {
if (!VersionCheckUtils.versionCheck(envName)) {
VersionCheckMessageDialog versionCheckMessageDialog = new VersionCheckMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Sync_Check_Brief_Info"), envName);
versionCheckMessageDialog.setVisible(true);
}
}
@ -96,7 +95,7 @@ public class VersionCheckUtils {
return checkLocalAndRemoteJartime(selectedEnv);
}
public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv){
public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv) {
//是否需要做服务校验
if (needCheckBranch(selectedEnv)) {
String localBranch;
@ -334,55 +333,21 @@ public class VersionCheckUtils {
private static void downloadPlugins(Map<String, String> urls, UpdateCallBack callBack) {
CommonIOUtils.deleteFile(new File(SYNCLIB));
UpdateProcessBean bean = new UpdateProcessBean();
FileOutputStream fos = null;
CloseableHttpClient httpClient;
CloseableHttpResponse httpResponse;
HttpGet httpGet = new HttpGet();
InputStream in = null;
try {
for (String idAndVersion : urls.keySet()) {
try {
httpGet.setURI(URI.create(urls.get(idAndVersion)));
httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion));
String target = SYNCPLUGINLIB + idAndVersion + ZIP;
httpResponse = httpClient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
FineLoggerFactory.getLogger().error("download plugin error :" + urls.get(idAndVersion));
continue;
}
long totalSize = httpResponse.getEntity().getContentLength();
in = httpResponse.getEntity().getContent();
//保存文件
File saveDir = new File(target);
StableUtils.makesureFileExist(saveDir);
bean.setDownloadedFiles(bean.getDownloadedFiles() + 1);
bean.setName(idAndVersion);
bean.setTotalLength((int) totalSize);
bean.setDownloadLength(0);
callBack.updateProgress(bean);
fos = new FileOutputStream(saveDir);
int bytesRead;
int totalBytesRead = 0;
byte[] getData = new byte[UpdateConstants.BYTE];
while ((bytesRead = in.read(getData)) != -1) {
fos.write(getData, 0, bytesRead);
getData = new byte[UpdateConstants.BYTE];
totalBytesRead += bytesRead;
bean.setDownloadLength(totalBytesRead);
callBack.updateProgress(bean);
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
for (String idAndVersion : urls.keySet()) {
try {
String url = urls.get(idAndVersion);
if (null == url) {
continue;
}
String target = SYNCPLUGINLIB + idAndVersion + ZIP;
UpdateFileUtils.downloadFile(url, target, callBack, bean,idAndVersion);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
} finally {
CommonIOUtils.close(fos);
CommonIOUtils.close(in);
}
}
private static Map<String, String> getPluginsDownloadURL(JSONArray differentPlugins, Set<String> uninstallFailed) {
Map<String, String> downloadURL = new HashMap<>();
JSONObject differentPlugin;
@ -415,7 +380,7 @@ public class VersionCheckUtils {
CloseableHttpResponse httpResponse;
HttpGet httpGet = new HttpGet();
InputStream in = null;
HashMap<String,String> downloadURLs = new HashMap<>();
HashMap<String, String> downloadURLs = new HashMap<>();
try {
for (String idAndVersion : urls.keySet()) {
httpClient = HttpToolbox.getHttpClient(urls.get(idAndVersion));
@ -425,7 +390,7 @@ public class VersionCheckUtils {
JSONObject urlJson = new JSONObject(IOUtils.inputStream2String(in));
String downloadURL = urlJson.getString("result");
if (downloadURL != null) {
downloadURLs.put(idAndVersion,downloadURL);
downloadURLs.put(idAndVersion, downloadURL);
}
}
} catch (Exception e) {

8
designer-base/src/main/java/com/fr/design/update/actions/FileProcess.java

@ -15,20 +15,14 @@ import java.util.concurrent.ExecutionException;
public abstract class FileProcess extends SwingWorker<Boolean, Void> {
private UpdateCallBack callBack;
private String fullBuildNo = null;
public FileProcess(UpdateCallBack callBack) {
this.callBack = callBack;
}
public FileProcess(UpdateCallBack callBack,String fullBuildNo) {
this.callBack = callBack;
this.fullBuildNo = fullBuildNo;
}
@Override
protected Boolean doInBackground() throws Exception {
return UpdateExecutor.getInstance().execute(callBack,fullBuildNo);
return UpdateExecutor.getInstance().execute(callBack);
}
@Override

50
designer-base/src/main/java/com/fr/design/update/actions/SyncFileProcess.java

@ -0,0 +1,50 @@
package com.fr.design.update.actions;
import com.fr.decision.update.SyncExecutor;
import com.fr.decision.update.info.UpdateCallBack;
import com.fr.log.FineLoggerFactory;
import java.util.concurrent.ExecutionException;
import javax.swing.SwingWorker;
public abstract class SyncFileProcess extends SwingWorker<Boolean, Void> {
private UpdateCallBack callBack;
private String buildNo;
public SyncFileProcess(UpdateCallBack callBack,String buildNo) {
this.callBack = callBack;
this.buildNo = buildNo;
}
@Override
protected Boolean doInBackground() throws Exception {
return SyncExecutor.getInstance().execute(callBack,buildNo);
}
@Override
protected void done() {
boolean success = false;
try {
success = get();
} catch (InterruptedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
if (success) {
onDownloadSuccess();
} else {
onDownloadFailed();
}
}
/**
* 下载成功
*/
public abstract void onDownloadSuccess();
/**
* 下载失败
*/
public abstract void onDownloadFailed();
}

7
designer-base/src/main/java/com/fr/env/CheckServiceDialog.java vendored

@ -13,8 +13,7 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.update.actions.FileProcess;
import com.fr.design.update.ui.dialog.RestoreResultDialog;
import com.fr.design.update.actions.SyncFileProcess;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.CloudCenter;
import com.fr.general.CloudCenterConfig;
@ -327,7 +326,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener {
final JFrame frame = DesignerContext.getDesignerFrame();
final RestartHelper helper = new RestartHelper();
FineProcessContext.getParentPipe().fire(FineProcessEngineEvent.DESTROY);
new FileProcess(callBack, remoteBuildNo) {
new SyncFileProcess(callBack, remoteBuildNo) {
@Override
public void onDownloadSuccess() {
deleteForDesignerUpdate(installLib);
@ -389,7 +388,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener {
syncFailedPluginsDialog.setVisible(true);
} else {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("同步成功"),
Toolkit.i18nText("Fine-Design_Basic_Sync_Success"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
FineJOptionPane.INFORMATION_MESSAGE);
}

Loading…
Cancel
Save