Skip to content

Commit

Permalink
#569 added option to ignore jQA properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Aug 2, 2024
1 parent 759dc6f commit aa6198e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.buschmais.jqassistant.commandline;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;

import com.buschmais.jqassistant.commandline.configuration.CliConfiguration;
import com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory;
Expand Down Expand Up @@ -52,6 +49,8 @@ public class Main {

private static final String CMDLINE_OPTION_PROFILES = "-profiles";

private static final Set<String> IGNORE_PROPERTIES = Set.of("jqassistant.opts", "jqassistant.home"); // env variables provided by jqassistant shell scripts

/**
* The main method.
*
Expand Down Expand Up @@ -245,6 +244,7 @@ private CliConfiguration getCliConfiguration(CommandLine commandLine, File worki
.withClasspath()
.withEnvVariables()
.withProfiles(profiles)
.withIgnoreProperties(IGNORE_PROPERTIES)
.load(configSource, new SysPropConfigSource(), commandLineProperties, mavenSettingsConfigSource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.*;

import io.smallrye.config.*;
import io.smallrye.config.source.yaml.YamlConfigSource;
Expand Down Expand Up @@ -96,6 +93,8 @@ public static class Builder<C extends Configuration> {

private final List<String> profiles = new ArrayList<>();

private final Set<String> ignoreProperties = new HashSet<>();

private Builder(Class<C> configurationMapping, List<String> configLocations) {
this.configurationMapping = configurationMapping;
if (configLocations.isEmpty()) {
Expand Down Expand Up @@ -183,6 +182,18 @@ public Builder<C> withProfiles(List<String> profiles) {
return this;
}

/**
* Add properties to ignore.
*
* @param ignoreProperties
* The properties to ignore.
* @return The {@link Builder}.
*/
public Builder<C> withIgnoreProperties(Collection<String> ignoreProperties) {
this.ignoreProperties.addAll(ignoreProperties);
return this;
}

/**
* Load the {@link Configuration} using the given directory including
* <p/>
Expand All @@ -205,9 +216,10 @@ public C load(ConfigSource... additionalConfigSources) {
// Create final config including validation, including only jqassistant properties
Map<String, String> interpolatedProperties = stream(interpolatedConfig.getPropertyNames()
.spliterator(), false).filter(property -> property.startsWith(Configuration.PREFIX))
.filter(property -> !ignoreProperties.contains(property))
.collect(toMap(property -> property, interpolatedConfig::getRawValue));
SmallRyeConfig config = new SmallRyeConfigBuilder().withMapping(configurationMapping)
.withSources(new PropertiesConfigSource(interpolatedProperties, "Interpolated Configuration", ConfigSource.DEFAULT_ORDINAL))
.withSources(new PropertiesConfigSource(interpolatedProperties, "jQAssistant Configuration", ConfigSource.DEFAULT_ORDINAL))
.build();
C configMapping = config.getConfigMapping(configurationMapping);
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader;
import com.buschmais.jqassistant.core.scanner.api.configuration.Scan;
Expand Down Expand Up @@ -94,6 +95,19 @@ void unknownProperty() {
.withMessageContaining(unknownProperty);
}

@Test
void ignoreProperty() {
String unknownProperty = "jqassistant.unknown";

TestConfiguration configuration = ConfigurationMappingLoader.builder(TestConfiguration.class, emptyList())
.withUserHome(USER_HOME)
.withWorkingDirectory(WORKING_DIRECTORY)
.withIgnoreProperties(Set.of(unknownProperty))
.load(new PropertiesConfigSource(Map.of(unknownProperty, "test value"), "Test", ConfigSource.DEFAULT_ORDINAL));

assertThat(configuration).isNotNull();
}

@Test
@SetEnvironmentVariable(key = "jqassistant_scan_continue_on_error", value = "false")
void overrideFromEnvVariable() {
Expand Down

0 comments on commit aa6198e

Please sign in to comment.