use of liquibase.integration.IntegrationDetails in project liquibase by liquibase.
the class StandardHubService method createOperationInOrganization.
@Override
public Operation createOperationInOrganization(String operationType, String operationCommand, UUID organizationId) throws LiquibaseHubException {
final IntegrationDetails integrationDetails = Scope.getCurrentScope().get("integrationDetails", IntegrationDetails.class);
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("operationType", operationType);
requestBody.put("operationCommand", operationCommand);
requestBody.put("operationStatusType", "PASS");
requestBody.put("statusMessage", operationType);
requestBody.put("clientMetadata", getClientMetadata(integrationDetails));
if (integrationDetails != null) {
requestBody.put("operationParameters", getCleanOperationParameters(integrationDetails.getParameters()));
}
return http.doPost("/api/v1/organizations/" + organizationId.toString() + "/operations", requestBody, Operation.class);
}
use of liquibase.integration.IntegrationDetails in project liquibase by liquibase.
the class AbstractLiquibaseMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (StringUtil.trimToNull(logging) != null) {
getLog().error("The liquibase-maven-plugin now manages logging via the standard maven logging config, not the 'logging' configuration. Use the -e, -X or -q flags or see https://maven.apache.org/maven-logging.html");
}
try {
Scope.child(Scope.Attr.logService, new MavenLogService(getLog()), () -> {
getLog().info(MavenUtils.LOG_SEPARATOR);
if (server != null) {
AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
if (info != null) {
username = info.getUserName();
password = info.getPassword();
}
}
processSystemProperties();
if (!LiquibaseCommandLineConfiguration.SHOULD_RUN.getCurrentValue()) {
getLog().info("Liquibase did not run because " + LiquibaseCommandLineConfiguration.SHOULD_RUN.getKey() + " was set to false");
return;
}
if (skip) {
getLog().warn("Liquibase skipped due to Maven configuration");
return;
}
ClassLoader mavenClassLoader = getClassLoaderIncludingProjectClasspath();
Map<String, Object> scopeValues = new HashMap<>();
scopeValues.put(Scope.Attr.resourceAccessor.name(), getResourceAccessor(mavenClassLoader));
scopeValues.put(Scope.Attr.classLoader.name(), getClassLoaderIncludingProjectClasspath());
IntegrationDetails integrationDetails = new IntegrationDetails();
integrationDetails.setName("maven");
final PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
for (MojoDescriptor descriptor : pluginDescriptor.getMojos()) {
if (!descriptor.getImplementationClass().equals(this.getClass())) {
continue;
}
for (Parameter param : descriptor.getParameters()) {
final String name = param.getName();
if (name.equalsIgnoreCase("project") || name.equalsIgnoreCase("systemProperties")) {
continue;
}
final Field field = getField(this.getClass(), name);
if (field == null) {
getLog().debug("Cannot read current maven value for. Will not send the value to hub " + name);
} else {
field.setAccessible(true);
final Object value = field.get(this);
if (value != null) {
try {
integrationDetails.setParameter("maven__" + param.getName().replaceAll("[${}]", ""), String.valueOf(value));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
}
scopeValues.put("integrationDetails", integrationDetails);
final Map pluginContext = this.getPluginContext();
System.out.println(pluginContext.keySet());
Scope.child(scopeValues, () -> {
configureFieldsAndValues();
//
// Check for a LiquibasePro license
//
hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
getLog().info(CommandLineUtils.getBanner());
// Displays the settings for the Mojo depending of verbosity mode.
displayMojoSettings();
// Check that all the parameters that must be specified have been by the user.
checkRequiredParametersAreSpecified();
Database database = null;
try {
String dbPassword = (emptyPassword || (password == null)) ? "" : password;
String driverPropsFile = (driverPropertiesFile == null) ? null : driverPropertiesFile.getAbsolutePath();
database = CommandLineUtils.createDatabaseObject(mavenClassLoader, url, username, dbPassword, driver, defaultCatalogName, defaultSchemaName, outputDefaultCatalog, outputDefaultSchema, databaseClass, driverPropsFile, propertyProviderClass, changelogCatalogName, changelogSchemaName, databaseChangeLogTableName, databaseChangeLogLockTableName);
liquibase = createLiquibase(database);
configureChangeLogProperties();
getLog().debug("expressionVars = " + String.valueOf(expressionVars));
if (expressionVars != null) {
for (Map.Entry<Object, Object> var : expressionVars.entrySet()) {
this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
}
}
getLog().debug("expressionVariables = " + String.valueOf(expressionVariables));
if (expressionVariables != null) {
for (Map.Entry var : (Set<Map.Entry>) expressionVariables.entrySet()) {
if (var.getValue() != null) {
this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
}
}
}
if (clearCheckSums) {
getLog().info("Clearing the Liquibase checksums on the database");
liquibase.clearCheckSums();
}
getLog().info("Executing on Database: " + url);
if (isPromptOnNonLocalDatabase()) {
getLog().info("NOTE: The promptOnLocalDatabase functionality has been removed");
}
setupBindInfoPackage();
performLiquibaseTask(liquibase);
} catch (LiquibaseException e) {
cleanup(database);
throw new MojoExecutionException("\nError setting up or running Liquibase:\n" + e.getMessage(), e);
}
cleanup(database);
getLog().info(MavenUtils.LOG_SEPARATOR);
getLog().info("");
});
});
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of liquibase.integration.IntegrationDetails in project liquibase by liquibase.
the class Main method parsePropertiesFile.
/**
* Reads various execution parameters from an InputStream and sets our internal state according to the values
* found.
*
* @param propertiesInputStream an InputStream from a Java properties file
* @throws IOException if there is a problem reading the InputStream
* @throws CommandLineParsingException if an invalid property is encountered
*/
protected void parsePropertiesFile(InputStream propertiesInputStream) throws IOException, CommandLineParsingException {
final IntegrationDetails integrationDetails = Scope.getCurrentScope().get("integrationDetails", IntegrationDetails.class);
Properties props = new Properties();
props.load(propertiesInputStream);
if (Main.runningFromNewCli) {
parsePropertiesFileForNewCli(props);
return;
}
boolean strict = GlobalConfiguration.STRICT.getCurrentValue();
//
for (Map.Entry entry : props.entrySet()) {
String entryValue = null;
if (entry.getValue() != null) {
entryValue = String.valueOf(entry.getValue());
}
if (integrationDetails != null) {
integrationDetails.setParameter("defaultsFile__" + String.valueOf(entry.getKey()), entryValue);
}
try {
if ("promptOnNonLocalDatabase".equals(entry.getKey())) {
continue;
}
if (((String) entry.getKey()).startsWith("parameter.")) {
changeLogParameters.put(((String) entry.getKey()).replaceFirst("^parameter.", ""), entry.getValue());
} else if (((String) entry.getKey()).contains(".")) {
if (Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getRegisteredDefinition((String) entry.getKey()) == null) {
if (strict) {
throw new CommandLineParsingException(String.format(coreBundle.getString("parameter.unknown"), entry.getKey()));
} else {
Scope.getCurrentScope().getLog(getClass()).warning(String.format(coreBundle.getString("parameter.ignored"), entry.getKey()));
}
}
if (System.getProperty((String) entry.getKey()) == null) {
DeprecatedConfigurationValueProvider.setData((String) entry.getKey(), entry.getValue());
}
} else {
Field field = getDeclaredField((String) entry.getKey());
Object currentValue = field.get(this);
if (currentValue == null) {
String value = entry.getValue().toString().trim();
if (field.getType().equals(Boolean.class)) {
field.set(this, Boolean.valueOf(value));
} else {
field.set(this, value);
}
}
}
} catch (NoSuchFieldException ignored) {
if (strict) {
throw new CommandLineParsingException(String.format(coreBundle.getString("parameter.unknown"), entry.getKey()));
} else {
Scope.getCurrentScope().getLog(getClass()).warning(String.format(coreBundle.getString("parameter.ignored"), entry.getKey()));
}
} catch (IllegalAccessException e) {
throw new UnexpectedLiquibaseException(String.format(coreBundle.getString("parameter.unknown"), entry.getKey()));
}
}
}
use of liquibase.integration.IntegrationDetails in project liquibase by liquibase.
the class HubUpdater method loadDatabaseMetadata.
//
// Put database/driver version information in the details map
//
private void loadDatabaseMetadata() throws DatabaseException, SQLException {
if (database.getConnection() == null) {
return;
}
final IntegrationDetails integrationDetails = Scope.getCurrentScope().get("integrationDetails", IntegrationDetails.class);
if (integrationDetails == null) {
return;
}
String databaseProductName = database.getDatabaseProductName();
String databaseProductVersion = database.getDatabaseProductVersion();
Scope.getCurrentScope().getLog(getClass()).fine("Database product name " + databaseProductName);
Scope.getCurrentScope().getLog(getClass()).fine("Database product version " + databaseProductVersion);
DatabaseConnection connection = database.getConnection();
if (connection instanceof JdbcConnection) {
JdbcConnection jdbcConnection = (JdbcConnection) connection;
java.sql.Connection conn = jdbcConnection.getUnderlyingConnection();
int driverMajorVersion = conn.getMetaData().getDriverMajorVersion();
int driverMinorVersion = conn.getMetaData().getDriverMinorVersion();
Scope.getCurrentScope().getLog(getClass()).fine("Database driver version " + driverMajorVersion + "." + driverMinorVersion);
integrationDetails.setParameter("db__driverVersion", driverMajorVersion + "." + driverMinorVersion);
} else {
integrationDetails.setParameter("db__driverVersion", "Unable to determine");
}
integrationDetails.setParameter("db__databaseProduct", databaseProductName);
integrationDetails.setParameter("db__databaseVersion", databaseProductVersion);
}
use of liquibase.integration.IntegrationDetails in project liquibase by liquibase.
the class StandardHubService method createOperation.
@Override
public Operation createOperation(String operationType, String operationCommand, HubChangeLog changeLog, Connection connection) throws LiquibaseHubException {
final IntegrationDetails integrationDetails = Scope.getCurrentScope().get("integrationDetails", IntegrationDetails.class);
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("connectionId", connection.getId());
requestBody.put("connectionJdbcUrl", connection.getJdbcUrl());
requestBody.put("projectId", connection.getProject() == null ? null : connection.getProject().getId());
requestBody.put("changelogId", changeLog == null ? null : changeLog.getId());
requestBody.put("operationType", operationType);
requestBody.put("operationCommand", operationCommand);
requestBody.put("operationStatusType", "PASS");
requestBody.put("statusMessage", operationType);
requestBody.put("clientMetadata", getClientMetadata(integrationDetails));
if (integrationDetails != null) {
requestBody.put("operationParameters", getCleanOperationParameters(integrationDetails.getParameters()));
}
final Operation operation = http.doPost("/api/v1/operations", requestBody, Operation.class);
operation.setConnection(connection);
return operation;
}
Aggregations