use of com.blackducksoftware.integration.hub.detect.DetectConfiguration 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