Skip to content

Commit

Permalink
Move dispatch logic to linters
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed Nov 27, 2024
1 parent 28e25c3 commit 5b2bf38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import schemacrawler.tools.command.lint.options.LintOptions;
import schemacrawler.tools.command.lint.options.LintReportOutputFormat;
import schemacrawler.tools.executable.BaseSchemaCrawlerCommand;
import schemacrawler.tools.lint.LintDispatch;
import schemacrawler.tools.lint.Linters;
import schemacrawler.tools.lint.config.LinterConfigs;
import schemacrawler.tools.lint.formatter.LintReportGenerator;
Expand All @@ -44,7 +43,6 @@
import schemacrawler.tools.lint.report.LintReport;
import schemacrawler.tools.lint.report.LintReportBuilder;
import us.fatehi.utility.string.ObjectToStringFormat;
import us.fatehi.utility.string.StringFormat;

public class LintCommand extends BaseSchemaCrawlerCommand<LintOptions> {

Expand Down Expand Up @@ -83,8 +81,8 @@ public void execute() {
LOGGER.log(Level.INFO, "Generating lint report");
getLintReportBuilder().generateLintReport(lintReport);

LOGGER.log(Level.INFO, "Dispatching lint results");
dispatch(linters);
linters.dispatch(commandOptions.getLintDispatch());

} catch (final Exception e) {
LOGGER.log(Level.WARNING, "Could not run lint command", e);
}
Expand All @@ -95,25 +93,6 @@ public boolean usesConnection() {
return true;
}

private void dispatch(final Linters linters) {
final boolean exceedsThreshold = linters.exceedsThreshold();

final String lintSummary = linters.getLintSummary();
if (!lintSummary.isEmpty()) {
LOGGER.log(Level.INFO, new StringFormat("Lint summary:%n%s", lintSummary));
if (exceedsThreshold) {
System.err.println(lintSummary);
}
}

if (!exceedsThreshold) {
return;
}

final LintDispatch lintDispatch = commandOptions.getLintDispatch();
lintDispatch.dispatch();
}

private LintReportGenerator getLintReportBuilder() {
final LintReportOutputFormat outputFormat =
LintReportOutputFormat.fromFormat(outputOptions.getOutputFormatValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

package schemacrawler.tools.lint;

import static schemacrawler.tools.lint.LintUtility.LINTER_COMPARATOR;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -79,7 +80,7 @@ public LintReport getLintReport() {
public String getLintSummary() {

final List<Linter> linters = new ArrayList<>(this.linters);
linters.sort(LintUtility.LINTER_COMPARATOR);
linters.sort(LINTER_COMPARATOR);

final StringBuilder buffer = new StringBuilder(1024);
for (final Linter linter : linters) {
Expand Down Expand Up @@ -113,6 +114,21 @@ public void lint(final Catalog catalog, final Connection connection) {
LintReportBuilder.builder().withCatalog(catalog).withLints(collector.getLints()).build();
}

public void dispatch(final LintDispatch lintDispatch) {

LOGGER.log(Level.INFO, () -> getLintSummary());

if (lintDispatch == null || lintDispatch == LintDispatch.none) {
return;
}

if (!linters.isEmpty() && exceedsThreshold()) {
LOGGER.log(Level.INFO, "Dispatching lint results");
System.err.println(getLintSummary());
lintDispatch.dispatch();
}
}

/**
* Number of linters configured to run
*
Expand Down

0 comments on commit 5b2bf38

Please sign in to comment.