Top Description Inners Fields Constructors Methods
liquibase.change.core

public Class ExecuteShellCommandChange

extends AbstractChange
Class Inheritance
Annotations
@DatabaseChange
name:executeCommand
description:Executes a system command. Because this refactoring doesn\'t generate SQL, using Liquibase commands such as update-sql may not work as expected. Therefore, prefer refactorings that generate SQL.
priority:1
Imports
liquibase.GlobalConfiguration, .Scope, liquibase.change.AbstractChange, .ChangeMetaData, .DatabaseChange, .DatabaseChangeProperty, liquibase.database.Database, liquibase.exception.UnexpectedLiquibaseException, .ValidationErrors, .Warnings, liquibase.parser.core.ParsedNode, .ParsedNodeException, liquibase.resource.ResourceAccessor, liquibase.sql.Sql, liquibase.statement.SqlStatement, liquibase.statement.core.CommentStatement, .RuntimeStatement, liquibase.util.StringUtil, java.io.*, java.util.*, java.util.concurrent.TimeoutException, java.util.concurrent.atomic.AtomicBoolean, java.util.regex.Matcher, .Pattern

Executes a given shell executable.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField and Description
private final List<String>
private String
protected List<String>
private static final Long
protected Integer
private static final Long
private List<String>
private static final Long
private String
private static final Pattern
private static final String
Inherited from liquibase.change.AbstractChange:
NODENAME_COLUMN

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected ExecuteShellCommandChange.StreamGobbler
createErrorGobbler(InputStream processStream, OutputStream outputStream)

protected List<String>
protected ProcessBuilder
protected void
protected void
public boolean
generateRollbackStatementsVolatile(Database database)

Overrides liquibase.change.AbstractChange.generateRollbackStatementsVolatile.

Implements liquibase.change.Change.generateRollbackStatementsVolatile.

Implementation delegates logic to the liquibase.sqlgenerator.SqlGenerator#generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by generateStatements If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.

public SqlStatement[]
generateStatements(final Database database)

Implements liquibase.change.Change.generateStatements.

Generates the SqlStatement objects required to run the change for the given database.

public boolean
public List<String>
protected String
public String
getConfirmationMessage()

Implements liquibase.change.Change.getConfirmationMessage.

Confirmation message to be displayed after the change is executed.

public String
protected Integer
public List<String>
public String
public String
protected long

Returns:

the timeout value in millisecond
getTimeoutInMillis
()

protected void
processResult(int returnCode, String errorStreamOut, String infoStreamOut, Database database)

Called by executeCommand(Database) after running the command.

public void
setExecutable(String executable)

public void
public void
setTimeout(String timeout)

public String
toString()

Overrides liquibase.change.AbstractChange.toString.

Returns a string representation of the object.

public ValidationErrors
validate(Database database)

Overrides liquibase.change.AbstractChange.validate.

Implements liquibase.change.Change.validate.

Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the liquibase.sqlgenerator.SqlGenerator#validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by generateStatements.

private int
waitForOrKill(final Process process, final long
waits for specified timeoutInMillis before destroying the process.
timeoutInMillis
)

Waits for the process to complete and kills it if the process is not finished after the specified timeoutInMillis.

public Warnings
Inherited from liquibase.change.AbstractChange:
checkStatuscreateChangeMetaDatacreateChangeParameterMetadatacreateDescriptionMetaDatacreateEmptyColumnConfigcreateExampleValueMetaDatacreateInversescreateMustEqualExistingMetaDatacreateRequiredDatabasesMetaDatacreateSerializationTypeMetaDatacreateSinceMetaDatacreateSupportedDatabasesMetaDataequalsfinishInitializationgenerateCheckSumgenerateRollbackStatementsgetAffectedDatabaseObjectsgetChangeSetgetDescriptiongetExcludedFieldFiltersgetResourceAccessorgetSerializableFieldNamespacegetSerializableFieldsgetSerializableFieldTypegetSerializableFieldValuegetSerializedObjectNamehashCodeisInvalidPropertyloadmodifyserializeserializeValuesetChangeSetsetResourceAccessorshouldExecuteChangesupportssupportsRollback

