diff --git a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java index 56f847bae..8fbc93c55 100644 --- a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java @@ -10,6 +10,7 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; +import java.util.stream.Stream; import io.smallrye.config.*; import io.smallrye.config.source.yaml.YamlConfigSource; @@ -61,8 +62,7 @@ public class ConfigurationMappingLoader { /** * The default names of configuration files */ - private static final List DEFAULT_CONFIG_LOCATIONS = List.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant") - .stream() + private static final List DEFAULT_CONFIG_LOCATIONS = Stream.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant") .map(Paths::get) .collect(toUnmodifiableList()); @@ -215,6 +215,7 @@ public Builder withIgnoreProperties(Collection ignoreProperties) { * @return The configuration. */ public C load(ConfigSource... additionalConfigSources) { + log.debug("Loading configuration using profiles {}. ", profiles); // Create intermediate configuration with applied profiles and interpolated properties (without validation) SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(this.configSources) .withSources(additionalConfigSources) @@ -237,7 +238,7 @@ private void logConfigProblems(SmallRyeConfig interpolatedConfig) { Map filteredProperties = stream(interpolatedConfig.getPropertyNames() .spliterator(), false).filter(property -> property.startsWith(PREFIX)) .filter(property -> !ignoreProperties.contains(property)) - .collect(toMap(property -> property, interpolatedConfig::getRawValue, (s1, s2) -> null, () -> new TreeMap<>())); + .collect(toMap(property -> property, interpolatedConfig::getRawValue, (s1, s2) -> null, TreeMap::new)); log.debug("jQAssistant config properties:"); for (Map.Entry entry : filteredProperties.entrySet()) { log.debug("\t{}={}", entry.getKey(), entry.getValue()); @@ -283,7 +284,7 @@ private List getExternalYamlConfigSources(Path configLocationPath, private List findYamlConfigurationFiles(Path configurationDirectory) { List configurationFiles = new ArrayList<>(); try { - walkFileTree(configurationDirectory, new SimpleFileVisitor() { + walkFileTree(configurationDirectory, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { diff --git a/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractPluginIT.java b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractPluginIT.java index 2d0d854dc..e9ee2fcdf 100644 --- a/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractPluginIT.java +++ b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractPluginIT.java @@ -21,6 +21,7 @@ import com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin; import com.buschmais.jqassistant.core.report.impl.ReportContextImpl; import com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory; +import com.buschmais.jqassistant.core.resolver.api.MavenSettingsConfigSourceBuilder; import com.buschmais.jqassistant.core.rule.api.model.*; import com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin; import com.buschmais.jqassistant.core.rule.api.source.FileRuleSource; @@ -50,6 +51,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; +import org.eclipse.microprofile.config.spi.ConfigSource; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -57,6 +59,7 @@ import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Optional.ofNullable; import static lombok.AccessLevel.PRIVATE; import static org.assertj.core.api.Assertions.assertThat; @@ -65,6 +68,9 @@ */ public abstract class AbstractPluginIT { + private static final String PROPERTY_MAVEN_SETTINGS = "jqassistant.it.maven-settings"; + private static final String PROPERTY_PROFILES = "jqassistant.it.profiles"; + private static final File USER_HOME = new File(System.getProperty("user.home")); private static final File WORKING_DIRECTORY = new File("."); @@ -75,6 +81,8 @@ public abstract class AbstractPluginIT { protected static final String ARTIFACT_ID = "artifact"; + private static ConfigSource mavenSettingsConfigSource; + private static ArtifactProviderFactory artifactProviderFactory; private static PluginRepositoryImpl pluginRepository; @@ -86,17 +94,21 @@ public abstract class AbstractPluginIT { protected RuleSet ruleSet; @BeforeAll - public static final void initPluginRepository() { + public static void initPluginRepository() { artifactProviderFactory = new ArtifactProviderFactory(USER_HOME); - OUTPUT_DIRECTORY.mkdirs(); + Optional mavenSettingsFile = ofNullable(System.getProperty(PROPERTY_MAVEN_SETTINGS)).map(File::new); + List profiles = ofNullable(System.getProperty(PROPERTY_PROFILES)).map(p -> List.of(p.split(","))) + .orElse(emptyList()); + mavenSettingsConfigSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(USER_HOME, mavenSettingsFile, profiles); PluginClassLoader pluginClassLoader = new PluginClassLoader(AbstractPluginIT.class.getClassLoader()); PluginConfigurationReader pluginConfigurationReader = new PluginConfigurationReaderImpl(pluginClassLoader); pluginRepository = new PluginRepositoryImpl(pluginConfigurationReader); pluginRepository.initialize(); + OUTPUT_DIRECTORY.mkdirs(); } @AfterAll - public static final void destroyPluginRepository() { + public static void destroyPluginRepository() { if (pluginRepository != null) { pluginRepository.destroy(); } @@ -145,7 +157,7 @@ private ITConfiguration createConfiguration(ConfigurationBuilder configurationBu .withClasspath() .withProfiles(getConfigurationProfiles()) .load(configurationBuilder.build(), new EnvConfigSource() { - }, new SysPropConfigSource()); + }, new SysPropConfigSource(), mavenSettingsConfigSource); } private void initializeRuleSet(Configuration configuration) throws RuleException, IOException { @@ -281,23 +293,22 @@ protected TestResult query(String query) { * @return The {@link AbstractPluginIT.TestResult}. */ protected TestResult query(String query, Map parameters) { - Query.Result compositeRowObjects = store.executeQuery(query, parameters); - List> rows = new ArrayList<>(); - Map> columns = new HashMap<>(); - for (CompositeRowObject rowObject : compositeRowObjects) { - Map row = new HashMap<>(); - Iterable columnNames = rowObject.getColumns(); - for (String columnName : columnNames) { - List columnValues = columns.get(columnName); - if (columnValues == null) { - columnValues = new ArrayList<>(); - columns.put(columnName, columnValues); + List> rows; + Map> columns; + try (Query.Result compositeRowObjects = store.executeQuery(query, parameters)) { + rows = new ArrayList<>(); + columns = new HashMap<>(); + for (CompositeRowObject rowObject : compositeRowObjects) { + Map row = new HashMap<>(); + Iterable columnNames = rowObject.getColumns(); + for (String columnName : columnNames) { + List columnValues = columns.computeIfAbsent(columnName, k -> new ArrayList<>()); + Object value = rowObject.get(columnName, Object.class); + row.put(columnName, value); + columnValues.add(value); } - Object value = rowObject.get(columnName, Object.class); - row.put(columnName, value); - columnValues.add(value); + rows.add(row); } - rows.add(row); } return new TestResult(rows, columns); } @@ -344,7 +355,7 @@ protected Result applyConcept(String id, Map parameters * @return The result. */ protected Result validateConstraint(String id) throws RuleException { - return validateConstraint(id, Collections.emptyMap()); + return validateConstraint(id, emptyMap()); } /** @@ -376,7 +387,7 @@ protected Result validateConstraint(String id, Map p * The id. */ protected void executeGroup(String id) throws RuleException { - executeGroup(id, Collections.emptyMap()); + executeGroup(id, emptyMap()); } /** @@ -404,7 +415,7 @@ protected void executeGroup(String id, Map parameters) throws Ru @Getter @AllArgsConstructor(access = PRIVATE) @ToString - protected class TestResult { + protected static class TestResult { private List> rows; private Map> columns; diff --git a/pom.xml b/pom.xml index 734e653e3..379448f59 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,7 @@ 4.4.18 5.24.0 2.0.16 - 3.9.1 + 3.10.2 1.9.22 2.3 2.8