Search in sources :

Example 1 with PlexusConfiguration

use of org.codehaus.plexus.configuration.PlexusConfiguration in project liquibase by liquibase.

the class AbstractLiquibaseMojoTest method loadConfiguration.

protected PlexusConfiguration loadConfiguration(String configFile) throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/" + configFile);
    assertTrue("The configuration pom could not be found, " + testPom.getAbsolutePath(), testPom.exists());
    PlexusConfiguration config = extractPluginConfiguration("liquibase-plugin", testPom);
    assertNotNull("There should be a configuration for the plugin in the pom", config);
    return config;
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) File(java.io.File)

Example 2 with PlexusConfiguration

use of org.codehaus.plexus.configuration.PlexusConfiguration in project liquibase by liquibase.

the class LiquibaseDBDocMojoTest method createDBDocMojo.

private LiquibaseDBDocMojo createDBDocMojo(String configFileName) throws Exception {
    LiquibaseDBDocMojo mojo = new LiquibaseDBDocMojo();
    PlexusConfiguration config = loadConfiguration(configFileName);
    configureMojo(mojo, config);
    return mojo;
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration)

Example 3 with PlexusConfiguration

use of org.codehaus.plexus.configuration.PlexusConfiguration in project maven-plugins by apache.

the class AntrunXmlPlexusConfigurationWriter method write.

