4 changed files with 192 additions and 6 deletions
@ -0,0 +1,44 @@ |
|||||||
|
package com.fr.design.update.processor; |
||||||
|
|
||||||
|
import com.fr.decision.update.SyncProcessor; |
||||||
|
import com.fr.decision.update.info.UpdateCallBack; |
||||||
|
import com.fr.plugin.context.PluginMarker; |
||||||
|
|
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author shengzu.xue |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2025/5/15 15:27 |
||||||
|
* jar更新接口默认实现 |
||||||
|
*/ |
||||||
|
public class AbstractSyncProcessor implements SyncProcessor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return SyncProcessor.CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int layerIndex() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean executeJarSync (UpdateCallBack callBack, String fullBuildNo, String designerJarsPath, String commonJarsPath){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<PluginMarker> executePluginSync(List<PluginMarker> differentPlugins) { |
||||||
|
return Collections.emptyList(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Set<SyncType> supportedSyncType() { |
||||||
|
//所有类型都不支持
|
||||||
|
return Collections.emptySet(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,142 @@ |
|||||||
|
|
||||||
|
package com.fr.design.update.processor; |
||||||
|
|
||||||
|
import com.fr.decision.update.SyncExecutor; |
||||||
|
import com.fr.decision.update.SyncProcessor; |
||||||
|
import com.fr.decision.update.backup.Recover; |
||||||
|
import com.fr.decision.update.backup.RecoverForSync; |
||||||
|
import com.fr.decision.update.command.Command; |
||||||
|
import com.fr.decision.update.command.CommandGroup; |
||||||
|
import com.fr.decision.update.data.UpdateConstants; |
||||||
|
import com.fr.decision.update.impl.RemoveCommand; |
||||||
|
import com.fr.decision.update.info.UpdateCallBack; |
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.versioncheck.VersionCheckUtils; |
||||||
|
import com.fr.general.CommonIOUtils; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugin.context.PluginMarker; |
||||||
|
import com.fr.stable.ProjectLibrary; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.project.ProjectConstants; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author shengzu.xue |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2025/5/15 |
||||||
|
* 设计器服务器远程同步执行器 |
||||||
|
*/ |
||||||
|
public class SyncProcessorExecutor { |
||||||
|
|
||||||
|
private static final String ID = "id"; |
||||||
|
private static final String VERSION = "version"; |
||||||
|
|
||||||
|
// 单例实例
|
||||||
|
private static final SyncProcessorExecutor INSTANCE = new SyncProcessorExecutor(); |
||||||
|
|
||||||
|
private SyncProcessorExecutor() { |
||||||
|
} // 私有构造
|
||||||
|
|
||||||
|
public static SyncProcessorExecutor getInstance() { |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取执行器实例 |
||||||
|
*/ |
||||||
|
public SyncProcessor getExecutor() { |
||||||
|
return ExtraDesignClassManager.getInstance().getSingle(SyncProcessor.XML_TAG, new AbstractSyncProcessor()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 执行jar同步 |
||||||
|
*/ |
||||||
|
public boolean executeJarSync(UpdateCallBack callBack, String fullBuildNo) { |
||||||
|
SyncProcessor processor = getExecutor(); |
||||||
|
if (processor.supportedSyncType().contains(SyncProcessor.SyncType.JAR_SYNC)) { |
||||||
|
String dir = StableUtils.pathJoin(ProjectLibrary.getInstance().getLibHome(), ProjectConstants.ASSIST_NAME, UpdateConstants.ENV_LIB); |
||||||
|
try { |
||||||
|
// 备份jar
|
||||||
|
Recover recoverForSync = RecoverForSync.getInstance(); |
||||||
|
if (fullBuildNo != null) { |
||||||
|
if (recoverForSync.backup()) { |
||||||
|
if (processor.executeJarSync(callBack, fullBuildNo, processor.DESIGNER_JARS_PATH, processor.COMMON_JARS_PATH)) { |
||||||
|
CommandGroup commands = getCommandGroup(processor.DESIGNER_JARS_PATH, processor.COMMON_JARS_PATH); |
||||||
|
return commands.execute(callBack); |
||||||
|
} |
||||||
|
// 同步失败,恢复
|
||||||
|
recoverForSync.recover(); |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return false; |
||||||
|
} finally { |
||||||
|
CommonIOUtils.deleteFile(new File(dir)); |
||||||
|
} |
||||||
|
} else { |
||||||
|
return SyncExecutor.getInstance().execute(callBack, fullBuildNo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 执行插件同步 |
||||||
|
*/ |
||||||
|
public JSONArray executePluginSync(JSONArray differentPlugins) { |
||||||
|
SyncProcessor processor = getExecutor(); |
||||||
|
if (processor.supportedSyncType().contains(SyncProcessor.SyncType.PLUGIN_SYNC)) { |
||||||
|
return getPluginJsonArray(processor.executePluginSync(getPluginMaker(differentPlugins))); |
||||||
|
} |
||||||
|
return VersionCheckUtils.syncPlugins(VersionCheckUtils.checkLocalAndRemotePlugin()); |
||||||
|
} |
||||||
|
|
||||||
|
private static @NotNull CommandGroup getCommandGroup(String designerJarsPath, String commonJarsPath) { |
||||||
|
// 获取换jar的命令
|
||||||
|
List<Command> commandList = new ArrayList<>(); |
||||||
|
CommandGroup commands = new CommandGroup(commandList); |
||||||
|
Command designCommand = new RemoveCommand(designerJarsPath, StableUtils.pathJoin(StableUtils.getInstallHome(), ProjectConstants.LIB_NAME)); |
||||||
|
Command commonCommand = new RemoveCommand(commonJarsPath, StableUtils.pathJoin(ProjectLibrary.getInstance().getLibHome(), ProjectConstants.LIB_NAME)); |
||||||
|
commands.addCommands(designCommand); |
||||||
|
commands.addCommands(commonCommand); |
||||||
|
return commands; |
||||||
|
} |
||||||
|
|
||||||
|
private static List<PluginMarker> getPluginMaker(JSONArray differentPlugins) { |
||||||
|
JSONObject differentPlugin; |
||||||
|
String id; |
||||||
|
String version; |
||||||
|
List<PluginMarker> plugins = new ArrayList<>(); |
||||||
|
if (differentPlugins != null) { |
||||||
|
for (int i = 0; i < differentPlugins.size(); i++) { |
||||||
|
differentPlugin = differentPlugins.getJSONObject(i); |
||||||
|
id = differentPlugin.getString(ID); |
||||||
|
version = differentPlugin.getString(VERSION); |
||||||
|
plugins.add(PluginMarker.create(id, version)); |
||||||
|
} |
||||||
|
} |
||||||
|
return plugins; |
||||||
|
} |
||||||
|
|
||||||
|
private static JSONArray getPluginJsonArray(List<PluginMarker> differentPlugins) { |
||||||
|
JSONObject differentPlugin; |
||||||
|
JSONArray differentPluginsJsonArray = new JSONArray(); |
||||||
|
if (differentPlugins != null) { |
||||||
|
for (PluginMarker pluginMarker : differentPlugins) { |
||||||
|
differentPlugin = new JSONObject(); |
||||||
|
differentPlugin.put(ID, pluginMarker.getPluginID()); |
||||||
|
differentPlugin.put(VERSION, pluginMarker.getVersion()); |
||||||
|
} |
||||||
|
} |
||||||
|
return differentPluginsJsonArray; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue