Skip to content

Commit

Permalink
MID-9162 fixing verify suggestion message + now guessing report style…
Browse files Browse the repository at this point in the history
… (if not defined by option)

(cherry picked from commit 0e57753)
  • Loading branch information
1azyman committed Oct 4, 2023
1 parent 157a64f commit 599478b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.concurrent.Callable;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.file.PathUtils;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.ninja.action.verify.VerificationReporter;
Expand Down Expand Up @@ -65,13 +67,34 @@ protected Callable<VerifyResult> createConsumer(BlockingQueue<ObjectType> queue,
};
}

private void guessReportStyle() {
if (options.getOutput() == null) {
options.setReportStyle(VerifyOptions.ReportStyle.PLAIN);
return;
}

File output = options.getOutput();
String extension = FilenameUtils.getExtension(output.getName());
VerifyOptions.ReportStyle style = "csv".equalsIgnoreCase(extension) ?
VerifyOptions.ReportStyle.CSV : VerifyOptions.ReportStyle.PLAIN;

options.setReportStyle(style);
}

@Override
public VerifyResult execute() throws Exception {
if (options.getReportStyle() == null) {
guessReportStyle();
}

VerifyResult result;
if (options.getOutput() != null) {
log.info("Verification report will be saved to '{}'", options.getOutput().getPath());
log.info("Verification report will be saved to '{}' ({})", options.getOutput().getPath(), options.getReportStyle().name().toLowerCase());
} else if (context.isUserMode() && !partial) {
log.warn("Consider using '-o verify-output.csv' option for CSV output with upgradeability status of deprecated items.");
log.warn(
"Consider using '" + VerifyOptions.P_OUTPUT + " verify-output.csv " + VerifyOptions.P_REPORT_STYLE
+ " " + VerifyOptions.ReportStyle.CSV.name().toLowerCase()
+ "' option for CSV output with upgradeability status of deprecated items.");
log.warn("It is recommended to review this report and actions for proper upgrade procedure.");
}
if (!options.getFiles().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public VerificationCategoryConverter() {

@Parameter(names = { P_REPORT_STYLE }, descriptionKey = "verify.reportStyle",
converter = ReportStyleConverter.class, validateWith = ReportStyleConverter.class)
private ReportStyle reportStyle = ReportStyle.PLAIN;
private ReportStyle reportStyle;

@Parameter(names = { P_STOP_ON_CRITICAL_ERROR }, descriptionKey = "verify.stopOnCriticalError")
private boolean stopOnCriticalError;
Expand Down

0 comments on commit 599478b

Please sign in to comment.