Skip to content

Commit

Permalink
internal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DoodleBobBuffPants committed Dec 7, 2021
1 parent 2e42e73 commit c063c9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
Expand Up @@ -16,11 +16,12 @@
package org.flywaydb.commandline;

import lombok.RequiredArgsConstructor;
import org.flywaydb.commandline.extensibility.CommandLineExtension;
import org.flywaydb.commandline.logging.console.ConsoleLog.Level;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.MigrationState;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.extensibility.CommandExtension;
import org.flywaydb.core.internal.plugin.PluginRegister;
import org.flywaydb.core.internal.util.FlywayDbWebsiteLinks;
import org.flywaydb.core.internal.util.StringUtils;

Expand Down Expand Up @@ -110,8 +111,7 @@ private static List<String> getValidOperationsAndFlags() {
"validate",
"undo",
"baseline",
"repair"
));
"repair"));
operationsAndFlags.addAll(PRINT_VERSION_AND_EXIT_FLAGS);
operationsAndFlags.addAll(PRINT_USAGE_FLAGS);
return operationsAndFlags;
Expand Down Expand Up @@ -206,10 +206,8 @@ public void validate() {
}

private boolean isHandledByExtension(String arg) {
ServiceLoader<CommandLineExtension> loader = ServiceLoader.load(CommandLineExtension.class);

for (CommandLineExtension extension : loader) {
if (extension.handlesVerb(arg) || extension.handlesParameter(arg)) {
for (CommandExtension extension : PluginRegister.getPlugins(CommandExtension.class)) {
if (extension.handlesCommand(arg) || extension.handlesParameter(arg)) {
return true;
}
}
Expand Down Expand Up @@ -237,15 +235,12 @@ public boolean shouldPrintUsage() {
}

public Level getLogLevel() {

if (isFlagSet(args, QUIET_FLAG)) {
return Level.WARN;
}

if (isFlagSet(args, DEBUG_FLAG)) {
return Level.DEBUG;
}

return Level.INFO;
}

Expand Down
34 changes: 16 additions & 18 deletions flyway-commandline/src/main/java/org/flywaydb/commandline/Main.java
Expand Up @@ -17,27 +17,20 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.flywaydb.commandline.extensibility.CommandLineExtension;
import org.flywaydb.core.api.configuration.FluentConfiguration;
import org.flywaydb.core.api.output.*;
import org.flywaydb.core.internal.command.DbMigrate;
import org.flywaydb.core.internal.logging.EvolvingLog;
import org.flywaydb.core.internal.logging.buffered.BufferedLog;
import org.flywaydb.core.internal.logging.multi.MultiLogCreator;
import org.flywaydb.commandline.logging.console.ConsoleLog.Level;
import org.flywaydb.commandline.logging.console.ConsoleLogCreator;
import org.flywaydb.commandline.logging.file.FileLogCreator;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.*;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.api.configuration.FluentConfiguration;
import org.flywaydb.core.api.logging.Log;
import org.flywaydb.core.api.logging.LogCreator;
import org.flywaydb.core.api.logging.LogFactory;
import org.flywaydb.core.api.output.CompositeResult;
import org.flywaydb.core.api.output.ErrorOutput;
import org.flywaydb.core.api.output.OperationResult;
import org.flywaydb.core.api.output.OperationResultBase;
import org.flywaydb.core.api.output.*;

import org.flywaydb.core.extensibility.CommandExtension;
import org.flywaydb.core.internal.command.DbMigrate;
import org.flywaydb.core.internal.configuration.ConfigUtils;
import org.flywaydb.core.internal.database.DatabaseType;
import org.flywaydb.core.internal.database.DatabaseTypeRegister;
Expand All @@ -46,8 +39,14 @@
import org.flywaydb.core.internal.license.FlywayTrialExpiredException;
import org.flywaydb.core.internal.license.VersionPrinter;

import org.flywaydb.core.internal.logging.EvolvingLog;
import org.flywaydb.core.internal.logging.buffered.BufferedLog;
import org.flywaydb.core.internal.logging.multi.MultiLogCreator;
import org.flywaydb.core.internal.plugin.PluginRegister;
import org.flywaydb.core.internal.schemahistory.SchemaHistoryFactory;
import org.flywaydb.core.internal.util.*;
import org.flywaydb.core.internal.util.ClassUtils;
import org.flywaydb.core.internal.util.FlywayDbWebsiteLinks;
import org.flywaydb.core.internal.util.StringUtils;

import java.io.Console;
import java.io.File;
Expand Down Expand Up @@ -278,9 +277,8 @@ private static OperationResultBase executeOperation(Flyway flyway, String operat
result = flyway.repair();
} else {
boolean handled = false;
ServiceLoader<CommandLineExtension> loader = ServiceLoader.load(CommandLineExtension.class);
for (CommandLineExtension extension : loader) {
if (extension.handlesVerb(operation)) {
for (CommandExtension extension : PluginRegister.getPlugins(CommandExtension.class)) {
if (extension.handlesCommand(operation)) {
result = extension.handle(operation, config);
handled = true;
}
Expand Down Expand Up @@ -463,13 +461,13 @@ private static void printUsage() {
LOG.info("--help, -h, -? : Print this usage info and exit");
LOG.info("-community : Run the Flyway Community Edition (default)");
LOG.info("-teams : Run the Flyway Teams Edition");
ServiceLoader<CommandLineExtension> loader = ServiceLoader.load(CommandLineExtension.class);
if (loader.iterator().hasNext()) {
List<CommandExtension> extensions = PluginRegister.getPlugins(CommandExtension.class);
if (!extensions.isEmpty()) {
LOG.info("");
LOG.info("Command-line extensions");
LOG.info("-----------------------");
}
for (CommandLineExtension extension : loader) {
for (CommandExtension extension : extensions) {
LOG.info(extension.getUsage());
}
LOG.info("");
Expand Down
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flywaydb.commandline.extensibility;
package org.flywaydb.core.extensibility;

import org.flywaydb.core.api.output.OperationResultBase;

Expand All @@ -22,12 +22,12 @@
/**
* @apiNote This interface is under development and not recommended for use.
*/
public interface CommandLineExtension {
public interface CommandExtension extends Plugin {
/**
* @param verb The CLI verb to check is handled
* @return Whether this extension handles the specified verb
* @param command The CLI command to check is handled
* @return Whether this extension handles the specified command
*/
boolean handlesVerb(String verb);
boolean handlesCommand(String command);

/**
* @param parameter The parameter to check is handled
Expand All @@ -41,9 +41,9 @@ public interface CommandLineExtension {
String getUsage();

/**
* @param verb The verb to handle
* @param command The command to handle
* @param config The configuration provided to Flyway
* @return The result of this verb being handled
* @return The result of this command being handled
*/
OperationResultBase handle(String verb, Map<String, String> config);
OperationResultBase handle(String command, Map<String, String> config);
}

0 comments on commit c063c9c

Please sign in to comment.