|
|
|
@ -46,8 +46,6 @@ public class HistoryTemplateListCache implements CallbackEvent {
|
|
|
|
|
private List<JTemplate<?, ?>> historyList; |
|
|
|
|
private JTemplate<?, ?> editingTemplate; |
|
|
|
|
|
|
|
|
|
private Map<String, Boolean> templateNeedReloadMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
public static HistoryTemplateListCache getInstance() { |
|
|
|
|
return Holder.INSTANCE; |
|
|
|
|
} |
|
|
|
@ -78,9 +76,6 @@ public class HistoryTemplateListCache implements CallbackEvent {
|
|
|
|
|
selected.fireJTemplateClosed(); |
|
|
|
|
selected.stopEditing(); |
|
|
|
|
try { |
|
|
|
|
if (!templateNeedReloadMap.isEmpty()) { |
|
|
|
|
templateNeedReloadMap.remove(selected.getEditingFILE().getName()); |
|
|
|
|
} |
|
|
|
|
historyList.remove(contains(selected)); |
|
|
|
|
selected.getEditingFILE().closeTemplate(); |
|
|
|
|
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); |
|
|
|
@ -412,7 +407,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
|
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
public void reloadCurrentTemplate() { |
|
|
|
|
reloadAllEditingTemplate(true); |
|
|
|
|
reloadAllEditingTemplate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -430,15 +425,14 @@ public class HistoryTemplateListCache implements CallbackEvent {
|
|
|
|
|
/** |
|
|
|
|
* 插件安装后/启用 重新加载模板资源 |
|
|
|
|
*/ |
|
|
|
|
public void reloadAllEditingTemplate(boolean mustReload) { |
|
|
|
|
private void _reloadAllEditingTemplate(PluginContext context) { |
|
|
|
|
FineLoggerFactory.getLogger().info("Plugin env change reload all template started"); |
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
int size = historyList.size(); |
|
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
|
JTemplate<?, ?> template = historyList.get(i); |
|
|
|
|
FILE file = template.getEditingFILE(); |
|
|
|
|
Boolean value = templateNeedReloadMap.get(file.getName()); |
|
|
|
|
boolean needReload = mustReload || (value != null && value); |
|
|
|
|
boolean needReload = context == null || needReloadTemplate(context, template); |
|
|
|
|
if (needReload) { |
|
|
|
|
try { |
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
@ -455,31 +449,38 @@ public class HistoryTemplateListCache implements CallbackEvent {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
templateNeedReloadMap.clear(); |
|
|
|
|
FineLoggerFactory.getLogger().info("Plugin env change reload all template ended"); |
|
|
|
|
FineLoggerFactory.getLogger().info("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void calNeedReloadTemplate(PluginContext context) { |
|
|
|
|
for (JTemplate<?, ?> template : historyList) { |
|
|
|
|
BaseBook baseBook = template.getTarget(); |
|
|
|
|
if (baseBook != null) { |
|
|
|
|
String name = template.getEditingFILE().getName(); |
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
Set<ClassLoader> set = ClassHelper.getClassLoaders(baseBook); |
|
|
|
|
FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); |
|
|
|
|
if (set != null) { |
|
|
|
|
for (ClassLoader classLoader : set) { |
|
|
|
|
PluginContext pluginContext = PluginManager.getContext(classLoader); |
|
|
|
|
if (pluginContext != null && ComparatorUtils.equals(context.getName(), pluginContext.getName())) { |
|
|
|
|
templateNeedReloadMap.put(name, true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
templateNeedReloadMap.put(name, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void reloadAllEditingTemplateByPlugin(PluginContext context) { |
|
|
|
|
_reloadAllEditingTemplate(context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void reloadAllEditingTemplate() { |
|
|
|
|
_reloadAllEditingTemplate(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean needReloadTemplate(PluginContext context, JTemplate<?, ?> template) { |
|
|
|
|
BaseBook baseBook = template.getTarget(); |
|
|
|
|
if (baseBook != null) { |
|
|
|
|
String name = template.getEditingFILE().getName(); |
|
|
|
|
String pluginId = context.getID(); |
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
Set<ClassLoader> set = ClassHelper.getClassLoaders(baseBook); |
|
|
|
|
FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); |
|
|
|
|
if (set != null) { |
|
|
|
|
for (ClassLoader classLoader : set) { |
|
|
|
|
if (PluginManager.isBeforeLoadBy(classLoader, pluginId)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|