Skip to content

Commit

Permalink
US #2048033: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bbokhonko-mf committed Jan 31, 2023
1 parent 473dcf8 commit a0ad83d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
<dependency>
<artifactId>integrations-sdk</artifactId>
<groupId>com.hpe.adm.octane.ciplugins</groupId>
<version>2.7.7.0</version>
<version>2.7.8.0</version>
</dependency>

<!--BUILDER providers integration-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@

import java.util.List;

import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams;

/**
* Run Listener that handles basic CI events and dispatches notifications to the Octane server
* User: gullery
Expand Down Expand Up @@ -129,7 +127,7 @@ private void publishFinishEvent(AbstractBuild build) {
.setResult(BuildHandlerUtils.translateRunResult(build))
.setDuration(build.getDuration())
.setTestResultExpected(hasTests)
.setEnvironmentOutputtedParameters(getOutputEnvironmentParams(build));
.setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(build));
CommonOriginRevision commonOriginRevision = getCommonOriginRevision(build);
if (commonOriginRevision != null) {
event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.microfocus.application.automation.tools.octane.events;

import com.microfocus.application.automation.tools.settings.OctaneBuildWrapper;
import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider;
import com.microfocus.application.automation.tools.settings.OutputEnvironmentVariablesBuildWrapper;
import com.microfocus.application.automation.tools.settings.RunnerMiscSettingsGlobalConfiguration;
import com.microfocus.application.automation.tools.sse.common.StringUtils;
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.Job;
import hudson.model.Run;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.*;
Expand All @@ -18,6 +20,8 @@ public class OutputEnvironmentParametersHelper {

public static final String SPLIT_SYMBOL = " ";

private static Logger logger = SDKBasedLoggerProvider.getLogger(OutputEnvironmentParametersHelper.class);

public static Map<String, String> getOutputEnvironmentParams(Run run) {
EnvVars environment = getEnvironment(run);
if (environment == null) {
Expand Down Expand Up @@ -51,7 +55,8 @@ private static EnvVars getEnvironment(Run run) {
EnvVars environment = null;
try {
environment = run.getEnvironment(null);
} catch (IOException | InterruptedException ignored) {
} catch (IOException | InterruptedException e) {
logger.error("Can not get Run(id: " + run.getId() + ") Environment: " + e.getMessage());
}
return environment;
}
Expand All @@ -68,11 +73,14 @@ private static List<String> getGlobalParamsList() {
private static List<String> getJobParamsList(Run run) {
Job<?, ?> job = run.getParent();
if (job instanceof BuildableItemWithBuildWrappers) {
String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList().
get(OctaneBuildWrapper.class).getOutputEnvironmentParameters();
if (paramsStr != null) {
String[] params = paramsStr.split(SPLIT_SYMBOL);
return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList());
OutputEnvironmentVariablesBuildWrapper outputEnvVarsBuildWrapper = ((BuildableItemWithBuildWrappers) job)
.getBuildWrappersList().get(OutputEnvironmentVariablesBuildWrapper.class);
if (outputEnvVarsBuildWrapper != null) {
String paramsStr = outputEnvVarsBuildWrapper.getOutputEnvironmentParameters();
if (!StringUtils.isNullOrEmpty(paramsStr)) {
String[] params = paramsStr.split(SPLIT_SYMBOL);
return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList());
}
}
}
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ private void sendPipelineFinishedEvent(WorkflowRun parentRun) {
.setDuration(parentRun.getDuration())
.setResult(BuildHandlerUtils.translateRunResult(parentRun))
.setCauses(CIEventCausesFactory.processCauses(parentRun))
.setTestResultExpected(hasTests);
.setTestResultExpected(hasTests)
.setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(parentRun));
CIJenkinsServicesImpl.publishEventToRelevantClients(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.hp.octane.integrations.utils.SdkConstants;
import com.hp.octane.integrations.utils.SdkStringUtils;
import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider;
import com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper;
import com.microfocus.application.automation.tools.octane.executor.UftConstants;
import com.microfocus.application.automation.tools.octane.model.processors.builders.AbstractBuilderProcessor;
import com.microfocus.application.automation.tools.octane.model.processors.builders.BuildTriggerProcessor;
Expand All @@ -52,8 +53,6 @@
import java.util.List;
import java.util.Set;

import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams;

/**
* Created with IntelliJ IDEA.
* User: gullery
Expand Down Expand Up @@ -211,7 +210,7 @@ public CIBuildStatusInfo getBuildStatus(String paramName, String paramValue) {
} else {
status.setBuildStatus(CIBuildStatus.FINISHED);
status.setResult(BuildHandlerUtils.translateRunResult(aBuild));
status.setEnvironmentOutputtedParameters(getOutputEnvironmentParams(aBuild));
status.setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(aBuild));
}
status.setAllBuildParams(ParameterProcessors.getInstances(aBuild));
status.setBuildCiId(BuildHandlerUtils.getBuildCiId(aBuild));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.SPLIT_SYMBOL;

public class OctaneBuildWrapper extends BuildWrapper implements Serializable {
public class OutputEnvironmentVariablesBuildWrapper extends BuildWrapper implements Serializable {

private String outputEnvironmentParameters;
@DataBoundConstructor
public OctaneBuildWrapper(String outputEnvironmentParameters) {
public OutputEnvironmentVariablesBuildWrapper(String outputEnvironmentParameters) {
setOutputEnvironmentParameters(outputEnvironmentParameters);
}

Expand Down

0 comments on commit a0ad83d

Please sign in to comment.