private void write(PlexusConfiguration c, XMLWriter w, int depth) throws IOException {
    int count = c.getChildCount();
    if (count == 0) {
        writeTag(c, w, depth);
    } else {
        w.startElement(c.getName());
        writeAttributes(c, w);
        for (int i = 0; i < count; i++) {
            PlexusConfiguration child = c.getChild(i);
            write(child, w, depth + 1);
        }
        w.endElement();
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration)

Example 4 with PlexusConfiguration

use of org.codehaus.plexus.configuration.PlexusConfiguration in project maven-plugins by apache.

the class CheckstyleViolationCheckMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
    checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories");
    if (skip) {
        return;
    }
    outputXmlFile = outputFile;
    if (!skipExec) {
        if (checkstyleRules != null) {
            if (!"sun_checks.xml".equals(configLocation)) {
                throw new MojoExecutionException("If you use inline configuration for rules, don't specify " + "a configLocation");
            }
            if (checkstyleRules.getChildCount() > 1) {
                throw new MojoExecutionException("Currently only one root module is supported");
            }
            PlexusConfiguration checkerModule = checkstyleRules.getChild(0);
            try {
                FileUtils.forceMkdir(rulesFiles.getParentFile());
                FileUtils.fileWrite(rulesFiles, CHECKSTYLE_FILE_HEADER + checkerModule.toString());
            } catch (final IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            configLocation = rulesFiles.getAbsolutePath();
        }
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
            request.setConsoleListener(getConsoleListener()).setConsoleOutput(consoleOutput).setExcludes(excludes).setFailsOnError(failsOnError).setIncludes(includes).setResourceIncludes(resourceIncludes).setResourceExcludes(resourceExcludes).setIncludeResources(includeResources).setIncludeTestResources(includeTestResources).setIncludeTestSourceDirectory(includeTestSourceDirectory).setListener(getListener()).setProject(project).setSourceDirectories(getSourceDirectories()).setResources(resources).setTestResources(testResources).setStringOutputStream(stringOutputStream).setSuppressionsLocation(suppressionsLocation).setTestSourceDirectories(getTestSourceDirectories()).setConfigLocation(configLocation).setConfigurationArtifacts(collectArtifacts("config")).setPropertyExpansion(propertyExpansion).setHeaderLocation(headerLocation).setLicenseArtifacts(collectArtifacts("license")).setCacheFile(cacheFile).setSuppressionsFileExpression(suppressionsFileExpression).setEncoding(encoding).setPropertiesLocation(propertiesLocation).setOmitIgnoredModules(omitIgnoredModules);
            checkstyleExecutor.executeCheckstyle(request);
        } catch (CheckstyleException e) {
            throw new MojoExecutionException("Failed during checkstyle configuration", e);
        } catch (CheckstyleExecutorException e) {
            throw new MojoExecutionException("Failed during checkstyle execution", e);
        } finally {
            //be sure to restore original context classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    }
    if (!"xml".equals(outputFileFormat) && skipExec) {
        throw new MojoExecutionException("Output format is '" + outputFileFormat + "', checkstyle:check requires format to be 'xml' when using skipExec.");
    }
    if (!outputXmlFile.exists()) {
        getLog().info("Unable to perform checkstyle:check, unable to find checkstyle:checkstyle outputFile.");
        return;
    }
    try (Reader reader = new BufferedReader(ReaderFactory.newXmlReader(outputXmlFile))) {
        XmlPullParser xpp = new MXParser();
        xpp.setInput(reader);
        int violations = countViolations(xpp);
        if (violations > maxAllowedViolations) {
            if (failOnViolation) {
                String msg = "You have " + violations + " Checkstyle violation" + ((violations > 1) ? "s" : "") + ".";
                if (maxAllowedViolations > 0) {
                    msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
                }
                throw new MojoFailureException(msg);
            }
            getLog().warn("checkstyle:check violations detected but failOnViolation set to false");
        }
    } catch (IOException | XmlPullParserException e) {
        throw new MojoExecutionException("Unable to read Checkstyle results xml: " + outputXmlFile.getAbsolutePath(), e);
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MXParser(org.codehaus.plexus.util.xml.pull.MXParser) CheckstyleExecutorRequest(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest) CheckstyleExecutorException(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException) XmlPullParser(org.codehaus.plexus.util.xml.pull.XmlPullParser) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 5 with PlexusConfiguration

use of org.codehaus.plexus.configuration.PlexusConfiguration in project maven-plugins by apache.

the class AbstractEarMojo method initializeJbossConfiguration.

/**
     * Initializes the JBoss configuration.
     * 
     * @throws EarPluginException if the configuration is invalid
     */
private void initializeJbossConfiguration() throws EarPluginException {
    if (jboss == null) {
        jbossConfiguration = null;
    } else {
        String childVersion = jboss.getChild(JbossConfiguration.VERSION).getValue();
        if (childVersion == null) {
            getLog().info("JBoss version not set, using JBoss 4 by default");
            childVersion = JbossConfiguration.VERSION_4;
        }
        final String securityDomain = jboss.getChild(JbossConfiguration.SECURITY_DOMAIN).getValue();
        final String unauthenticatedPrincipal = jboss.getChild(JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL).getValue();
        final PlexusConfiguration loaderRepositoryEl = jboss.getChild(JbossConfiguration.LOADER_REPOSITORY);
        final String loaderRepository = loaderRepositoryEl.getValue();
        final String loaderRepositoryClass = loaderRepositoryEl.getAttribute(JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE);
        final PlexusConfiguration loaderRepositoryConfigEl = jboss.getChild(JbossConfiguration.LOADER_REPOSITORY_CONFIG);
        final String loaderRepositoryConfig = loaderRepositoryConfigEl.getValue();
        final String configParserClass = loaderRepositoryConfigEl.getAttribute(JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE);
        final String jmxName = jboss.getChild(JbossConfiguration.JMX_NAME).getValue();
        final String moduleOrder = jboss.getChild(JbossConfiguration.MODULE_ORDER).getValue();
        final List<String> dataSources = new ArrayList<String>();
        final PlexusConfiguration dataSourcesEl = jboss.getChild(JbossConfiguration.DATASOURCES);
        if (dataSourcesEl != null) {
            final PlexusConfiguration[] dataSourcesConfig = dataSourcesEl.getChildren(JbossConfiguration.DATASOURCE);
            for (PlexusConfiguration dataSourceConfig : dataSourcesConfig) {
                dataSources.add(dataSourceConfig.getValue());
            }
        }
        final String libraryDirectory = jboss.getChild(JbossConfiguration.LIBRARY_DIRECTORY).getValue();
        jbossConfiguration = new JbossConfiguration(childVersion, securityDomain, unauthenticatedPrincipal, jmxName, loaderRepository, moduleOrder, dataSources, libraryDirectory, loaderRepositoryConfig, loaderRepositoryClass, configParserClass);
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) ArrayList(java.util.ArrayList)

Aggregations

PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)19 ArrayList (java.util.ArrayList)5 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)5 Map (java.util.Map)2 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)2 InterpolationException (org.codehaus.plexus.interpolation.InterpolationException)2 MapBasedValueSource (org.codehaus.plexus.interpolation.MapBasedValueSource)2 StringSearchInterpolator (org.codehaus.plexus.interpolation.StringSearchInterpolator)2 ValueSource (org.codehaus.plexus.interpolation.ValueSource)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 CheckstyleExecutorException (org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException)1 CheckstyleExecutorRequest (org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest)1