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

Refactor Code to pass Sonar #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ java {
project.ext.excludesFromTestCoverage = ['**/DetectDownloadStrategy.java', '**/DetectPipelineStep.java', '**/DetectPostBuildStep.java', '**/DetectAirGapInstallation.java']

group = 'com.blackducksoftware.integration'
version = '10.0.1-SNAPSHOT'
version = '10.0.1-SIGQA2-SNAPSHOT'
description = 'Black Duck Detect for Jenkins'

apply plugin: 'com.blackduck.integration.solution'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,32 @@ private String getAirGapJar(String airGapBaseDir) throws DetectJenkinsException
FileFilter backUpFileFilter = file -> file.getName().startsWith(FALLBACK_DETECT_JAR_PREFIX) && file.getName().endsWith(DETECT_JAR_SUFFIX);
File[] foundFallbackJars = new File(airGapBaseDir).listFiles(backUpFileFilter);

if ((foundAirGapJars == null || foundAirGapJars.length == 0) && (foundFallbackJars == null || foundFallbackJars.length == 0)) {
try {
return findAirGapJar(airGapBaseDir, foundAirGapJars);
} catch (Exception e) {
if(foundAirGapJars == null || foundAirGapJars.length == 0) {
return findAirGapJar(airGapBaseDir, foundFallbackJars);
} else {
throw e;
}
}
}


private String findAirGapJar(String airGapBaseDir, File[] foundJars) throws DetectJenkinsException {
if (foundJars == null || foundJars.length == 0) {
throw new DetectJenkinsException(String.format(
"Expected 1 jar from Detect Air Gap tool installation at <%s> and did not find any. Check your Jenkins plugin and tool configuration.",
airGapBaseDir
));
} else if ((foundAirGapJars != null && foundAirGapJars.length > 1) || (foundFallbackJars != null && foundFallbackJars.length > 1)) {
} else if (foundJars.length > 1) {
throw new DetectJenkinsException(
String.format(
"Expected 1 jar from Detect Air Gap tool installation at <%s> and instead found multiple jars. Check your Jenkins plugin and tool configuration.",
airGapBaseDir
));
} else {
if (foundAirGapJars != null && foundAirGapJars.length == 1) {
return foundAirGapJars[0].toString();
} else if(foundFallbackJars != null && foundFallbackJars.length == 1) {
return foundFallbackJars[0].toString();
} else {
throw new DetectJenkinsException(String.format(
"Expected 1 jar from Detect Air Gap tool installation at <%s> and did not find any. Check your Jenkins plugin and tool configuration.",
airGapBaseDir
));
}
return foundJars[0].toString();
}
}
}
Expand Down