From e4332f32c538c4515e8bf0176bf057b0d59f92f7 Mon Sep 17 00:00:00 2001 From: Dirk Mahler Date: Thu, 10 Oct 2024 19:35:59 +0200 Subject: [PATCH] #665 added "properties" to Maven plugin configuration (#667) * #665 added "properties" to Maven plugin configuration * #665 updated Maven plugin documentation --- .../configuration/embedded/invoker.properties | 3 +- maven/src/it/configuration/embedded/pom.xml | 96 +++++++++++++------ .../it/configuration/embedded/verify.groovy | 15 ++- maven/src/main/asciidoc/readme.adoc | 14 ++- .../jqassistant/scm/maven/AbstractMojo.java | 20 +++- 5 files changed, 106 insertions(+), 42 deletions(-) diff --git a/maven/src/it/configuration/embedded/invoker.properties b/maven/src/it/configuration/embedded/invoker.properties index 0b0b586d53..d12705a8d6 100644 --- a/maven/src/it/configuration/embedded/invoker.properties +++ b/maven/src/it/configuration/embedded/invoker.properties @@ -1 +1,2 @@ -invoker.goals = verify +invoker.goals.1 = verify -Pyaml +invoker.goals.2 = verify -Pproperties diff --git a/maven/src/it/configuration/embedded/pom.xml b/maven/src/it/configuration/embedded/pom.xml index 07545054db..f6aeb13c29 100644 --- a/maven/src/it/configuration/embedded/pom.xml +++ b/maven/src/it/configuration/embedded/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @project.groupId@ @@ -6,33 +7,70 @@ @project.version@ - - - @project.groupId@ - @project.artifactId@ - @project.version@ - - - - scan - analyze - - - - - - jqassistant: - store: - # used - uri: file:target/custom-store - analyze: - # overwritten by .jqassistant.yml - groups: - - plugin-execution-configuration - - - - + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + scan + analyze + + + + + + - \ No newline at end of file + + + yaml + + + + @project.groupId@ + @project.artifactId@ + + + + + + + + + + properties + + + + @project.groupId@ + @project.artifactId@ + + + file:target/custom-store-properties + plugin-execution-configuration + target/jqassistant/jqassistant-report-properties.xml + + + + + + + + diff --git a/maven/src/it/configuration/embedded/verify.groovy b/maven/src/it/configuration/embedded/verify.groovy index 1cd0379cfd..67cc2fa5c4 100644 --- a/maven/src/it/configuration/embedded/verify.groovy +++ b/maven/src/it/configuration/embedded/verify.groovy @@ -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 +} diff --git a/maven/src/main/asciidoc/readme.adoc b/maven/src/main/asciidoc/readme.adoc index 28109af2a5..970e0898bb 100644 --- a/maven/src/main/asciidoc/readme.adoc +++ b/maven/src/main/asciidoc/readme.adoc @@ -144,10 +144,13 @@ The configuration furthermore supports profiles, e.g. for `mvn verify -Pcustom-p ${project.basedir}/.jqassistant.yml - + + ]]> + + true + --> @@ -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 diff --git a/maven/src/main/java/com/buschmais/jqassistant/scm/maven/AbstractMojo.java b/maven/src/main/java/com/buschmais/jqassistant/scm/maven/AbstractMojo.java index 8634b5abe9..a6b09e2d4c 100644 --- a/maven/src/main/java/com/buschmais/jqassistant/scm/maven/AbstractMojo.java +++ b/maven/src/main/java/com/buschmais/jqassistant/scm/maven/AbstractMojo.java @@ -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; @@ -62,6 +63,9 @@ private static String createExecutionKey(MojoExecution mojoExecution) { @Parameter private String yaml; + @Parameter + private Properties properties; + /** * The Maven Session. */ @@ -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 builder = ConfigurationMappingLoader.builder(MavenConfiguration.class, configurationLocations) @@ -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; }