diff --git a/schemacrawler-commandline/src/main/java/schemacrawler/tools/commandline/command/AvailableCommands.java b/schemacrawler-commandline/src/main/java/schemacrawler/tools/commandline/command/AvailableCommands.java index 297781a6f9..7f17de1337 100644 --- a/schemacrawler-commandline/src/main/java/schemacrawler/tools/commandline/command/AvailableCommands.java +++ b/schemacrawler-commandline/src/main/java/schemacrawler/tools/commandline/command/AvailableCommands.java @@ -42,14 +42,14 @@ private static Collection availableCommands() { supportedCommands.add( new PropertyName( "", - "Shows results of query , " + "Show results of query , " + "as specified in the configuration properties file")); supportedCommands.add( new PropertyName( "", String.join( "\n", - "Shows results of SQL ", + "Show results of SQL ", "The query itself can contain the variables ${table}, ${columns} " + "and ${tabletype}, or system properties referenced as ${}", "Queries without any variables are executed exactly once", diff --git a/schemacrawler-commandline/src/test/resources/commandline_help_output/help.stdout.txt b/schemacrawler-commandline/src/test/resources/commandline_help_output/help.stdout.txt index 73649b2f93..248c16d851 100644 --- a/schemacrawler-commandline/src/test/resources/commandline_help_output/help.stdout.txt +++ b/schemacrawler-commandline/src/test/resources/commandline_help_output/help.stdout.txt @@ -1,4 +1,4 @@ -SchemaCrawler 16.23.1 +SchemaCrawler 16.24.1 Database schema discovery and comprehension tool https://www.schemacrawler.com/ Copyright (c) 2000-2025, Sualeh Fatehi . @@ -222,7 +222,7 @@ Options: Optional, default is 0 -Loader for catalog attributes, such as remarks or tags +** Loader for catalog attributes, such as remarks or tags Command: loader:attributesloader @@ -233,7 +233,7 @@ Options: Add loader options to the `load` command in the SchemaCrawler Shell -Loader for table row counts +** Loader for table row counts Command: loader:countsloader @@ -247,7 +247,7 @@ Options: Add loader options to the `load` command in the SchemaCrawler Shell -Loader for testing +** Loader for testing Command: loader:testloader @@ -257,7 +257,7 @@ Options: Add loader options to the `load` command in the SchemaCrawler Shell -Loader for weak associations +** Loader for weak associations Command: loader:weakassociationsloader @@ -291,7 +291,8 @@ run SchemaCrawler with: `-h loaders` or from the SchemaCrawler interactive shell: `help loaders` -** Generate text output to show details of a schema +** Show the commonly needed detail of the schema, including details of tables, +views and routines, columns, primary keys, indexes, foreign keys, and triggers Command: command:schema Applies to all commands that show schema information diff --git a/schemacrawler-commandline/src/test/resources/shell_commands_output/availableCommands.stdout.txt b/schemacrawler-commandline/src/test/resources/shell_commands_output/availableCommands.stdout.txt index b4b0a9279a..bea6d181be 100644 --- a/schemacrawler-commandline/src/test/resources/shell_commands_output/availableCommands.stdout.txt +++ b/schemacrawler-commandline/src/test/resources/shell_commands_output/availableCommands.stdout.txt @@ -1,23 +1,23 @@ Available SchemaCrawler Commands: - brief Shows basic schema information, for tables, views and routines, + brief Show basic schema information, for tables, views and routines, columns, primary keys, and foreign keys - count Shows counts of rows in the tables - details Shows maximum possible detail of the schema, including + count Show counts of rows in the tables + details Show maximum possible detail of the schema, including privileges, and details of privileges, triggers, and check constraints - dump Shows data from all rows in the tables - list Shows a list of schema objects - quickdump Shows data from all rows in the tables, but row order is not + dump Show data from all rows in the tables + list Show a list of schema objects + quickdump Show data from all rows in the tables, but row order is not guaranteed - this can be used with a minimum info-level for speed - schema Shows the commonly needed detail of the schema, including + schema Show the commonly needed detail of the schema, including details of tables, views and routines, columns, primary keys, indexes, foreign keys, and triggers test-command Test command which is not deployed with the release - Shows results of query , as specified in the + Show results of query , as specified in the configuration properties file - Shows results of SQL + Show results of SQL The query itself can contain the variables ${table}, ${columns} and ${tabletype}, or system properties referenced as ${} diff --git a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramCommandProvider.java b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramCommandProvider.java index 9e6cc9e463..958874e5c2 100644 --- a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramCommandProvider.java +++ b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramCommandProvider.java @@ -35,6 +35,7 @@ import schemacrawler.tools.executable.BaseCommandProvider; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; +import us.fatehi.utility.property.PropertyName; public final class DiagramCommandProvider extends BaseCommandProvider { @@ -44,9 +45,13 @@ public DiagramCommandProvider() { @Override public DiagramRenderer newSchemaCrawlerCommand(final String command, final Config config) { + final PropertyName commandName = lookupSupportedCommand(command); + if (commandName == null) { + throw new IllegalArgumentException("Cannot support command, " + command); + } final DiagramOptions diagramOptions = DiagramOptionsBuilder.builder().fromConfig(config).toOptions(); - final DiagramRenderer scCommand = new DiagramRenderer(command, new GraphExecutorFactory()); + final DiagramRenderer scCommand = new DiagramRenderer(commandName, new GraphExecutorFactory()); scCommand.configure(diagramOptions); return scCommand; } diff --git a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramRenderer.java b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramRenderer.java index 1e8c67f710..25c60f7038 100644 --- a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramRenderer.java +++ b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/diagram/DiagramRenderer.java @@ -28,12 +28,12 @@ package schemacrawler.tools.command.text.diagram; -import static java.util.Objects.requireNonNull; import static schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat.scdot; import static us.fatehi.utility.IOUtility.createTempFilePath; import static us.fatehi.utility.IOUtility.readResourceFully; import java.io.IOException; import java.nio.file.Path; +import static java.util.Objects.requireNonNull; import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.schemacrawler.exceptions.IORuntimeException; import schemacrawler.schemacrawler.exceptions.SchemaCrawlerException; @@ -47,13 +47,15 @@ import schemacrawler.tools.traversal.SchemaTraversalHandler; import schemacrawler.tools.traversal.SchemaTraverser; import schemacrawler.utility.NamedObjectSort; +import us.fatehi.utility.property.PropertyName; public final class DiagramRenderer extends BaseSchemaCrawlerCommand { private DiagramOutputFormat diagramOutputFormat; private final GraphExecutorFactory graphExecutorFactory; - public DiagramRenderer(final String command, final GraphExecutorFactory graphExecutorFactory) { + public DiagramRenderer( + final PropertyName command, final GraphExecutorFactory graphExecutorFactory) { super(command); this.graphExecutorFactory = requireNonNull(graphExecutorFactory, "No graph executor factory provided"); @@ -152,7 +154,7 @@ private String extractErrorMessage(final Exception e) { private SchemaTextDetailType getSchemaTextDetailType() { SchemaTextDetailType schemaTextDetailType; try { - schemaTextDetailType = SchemaTextDetailType.valueOf(command); + schemaTextDetailType = SchemaTextDetailType.valueOf(command.getName()); } catch (final IllegalArgumentException e) { schemaTextDetailType = null; } diff --git a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramCommandProvider.java b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramCommandProvider.java index 7ac0a43692..ae8fa41a3e 100644 --- a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramCommandProvider.java +++ b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramCommandProvider.java @@ -36,6 +36,7 @@ import schemacrawler.tools.executable.BaseCommandProvider; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; +import us.fatehi.utility.property.PropertyName; public final class EmbeddedDiagramCommandProvider extends BaseCommandProvider { @@ -46,10 +47,15 @@ public EmbeddedDiagramCommandProvider() { @Override public EmbeddedDiagramRenderer newSchemaCrawlerCommand( final String command, final Config config) { + final PropertyName commandName = lookupSupportedCommand(command); + if (commandName == null) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final DiagramOptions diagramOptions = DiagramOptionsBuilder.builder().fromConfig(config).toOptions(); final EmbeddedDiagramRenderer scCommand = - new EmbeddedDiagramRenderer(command, new GraphExecutorFactory()); + new EmbeddedDiagramRenderer(commandName, new GraphExecutorFactory()); scCommand.configure(diagramOptions); return scCommand; } diff --git a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramRenderer.java b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramRenderer.java index 580b434b0a..51c6e955e0 100644 --- a/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramRenderer.java +++ b/schemacrawler-diagram/src/main/java/schemacrawler/tools/command/text/embeddeddiagram/EmbeddedDiagramRenderer.java @@ -58,6 +58,7 @@ import schemacrawler.tools.options.OutputFormat; import schemacrawler.tools.options.OutputOptions; import schemacrawler.tools.options.OutputOptionsBuilder; +import us.fatehi.utility.property.PropertyName; public class EmbeddedDiagramRenderer extends BaseSchemaCrawlerCommand { @@ -90,7 +91,7 @@ private static void insertSvg( private final GraphExecutorFactory graphExecutorFactory; public EmbeddedDiagramRenderer( - final String command, final GraphExecutorFactory graphExecutorFactory) { + final PropertyName command, final GraphExecutorFactory graphExecutorFactory) { super(command); this.graphExecutorFactory = requireNonNull(graphExecutorFactory, "No graph executor factory provided"); diff --git a/schemacrawler-diagram/src/test/java/schemacrawler/tools/command/text/diagram/DiagramRendererTest.java b/schemacrawler-diagram/src/test/java/schemacrawler/tools/command/text/diagram/DiagramRendererTest.java index 853dbbaea4..441b167537 100644 --- a/schemacrawler-diagram/src/test/java/schemacrawler/tools/command/text/diagram/DiagramRendererTest.java +++ b/schemacrawler-diagram/src/test/java/schemacrawler/tools/command/text/diagram/DiagramRendererTest.java @@ -214,7 +214,8 @@ public void diagramRenderer_graphviz( final Catalog catalog = getCatalog(dataSource); commandDiagram( - new DiagramRenderer(SchemaTextDetailType.details.name(), new GraphExecutorFactory()), + new DiagramRenderer( + SchemaTextDetailType.details.toPropertyName(), new GraphExecutorFactory()), dataSource, catalog, diagramOptions, @@ -233,7 +234,8 @@ public void diagramRenderer_graphviz_java( final Catalog catalog = getCatalog(dataSource); commandDiagram( - new DiagramRenderer(SchemaTextDetailType.details.name(), new GraphvizJavaExecutorFactory()), + new DiagramRenderer( + SchemaTextDetailType.details.toPropertyName(), new GraphvizJavaExecutorFactory()), dataSource, catalog, diagramOptions, @@ -254,7 +256,7 @@ public void embeddedDiagramRenderer_graphviz( commandDiagram( new EmbeddedDiagramRenderer( - SchemaTextDetailType.details.name(), new GraphExecutorFactory()), + SchemaTextDetailType.details.toPropertyName(), new GraphExecutorFactory()), dataSource, catalog, diagramOptions, @@ -274,7 +276,7 @@ public void embeddedDiagramRenderer_graphviz_java( commandDiagram( new EmbeddedDiagramRenderer( - SchemaTextDetailType.details.name(), new GraphvizJavaExecutorFactory()), + SchemaTextDetailType.details.toPropertyName(), new GraphvizJavaExecutorFactory()), dataSource, catalog, diagramOptions, diff --git a/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommand.java b/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommand.java index 957723c0d0..a134d17945 100644 --- a/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommand.java +++ b/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommand.java @@ -42,13 +42,18 @@ import schemacrawler.tools.lint.formatter.LintReportTextFormatter; import schemacrawler.tools.lint.formatter.LintReportTextGenerator; import schemacrawler.tools.lint.formatter.LintReportYamlGenerator; +import us.fatehi.utility.property.PropertyName; import us.fatehi.utility.string.ObjectToStringFormat; public class LintCommand extends BaseSchemaCrawlerCommand { private static final Logger LOGGER = Logger.getLogger(LintCommand.class.getName()); - public static final String COMMAND = "lint"; + static final PropertyName COMMAND = + new PropertyName( + "lint", + "Find lints (non-adherence to coding standards and conventions) " + + "in the database schema"); public LintCommand() { super(COMMAND); diff --git a/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommandProvider.java b/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommandProvider.java index 0f10780a60..b75f55abce 100644 --- a/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommandProvider.java +++ b/schemacrawler-lint/src/main/java/schemacrawler/tools/command/lint/LintCommandProvider.java @@ -28,6 +28,7 @@ package schemacrawler.tools.command.lint; +import static schemacrawler.tools.command.lint.LintCommand.COMMAND; import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import java.nio.file.Path; import schemacrawler.tools.command.lint.options.LintOptions; @@ -39,23 +40,18 @@ import schemacrawler.tools.lint.LinterHelp; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; -import us.fatehi.utility.property.PropertyName; public class LintCommandProvider extends BaseCommandProvider { - public static final String DESCRIPTION_HEADER = - "Find lints (non-adherence to coding standards and conventions) " + "in the database schema"; - public LintCommandProvider() { - super(new PropertyName(LintCommand.COMMAND, DESCRIPTION_HEADER)); + super(COMMAND); } @Override public PluginCommand getCommandLineCommand() { final PluginCommand pluginCommand = newPluginCommand( - "lint", - "** " + DESCRIPTION_HEADER, + COMMAND, () -> new String[] { "For more information, see https://www.schemacrawler.com/lint.html %n" @@ -94,6 +90,10 @@ public PluginCommand getHelpCommand() { @Override public LintCommand newSchemaCrawlerCommand(final String command, final Config config) { + if (!supportsCommand(command)) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final LintOptions lintOptions = LintOptionsBuilder.builder().fromConfig(config).toOptions(); final LintCommand scCommand = new LintCommand(); scCommand.configure(lintOptions); diff --git a/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/AbstractLinter.java b/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/AbstractLinter.java index 43fd404c40..8b860a0ade 100644 --- a/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/AbstractLinter.java +++ b/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/AbstractLinter.java @@ -35,6 +35,7 @@ import static java.util.Objects.requireNonNull; import schemacrawler.schema.AttributedObject; import schemacrawler.schema.NamedObject; +import schemacrawler.tools.executable.BaseCommand; import schemacrawler.tools.lint.config.LinterConfig; import schemacrawler.tools.options.Config; import us.fatehi.utility.property.PropertyName; @@ -44,11 +45,10 @@ * Evaluates a catalog and creates lints. This base class has core functionality for maintaining * state, but not for visiting a catalog. Includes code for dispatching a linter. */ -public abstract class AbstractLinter implements Linter { +public abstract class AbstractLinter extends BaseCommand implements Linter { private static final Logger LOGGER = Logger.getLogger(AbstractLinter.class.getName()); - private final PropertyName linterName; private final UUID linterInstanceId; private final LintCollector lintCollector; private LintSeverity severity; @@ -56,7 +56,7 @@ public abstract class AbstractLinter implements Linter { private int lintCount; protected AbstractLinter(final PropertyName linterName, final LintCollector lintCollector) { - this.linterName = requireNonNull(linterName, "Linter name cannot be null"); + super(requireNonNull(linterName, "Linter name not provided")); linterInstanceId = UUID.randomUUID(); this.lintCollector = requireNonNull(lintCollector, "Lint collector cannot be null"); @@ -66,11 +66,10 @@ protected AbstractLinter(final PropertyName linterName, final LintCollector lint @Override public void configure(final LinterConfig linterConfig) { - if (linterConfig != null) { - setSeverity(linterConfig.getSeverity()); - threshold = linterConfig.getThreshold(); - configure(linterConfig.getConfig()); - } + super.configure(linterConfig); + setSeverity(linterConfig.getSeverity()); + threshold = linterConfig.getThreshold(); + configure(linterConfig.getConfig()); } /** @@ -86,7 +85,7 @@ public final boolean exceedsThreshold() { */ @Override public String getDescription() { - return linterName.getDescription(); + return command.getDescription(); } /** @@ -102,7 +101,7 @@ public final int getLintCount() { */ @Override public String getLinterId() { - return linterName.getName(); + return command.getName(); } /** @@ -113,11 +112,6 @@ public final String getLinterInstanceId() { return linterInstanceId.toString(); } - @Override - public final String getName() { - return getLinterId(); - } - /** * @{@inheritDoc} */ diff --git a/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/BaseLinter.java b/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/BaseLinter.java index 35a6de54fa..5ae2db5041 100644 --- a/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/BaseLinter.java +++ b/schemacrawler-lint/src/main/java/schemacrawler/tools/lint/BaseLinter.java @@ -36,15 +36,12 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import static java.util.Objects.requireNonNull; import schemacrawler.filter.TableTypesFilter; import schemacrawler.inclusionrule.IncludeAll; import schemacrawler.inclusionrule.InclusionRule; -import schemacrawler.schema.Catalog; import schemacrawler.schema.Column; import schemacrawler.schema.CrawlInfo; import schemacrawler.schema.Table; -import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.tools.lint.config.LinterConfig; import us.fatehi.utility.property.PropertyName; import us.fatehi.utility.string.StringFormat; @@ -58,8 +55,6 @@ public abstract class BaseLinter extends AbstractLinter { private static final Logger LOGGER = Logger.getLogger(BaseLinter.class.getName()); - private Catalog catalog; - private Connection connection; private InclusionRule tableInclusionRule; private InclusionRule columnInclusionRule; private TableTypesFilter tableTypesFilter; @@ -98,34 +93,11 @@ public final void configure(final LinterConfig linterConfig) { } } - @Override - public Catalog getCatalog() { - return catalog; - } - - @Override - public Connection getConnection() { - return connection; - } - @Override public void initialize() { // Default implementation - NO-OP } - @Override - public void setCatalog(final Catalog catalog) { - this.catalog = requireNonNull(catalog, "No catalog provided"); - } - - @Override - public void setConnection(final Connection connection) { - if (!usesConnection()) { - throw new ExecutionRuntimeException("Linter does not use a connection"); - } - this.connection = requireNonNull(connection, "No connection provided"); - } - protected final void addCatalogLint(final String message) { addLint(LintObjectType.catalog, catalog, message, null); } diff --git a/schemacrawler-loader/src/main/java/schemacrawler/loader/attributes/AttributesCatalogLoader.java b/schemacrawler-loader/src/main/java/schemacrawler/loader/attributes/AttributesCatalogLoader.java index 9f9b9a190c..529a0dbb80 100644 --- a/schemacrawler-loader/src/main/java/schemacrawler/loader/attributes/AttributesCatalogLoader.java +++ b/schemacrawler-loader/src/main/java/schemacrawler/loader/attributes/AttributesCatalogLoader.java @@ -29,13 +29,11 @@ package schemacrawler.loader.attributes; import static schemacrawler.loader.attributes.model.CatalogAttributesUtility.readCatalogAttributes; -import static us.fatehi.utility.Utility.isBlank; - import java.util.Map.Entry; import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; - +import static us.fatehi.utility.Utility.isBlank; import schemacrawler.crawl.AlternateKeyBuilder; import schemacrawler.crawl.AlternateKeyBuilder.AlternateKeyDefinition; import schemacrawler.crawl.WeakAssociationBuilder; @@ -79,9 +77,7 @@ public AttributesCatalogLoader() { @Override public PluginCommand getCommandLineCommand() { final PropertyName catalogLoaderName = getCatalogLoaderName(); - final PluginCommand pluginCommand = - PluginCommand.newCatalogLoaderCommand( - catalogLoaderName.getName(), catalogLoaderName.getDescription()); + final PluginCommand pluginCommand = PluginCommand.newCatalogLoaderCommand(catalogLoaderName); pluginCommand.addOption( OPTION_ATTRIBUTES_FILE, String.class, @@ -161,12 +157,11 @@ private void loadRemarks(final Catalog catalog, final CatalogAttributes catalogA final Optional lookupTable = catalog.lookupTable(tableAttributes.getSchema(), tableAttributes.getName()); final Table table; - if (lookupTable.isPresent()) { - table = lookupTable.get(); - } else { + if (!lookupTable.isPresent()) { LOGGER.log(Level.CONFIG, new StringFormat("Table %s not found", tableAttributes)); continue; } + table = lookupTable.get(); if (tableAttributes.hasRemarks()) { table.setRemarks(tableAttributes.getRemarks()); diff --git a/schemacrawler-loader/src/main/java/schemacrawler/loader/counts/TableRowCountsCatalogLoader.java b/schemacrawler-loader/src/main/java/schemacrawler/loader/counts/TableRowCountsCatalogLoader.java index d072cf08ef..147663ecef 100644 --- a/schemacrawler-loader/src/main/java/schemacrawler/loader/counts/TableRowCountsCatalogLoader.java +++ b/schemacrawler-loader/src/main/java/schemacrawler/loader/counts/TableRowCountsCatalogLoader.java @@ -29,10 +29,8 @@ package schemacrawler.loader.counts; import static schemacrawler.filter.ReducerFactory.getTableReducer; - import java.util.logging.Level; import java.util.logging.Logger; - import schemacrawler.schema.Catalog; import schemacrawler.schema.Table; import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; @@ -59,9 +57,7 @@ public TableRowCountsCatalogLoader() { @Override public PluginCommand getCommandLineCommand() { final PropertyName catalogLoaderName = getCatalogLoaderName(); - final PluginCommand pluginCommand = - PluginCommand.newCatalogLoaderCommand( - catalogLoaderName.getName(), catalogLoaderName.getDescription()); + final PluginCommand pluginCommand = PluginCommand.newCatalogLoaderCommand(catalogLoaderName); pluginCommand .addOption( OPTION_LOAD_ROW_COUNTS, diff --git a/schemacrawler-loader/src/main/java/schemacrawler/loader/weakassociations/WeakAssociationsCatalogLoader.java b/schemacrawler-loader/src/main/java/schemacrawler/loader/weakassociations/WeakAssociationsCatalogLoader.java index e655a1eafe..8e8e910c68 100644 --- a/schemacrawler-loader/src/main/java/schemacrawler/loader/weakassociations/WeakAssociationsCatalogLoader.java +++ b/schemacrawler-loader/src/main/java/schemacrawler/loader/weakassociations/WeakAssociationsCatalogLoader.java @@ -64,9 +64,7 @@ public WeakAssociationsCatalogLoader() { @Override public PluginCommand getCommandLineCommand() { final PropertyName catalogLoaderName = getCatalogLoaderName(); - final PluginCommand pluginCommand = - PluginCommand.newCatalogLoaderCommand( - catalogLoaderName.getName(), catalogLoaderName.getDescription()); + final PluginCommand pluginCommand = PluginCommand.newCatalogLoaderCommand(catalogLoaderName); pluginCommand.addOption( OPTION_WEAK_ASSOCIATIONS, Boolean.class, diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/CommandChain.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/CommandChain.java index dfacd6309d..a45034baf7 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/CommandChain.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/CommandChain.java @@ -45,6 +45,7 @@ import schemacrawler.tools.options.LanguageOptions; import schemacrawler.tools.options.OutputOptions; import schemacrawler.tools.options.OutputOptionsBuilder; +import us.fatehi.utility.property.PropertyName; /** * Allows chaining multiple executables together, that produce different artifacts, such as an image @@ -52,7 +53,9 @@ */ public final class CommandChain extends BaseSchemaCrawlerCommand { - private static final String COMMAND = "chain"; + private static final PropertyName COMMAND = + new PropertyName( + "chain", "Runs SchemaCrawler commands sequentially, each relying on the previous one"); private static final Logger LOGGER = Logger.getLogger(CommandChain.class.getName()); diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommand.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommand.java index 6866b3009f..6f1573a6e9 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommand.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommand.java @@ -42,6 +42,7 @@ import schemacrawler.tools.executable.BaseSchemaCrawlerCommand; import schemacrawler.tools.registry.ScriptEngineRegistry; import us.fatehi.utility.ioresource.InputResource; +import us.fatehi.utility.property.PropertyName; import us.fatehi.utility.string.StringFormat; /** Main executor for the script engine integration. */ @@ -49,7 +50,9 @@ public final class ScriptCommand extends BaseSchemaCrawlerCommand private static final Logger LOGGER = Logger.getLogger(ScriptCommand.class.getName()); - static final String COMMAND = "script"; + static final PropertyName COMMAND = + new PropertyName( + "script", "Process a script file, such as JavaScript, against the database schema"); private ScriptExecutor scriptExecutor; diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommandProvider.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommandProvider.java index 32f620b8bf..dd14131c41 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommandProvider.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/script/ScriptCommandProvider.java @@ -28,6 +28,7 @@ package schemacrawler.tools.command.script; +import static schemacrawler.tools.command.script.ScriptCommand.COMMAND; import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import schemacrawler.tools.command.script.options.ScriptLanguageOptionsBuilder; import schemacrawler.tools.command.script.options.ScriptOptions; @@ -35,21 +36,16 @@ import schemacrawler.tools.executable.commandline.PluginCommand; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; -import us.fatehi.utility.property.PropertyName; public class ScriptCommandProvider extends BaseCommandProvider { - public static final String DESCRIPTION_HEADER = - "Process a script file, such as JavaScript, " + "against the database schema"; - public ScriptCommandProvider() { - super(new PropertyName(ScriptCommand.COMMAND, DESCRIPTION_HEADER)); + super(COMMAND); } @Override public PluginCommand getCommandLineCommand() { - final PluginCommand pluginCommand = - newPluginCommand(ScriptCommand.COMMAND, "** " + DESCRIPTION_HEADER); + final PluginCommand pluginCommand = newPluginCommand(COMMAND); pluginCommand .addOption("script", String.class, "Path to the script file or to the CLASSPATH resource") .addOption("script-language", String.class, "Scripting language"); @@ -58,6 +54,10 @@ public PluginCommand getCommandLineCommand() { @Override public ScriptCommand newSchemaCrawlerCommand(final String command, final Config config) { + if (!supportsCommand(command)) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final ScriptOptions scriptOptions = ScriptLanguageOptionsBuilder.builder().fromConfig(config).toOptions(); diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommand.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommand.java index 1d237cccf1..3f244efbae 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommand.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommand.java @@ -45,11 +45,13 @@ import schemacrawler.tools.executable.BaseSchemaCrawlerCommand; import schemacrawler.tools.formatter.serialize.CatalogSerializer; import schemacrawler.tools.options.OutputOptionsBuilder; +import us.fatehi.utility.property.PropertyName; /** Main executor for the serialization integration. */ public final class SerializationCommand extends BaseSchemaCrawlerCommand { - static final String COMMAND = "serialize"; + static final PropertyName COMMAND = + new PropertyName("serialize", "Create an offline catalog snapshot"); public SerializationCommand() { super(COMMAND); diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommandProvider.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommandProvider.java index 72575d42be..2bb81ca4e4 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommandProvider.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/serialize/SerializationCommandProvider.java @@ -28,6 +28,7 @@ package schemacrawler.tools.command.serialize; +import static schemacrawler.tools.command.serialize.SerializationCommand.COMMAND; import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import schemacrawler.tools.command.serialize.options.SerializationFormat; import schemacrawler.tools.command.serialize.options.SerializationOptions; @@ -35,22 +36,18 @@ import schemacrawler.tools.executable.commandline.PluginCommand; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; -import us.fatehi.utility.property.PropertyName; public class SerializationCommandProvider extends BaseCommandProvider { - private static final String DESCRIPTION_HEADER = "Create an offline catalog snapshot"; - public SerializationCommandProvider() { - super(new PropertyName(SerializationCommand.COMMAND, DESCRIPTION_HEADER)); + super(COMMAND); } @Override public PluginCommand getCommandLineCommand() { final PluginCommand pluginCommand = newPluginCommand( - SerializationCommand.COMMAND, - "** " + DESCRIPTION_HEADER, + COMMAND, () -> new String[] { "For more information, see https://www.schemacrawler.com/serialize.html %n" diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommand.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommand.java index dab8312fed..05740528ce 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommand.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommand.java @@ -28,19 +28,20 @@ package schemacrawler.tools.command.template; -import static java.util.Objects.requireNonNull; - import java.util.HashMap; import java.util.Map; - +import static java.util.Objects.requireNonNull; import schemacrawler.schemacrawler.exceptions.InternalRuntimeException; import schemacrawler.tools.command.template.options.TemplateLanguageType; import schemacrawler.tools.executable.BaseSchemaCrawlerCommand; import schemacrawler.tools.options.LanguageOptions; +import us.fatehi.utility.property.PropertyName; public final class TemplateCommand extends BaseSchemaCrawlerCommand { - static final String COMMAND = "template"; + static final PropertyName COMMAND = + new PropertyName( + "template", "Process a template file, such as Freemarker, against the database schema"); public TemplateCommand() { super(COMMAND); diff --git a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommandProvider.java b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommandProvider.java index 1ca529814f..a52d6c4c73 100644 --- a/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommandProvider.java +++ b/schemacrawler-scripting/src/main/java/schemacrawler/tools/command/template/TemplateCommandProvider.java @@ -28,6 +28,7 @@ package schemacrawler.tools.command.template; +import static schemacrawler.tools.command.template.TemplateCommand.COMMAND; import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import schemacrawler.tools.command.template.options.TemplateLanguageOptionsBuilder; import schemacrawler.tools.command.template.options.TemplateLanguageType; @@ -36,21 +37,16 @@ import schemacrawler.tools.options.Config; import schemacrawler.tools.options.LanguageOptions; import schemacrawler.tools.options.OutputOptions; -import us.fatehi.utility.property.PropertyName; public class TemplateCommandProvider extends BaseCommandProvider { - public static final String DESCRIPTION_HEADER = - "Process a template file, such as Freemarker, " + "against the database schema"; - public TemplateCommandProvider() { - super(new PropertyName(TemplateCommand.COMMAND, DESCRIPTION_HEADER)); + super(COMMAND); } @Override public PluginCommand getCommandLineCommand() { - final PluginCommand pluginCommand = - newPluginCommand(TemplateCommand.COMMAND, "** " + DESCRIPTION_HEADER); + final PluginCommand pluginCommand = newPluginCommand(COMMAND); pluginCommand .addOption( "template", String.class, "Path to the template file or to the CLASSPATH resource") @@ -60,6 +56,10 @@ public PluginCommand getCommandLineCommand() { @Override public TemplateCommand newSchemaCrawlerCommand(final String command, final Config config) { + if (!supportsCommand(command)) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final LanguageOptions toOptions = TemplateLanguageOptionsBuilder.builder().fromConfig(config).toOptions(); diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommand.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommand.java index 610dacf8cc..33011378cb 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommand.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommand.java @@ -52,12 +52,13 @@ import schemacrawler.tools.text.formatter.operation.DataTextFormatter; import schemacrawler.tools.traversal.DataTraversalHandler; import schemacrawler.utility.NamedObjectSort; +import us.fatehi.utility.property.PropertyName; import us.fatehi.utility.string.StringFormat; public final class OperationCommand extends BaseSchemaCrawlerCommand { private static final Logger LOGGER = Logger.getLogger(OperationCommand.class.getName()); - public OperationCommand(final String command) { + public OperationCommand(final PropertyName command) { super(command); } @@ -75,7 +76,7 @@ public void execute() { Level.INFO, new StringFormat( "Output format <%s> not supported for command <%s>", - outputOptions.getOutputFormatValue(), getCommand())); + outputOptions.getOutputFormatValue(), getCommandName().getName())); return; } diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommandProvider.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommandProvider.java index eadacb03eb..afc316dccc 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommandProvider.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/OperationCommandProvider.java @@ -55,10 +55,20 @@ public OperationCommandProvider() { @Override public OperationCommand newSchemaCrawlerCommand(final String command, final Config config) { + final PropertyName commandName; + if (isNamedQuery(command, config)) { + commandName = new PropertyName(command); + } else { + commandName = lookupSupportedCommand(command); + } + if (commandName == null) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final OperationOptions operationOptions = OperationOptionsBuilder.builder().withCommand(command).fromConfig(config).toOptions(); - final OperationCommand scCommand = new OperationCommand(command); + final OperationCommand scCommand = new OperationCommand(commandName); scCommand.configure(operationOptions); return scCommand; } @@ -76,7 +86,20 @@ public boolean supportsSchemaCrawlerCommand( final OutputOptions outputOptions) { // Check if the command is an operation final boolean isOperation = supportsCommand(command); + // Check if the command is a query + final boolean isNamedQuery = isNamedQuery(command, additionalConfig); + + // Operation and query output is only in text or HTML, + // but nevertheless some operations such as count can be + // represented on diagrams (since the catalog is annotated with attributes). + // Also, if a query is part of a comma-separated list of commands, + // the run should not fail due to a bad output format. + // So no check is done for output format. + final boolean supportsSchemaCrawlerCommand = isOperation || isNamedQuery; + return supportsSchemaCrawlerCommand; + } + private boolean isNamedQuery(final String command, final Config additionalConfig) { /// Check if the command is a named query final boolean isNamedQuery; if (additionalConfig != null) { @@ -84,14 +107,6 @@ public boolean supportsSchemaCrawlerCommand( } else { isNamedQuery = false; } - - // Operation and query output is only in text or HTMl, but nevertheless some operations such as - // count - // can be represented on diagrams (since the catalog is annotated with attributes). - // Also, if a query is part of a comma-separated list of commands, the run should not fail due - // to a bad output format. - // So no check is done for output format. - final boolean supportsSchemaCrawlerCommand = isOperation || isNamedQuery; - return supportsSchemaCrawlerCommand; + return isNamedQuery; } } diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/options/OperationType.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/options/OperationType.java index 899a58e28e..fc54c1b566 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/options/OperationType.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/operation/options/OperationType.java @@ -34,11 +34,11 @@ public enum OperationType implements Operation { /** Count operation */ - count("Row Count", "Shows counts of rows in the tables", "SELECT COUNT(*) FROM ${table}"), + count("Row Count", "Show counts of rows in the tables", "SELECT COUNT(*) FROM ${table}"), /** Dump operation */ dump( "Dump", - "Shows data from all rows in the tables", + "Show data from all rows in the tables", "SELECT ${columns} FROM ${table} ORDER BY ${orderbycolumns}"), /** * Quick dump operation, where columns do not need to be retrieved (minimum infolevel), but the @@ -46,7 +46,7 @@ public enum OperationType implements Operation { */ quickdump( "Dump", - "Shows data from all rows in the tables, " + "Show data from all rows in the tables, " + "but row order is not guaranteed - " + "this can be used with a minimum info-level for speed", "SELECT * FROM ${table}"), diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextCommandProvider.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextCommandProvider.java index 8480a08881..d6eef4abbd 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextCommandProvider.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextCommandProvider.java @@ -31,6 +31,7 @@ import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import schemacrawler.tools.command.text.schema.options.CommandProviderUtility; import schemacrawler.tools.command.text.schema.options.PortableType; +import schemacrawler.tools.command.text.schema.options.SchemaTextDetailType; import schemacrawler.tools.command.text.schema.options.SchemaTextOptions; import schemacrawler.tools.command.text.schema.options.SchemaTextOptionsBuilder; import schemacrawler.tools.command.text.schema.options.TextOutputFormat; @@ -38,12 +39,10 @@ import schemacrawler.tools.executable.commandline.PluginCommand; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; +import us.fatehi.utility.property.PropertyName; public final class SchemaTextCommandProvider extends BaseCommandProvider { - private static final String DESCRIPTION_HEADER = - "Generate text output to show details of a schema"; - public SchemaTextCommandProvider() { super(CommandProviderUtility.schemaTextCommands()); } @@ -53,8 +52,7 @@ public PluginCommand getCommandLineCommand() { final PluginCommand pluginCommand = newPluginCommand( - "schema", - "** " + DESCRIPTION_HEADER, + SchemaTextDetailType.schema.toPropertyName(), () -> new String[] {"Applies to all commands that show schema information"}, () -> new String[0]); @@ -112,10 +110,15 @@ public PluginCommand getCommandLineCommand() { @Override public SchemaTextRenderer newSchemaCrawlerCommand(final String command, final Config config) { + final PropertyName commandName = lookupSupportedCommand(command); + if (commandName == null) { + throw new IllegalArgumentException("Cannot support command, " + command); + } + final SchemaTextOptions schemaTextOptions = SchemaTextOptionsBuilder.builder().fromConfig(config).toOptions(); - final SchemaTextRenderer scCommand = new SchemaTextRenderer(command); + final SchemaTextRenderer scCommand = new SchemaTextRenderer(commandName); scCommand.configure(schemaTextOptions); return scCommand; } diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextRenderer.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextRenderer.java index 8a1bd8ebe7..ed835e66c4 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextRenderer.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/SchemaTextRenderer.java @@ -36,11 +36,12 @@ import schemacrawler.tools.traversal.SchemaTraversalHandler; import schemacrawler.tools.traversal.SchemaTraverser; import schemacrawler.utility.NamedObjectSort; +import us.fatehi.utility.property.PropertyName; /** Basic SchemaCrawler executor for text output. */ public final class SchemaTextRenderer extends BaseSchemaCrawlerCommand { - public SchemaTextRenderer(final String command) { + public SchemaTextRenderer(final PropertyName command) { super(command); } @@ -74,7 +75,7 @@ public boolean usesConnection() { private SchemaTextDetailType getSchemaTextDetailType() { SchemaTextDetailType schemaTextDetailType; try { - schemaTextDetailType = SchemaTextDetailType.valueOf(command); + schemaTextDetailType = SchemaTextDetailType.valueOf(command.getName()); } catch (final IllegalArgumentException e) { schemaTextDetailType = SchemaTextDetailType.schema; } diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/CommandProviderUtility.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/CommandProviderUtility.java index 149d756391..7e44aead87 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/CommandProviderUtility.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/CommandProviderUtility.java @@ -37,8 +37,7 @@ public class CommandProviderUtility { public static Collection schemaTextCommands() { final Collection supportedCommands = new ArrayList<>(); for (final SchemaTextDetailType schemaTextDetailType : SchemaTextDetailType.values()) { - supportedCommands.add( - new PropertyName(schemaTextDetailType.name(), schemaTextDetailType.getDescription())); + supportedCommands.add(schemaTextDetailType.toPropertyName()); } return supportedCommands; } diff --git a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/SchemaTextDetailType.java b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/SchemaTextDetailType.java index 591ca3df21..2a42dd5fd4 100644 --- a/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/SchemaTextDetailType.java +++ b/schemacrawler-text/src/main/java/schemacrawler/tools/command/text/schema/options/SchemaTextDetailType.java @@ -28,21 +28,23 @@ package schemacrawler.tools.command.text.schema.options; +import us.fatehi.utility.property.PropertyName; + /** Enumeration for level of schema text output detail. */ public enum SchemaTextDetailType { brief( - "Shows basic schema information, " + "Show basic schema information, " + "for tables, views and routines, columns, " + "primary keys, and foreign keys"), schema( - "Shows the commonly needed detail of the schema, " + "Show the commonly needed detail of the schema, " + "including details of tables, views and routines, columns, " + "primary keys, indexes, foreign keys, and triggers"), details( - "Shows maximum possible detail of the schema, " + "Show maximum possible detail of the schema, " + "including privileges, and details of privileges, triggers, " + "and check constraints"), - list("Shows a list of schema objects"); + list("Show a list of schema objects"); private final String description; @@ -50,7 +52,7 @@ public enum SchemaTextDetailType { this.description = description; } - public String getDescription() { - return description; + public PropertyName toPropertyName() { + return new PropertyName(name(), description); } } diff --git a/schemacrawler-text/src/test/java/schemacrawler/crawl/TextFormatterCoverageTest.java b/schemacrawler-text/src/test/java/schemacrawler/crawl/TextFormatterCoverageTest.java index 163ffc2854..9bc4885019 100644 --- a/schemacrawler-text/src/test/java/schemacrawler/crawl/TextFormatterCoverageTest.java +++ b/schemacrawler-text/src/test/java/schemacrawler/crawl/TextFormatterCoverageTest.java @@ -29,18 +29,16 @@ package schemacrawler.crawl; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; import static schemacrawler.test.utility.FileHasContent.classpathResource; import static schemacrawler.test.utility.FileHasContent.hasNoContent; import static schemacrawler.test.utility.FileHasContent.hasSameContentAs; import static schemacrawler.test.utility.FileHasContent.outputOf; -import static us.fatehi.utility.Utility.isBlank; import java.util.Arrays; import java.util.function.Consumer; import org.junit.jupiter.api.Test; +import static us.fatehi.utility.Utility.isBlank; import schemacrawler.schema.CrawlInfo; import schemacrawler.schema.DataTypeType; -import schemacrawler.schema.DatabaseInfo; import schemacrawler.schema.Table; import schemacrawler.schemacrawler.Identifiers; import schemacrawler.schemacrawler.SchemaReference; @@ -110,10 +108,14 @@ public void hiddenColumnTable(final TestContext testContext) throws Exception { @Test public void nullCrawlInfo(final TestContext testContext) throws Exception { + final MutableDatabaseInfo dbInfo = new MutableDatabaseInfo("FakeDB", "v0.0", "nouser"); + dbInfo.addServerInfo( + new ImmutableServerInfoProperty("PROP1", "VALUE1", "Server info property")); + checkTextOutput( formatter -> { formatter.handleHeader((CrawlInfo) null); - formatter.handleInfo(mock(DatabaseInfo.class)); + formatter.handleInfo(dbInfo); }, testContext.testMethodFullName()); } diff --git a/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderHelpCommand b/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderHelpCommand index 0f19dbc9e5..caf034d4d3 100644 --- a/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderHelpCommand +++ b/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderHelpCommand @@ -1,6 +1,6 @@ command:schema -** Generate text output to show details of a schema +** Show the commonly needed detail of the schema, including details of tables, views and routines, columns, primary keys, indexes, foreign keys, and triggers Applies to all commands that show schema information no-info diff --git a/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderPluginCommand b/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderPluginCommand index 0f19dbc9e5..caf034d4d3 100644 --- a/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderPluginCommand +++ b/schemacrawler-text/src/test/resources/PluginCommandTest.testSchemaTextCommandProviderPluginCommand @@ -1,6 +1,6 @@ command:schema -** Generate text output to show details of a schema +** Show the commonly needed detail of the schema, including details of tables, views and routines, columns, primary keys, indexes, foreign keys, and triggers Applies to all commands that show schema information no-info diff --git a/schemacrawler-text/src/test/resources/formatter_coverage/TextFormatterCoverageTest.nullCrawlInfo.txt b/schemacrawler-text/src/test/resources/formatter_coverage/TextFormatterCoverageTest.nullCrawlInfo.txt index 6b56e206b1..cd7cb93ac1 100644 --- a/schemacrawler-text/src/test/resources/formatter_coverage/TextFormatterCoverageTest.nullCrawlInfo.txt +++ b/schemacrawler-text/src/test/resources/formatter_coverage/TextFormatterCoverageTest.nullCrawlInfo.txt @@ -1,7 +1,12 @@ +Database Server Information +-=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=- +PROP1 VALUE1 + + Database Information -=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=- -database product name -database product version -database user name +database product name FakeDB +database product version v0.0 +database user name nouser diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/databaseconnector/DatabaseConnector.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/databaseconnector/DatabaseConnector.java index 41c228eda8..449cda167c 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/databaseconnector/DatabaseConnector.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/databaseconnector/DatabaseConnector.java @@ -37,7 +37,6 @@ import java.util.function.Supplier; import static java.util.Objects.requireNonNull; import static us.fatehi.utility.Utility.isBlank; -import static us.fatehi.utility.Utility.trimToEmpty; import schemacrawler.schemacrawler.DatabaseServerType; import schemacrawler.schemacrawler.InformationSchemaViews; import schemacrawler.schemacrawler.InformationSchemaViewsBuilder; @@ -100,10 +99,7 @@ public final DatabaseServerType getDatabaseServerType() { public PluginCommand getHelpCommand() { - final PluginCommand pluginCommand = - newDatabasePluginCommand( - dbServerType.getDatabaseSystemIdentifier(), - "** Connect to " + trimToEmpty(dbServerType.getDatabaseSystemName())); + final PluginCommand pluginCommand = newDatabasePluginCommand(dbServerType); return pluginCommand; } diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommand.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommand.java new file mode 100644 index 0000000000..7f7e228720 --- /dev/null +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommand.java @@ -0,0 +1,93 @@ +/* +======================================================================== +SchemaCrawler +http://www.schemacrawler.com +Copyright (c) 2000-2025, Sualeh Fatehi . +All rights reserved. +------------------------------------------------------------------------ + +SchemaCrawler is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +SchemaCrawler and the accompanying materials are made available under +the terms of the Eclipse Public License v1.0, GNU General Public License +v3 or GNU Lesser General Public License v3. + +You may elect to redistribute this code under any of these licenses. + +The Eclipse Public License is available at: +http://www.eclipse.org/legal/epl-v10.html + +The GNU General Public License v3 and the GNU Lesser General Public +License v3 are available at: +http://www.gnu.org/licenses/ + +======================================================================== +*/ + +package schemacrawler.tools.executable; + +import java.sql.Connection; +import static java.util.Objects.requireNonNull; +import schemacrawler.schema.Catalog; +import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; +import us.fatehi.utility.property.PropertyName; + +/** A SchemaCrawler tools executable unit. */ +public abstract class BaseCommand implements Command { + + protected final PropertyName command; + protected C commandOptions; + protected Catalog catalog; + protected Connection connection; + + protected BaseCommand(final PropertyName command) { + this.command = requireNonNull(command, "No command specified"); + } + + @Override + public void configure(final C commandOptions) { + this.commandOptions = requireNonNull(commandOptions, "No command options provided"); + } + + @Override + public final Catalog getCatalog() { + return catalog; + } + + @Override + public final Connection getConnection() { + return connection; + } + + @Override + public final PropertyName getCommandName() { + return command; + } + + @Override + public void initialize() { + // No-op by default + } + + @Override + public final void setCatalog(final Catalog catalog) { + this.catalog = requireNonNull(catalog, "No catalog provided"); + } + + @Override + public final void setConnection(final Connection connection) { + if (!usesConnection()) { + throw new ExecutionRuntimeException( + String.format("<%s> does not use a connection", command.getName())); + } + this.connection = connection; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return command.toString(); + } +} diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommandProvider.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommandProvider.java index bfc9006df9..e73e1952e6 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommandProvider.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseCommandProvider.java @@ -28,12 +28,12 @@ package schemacrawler.tools.executable; -import static java.util.Objects.requireNonNull; -import static us.fatehi.utility.Utility.isBlank; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.function.Predicate; +import static java.util.Objects.requireNonNull; +import static us.fatehi.utility.Utility.isBlank; import schemacrawler.schemacrawler.SchemaCrawlerOptions; import schemacrawler.tools.executable.commandline.PluginCommand; import schemacrawler.tools.options.Config; @@ -71,18 +71,19 @@ public boolean supportsSchemaCrawlerCommand( } protected final boolean supportsCommand(final String command) { + return lookupSupportedCommand(command) != null; + } + + protected final PropertyName lookupSupportedCommand(final String command) { if (isBlank(command)) { - return false; + return null; } for (final PropertyName supportedCommand : supportedCommands) { - if (supportedCommand == null) { - continue; - } - if (command.equalsIgnoreCase(supportedCommand.getName())) { - return true; + if (supportedCommand != null && command.equalsIgnoreCase(supportedCommand.getName())) { + return supportedCommand; } } - return false; + return null; } protected boolean supportsOutputFormat( diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseSchemaCrawlerCommand.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseSchemaCrawlerCommand.java index 21be90cc69..36dc2db2f0 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseSchemaCrawlerCommand.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/BaseSchemaCrawlerCommand.java @@ -28,31 +28,24 @@ package schemacrawler.tools.executable; -import java.sql.Connection; import static java.util.Objects.requireNonNull; -import static us.fatehi.utility.Utility.requireNotBlank; -import schemacrawler.schema.Catalog; import schemacrawler.schemacrawler.Identifiers; import schemacrawler.schemacrawler.SchemaCrawlerOptions; import schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder; -import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.tools.options.OutputOptions; import schemacrawler.tools.options.OutputOptionsBuilder; +import us.fatehi.utility.property.PropertyName; /** A SchemaCrawler tools executable unit. */ public abstract class BaseSchemaCrawlerCommand - implements SchemaCrawlerCommand { + extends BaseCommand implements SchemaCrawlerCommand { - protected final String command; - protected C commandOptions; - protected Catalog catalog; - protected Connection connection; protected Identifiers identifiers; protected OutputOptions outputOptions; protected SchemaCrawlerOptions schemaCrawlerOptions; - protected BaseSchemaCrawlerCommand(final String command) { - this.command = requireNotBlank(command, "No command specified"); + protected BaseSchemaCrawlerCommand(final PropertyName command) { + super(command); schemaCrawlerOptions = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions(); outputOptions = OutputOptionsBuilder.newOutputOptions(); @@ -73,37 +66,16 @@ public final void configure(final C commandOptions) { this.commandOptions = requireNonNull(commandOptions, "No command options provided"); } - @Override - public Catalog getCatalog() { - return catalog; - } - - /** {@inheritDoc} */ - @Override - public final String getCommand() { - return command; - } - @Override public final C getCommandOptions() { return commandOptions; } - @Override - public Connection getConnection() { - return connection; - } - @Override public Identifiers getIdentifiers() { return identifiers; } - @Override - public final String getName() { - return getCommand(); - } - /** {@inheritDoc} */ @Override public final OutputOptions getOutputOptions() { @@ -121,19 +93,6 @@ public void initialize() { checkOptions(); } - @Override - public void setCatalog(final Catalog catalog) { - this.catalog = catalog; - } - - @Override - public void setConnection(final Connection connection) { - if (!usesConnection()) { - throw new ExecutionRuntimeException("SchemaCrawler command does not use a connection"); - } - this.connection = connection; - } - @Override public void setIdentifiers(final Identifiers identifiers) { this.identifiers = identifiers; @@ -159,12 +118,6 @@ public final void setSchemaCrawlerOptions(final SchemaCrawlerOptions schemaCrawl } } - /** {@inheritDoc} */ - @Override - public final String toString() { - return command; - } - protected void checkCatalog() { requireNonNull(catalog, "No database catalog provided"); if (usesConnection()) { diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/Command.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/Command.java index 62b88c73e0..58737c8384 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/Command.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/Command.java @@ -31,6 +31,7 @@ import java.sql.Connection; import java.util.concurrent.Callable; import schemacrawler.schema.Catalog; +import us.fatehi.utility.property.PropertyName; /** A SchemaCrawler executable unit. */ public interface Command extends Callable { @@ -41,7 +42,7 @@ public interface Command extends Callable { Connection getConnection(); - String getName(); + PropertyName getCommandName(); /** Initializes the command for execution. */ void initialize(); diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/CommandRegistry.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/CommandRegistry.java index aefc96a36b..3d10e70dd2 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/CommandRegistry.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/CommandRegistry.java @@ -41,7 +41,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import schemacrawler.schemacrawler.SchemaCrawlerOptions; -import schemacrawler.schemacrawler.exceptions.ConfigurationException; import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.schemacrawler.exceptions.InternalRuntimeException; import schemacrawler.tools.executable.commandline.PluginCommand; @@ -217,7 +216,7 @@ private void findSupportedOutputFormats( } } if (executableCommandProviders.isEmpty()) { - throw new ConfigurationException( + throw new ExecutionRuntimeException( String.format( "Output format <%s> not supported for command <%s>", outputOptions.getOutputFormatValue(), command)); diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/SchemaCrawlerCommand.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/SchemaCrawlerCommand.java index b36db7268c..8b2674fa4a 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/SchemaCrawlerCommand.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/SchemaCrawlerCommand.java @@ -46,8 +46,6 @@ public interface SchemaCrawlerCommand extends Command< */ void execute(); - String getCommand(); - C getCommandOptions(); Identifiers getIdentifiers(); diff --git a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/commandline/PluginCommand.java b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/commandline/PluginCommand.java index 06308c1e34..f8c3dcbb18 100644 --- a/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/commandline/PluginCommand.java +++ b/schemacrawler-tools/src/main/java/schemacrawler/tools/executable/commandline/PluginCommand.java @@ -42,7 +42,9 @@ import java.util.function.Supplier; import static java.util.Objects.requireNonNull; import static us.fatehi.utility.Utility.trimToEmpty; +import schemacrawler.schemacrawler.DatabaseServerType; import us.fatehi.utility.Nullable; +import us.fatehi.utility.property.PropertyName; public class PluginCommand implements Iterable { @@ -50,24 +52,27 @@ public static PluginCommand empty() { return new PluginCommand(unknown, "unknown", null, null, null); } - public static PluginCommand newCatalogLoaderCommand(final String name, final String helpHeader) { - return newPluginCommand(loader, name, helpHeader); + public static PluginCommand newCatalogLoaderCommand(final PropertyName name) { + return newPluginCommand(loader, name.getName(), "** " + name.getDescription()); } - public static PluginCommand newDatabasePluginCommand(final String name, final String helpHeader) { - return newPluginCommand(server, name, helpHeader); + public static PluginCommand newDatabasePluginCommand(final DatabaseServerType dbServerType) { + return newPluginCommand( + server, + dbServerType.getDatabaseSystemIdentifier(), + "** Connect to " + trimToEmpty(dbServerType.getDatabaseSystemName())); } - public static PluginCommand newPluginCommand(final String name, final String helpHeader) { - return newPluginCommand(command, name, helpHeader); + public static PluginCommand newPluginCommand(final PropertyName name) { + return newPluginCommand(command, name.getName(), "** " + name.getDescription()); } public static PluginCommand newPluginCommand( - final String name, - final String helpHeader, + final PropertyName name, @Nullable final Supplier helpDescription, @Nullable final Supplier helpFooter) { - return new PluginCommand(command, name, helpHeader, helpDescription, helpFooter); + return new PluginCommand( + command, name.getName(), "** " + name.getDescription(), helpDescription, helpFooter); } private static PluginCommand newPluginCommand( diff --git a/schemacrawler-tools/src/test/java/schemacrawler/test/CommandRegistryTest.java b/schemacrawler-tools/src/test/java/schemacrawler/test/CommandRegistryTest.java index cc31661658..d8438952f6 100644 --- a/schemacrawler-tools/src/test/java/schemacrawler/test/CommandRegistryTest.java +++ b/schemacrawler-tools/src/test/java/schemacrawler/test/CommandRegistryTest.java @@ -9,7 +9,6 @@ import static schemacrawler.test.utility.PluginRegistryTestUtility.reload; import java.util.Collection; import org.junit.jupiter.api.Test; -import schemacrawler.schemacrawler.exceptions.ConfigurationException; import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.schemacrawler.exceptions.InternalRuntimeException; import schemacrawler.test.utility.testcommand.TestCommandProvider; @@ -36,7 +35,7 @@ public void configureNewCommand() { final OutputOptions outputOptions = OutputOptionsBuilder.builder().withOutputFormatValue("unknown-output-format").toOptions(); assertThrows( - ConfigurationException.class, + ExecutionRuntimeException.class, () -> commandRegistry.configureNewCommand("test-command", null, null, outputOptions)); } diff --git a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/TestCatalogLoader.java b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/TestCatalogLoader.java index 1efc9db349..1046a4dd83 100644 --- a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/TestCatalogLoader.java +++ b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/TestCatalogLoader.java @@ -43,9 +43,7 @@ public TestCatalogLoader() { @Override public PluginCommand getCommandLineCommand() { final PropertyName catalogLoaderName = getCatalogLoaderName(); - final PluginCommand pluginCommand = - PluginCommand.newCatalogLoaderCommand( - catalogLoaderName.getName(), catalogLoaderName.getDescription()); + final PluginCommand pluginCommand = PluginCommand.newCatalogLoaderCommand(catalogLoaderName); pluginCommand.addOption( "test-load-option", Boolean.class, diff --git a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommand.java b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommand.java index bad81949a0..74a31ad968 100644 --- a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommand.java +++ b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommand.java @@ -30,10 +30,12 @@ import java.io.PrintWriter; import schemacrawler.tools.executable.BaseSchemaCrawlerCommand; +import us.fatehi.utility.property.PropertyName; public final class TestCommand extends BaseSchemaCrawlerCommand { - static final String COMMAND = "test-command"; + static final PropertyName COMMAND = + new PropertyName("test-command", "Test command which is not deployed with the release"); public TestCommand() { super(COMMAND); diff --git a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommandProvider.java b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommandProvider.java index ffeb4755c9..87105c151e 100644 --- a/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommandProvider.java +++ b/schemacrawler-tools/src/test/java/schemacrawler/test/utility/testcommand/TestCommandProvider.java @@ -28,27 +28,23 @@ package schemacrawler.test.utility.testcommand; +import static schemacrawler.test.utility.testcommand.TestCommand.COMMAND; import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand; import schemacrawler.tools.executable.BaseCommandProvider; import schemacrawler.tools.executable.commandline.PluginCommand; import schemacrawler.tools.options.Config; import schemacrawler.tools.options.OutputOptions; -import us.fatehi.utility.property.PropertyName; public class TestCommandProvider extends BaseCommandProvider { - public static final String DESCRIPTION_HEADER = - "Test command which is not deployed with the release"; - public TestCommandProvider() { - super(new PropertyName(TestCommand.COMMAND, DESCRIPTION_HEADER)); + super(COMMAND); forceInstantiationFailureIfConfigured(); } @Override public PluginCommand getCommandLineCommand() { - final PluginCommand pluginCommand = - newPluginCommand(TestCommand.COMMAND, "** " + DESCRIPTION_HEADER); + final PluginCommand pluginCommand = newPluginCommand(COMMAND); pluginCommand.addOption("test-command-parameter", String.class, "Parameter for test command"); return pluginCommand; } diff --git a/schemacrawler-tools/src/test/java/schemacrawler/tools/executable/commandline/PluginCommandPojoTest.java b/schemacrawler-tools/src/test/java/schemacrawler/tools/executable/commandline/PluginCommandPojoTest.java index b0d0bac426..64afc00f50 100644 --- a/schemacrawler-tools/src/test/java/schemacrawler/tools/executable/commandline/PluginCommandPojoTest.java +++ b/schemacrawler-tools/src/test/java/schemacrawler/tools/executable/commandline/PluginCommandPojoTest.java @@ -45,6 +45,9 @@ import com.openpojo.validation.test.impl.GetterTester; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import schemacrawler.schemacrawler.DatabaseServerType; +import schemacrawler.test.utility.TestDatabaseConnector; +import us.fatehi.utility.property.PropertyName; public class PluginCommandPojoTest { @@ -65,40 +68,47 @@ public void emptyCommand() { @Test public void newCatalogLoaderCommand() { - final PluginCommand pluginCommand = PluginCommand.newCatalogLoaderCommand("name", "helpHeader"); + final PluginCommand pluginCommand = + PluginCommand.newCatalogLoaderCommand(new PropertyName("name", "helpHeader")); pluginCommand.addOption("option1", Object.class, "helpOption1", "helpOption2"); assertPluginCommandValues( - pluginCommand, "Add loader options to the `load` command in the SchemaCrawler Shell"); + pluginCommand, + "** helpHeader", + "Add loader options to the `load` command in the SchemaCrawler Shell"); } @Test - public void newDatabasePluginCommand() { + public void newDatabasePluginCommand() throws Exception { final PluginCommand pluginCommand = - PluginCommand.newDatabasePluginCommand("name", "helpHeader"); + PluginCommand.newDatabasePluginCommand(new DatabaseServerType("name", "helpHeader")); pluginCommand.addOption("option1", Object.class, "helpOption1", "helpOption2"); assertPluginCommandValues( pluginCommand, + "** Connect to helpHeader", "Add connection options to the `connect` command in the SchemaCrawler Shell"); } @Test public void newPluginCommand() { - final PluginCommand pluginCommand = PluginCommand.newPluginCommand("name", "helpHeader"); + final PluginCommand pluginCommand = + PluginCommand.newPluginCommand(new PropertyName("name", "helpHeader")); pluginCommand.addOption("option1", Object.class, "helpOption1", "helpOption2"); assertPluginCommandValues( - pluginCommand, "Add command options to the `execute` command in the SchemaCrawler Shell"); + pluginCommand, + "** helpHeader", + "Add command options to the `execute` command in the SchemaCrawler Shell"); } @Test - public void pluginCommand() { + public void pluginCommand() throws Exception { EqualsVerifier.forClass(PluginCommand.class) .suppress(Warning.STRICT_INHERITANCE) .withOnlyTheseFields("name") .verify(); final PluginCommand pluginCommand = - PluginCommand.newDatabasePluginCommand("name", "helpHeader"); - assertThat(pluginCommand.toString(), is("PluginCommand[name='name', options=[]]")); + PluginCommand.newDatabasePluginCommand(new TestDatabaseConnector().getDatabaseServerType()); + assertThat(pluginCommand.toString(), is("PluginCommand[name='test-db', options=[]]")); } @Test @@ -106,13 +116,12 @@ public void pluginCommandExtraMethods() { final PluginCommand pluginCommand = PluginCommand.newPluginCommand( - "name", - "helpHeader", + new PropertyName("name", "helpHeader"), () -> new String[] {"helpDescription1", "helpDescription2"}, () -> new String[] {"helpFooter1", "helpFooter2"}); assertThat(pluginCommand.toString(), is("PluginCommand[name='name', options=[]]")); assertThat(pluginCommand.getName(), endsWith(":name")); - assertThat(pluginCommand.getHelpHeader(), is("helpHeader")); + assertThat(pluginCommand.getHelpHeader(), is("** helpHeader")); assertThat( pluginCommand.getHelpDescription().get(), is(arrayContaining("helpDescription1", "helpDescription2"))); @@ -157,7 +166,7 @@ public void pluginCommandOptionEmpty() { } private void assertPluginCommandValues( - final PluginCommand pluginCommand, final String standardFooter) { + final PluginCommand pluginCommand, final String helpHeader, final String standardFooter) { final PluginCommandOption option = new PluginCommandOption("option1", Object.class, "helpOption1", "helpOption2"); @@ -167,7 +176,7 @@ private void assertPluginCommandValues( is( "PluginCommand[name='name', options=[PluginCommandOption[name='option1', valueClass=java.lang.Object]]]")); assertThat(pluginCommand.getName(), endsWith(":name")); - assertThat(pluginCommand.getHelpHeader(), is("helpHeader")); + assertThat(pluginCommand.getHelpHeader(), is(helpHeader)); assertThat(pluginCommand.getHelpDescription(), is(not(nullValue()))); assertThat(pluginCommand.getHelpFooter().get(), is(arrayContaining(standardFooter))); assertThat(pluginCommand.getOptions(), contains(option)); diff --git a/schemacrawler/src/test/java/schemacrawler/test/Issue342Test.java b/schemacrawler/src/test/java/schemacrawler/test/Issue342Test.java index c6bf3866ec..75f9a5faad 100644 --- a/schemacrawler/src/test/java/schemacrawler/test/Issue342Test.java +++ b/schemacrawler/src/test/java/schemacrawler/test/Issue342Test.java @@ -5,18 +5,15 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static schemacrawler.test.utility.DatabaseTestUtility.schemaRetrievalOptionsDefault; - import java.nio.file.Path; - import org.junit.jupiter.api.Test; - import schemacrawler.inclusionrule.RegularExpressionInclusionRule; import schemacrawler.schemacrawler.LimitOptionsBuilder; import schemacrawler.schemacrawler.LoadOptionsBuilder; import schemacrawler.schemacrawler.SchemaCrawlerOptions; import schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder; import schemacrawler.schemacrawler.SchemaInfoLevelBuilder; -import schemacrawler.schemacrawler.exceptions.ConfigurationException; +import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException; import schemacrawler.test.utility.ExecutableTestUtility; import schemacrawler.test.utility.WithTestDatabase; import schemacrawler.tools.executable.SchemaCrawlerExecutable; @@ -52,8 +49,8 @@ public void unsupportedOutputFormat(final DatabaseConnectionSource dataSource) t executable.setDataSource(dataSource); executable.setSchemaRetrievalOptions(schemaRetrievalOptionsDefault); - final ConfigurationException exception = - assertThrows(ConfigurationException.class, () -> executable.execute()); + final Exception exception = + assertThrows(ExecutionRuntimeException.class, () -> executable.execute()); assertThat( exception.getMessage(), is("Output format not supported for command ")); }