Field Detail

argsback to summary
private final List<String> args
executableback to summary
private String executable
finalCommandArrayback to summary
protected List<String> finalCommandArray
HOUR_IN_MILLISback to summary
private static final Long HOUR_IN_MILLIS
maxStreamGobblerOutputback to summary
protected Integer maxStreamGobblerOutput
MIN_IN_MILLISback to summary
private static final Long MIN_IN_MILLIS
osback to summary
private List<String> os
SECS_IN_MILLISback to summary
private static final Long SECS_IN_MILLIS
timeoutback to summary
private String timeout
TIMEOUT_PATTERNback to summary
private static final Pattern TIMEOUT_PATTERN
TIMEOUT_REGEXback to summary
private static final String TIMEOUT_REGEX

Constructor Detail

ExecuteShellCommandChangeback to summary
public ExecuteShellCommandChange()

Method Detail

addArgback to summary
public void addArg(String arg)
createErrorGobblerback to summary
protected ExecuteShellCommandChange.StreamGobbler createErrorGobbler(InputStream processStream, OutputStream outputStream)
createFinalCommandArrayback to summary
protected List<String> createFinalCommandArray(Database database)
createProcessBuilderback to summary
protected ProcessBuilder createProcessBuilder(Database database)
customLoadLogicback to summary
protected void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException

Overrides liquibase.change.AbstractChange.customLoadLogic.

Annotations
@Override
executeCommandback to summary
protected void executeCommand(Database database) throws Exception
generateRollbackStatementsVolatileback to summary
public boolean generateRollbackStatementsVolatile(Database database)

Overrides liquibase.change.AbstractChange.generateRollbackStatementsVolatile.

Implements liquibase.change.Change.generateRollbackStatementsVolatile.

Doc from liquibase.change.AbstractChange.generateRollbackStatementsVolatile.

Implementation delegates logic to the liquibase.sqlgenerator.SqlGenerator#generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by generateStatements If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.

Annotations
@Override
generateStatementsback to summary
public SqlStatement[] generateStatements(final Database database)

Implements liquibase.change.Change.generateStatements.

Doc from liquibase.change.Change.generateStatements.

Generates the SqlStatement objects required to run the change for the given database.

NOTE: This method may be called multiple times throughout the changelog execution process and may be called in documentation generation and other integration points as well.

If this method reads from the current database state or uses any other logic that will be affected by whether previous changeSets have ran or not, you must return true from generateStatementsVolatile.
Annotations
@Override
generateStatementsVolatileback to summary
public boolean generateStatementsVolatile(Database database)

Overrides liquibase.change.AbstractChange.generateStatementsVolatile.

Implements liquibase.change.Change.generateStatementsVolatile.

Doc from liquibase.change.AbstractChange.generateStatementsVolatile.

Implementation delegates logic to the liquibase.sqlgenerator.SqlGenerator#generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by generateStatements. If zero or null SqlStatements are returned by generateStatements then this method returns false.

Annotations
@Override
getArgsback to summary
public List<String> getArgs()
getCommandStringback to summary
protected String getCommandString()
getConfirmationMessageback to summary
public String getConfirmationMessage()

Implements liquibase.change.Change.getConfirmationMessage.

Doc from liquibase.change.Change.getConfirmationMessage.

Confirmation message to be displayed after the change is executed. Should include relevant configuration settings to make it as helpful as possible. This method may be called outside the changelog execution process, such as in documentation generation.

Annotations
@Override
getExecutableback to summary
public String getExecutable()
Annotations
@DatabaseChangeProperty
description:Name of the executable to run
exampleValue:mysqldump
requiredForDatabase:all
getMaxStreamGobblerOutputback to summary
protected Integer getMaxStreamGobblerOutput()

