use of com.blackducksoftware.integration.hub.detect.help.DetectOption in project hub-detect by blackducksoftware.
the class Application method init.
@PostConstruct
public void init() {
final long start = System.currentTimeMillis();
try {
detectInfo.init();
detectOptionManager.init();
final List<DetectOption> options = detectOptionManager.getDetectOptions();
boolean isPrintHelp = false;
boolean isPrintHelpDoc = false;
boolean isInteractive = false;
for (final String arg : applicationArguments.getSourceArgs()) {
if (arg.equals("-h") || arg.equals("--help")) {
isPrintHelp = true;
} else if (arg.equals("-hdoc") || arg.equals("--helpdocument")) {
isPrintHelpDoc = true;
} else if (arg.equals("-i") || arg.equals("--interactive")) {
isInteractive = true;
}
}
if (isPrintHelp) {
helpPrinter.printHelpMessage(System.out, options);
return;
}
if (isPrintHelpDoc) {
helpHtmlWriter.writeHelpMessage(String.format("hub-detect-%s-help.html", detectInfo.getDetectVersion()));
return;
}
if (isInteractive) {
final InteractiveReader interactiveReader = createInteractiveReader();
final PrintStream interactivePrintStream = new PrintStream(System.out);
interactiveManager.interact(interactiveReader, interactivePrintStream);
}
detectConfiguration.init();
logger.info("Configuration processed completely.");
if (!detectConfiguration.getSuppressConfigurationOutput()) {
final DetectInfoPrinter infoPrinter = new DetectInfoPrinter();
final DetectConfigurationPrinter detectConfigurationPrinter = new DetectConfigurationPrinter();
infoPrinter.printInfo(System.out, detectInfo);
detectConfigurationPrinter.print(System.out, detectInfo, detectConfiguration, options);
}
if (detectConfiguration.getTestConnection()) {
hubServiceWrapper.assertHubConnection(new SilentLogger());
return;
}
if (!detectConfiguration.getHubOfflineMode()) {
hubServiceWrapper.init();
}
final DetectProject detectProject = detectProjectManager.createDetectProject();
final List<File> createdBdioFiles = detectProjectManager.createBdioFiles(detectProject);
if (!detectConfiguration.getHubOfflineMode()) {
final ProjectVersionView projectVersionView = hubManager.updateHubProjectVersion(detectProject, createdBdioFiles);
hubManager.performPostHubActions(detectProject, projectVersionView);
} else if (!detectConfiguration.getHubSignatureScannerDisabled()) {
hubSignatureScanner.scanPathsOffline(detectProject);
}
for (final ExitCodeReporter exitCodeReporter : exitCodeReporters) {
exitCodeType = ExitCodeType.getWinningExitCodeType(exitCodeType, exitCodeReporter.getExitCodeType());
}
} catch (final Exception e) {
populateExitCodeFromExceptionDetails(e);
} finally {
try {
detectPhoneHomeManager.endPhoneHome();
} catch (final Exception e) {
logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
}
if (!detectConfiguration.getSuppressResultsOutput()) {
detectSummary.logResults(new Slf4jIntLogger(logger), exitCodeType);
}
detectFileManager.cleanupDirectories();
}
final long end = System.currentTimeMillis();
logger.info(String.format("Hub-Detect run duration: %s", DurationFormatUtils.formatPeriod(start, end, "HH'h' mm'm' ss's' SSS'ms'")));
if (detectConfiguration.getForceSuccess() && exitCodeType.getExitCode() != 0) {
logger.warn("Forcing success: Exiting with 0. Desired exit code was ${exitCodeType.getExitCode()}.");
System.exit(0);
} else {
System.exit(exitCodeType.getExitCode());
}
}
use of com.blackducksoftware.integration.hub.detect.help.DetectOption in project hub-detect by blackducksoftware.
the class HelpPrinter method printHelpMessage.
public void printHelpMessage(final PrintStream printStream, final List<DetectOption> options) {
final List<String> helpMessagePieces = new ArrayList<>();
helpMessagePieces.add("");
final List<String> headerColumns = Arrays.asList("Property Name", "Default", "Description");
final String headerText = formatColumns(headerColumns, 51, 30, 95);
helpMessagePieces.add(headerText);
helpMessagePieces.add(StringUtils.repeat('_', 175));
String group = null;
for (final DetectOption detectValue : options) {
final String currentGroup = detectValue.getGroup();
if (group == null) {
group = currentGroup;
} else if (!group.equals(currentGroup)) {
helpMessagePieces.add("");
group = currentGroup;
}
final List<String> bodyColumns = Arrays.asList("--" + detectValue.getKey(), detectValue.getDefaultValue(), detectValue.getDescription());
final String bodyText = formatColumns(bodyColumns, 51, 30, 95);
helpMessagePieces.add(bodyText);
}
helpMessagePieces.add("");
helpMessagePieces.add("Usage : ");
helpMessagePieces.add("\t--<property name>=<value>");
helpMessagePieces.add("");
printMessage(printStream, helpMessagePieces);
}
use of com.blackducksoftware.integration.hub.detect.help.DetectOption in project hub-detect by blackducksoftware.
the class HelpHtmlWriter method writeHelpMessage.
public void writeHelpMessage(final String filename) {
final List<GroupOptionListing> groupOptions = new ArrayList<>();
for (final String groupName : detectOptionManager.getDetectGroups()) {
final List<DetectOption> filteredOptions = getGroupDetectOptions(groupName);
groupOptions.add(new GroupOptionListing(StringUtils.capitalise(groupName), filteredOptions));
}
final Map<String, Object> dataModel = new HashMap<>();
dataModel.put("options", groupOptions);
try {
final File htmlHelpFile = new File(filename);
final Template htmlTemplate = configuration.getTemplate("templates/helpHtml.ftl");
htmlTemplate.process(dataModel, new FileWriter(htmlHelpFile));
logger.info(filename + " was created in your current directory.");
} catch (final IOException | TemplateException e) {
logger.error("There was an error when creating the html file", e);
}
}
use of com.blackducksoftware.integration.hub.detect.help.DetectOption in project hub-detect by blackducksoftware.
the class DetectConfigurationPrinter method print.
public void print(final PrintStream printStream, final DetectInfo detectInfo, final DetectConfiguration detectConfiguration, final List<DetectOption> detectOptions) throws IllegalArgumentException, IllegalAccessException {
printStream.println("");
printStream.println("Current property values:");
printStream.println("--property = value [notes]");
printStream.println(StringUtils.repeat("-", 60));
List<Field> annotatedProperties = new ArrayList<>();
final Field[] propertyFields = DetectConfiguration.class.getDeclaredFields();
for (final Field propertyField : propertyFields) {
final Optional<Annotation> foundField = Arrays.stream(propertyField.getAnnotations()).filter(annotation -> annotation.annotationType() == Value.class).findFirst();
final int modifiers = propertyField.getModifiers();
if (foundField.isPresent() && !Modifier.isStatic(modifiers) && Modifier.isPrivate(modifiers)) {
annotatedProperties.add(propertyField);
}
}
annotatedProperties = annotatedProperties.stream().sorted(new Comparator<Field>() {
@Override
public int compare(final Field field1, final Field field2) {
return field1.getName().compareTo(field2.getName());
}
}).collect(Collectors.toList());
for (final Field field : annotatedProperties) {
field.setAccessible(true);
final String fieldName = field.getName();
Object rawFieldValue;
rawFieldValue = field.get(detectConfiguration);
String fieldValue = "";
if (field.getType().isArray()) {
fieldValue = String.join(", ", (String[]) rawFieldValue);
} else {
if (rawFieldValue != null) {
fieldValue = rawFieldValue.toString();
}
}
if (!StringUtils.isEmpty(fieldName) && !StringUtils.isEmpty(fieldValue) && "metaClass" != fieldName) {
final boolean containsPassword = fieldName.toLowerCase().contains("password") || fieldName.toLowerCase().contains("apitoken");
if (containsPassword) {
fieldValue = StringUtils.repeat("*", fieldValue.length());
}
DetectOption option = null;
for (final DetectOption opt : detectOptions) {
if (opt.getFieldName().equals(fieldName)) {
option = opt;
}
}
if (option != null && !option.getResolvedValue().equals(fieldValue) && !containsPassword) {
if (option.interactiveValue != null) {
printStream.println(fieldName + " = " + fieldValue + " [interactive]");
} else if (option.getResolvedValue().equals("latest")) {
printStream.println(fieldName + " = " + fieldValue + " [latest]");
} else if (option.getResolvedValue().trim().length() == 0) {
printStream.println(fieldName + " = " + fieldValue + " [calculated]");
} else {
printStream.println(fieldName + " = " + fieldValue + " + [" + option.getResolvedValue() + "]");
}
} else {
printStream.println(fieldName + " = " + fieldValue);
}
}
field.setAccessible(false);
}
printStream.println(StringUtils.repeat("-", 60));
printStream.println("");
}
Aggregations