Skip to content

Commit

Permalink
#665 added "properties" to Maven plugin configuration (#667)
Browse files Browse the repository at this point in the history
* #665 added "properties" to Maven plugin configuration

* #665 updated Maven plugin documentation
  • Loading branch information
DirkMahler authored Oct 10, 2024
1 parent d83c25c commit e4332f3
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 42 deletions.
3 changes: 2 additions & 1 deletion maven/src/it/configuration/embedded/invoker.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
invoker.goals = verify
invoker.goals.1 = verify -Pyaml
invoker.goals.2 = verify -Pproperties
96 changes: 67 additions & 29 deletions maven/src/it/configuration/embedded/pom.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,76 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>@project.groupId@</groupId>
<artifactId>@[email protected]</artifactId>
<version>@project.version@</version>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>scan</goal>
<goal>analyze</goal>
</goals>
</execution>
</executions>
<configuration>
<yaml>
jqassistant:
store:
# used
uri: file:target/custom-store
analyze:
# overwritten by .jqassistant.yml
groups:
- plugin-execution-configuration
</yaml>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>scan</goal>
<goal>analyze</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
<profiles>
<profile>
<id>yaml</id>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<yaml><![CDATA[
jqassistant:
store:
# used
uri: file:target/custom-store-yaml
analyze:
# overwritten by .jqassistant.yml
groups:
- plugin-execution-configuration
report:
properties:
xml.report.file: target/jqassistant/jqassistant-report-yaml.xml
]]>
</yaml>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>properties</id>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<properties>
<jqassistant.store.uri>file:target/custom-store-properties</jqassistant.store.uri>
<jqassistant.analyze.groups>plugin-execution-configuration</jqassistant.analyze.groups>
<jqassistant.analyze.report.properties.xml.report.file>target/jqassistant/jqassistant-report-properties.xml</jqassistant.analyze.report.properties.xml.report.file>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
15 changes: 10 additions & 5 deletions maven/src/it/configuration/embedded/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
assert !new File(basedir, "target/jqassistant/store").exists()
verifyProfile("yaml")
verifyProfile("properties")

private void verifyProfile(profileName) {
// config from plugin execution configuration (embedded YAML)
assert new File(basedir, "target/custom-store").exists()
assert new File(basedir, "target/custom-store-" + profileName).exists()

// config from project configuration (.jqassistant.yml)
def reportFile = new File(basedir, 'target/jqassistant/jqassistant-report.xml')
assert reportFile.exists()
def jqassistantReport = new groovy.xml.XmlSlurper().parse(reportFile)
assert jqassistantReport.group.size() == 2
def reportFile = new File(basedir, 'target/jqassistant/jqassistant-report-' + profileName + '.xml')
assert reportFile.exists()
def jqassistantReport = new groovy.xml.XmlSlurper().parse(reportFile)
assert jqassistantReport.group.size() == 2
}
14 changes: 11 additions & 3 deletions maven/src/main/asciidoc/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ The configuration furthermore supports profiles, e.g. for `mvn verify -Pcustom-p
<configurationLocations>
<configurationLocation>${project.basedir}/.jqassistant.yml</configurationLocation>
</configurationLocations>
<yaml>
<yaml><![CDATA[
jqassistant:
skip: true
<yaml>
]]></yaml>
<properties>
<jqassistant.skip>true</jqassistant.skip>
</properties>
-->
</configuration>
</execution>
Expand Down Expand Up @@ -187,9 +190,14 @@ configurationLocations (-Djqassistant.configuration.locations)::
* default: '.jqassistant.yml, .jqassistant.yaml, .jqassistant/\*.yml, .jqassistant/**.yaml'

yaml::
* embedded YAML configuration
* embedded configuration using YAML
* can be used as an alternative to the .jqassistant.yml file, e.g. to provide the pom.xml as a parent with a pre-defined jQAssistant configuration

properties::
* embedded configuration using properties
* can be used as an alternative to the .jqassistant.yml file, e.g. to provide the pom.xml as a parent with a pre-defined jQAssistant configuration


If multiple, partially overlapping configurations are provided then the following priorities apply (from lowest to highest):

. `~/.jqassistant.yml` configuration file in the user's home directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.buschmais.jqassistant.scm.maven.provider.CachingStoreProvider;
import com.buschmais.jqassistant.scm.maven.provider.PluginRepositoryProvider;

import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.source.yaml.YamlConfigSource;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
Expand Down Expand Up @@ -62,6 +63,9 @@ private static String createExecutionKey(MojoExecution mojoExecution) {
@Parameter
private String yaml;

@Parameter
private Properties properties;

/**
* The Maven Session.
*/
Expand Down Expand Up @@ -266,10 +270,11 @@ private MavenConfiguration getConfiguration() {
MavenPropertiesConfigSource userPropertiesConfigSource = new MavenPropertiesConfigSource(session.getUserProperties(), "Maven Session User Properties ");
MavenPropertiesConfigSource systemPropertiesConfigSource = new MavenPropertiesConfigSource(session.getSystemProperties(),
"Maven Session System Properties");
ConfigSource mavenPluginConfiguration = getMavenPluginConfiguration();
ConfigSource yamlConfiguration = getYamlPluginConfiguration();
ConfigSource propertiesConfiguration = getPropertiesPluginConfiguration();

ConfigSource[] configSources = new ConfigSource[] { configurationBuilder.build(), projectConfigSource, settingsConfigSource,
projectPropertiesConfigSource, userPropertiesConfigSource, systemPropertiesConfigSource, mavenPluginConfiguration };
projectPropertiesConfigSource, userPropertiesConfigSource, systemPropertiesConfigSource, yamlConfiguration, propertiesConfiguration };
File userHome = new File(System.getProperty("user.home"));
File executionRootDirectory = new File(session.getExecutionRootDirectory());
ConfigurationMappingLoader.Builder<MavenConfiguration> builder = ConfigurationMappingLoader.builder(MavenConfiguration.class, configurationLocations)
Expand All @@ -286,9 +291,16 @@ private MavenConfiguration getConfiguration() {
return builder.load(configSources);
}

private ConfigSource getMavenPluginConfiguration() {
private ConfigSource getYamlPluginConfiguration() {
return isNotEmpty(yaml) ?
new YamlConfigSource("Maven plugin execution configuration", yaml, MavenPropertiesConfigSource.CONFIGURATION_ORDINAL_MAVEN_PROPERTIES) :
new YamlConfigSource("Maven plugin execution YAML configuration", yaml, MavenPropertiesConfigSource.CONFIGURATION_ORDINAL_MAVEN_PROPERTIES) :
EmptyConfigSource.INSTANCE;
}

private ConfigSource getPropertiesPluginConfiguration() {
return properties != null ?
new PropertiesConfigSource(properties, "Maven plugin execution properties configuration",
MavenPropertiesConfigSource.CONFIGURATION_ORDINAL_MAVEN_PROPERTIES) :
EmptyConfigSource.INSTANCE;
}

Expand Down

0 comments on commit e4332f3

Please sign in to comment.