Max bytes to copy from output to processResult(int, String, String, Database). If null, process all output.

getOsback to summary
public List<String> getOs()
Annotations
@DatabaseChangeProperty
exampleValue:Windows 7
description:List of operating systems on which to execute the command (taken from the os.name Java system property)
getSerializedObjectNamespaceback to summary
public String getSerializedObjectNamespace()

Overrides liquibase.change.AbstractChange.getSerializedObjectNamespace.

Implements liquibase.serializer.LiquibaseSerializable.getSerializedObjectNamespace.

Annotations
@Override
getTimeoutback to summary
public String getTimeout()
Annotations
@DatabaseChangeProperty
description:Timeout value for the executable to run
exampleValue:10s
getTimeoutInMillisback to summary
protected long getTimeoutInMillis()
Returns:long

the timeout value in millisecond

processResultback to summary
protected void processResult(int returnCode, String errorStreamOut, String infoStreamOut, Database database)

Called by executeCommand(Database) after running the command. Default implementation throws an error if returnCode != 0

setExecutableback to summary
public void setExecutable(String executable)
setOsback to summary
public void setOs(String os)
setTimeoutback to summary
public void setTimeout(String timeout)
toStringback to summary
public String toString()

Overrides liquibase.change.AbstractChange.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
validateback to summary
public ValidationErrors validate(Database database)

Overrides liquibase.change.AbstractChange.validate.

Implements liquibase.change.Change.validate.

Doc from liquibase.change.AbstractChange.validate.

Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the liquibase.sqlgenerator.SqlGenerator#validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by generateStatements. If no or null SqlStatements are returned by generateStatements then this method returns no errors. If there are no parameters than this method returns no errors

Annotations
@Override
waitForOrKillback to summary
private int waitForOrKill(final Process process, final long timeoutInMillis) throws TimeoutException

Waits for the process to complete and kills it if the process is not finished after the specified timeoutInMillis.

Creates a scheduled task to destroy the process in given timeout milliseconds. This killer task will be cancelled if the process returns before the timeout value.

Parameters
timeoutInMillis:long

waits for specified timeoutInMillis before destroying the process.

Annotations
@SuppressWarnings:squid:S2142
warnback to summary
public Warnings warn(Database database)

Overrides liquibase.change.AbstractChange.warn.

Implements liquibase.change.Change.warn.

Doc from liquibase.change.AbstractChange.warn.

Implementation delegates logic to the liquibase.sqlgenerator.SqlGenerator#warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by generateStatements. If a generated statement is not supported for the given database, no warning will be added since that is a validation error. If no or null SqlStatements are returned by generateStatements then this method returns no warnings.

Annotations
@Override
liquibase.change.core back to summary

public Class ExecuteShellCommandChange.StreamGobbler

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv boolean
private final OutputStream
private final Thread
private InputStream
private static final int
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public
StreamGobbler(InputStream processStream, OutputStream outputStream, Thread parentThread)

Method Summary

Modifier and TypeMethod and Description
public void
copy(InputStream inputStream, OutputStream outputStream)

public void
public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopthreadIdtoStringyield

Field Detail

copiedSizeback to summary
pack-priv long copiedSize
loggedTruncatedback to summary
pack-priv boolean loggedTruncated
outputStreamback to summary
private final OutputStream outputStream
parentThreadback to summary
private final Thread parentThread
processStreamback to summary
private InputStream processStream
THREAD_SLEEP_MILLISback to summary
private static final int THREAD_SLEEP_MILLIS

Constructor Detail

StreamGobblerback to summary
public StreamGobbler(InputStream processStream, OutputStream outputStream, Thread parentThread)

Method Detail

copyback to summary
public void copy(InputStream inputStream, OutputStream outputStream) throws IOException
finishback to summary
public void finish()
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override