[RM] Feature Support for loading IScriptReport from extensions and plugins.
MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/ISFContext.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/ISFContext.java
@@ -41,6 +41,7 @@ import com.exactpro.sf.embedded.updater.UpdateService;
import com.exactpro.sf.matrixhandlers.MatrixProviderHolder;
import com.exactpro.sf.scriptrunner.AbstractScriptRunner;
import com.exactpro.sf.scriptrunner.IConnectionManager;
+import com.exactpro.sf.scriptrunner.IScriptReportLoader;
import com.exactpro.sf.scriptrunner.actionmanager.IActionManager;
import com.exactpro.sf.scriptrunner.languagemanager.LanguageManager;
import com.exactpro.sf.scriptrunner.services.IStaticServiceManager;
@@ -121,4 +122,5 @@ public interface ISFContext {
SfInstanceInfo getSfInstanceInfo();
ServiceMarshalManager getServiceMarshalManager();
+ IScriptReportLoader getScriptReportLoader();
}

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/impl/PluginLoader.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/impl/PluginLoader.java
@@ -109,6 +109,8 @@ public class PluginLoader {
private final List<IVersion> pluginVersions;
+ private final ILoadableManager scriptReportLoader;
+
public PluginLoader(
IWorkspaceDispatcher wd,
ILoadableManager staticServiceManager,
@@ -124,7 +126,8 @@ public class PluginLoader {
ILoadableManager statisticsReportsLoader,
PluginServiceLoader pluginServiceLoader,
IVersion coreVersion,
- ILoadableManager messageStorageLoader) {
+ ILoadableManager messageStorageLoader,
+ ILoadableManager scriptReportLoader) {
if (wd == null) {
throw new NullPointerException("IWorkspaceDispatcher can't be null");
}
@@ -144,6 +147,7 @@ public class PluginLoader {
this.pluginServiceLoader = pluginServiceLoader;
this.coreVersion = coreVersion;
this.messageStorageLoader = messageStorageLoader;
+ this.scriptReportLoader = scriptReportLoader;
this.pluginVersions = new ArrayList<>();
}
@@ -517,6 +521,19 @@ public class PluginLoader {
logger.info("Ignore message storages [No MessageStorageLoader]. Plugin: {}", pluginPath);
}
+ //
+ // Load IScriptReport in plugins
+ //
+ if (scriptReportLoader != null) {
+ try {
+ scriptReportLoader.load(loadableContext);
+ } catch (Exception e) {
+ throw new EPSCommonException(e);
+ }
+ } else {
+ logger.info("Ignore scripts reports [No ScriptReportLoader]. Plugin: {}", pluginPath);
+ }
+
// Collect service description files
if(pluginServiceLoader != null) {
try {

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/impl/SFLocalContext.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/center/impl/SFLocalContext.java
@@ -22,8 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.Queue;
-import com.exactpro.sf.configuration.CleanupConfiguration;
-import com.exactpro.sf.configuration.CleanupService;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
@@ -44,6 +42,7 @@ import com.exactpro.sf.center.SFException;
import com.exactpro.sf.common.adapting.IAdapterManager;
import com.exactpro.sf.common.util.EPSCommonException;
import com.exactpro.sf.configuration.CleanupConfiguration;
+import com.exactpro.sf.configuration.CleanupService;
import com.exactpro.sf.configuration.DataManager;
import com.exactpro.sf.configuration.DefaultAdapterManager;
import com.exactpro.sf.configuration.DictionaryManager;
@@ -68,7 +67,9 @@ import com.exactpro.sf.scriptrunner.AsyncScriptRunner;
import com.exactpro.sf.scriptrunner.EnvironmentSettings;
import com.exactpro.sf.scriptrunner.EnvironmentSettings.StorageType;
import com.exactpro.sf.scriptrunner.IConnectionManager;
+import com.exactpro.sf.scriptrunner.IScriptReportLoader;
import com.exactpro.sf.scriptrunner.PreprocessorLoader;
+import com.exactpro.sf.scriptrunner.ScriptReportLoader;
import com.exactpro.sf.scriptrunner.ScriptRunnerSettings;
import com.exactpro.sf.scriptrunner.SyncScriptRunner;
import com.exactpro.sf.scriptrunner.ValidatorLoader;
@@ -192,6 +193,7 @@ public class SFLocalContext implements ISFContext {
private final IServiceStorage serviceStorage;
private final ServiceMarshalManager serviceMarshalManager;
+ private final IScriptReportLoader scriptReportLoader;
/**
@@ -311,6 +313,7 @@ public class SFLocalContext implements ISFContext {
PluginServiceLoader pluginServiceLoader = new PluginServiceLoader();
MessageStorageLoader messageStorageLoader = new MessageStorageLoader();
+ scriptReportLoader = new ScriptReportLoader();
// 5) Load core & plugins
PluginLoader pluginLoader = new PluginLoader(
@@ -328,7 +331,8 @@ public class SFLocalContext implements ISFContext {
statisticsService,
pluginServiceLoader,
version,
- messageStorageLoader);
+ messageStorageLoader,
+ scriptReportLoader);
LoadInfo loadInfo = pluginLoader.load();
loadInfo.appendClassPath(compilerClassPath);
@@ -728,4 +732,9 @@ public class SFLocalContext implements ISFContext {
public ServiceMarshalManager getServiceMarshalManager() {
return serviceMarshalManager;
}
+
+ @Override
+ public IScriptReportLoader getScriptReportLoader() {
+ return scriptReportLoader;
+ }
}

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/externalapi/ServiceFactory.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/externalapi/ServiceFactory.java
@@ -200,7 +200,7 @@ public class ServiceFactory implements IServiceFactory {
IVersion coreVersion = new CoreVersion();
PluginLoader pluginLoader = new PluginLoader(wd, staticServiceManager, null,
dictionaryManager, null, null, null, dataManager, null, null, null, null,
- null, coreVersion, null);
+ null, coreVersion, null, null);
pluginLoader.load();
this.marshalManager = new ServiceMarshalManager(staticServiceManager, dictionaryManager);

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/HelpBuilder.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/HelpBuilder.java
@@ -306,7 +306,7 @@ public class HelpBuilder {
}
PluginLoader pluginLoader = new PluginLoader(wd, staticServiceManager, actionManager, dictionaryManager, preprocessorLoader, validatorLoader,
- adapterManager, dataManager, languageManager, matrixProviderHolder, matrixConverterManager, statisticsReportLoader, null, version, null);
+ adapterManager, dataManager, languageManager, matrixProviderHolder, matrixConverterManager, statisticsReportLoader, null, version, null, null);
pluginLoader.load();

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/scriptrunner/AbstractScriptRunner.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/scriptrunner/AbstractScriptRunner.java
@@ -280,6 +280,8 @@ public abstract class AbstractScriptRunner implements IDisposable {
reportListeners.addAll(userListeners);
}
+ reportListeners.addAll(sfContext.getScriptReportLoader().createScriptReports(reportFolder, workspaceDispatcher, dictionaryManager, scriptDescription.getId()));
+
// NOTE: ZipReport must be latest
reportListeners.add(new ZipReport(reportFolder, workspaceDispatcher, scriptDescription, ReportOutputFormat.ZIP));

ADD
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/scriptrunner/IScriptReportFactory.java
+/*******************************************************************************
+ * Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.exactpro.sf.scriptrunner;
+
+import com.exactpro.sf.configuration.IDictionaryManager;
+import com.exactpro.sf.configuration.workspace.IWorkspaceDispatcher;
+
+public interface IScriptReportFactory {
+
+ IScriptReport createScriptReport(String reportFolder, IWorkspaceDispatcher workspaceDispatcher, IDictionaryManager dictionaryManager) throws Exception;
+
+}

ADD
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/scriptrunner/IScriptReportLoader.java
+/*******************************************************************************
+ * Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.exactpro.sf.scriptrunner;
+
+import java.util.Set;
+
+import com.exactpro.sf.configuration.IDictionaryManager;
+import com.exactpro.sf.configuration.ILoadableManager;
+import com.exactpro.sf.configuration.workspace.IWorkspaceDispatcher;
+
+public interface IScriptReportLoader extends ILoadableManager {
+ Set<IScriptReport> createScriptReports(String reportFolder, IWorkspaceDispatcher workspaceDispatcher, IDictionaryManager dictionaryManager, long scriptId);
+}

ADD
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/scriptrunner/ScriptReportLoader.java
+/*******************************************************************************
+ * Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.exactpro.sf.scriptrunner;
+
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.exactpro.sf.configuration.IDictionaryManager;
+import com.exactpro.sf.configuration.ILoadableManagerContext;
+import com.exactpro.sf.configuration.ILoggingConfigurator;
+import com.exactpro.sf.configuration.workspace.IWorkspaceDispatcher;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
+
+public class ScriptReportLoader implements IScriptReportLoader {
+
+ private final Logger logger = LoggerFactory.getLogger(ILoggingConfigurator.getLoggerName(this));
+
+ private final SetMultimap<String, IScriptReportFactory> factories = HashMultimap.create();
+
+ @Override
+ public void load(ILoadableManagerContext context) throws Exception {
+ for (IScriptReportFactory factory : ServiceLoader.load(IScriptReportFactory.class, context.getClassLoaders()[0])) {
+ factories.put(context.getVersion().getAlias(), factory);
+ }
+ }
+
+ @Override
+ public Set<IScriptReport> createScriptReports(String reportFolder, IWorkspaceDispatcher workspaceDispatcher, IDictionaryManager dictionaryManager, long scriptId) {
+ return factories.entries().stream().map(entry ->
+ createScriptReport(entry.getValue(),
+ reportFolder,
+ workspaceDispatcher,
+ dictionaryManager,
+ entry.getKey(),
+ scriptId)
+ ).filter(Objects::nonNull).collect(Collectors.toSet());
+ }
+
+ private IScriptReport createScriptReport(IScriptReportFactory factory, String reportFolder, IWorkspaceDispatcher workspaceDispatcher, IDictionaryManager dictionaryManager, String pluginName, long scriptID) {
+ try {
+ return factory.createScriptReport(reportFolder, workspaceDispatcher, dictionaryManager);
+ } catch (Exception e) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Can not create script report from class '{}' from plugin '{}' for script with id '{}'", factory.getClass().getName(), pluginName, scriptID, e);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void finalize(ILoadableManagerContext context) throws Exception {}
+}

[RM] Feature #62422. Support for loading IScriptReport from extensions and plugins.

Change-Id: Ie3f438a43d1751560c096797ea26585546171c07