Search in sources :

Example 71 with MojoExecutionException

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()));
}
Also used : Pattern(java.util.regex.Pattern) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashSet(java.util.HashSet)

Example 72 with MojoExecutionException

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("");
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) GlobalConfiguration(liquibase.configuration.GlobalConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) Database(liquibase.database.Database) LiquibaseConfiguration(liquibase.configuration.LiquibaseConfiguration) URLClassLoader(java.net.URLClassLoader) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 73 with MojoExecutionException

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.");
        }
    }
}
Also used : Field(java.lang.reflect.Field) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) MalformedURLException(java.net.MalformedURLException) DatabaseException(liquibase.exception.DatabaseException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 74 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) MalformedURLException(java.net.MalformedURLException) DatabaseException(liquibase.exception.DatabaseException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 75 with MojoExecutionException

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;
}
Also used : Liquibase(liquibase.Liquibase) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)586 IOException (java.io.IOException)322 File (java.io.File)261 MojoFailureException (org.apache.maven.plugin.MojoFailureException)138 Artifact (org.apache.maven.artifact.Artifact)86 ArrayList (java.util.ArrayList)70 FileInputStream (java.io.FileInputStream)56 HashMap (java.util.HashMap)47 MavenProject (org.apache.maven.project.MavenProject)37 MalformedURLException (java.net.MalformedURLException)34 Map (java.util.Map)34 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)32 Properties (java.util.Properties)30 FileOutputStream (java.io.FileOutputStream)28 FileWriter (java.io.FileWriter)28 List (java.util.List)25 URL (java.net.URL)22 InputStream (java.io.InputStream)21 LinkedHashSet (java.util.LinkedHashSet)21 FileNotFoundException (java.io.FileNotFoundException)20