Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Dec 9, 2024
2 parents e779d76 + 8f9edb2 commit e01aa63
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,8 +62,7 @@ public class ConfigurationMappingLoader {
/**
* The default names of configuration files
*/
private static final List<Path> DEFAULT_CONFIG_LOCATIONS = List.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant")
.stream()
private static final List<Path> DEFAULT_CONFIG_LOCATIONS = Stream.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant")
.map(Paths::get)
.collect(toUnmodifiableList());

Expand Down Expand Up @@ -215,6 +215,7 @@ public Builder<C> withIgnoreProperties(Collection<String> 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)
Expand All @@ -237,7 +238,7 @@ private void logConfigProblems(SmallRyeConfig interpolatedConfig) {
Map<String, String> 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<String, String> entry : filteredProperties.entrySet()) {
log.debug("\t{}={}", entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -283,7 +284,7 @@ private List<ConfigSource> getExternalYamlConfigSources(Path configLocationPath,
private List<Path> findYamlConfigurationFiles(Path configurationDirectory) {
List<Path> configurationFiles = new ArrayList<>();
try {
walkFileTree(configurationDirectory, new SimpleFileVisitor<Path>() {
walkFileTree(configurationDirectory, new SimpleFileVisitor<>() {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,13 +51,15 @@
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;
import org.junit.jupiter.api.BeforeEach;

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;

Expand All @@ -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(".");
Expand All @@ -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;
Expand All @@ -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<File> mavenSettingsFile = ofNullable(System.getProperty(PROPERTY_MAVEN_SETTINGS)).map(File::new);
List<String> 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();
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -281,23 +293,22 @@ protected TestResult query(String query) {
* @return The {@link AbstractPluginIT.TestResult}.
*/
protected TestResult query(String query, Map<String, Object> parameters) {
Query.Result<CompositeRowObject> compositeRowObjects = store.executeQuery(query, parameters);
List<Map<String, Object>> rows = new ArrayList<>();
Map<String, List<Object>> columns = new HashMap<>();
for (CompositeRowObject rowObject : compositeRowObjects) {
Map<String, Object> row = new HashMap<>();
Iterable<String> columnNames = rowObject.getColumns();
for (String columnName : columnNames) {
List<Object> columnValues = columns.get(columnName);
if (columnValues == null) {
columnValues = new ArrayList<>();
columns.put(columnName, columnValues);
List<Map<String, Object>> rows;
Map<String, List<Object>> columns;
try (Query.Result<CompositeRowObject> compositeRowObjects = store.executeQuery(query, parameters)) {
rows = new ArrayList<>();
columns = new HashMap<>();
for (CompositeRowObject rowObject : compositeRowObjects) {
Map<String, Object> row = new HashMap<>();
Iterable<String> columnNames = rowObject.getColumns();
for (String columnName : columnNames) {
List<Object> 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);
}
Expand Down Expand Up @@ -344,7 +355,7 @@ protected Result<Concept> applyConcept(String id, Map<String, String> parameters
* @return The result.
*/
protected Result<Constraint> validateConstraint(String id) throws RuleException {
return validateConstraint(id, Collections.<String, String>emptyMap());
return validateConstraint(id, emptyMap());
}

/**
Expand Down Expand Up @@ -376,7 +387,7 @@ protected Result<Constraint> validateConstraint(String id, Map<String, String> p
* The id.
*/
protected void executeGroup(String id) throws RuleException {
executeGroup(id, Collections.<String, String>emptyMap());
executeGroup(id, emptyMap());
}

/**
Expand Down Expand Up @@ -404,7 +415,7 @@ protected void executeGroup(String id, Map<String, String> parameters) throws Ru
@Getter
@AllArgsConstructor(access = PRIVATE)
@ToString
protected class TestResult {
protected static class TestResult {

private List<Map<String, Object>> rows;
private Map<String, List<Object>> columns;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<neo4j.neo4j-java-driver.version>4.4.18</neo4j.neo4j-java-driver.version>
<neo4j-browser.version>5.24.0</neo4j-browser.version>
<slf4j.version>2.0.16</slf4j.version>
<smallrye-config.version>3.9.1</smallrye-config.version>
<smallrye-config.version>3.10.2</smallrye-config.version>
<maven-resolver.version>1.9.22</maven-resolver.version>
<snakeyaml.version>2.3</snakeyaml.version>
<snakeyaml-engine.version>2.8</snakeyaml-engine.version>
Expand Down

0 comments on commit e01aa63

Please sign in to comment.