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;
}
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;
}
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();
}
}
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);
}
}
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);
}
}
Aggregations