Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F#2051006 Controller Service - Jenkins plugin integration #628

Draft
wants to merge 10 commits into
base: latest
Choose a base branch
from

Conversation

tinccristian
Copy link

This is the first attempt at productizing the new Controller Service app.

We want to provide the additional functionality in our Jenkins plugin to run a test using the Controller Service, using an LRS file

URL cmdExeCfgUrl = Jenkins.get().pluginManager.uberClassLoader.getResource(HP_TOOLS_LAUNCHER_EXE_CFG);
if (cmdExeCfgUrl == null) {
listener.fatalError(HP_TOOLS_LAUNCHER_EXE_CFG + " not found in resources");
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

URL cmdExe2Url = Jenkins.get().pluginManager.uberClassLoader.getResource(LRANALYSIS_LAUNCHER_EXE);
if (cmdExe2Url == null) {
listener.fatalError(LRANALYSIS_LAUNCHER_EXE + "not found in resources");
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

LogMessage("Test completed in", elapsedTime);
Dispose(client);
Cleanup(processesToKill);
return true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

} catch(IllegalArgumentException | EncryptionUtils.EncryptionException e) {
build.setResult(Result.FAILURE);
listener.fatalError(String.format("Build parameters check failed: %s.", e.getMessage()));
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

URL cmdExeUrl = Jenkins.get().pluginManager.uberClassLoader.getResource(HP_TOOLS_LAUNCHER_EXE);
if (cmdExeUrl == null) {
listener.fatalError(HP_TOOLS_LAUNCHER_EXE + " not found in resources");
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

mergedProperties.put("resultsFilename", ResultFilename);

// parallel runner is enabled
if (isParallelRunnerEnabled) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

}
}

try {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

mergedProperties.put("printTestParams", isPrintTestParams ? "1" : "0");

UftRunAsUser uftRunAsUser;
try {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@tinccristian tinccristian marked this pull request as draft November 22, 2023 09:26
if (UftToolUtils.isMtbxContent(expandedFsTests)) {
testsArr = new String[]{expandedFsTests};
} else {
testsArr = expandedFsTests.replaceAll("\r", "").split("\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this call to "replaceAll()" by a call to the "replace()" method.

}

@Override
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this method to reduce its Cognitive Complexity from 44 to the 15 allowed.

EnvVars env = null;
try {
env = build.getEnvironment(listener);
} catch (IOException | InterruptedException e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.


// clean actual tests' report folders
index = 1;
while (mergedProperties.getProperty("Test" + index) != null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.


// clean cleanuptests' report folders
int index = 1;
while (mergedProperties.getProperty("CleanupTest" + index) != null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

@AppVeyorBot
Copy link

}

@Override
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this method to reduce its Cognitive Complexity from 39 to the 15 allowed.

// *
// * @param fsTests the fs tests
// */
// public RunFromService(String fsTests) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

Util.displayIOException(ioe, listener);
build.setResult(Result.FAILURE);
listener.error("Failed running HpToolsLauncher " + ioe.getMessage());
} catch (InterruptedException e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

return createProperties(envVars, currNode);
}

private Properties createProperties(EnvVars envVars, Node currNode) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unused method parameter "currNode".

return UftToolUtils.getNodesList();
}

// public List<String> getEncodings() { return RunFromServiceModel.encodings; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

@AppVeyorBot
Copy link

if (StringUtils.isNotBlank(fsReportPath)) {
props.put("fsReportPath", fsReportPath);
}
if (!StringUtils.isEmpty(this.fsTests)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

* @param value the value
* @return the form validation
*/
public FormValidation doCheckFsTimeout(@QueryParameter String value) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

} catch (IOException e1) {
Util.displayIOException(e1, listener);
build.setResult(Result.FAILURE);
} catch (InterruptedException e1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

Util.displayIOException(ioe, listener);
build.setResult(Result.FAILURE);
listener.error("Failed running HpToolsLauncher " + ioe.getMessage());
} catch (InterruptedException e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

CmdLineExe.copyFrom(cmdExeUrl);
CmdLineExeCfg.copyFrom(cmdExeCfgUrl);
CmdLineExe2.copyFrom(cmdExe2Url);
} catch (IOException | InterruptedException e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

@AppVeyorBot
Copy link

// *
// * @param runFromServiceModel the run from file model
// */
// public RunFromService(RunFromServiceModel runFromServiceModel) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.


// cleanup report folders before running the build
String selectedNode = env.get("NODE_NAME");
if (selectedNode == null) {//if slave is given in the pipeline and not as part of build step
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

return;
}
int idx = 0;
for (Iterator<String> iterator = env.keySet().iterator(); iterator.hasNext(); ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link

codeclimate bot commented Feb 29, 2024

Code Climate has analyzed commit dc3dd6e and detected 30 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 4
Duplication 17
Clarity 4
Bug Risk 4
Performance 1

Note: there are 2 critical issues.

View more on Code Climate.

@AppVeyorBot
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants