Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Removing detect.fail.config.warning and letting configuration report …
Browse files Browse the repository at this point in the history
…the exit code.
  • Loading branch information
taikuukaits committed Aug 1, 2018
1 parent db79908 commit 696baf8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public enum DetectProperty {

// insert here

@HelpGroup(primary = GROUP_GENERAL)
@HelpDescription("If true, Detect will fail if there are any issues found in the configuration.")
DETECT_FAIL_CONFIG_WARNING("detect.fail.config.warning", DetectPropertyType.BOOLEAN, "true"),

@HelpGroup(primary = GROUP_GENERAL)
@HelpDescription("If true, detect will always exit with code 0.")
DETECT_FORCE_SUCCESS("detect.force.success", DetectPropertyType.BOOLEAN, "false"),
Expand Down Expand Up @@ -241,6 +237,7 @@ public enum DetectProperty {
@HelpDescription("A suffix to the name of the codelocations created by Detect.")
DETECT_PROJECT_CODELOCATION_SUFFIX("detect.project.codelocation.suffix", DetectPropertyType.STRING, ""),

@Deprecated
@HelpGroup(primary = GROUP_PROJECT_INFO, additional = { SEARCH_GROUP_PROJECT })
@HelpDescription("If set to true, unmaps all other code locations mapped to the project version produced by the current run of Detect.")
DETECT_PROJECT_CODELOCATION_UNMAP("detect.project.codelocation.unmap", DetectPropertyType.BOOLEAN, "false"),
Expand Down Expand Up @@ -462,9 +459,13 @@ public enum DetectProperty {
DETECT_HUB_SIGNATURE_SCANNER_DISABLED("detect.hub.signature.scanner.disabled", DetectPropertyType.BOOLEAN, "false"),

@HelpGroup(primary = GROUP_SIGNATURE_SCANNER, additional = { SEARCH_GROUP_SIGNATURE_SCANNER, SEARCH_GROUP_OFFLINE, SEARCH_GROUP_HUB })
@HelpDescription("To use a local signature scanner, specify the path where the signature scanner was unzipped. This will likely look similar to 'scan.cli-x.y.z' and includes the 'bin, icon, jre, and lib' directories of the expanded scan.cli.")
@HelpDescription("To use a local signature scanner and force offline, specify the path where the signature scanner was unzipped. This will likely look similar to 'scan.cli-x.y.z' and includes the 'bin, icon, jre, and lib' directories of the expanded scan.cli.")
DETECT_HUB_SIGNATURE_SCANNER_OFFLINE_LOCAL_PATH("detect.hub.signature.scanner.offline.local.path", DetectPropertyType.STRING),

@HelpGroup(primary = GROUP_SIGNATURE_SCANNER, additional = { SEARCH_GROUP_SIGNATURE_SCANNER, SEARCH_GROUP_OFFLINE, SEARCH_GROUP_HUB })
@HelpDescription("To use a local signature scanner, specify the path where the signature scanner was unzipped. This will likely look similar to 'scan.cli-x.y.z' and includes the 'bin, icon, jre, and lib' directories of the expanded scan.cli.")
DETECT_HUB_SIGNATURE_SCANNER_LOCAL_PATH("detect.hub.signature.scanner.local.path", DetectPropertyType.STRING),

@HelpGroup(primary = GROUP_SIGNATURE_SCANNER, additional = { SEARCH_GROUP_SIGNATURE_SCANNER, SEARCH_GROUP_HUB })
@HelpDescription("If this url is set, an attempt will be made to use it to download the signature scanner. The server url provided must respect the Hub's urls for different operating systems.")
DETECT_HUB_SIGNATURE_SCANNER_HOST_URL("detect.hub.signature.scanner.host.url", DetectPropertyType.STRING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import com.blackducksoftware.integration.hub.detect.configuration.DetectConfigWrapper;
import com.blackducksoftware.integration.hub.detect.configuration.DetectProperty;
import com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException;
import com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter;
import com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType;
import com.blackducksoftware.integration.hub.detect.help.DetectOption.OptionValidationResult;
import com.blackducksoftware.integration.hub.detect.interactive.InteractiveOption;

public class DetectOptionManager {
public class DetectOptionManager implements ExitCodeReporter {
private final Logger logger = LoggerFactory.getLogger(DetectOptionManager.class);

public final DetectConfigWrapper detectConfigWrapper;
Expand Down Expand Up @@ -220,4 +222,13 @@ private DetectOptionHelp processFieldHelp(final Field field) {
return help;
}

@Override
public ExitCodeType getExitCodeType() {
if (detectOptions.stream().anyMatch(DetectOption::hasWarnings)) {
logger.error("Configuration is using deprecated properties. Please fix deprecation issues. To ignore these messages and force detect to succeed supply --" + DetectProperty.DETECT_FORCE_SUCCESS.getPropertyName() + "=true");
return ExitCodeType.FAILURE_CONFIGURATION;
}
return ExitCodeType.SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ private WorkflowStep initializeDetect(final String[] sourceArgs) throws Integrat
configurationManager.printConfiguration(System.out, detectInfo, options);
}

if (detectConfigWrapper.getBooleanProperty(DetectProperty.DETECT_FAIL_CONFIG_WARNING) && options.stream().anyMatch(DetectOption::hasWarnings)) {
throw new DetectUserFriendlyException("Failing because the configuration had warnings.", ExitCodeType.FAILURE_CONFIGURATION);
}

final List<OptionValidationResult> invalidDetectOptionResults = detectOptionManager.getAllInvalidOptionResults();
if (!invalidDetectOptionResults.isEmpty()) {
throw new DetectUserFriendlyException(invalidDetectOptionResults.get(0).getValidationMessage(), ExitCodeType.FAILURE_GENERAL_ERROR);
Expand Down

0 comments on commit 696baf8

Please sign in to comment.