use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class CamelSalesforceMojo method filterObjectNames.
protected void filterObjectNames(Set<String> objectNames) throws MojoExecutionException {
getLog().info("Looking for matching Object names...");
// create a list of accepted names
final Set<String> includedNames = new HashSet<String>();
if (includes != null && includes.length > 0) {
for (String name : includes) {
name = name.trim();
if (name.isEmpty()) {
throw new MojoExecutionException("Invalid empty name in includes");
}
includedNames.add(name);
}
}
final Set<String> excludedNames = new HashSet<String>();
if (excludes != null && excludes.length > 0) {
for (String name : excludes) {
name = name.trim();
if (name.isEmpty()) {
throw new MojoExecutionException("Invalid empty name in excludes");
}
excludedNames.add(name);
}
}
// check whether a pattern is in effect
Pattern incPattern;
if (includePattern != null && !includePattern.trim().isEmpty()) {
incPattern = Pattern.compile(includePattern.trim());
} else if (includedNames.isEmpty()) {
// include everything by default if no include names are set
incPattern = MATCH_EVERYTHING_PATTERN;
} else {
// include nothing by default if include names are set
incPattern = MATCH_NOTHING_PATTERN;
}
// check whether a pattern is in effect
Pattern excPattern;
if (excludePattern != null && !excludePattern.trim().isEmpty()) {
excPattern = Pattern.compile(excludePattern.trim());
} else {
// exclude nothing by default
excPattern = MATCH_NOTHING_PATTERN;
}
final Set<String> acceptedNames = new HashSet<String>();
for (String name : objectNames) {
// and is not excluded and does not match exclude pattern
if ((includedNames.contains(name) || incPattern.matcher(name).matches()) && !excludedNames.contains(name) && !excPattern.matcher(name).matches()) {
acceptedNames.add(name);
}
}
objectNames.clear();
objectNames.addAll(acceptedNames);
getLog().info(String.format("Found %s matching Objects", objectNames.size()));
}
use of org.apache.maven.plugin.MojoExecutionException in project liquibase by liquibase.
the class AbstractLiquibaseMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info(MavenUtils.LOG_SEPARATOR);
if (server != null) {
AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
if (info != null) {
username = info.getUserName();
password = info.getPassword();
}
}
processSystemProperties();
LiquibaseConfiguration liquibaseConfiguration = LiquibaseConfiguration.getInstance();
if (!liquibaseConfiguration.getConfiguration(GlobalConfiguration.class).getShouldRun()) {
getLog().info("Liquibase did not run because " + liquibaseConfiguration.describeValueLookupLogic(GlobalConfiguration.class, GlobalConfiguration.SHOULD_RUN) + " was set to false");
return;
}
if (skip) {
getLog().warn("Liquibase skipped due to maven configuration");
return;
}
ClassLoader artifactClassLoader = getMavenArtifactClassLoader();
ResourceAccessor fileOpener = getFileOpener(artifactClassLoader);
configureFieldsAndValues(fileOpener);
LogFactory.getInstance().setDefaultLoggingLevel(logging);
// 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(artifactClassLoader, url, username, dbPassword, driver, defaultCatalogName, defaultSchemaName, outputDefaultCatalog, outputDefaultSchema, databaseClass, driverPropsFile, propertyProviderClass, changelogCatalogName, changelogSchemaName, databaseChangeLogTableName, databaseChangeLogLockTableName);
liquibase = createLiquibase(fileOpener, database);
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()) {
if (!liquibase.isSafeToRunUpdate()) {
if (UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
throw new LiquibaseException("User decided not to run against non-local database");
}
}
}
performLiquibaseTask(liquibase);
} catch (LiquibaseException e) {
cleanup(database);
throw new MojoExecutionException("Error setting up or running Liquibase: " + e.getMessage(), e);
}
cleanup(database);
getLog().info(MavenUtils.LOG_SEPARATOR);
getLog().info("");
}
use of org.apache.maven.plugin.MojoExecutionException in project liquibase by liquibase.
the class AbstractLiquibaseMojo method parsePropertiesFile.
/**
* Parses a properties file and sets the assocaited fields in the plugin.
*
* @param propertiesInputStream The input stream which is the Liquibase properties that
* needs to be parsed.
* @throws org.apache.maven.plugin.MojoExecutionException
* If there is a problem parsing
* the file.
*/
protected void parsePropertiesFile(InputStream propertiesInputStream) throws MojoExecutionException {
if (propertiesInputStream == null) {
throw new MojoExecutionException("Properties file InputStream is null.");
}
Properties props = new Properties();
try {
props.load(propertiesInputStream);
} catch (IOException e) {
throw new MojoExecutionException("Could not load the properties Liquibase file", e);
}
for (Iterator it = props.keySet().iterator(); it.hasNext(); ) {
String key = null;
try {
key = (String) it.next();
Field field = MavenUtils.getDeclaredField(this.getClass(), key);
if (propertyFileWillOverride) {
getLog().debug(" properties file setting value: " + field.getName());
setFieldValue(field, props.get(key).toString());
} else {
if (!isCurrentFieldValueSpecified(field)) {
getLog().debug(" properties file setting value: " + field.getName());
setFieldValue(field, props.get(key).toString());
}
}
} catch (Exception e) {
getLog().info(" '" + key + "' in properties file is not being used by this " + "task.");
}
}
}
use of org.apache.maven.plugin.MojoExecutionException in project liquibase by liquibase.
the class AbstractLiquibaseMojo method getClassLoaderIncludingProjectClasspath.
/**
* Returns an isolated classloader.
*
* @return ClassLoader
* @noinspection unchecked
*/
protected ClassLoader getClassLoaderIncludingProjectClasspath() throws MojoExecutionException {
try {
List classpathElements = project.getCompileClasspathElements();
classpathElements.add(project.getBuild().getOutputDirectory());
URL[] urls = new URL[classpathElements.size()];
for (int i = 0; i < classpathElements.size(); ++i) {
urls[i] = new File((String) classpathElements.get(i)).toURL();
}
return new URLClassLoader(urls, getMavenArtifactClassLoader());
} catch (Exception e) {
throw new MojoExecutionException("Failed to create project classloader", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project liquibase by liquibase.
the class LiquibaseMigrateSQL method createLiquibase.
@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(fo, db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; " + migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = getOutputWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
Aggregations