diff --git a/cli/application/pom.xml b/cli/application/pom.xml index beef0386dc..d555541687 100644 --- a/cli/application/pom.xml +++ b/cli/application/pom.xml @@ -39,42 +39,11 @@ com.buschmais.jqassistant jqa-distribution-specification - - - - org.apache.maven - maven-settings-builder - ${maven.version} - - - - org.apache.maven.resolver - maven-resolver-impl - - - org.apache.maven.resolver - maven-resolver-connector-basic - - - org.apache.maven.resolver - maven-resolver-transport-file - - org.apache.maven.resolver - maven-resolver-transport-http + com.buschmais.jqassistant.core + artifact-resolver + ${project.version} - - org.apache.maven - maven-resolver-provider - ${maven.version} - - - org.apache.maven.resolver - * - - - - org.projectlombok diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/Main.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/Main.java index b48d6d490e..0835a11367 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/Main.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/Main.java @@ -4,10 +4,8 @@ import java.util.*; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory; import com.buschmais.jqassistant.commandline.task.RegisteredTask; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; +import com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginClassLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginConfigurationReader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository; @@ -16,6 +14,8 @@ import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginRepositoryImpl; import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginResolverImpl; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.store.api.StoreFactory; import io.smallrye.config.PropertiesConfigSource; @@ -25,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.buschmais.jqassistant.commandline.configuration.MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource; +import static com.buschmais.jqassistant.core.resolver.api.MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource; import static java.lang.Thread.currentThread; import static java.util.Arrays.stream; import static java.util.Collections.emptyList; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/OptionsConsumer.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/OptionsConsumer.java index 3a3c0ffa2b..a13a33575b 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/OptionsConsumer.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/OptionsConsumer.java @@ -1,6 +1,6 @@ package com.buschmais.jqassistant.commandline; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; import org.apache.commons.cli.CommandLine; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/CliConfiguration.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/CliConfiguration.java index 1c68824b8b..5546241d05 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/CliConfiguration.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/CliConfiguration.java @@ -1,24 +1,14 @@ package com.buschmais.jqassistant.commandline.configuration; -import java.util.Optional; - +import com.buschmais.jqassistant.core.resolver.configuration.ArtifactResolverConfiguration; import com.buschmais.jqassistant.core.runtime.api.configuration.Configuration; import com.buschmais.jqassistant.core.shared.annotation.Description; import io.smallrye.config.ConfigMapping; -import static com.buschmais.jqassistant.core.runtime.api.configuration.Configuration.PREFIX; +import static com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader.PREFIX; @ConfigMapping(prefix = PREFIX) @Description("The configuration for the Command Line Utility.") -public interface CliConfiguration extends Configuration { - - String PROXY = "proxy"; - - @Description("The proxy to use for connecting to repositories.") - Optional proxy(); - - @Description("The repositories for resolving plugins and their dependencies.") - Repositories repositories(); - +public interface CliConfiguration extends Configuration, ArtifactResolverConfiguration { } diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/AbstractStoreTask.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/AbstractStoreTask.java index 799b550340..7a3681609d 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/AbstractStoreTask.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/AbstractStoreTask.java @@ -6,7 +6,7 @@ import com.buschmais.jqassistant.commandline.CliConfigurationException; import com.buschmais.jqassistant.commandline.CliExecutionException; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; import com.buschmais.jqassistant.core.store.api.Store; import com.buschmais.jqassistant.core.store.api.configuration.Embedded; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/EffectiveConfigurationTask.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/EffectiveConfigurationTask.java index 160870c5b7..9820b25a4e 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/EffectiveConfigurationTask.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/EffectiveConfigurationTask.java @@ -4,7 +4,7 @@ import com.buschmais.jqassistant.commandline.CliExecutionException; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationSerializer; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationSerializer; import lombok.extern.slf4j.Slf4j; import org.apache.commons.cli.Option; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/ScanTask.java b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/ScanTask.java index 24cbbd4bd3..f10a9e6d6b 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/ScanTask.java +++ b/cli/application/src/main/java/com/buschmais/jqassistant/commandline/task/ScanTask.java @@ -9,7 +9,6 @@ import com.buschmais.jqassistant.commandline.CliConfigurationException; import com.buschmais.jqassistant.commandline.CliExecutionException; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; import com.buschmais.jqassistant.core.scanner.api.Scanner; import com.buschmais.jqassistant.core.scanner.api.ScannerContext; import com.buschmais.jqassistant.core.scanner.api.Scope; @@ -17,6 +16,7 @@ import com.buschmais.jqassistant.core.scanner.api.configuration.Include; import com.buschmais.jqassistant.core.scanner.impl.ScannerContextImpl; import com.buschmais.jqassistant.core.scanner.impl.ScannerImpl; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.cli.CommandLine; diff --git a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/ServerTaskTest.java b/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/ServerTaskTest.java index 1db4c79e8c..f65103bbd3 100644 --- a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/ServerTaskTest.java +++ b/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/ServerTaskTest.java @@ -5,9 +5,9 @@ import com.buschmais.jqassistant.commandline.CliExecutionException; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; import com.buschmais.jqassistant.core.store.impl.EmbeddedGraphStore; import com.buschmais.jqassistant.neo4j.embedded.EmbeddedNeo4jServer; import com.buschmais.jqassistant.neo4j.embedded.api.configuration.Server; diff --git a/cli/test/src/test/java/com/buschmais/jqassistant/commandline/test/AbstractCLIIT.java b/cli/test/src/test/java/com/buschmais/jqassistant/commandline/test/AbstractCLIIT.java index 865553a7e3..ebd7a4eb40 100644 --- a/cli/test/src/test/java/com/buschmais/jqassistant/commandline/test/AbstractCLIIT.java +++ b/cli/test/src/test/java/com/buschmais/jqassistant/commandline/test/AbstractCLIIT.java @@ -9,14 +9,14 @@ import com.buschmais.jqassistant.commandline.Task; import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; +import com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginClassLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository; import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginConfigurationReaderImpl; import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginRepositoryImpl; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.store.api.Store; import com.buschmais.jqassistant.core.store.api.StoreFactory; diff --git a/core/artifact-resolver/pom.xml b/core/artifact-resolver/pom.xml new file mode 100644 index 0000000000..33a172c310 --- /dev/null +++ b/core/artifact-resolver/pom.xml @@ -0,0 +1,98 @@ + + 4.0.0 + + + com.buschmais.jqassistant.core + parent + 2.6.0-SNAPSHOT + + + artifact-resolver + + jQAssistant Artifact Provider + https://jqassistant.org/ + + + Provides an implementation for an artifact provider. + + + + + com.buschmais.jqassistant.core + shared + ${project.version} + + + + org.apache.maven + maven-settings-builder + ${maven.version} + + + + org.apache.maven.resolver + maven-resolver-impl + + + org.apache.maven.resolver + maven-resolver-connector-basic + + + org.apache.maven.resolver + maven-resolver-transport-file + + + org.apache.maven.resolver + maven-resolver-transport-http + + + org.apache.maven + maven-resolver-provider + ${maven.version} + + + org.apache.maven.resolver + * + + + + + org.projectlombok + lombok + + + + org.slf4j + slf4j-api + + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.mockito + mockito-junit-jupiter + + + org.assertj + assertj-core + + + org.slf4j + slf4j-simple + + + + diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactory.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactory.java similarity index 70% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactory.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactory.java index 97a9ba1b3e..adf04ed67c 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactory.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactory.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.plugin; +package com.buschmais.jqassistant.core.resolver.api; import java.io.File; import java.util.HashMap; @@ -6,11 +6,10 @@ import java.util.Map; import java.util.Optional; -import com.buschmais.jqassistant.commandline.configuration.*; -import com.buschmais.jqassistant.commandline.configuration.Proxy; -import com.buschmais.jqassistant.core.runtime.api.plugin.PluginResolver; -import com.buschmais.jqassistant.core.runtime.impl.plugin.AetherArtifactProvider; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; +import com.buschmais.jqassistant.core.resolver.configuration.*; +import com.buschmais.jqassistant.core.resolver.configuration.Proxy; +import com.buschmais.jqassistant.core.shared.aether.AetherArtifactProvider; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import lombok.extern.slf4j.Slf4j; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; @@ -34,10 +33,11 @@ import static java.util.Optional.of; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; -import static org.eclipse.aether.repository.RepositoryPolicy.*; +import static org.eclipse.aether.repository.RepositoryPolicy.CHECKSUM_POLICY_WARN; +import static org.eclipse.aether.repository.RepositoryPolicy.UPDATE_POLICY_DAILY; /** - * Factory for the {@link PluginResolver} to be used in standalone in the CLI. + * Factory for the {@link AetherArtifactProvider} to be used in standalone in the CLI. */ @Slf4j public class ArtifactProviderFactory { @@ -99,17 +99,17 @@ public ArtifactProviderFactory(File userHome) { } /** - * Creates a {@link PluginResolver} using the given {@link CliConfiguration} providing the required {@link Plugin}s and {@link Repositories} + * Creates a {@link AetherArtifactProvider} using the given {@link ArtifactResolverConfiguration} providing the required {@link Plugin}s and {@link Repositories} *

* The default local repository is ~/.jqassistant/repository. *

* If no remote repository is specified the resolver will use Maven Central. * * @param configuration - * The {@link CliConfiguration}. - * @return The {@link PluginResolver}. + * The {@link ArtifactResolverConfiguration}. + * @return The {@link AetherArtifactProvider}. */ - public AetherArtifactProvider create(CliConfiguration configuration) { + public AetherArtifactProvider create(ArtifactResolverConfiguration configuration) { Repositories repositories = configuration.repositories(); File localRepository = getLocalRepository(repositories); Optional proxy = getProxy(configuration.proxy()); @@ -119,16 +119,16 @@ public AetherArtifactProvider create(CliConfiguration configuration) { RepositorySystem repositorySystem = newRepositorySystem(); log.info("Local repository: {}", localRepository); log.info("Remote repositories: {}", remoteRepositories.stream() - .map(repository -> { - org.eclipse.aether.repository.Proxy repositoryProxy = repository.getProxy(); - List mirroredRepositories = repository.getMirroredRepositories(); - return String.format("'%s (%s%s%s)'", repository.getId(), repository.getUrl(), !mirroredRepositories.isEmpty() ? - String.format(", mirror of %s", mirroredRepositories.stream() - .map(r -> r.getId()) - .collect(joining(", "))) : - "", repositoryProxy != null ? String.format(" via proxy %s:%d", repositoryProxy.getHost(), repositoryProxy.getPort()) : ""); - }) - .collect(joining(", "))); + .map(repository -> { + org.eclipse.aether.repository.Proxy repositoryProxy = repository.getProxy(); + List mirroredRepositories = repository.getMirroredRepositories(); + return String.format("'%s (%s%s%s)'", repository.getId(), repository.getUrl(), !mirroredRepositories.isEmpty() ? + String.format(", mirror of %s", mirroredRepositories.stream() + .map(r -> r.getId()) + .collect(joining(", "))) : + "", repositoryProxy != null ? String.format(" via proxy %s:%d", repositoryProxy.getHost(), repositoryProxy.getPort()) : ""); + }) + .collect(joining(", "))); RepositorySystemSession session = newRepositorySystemSession(repositories, repositorySystem, localRepository, mirrorSelector, proxySelector); return new AetherArtifactProvider(repositorySystem, session, remoteRepositories); @@ -138,41 +138,41 @@ public AetherArtifactProvider create(CliConfiguration configuration) { * Determine the local repository to use. * * @param repositories - * The {@link Repositories} configuration. + * The {@link Repositories} configuration. * @return The local repository. */ private File getLocalRepository(Repositories repositories) { // determine local repository return repositories.local() - .orElseGet(() -> { - File repository = new File(jqassistantUserDir, "repository"); - repository.mkdirs(); - return repository; - }); + .orElseGet(() -> { + File repository = new File(jqassistantUserDir, "repository"); + repository.mkdirs(); + return repository; + }); } private Optional getProxy(Optional proxy) { return proxy.map(p -> { String protocol = p.protocol() - .orElse("https"); + .orElse("https"); String host = p.host(); Integer port = p.port(); AuthenticationBuilder authBuilder = new AuthenticationBuilder(); p.username() - .ifPresent(authBuilder::addUsername); + .ifPresent(authBuilder::addUsername); p.password() - .ifPresent(authBuilder::addPassword); + .ifPresent(authBuilder::addPassword); return new org.eclipse.aether.repository.Proxy(protocol, host, port, authBuilder.build()); }); } - private ProxySelector getProxySelector(CliConfiguration configuration, Optional optionalProxy) { + private ProxySelector getProxySelector(ArtifactResolverConfiguration configuration, Optional optionalProxy) { DefaultProxySelector proxySelector = new DefaultProxySelector(); optionalProxy.ifPresent(proxy -> proxySelector.add(proxy, configuration.proxy() - .map(proxyConfiguration -> proxyConfiguration.nonProxyHosts() - .orElse(null)) - .orElse(null))); + .map(proxyConfiguration -> proxyConfiguration.nonProxyHosts() + .orElse(null)) + .orElse(null))); return proxySelector; } @@ -180,11 +180,11 @@ private ProxySelector getProxySelector(CliConfiguration configuration, Optional< * Determines the remote repositories to use, using Maven Central as fallback. * * @param repositories - * The {@link Repositories} configuration. + * The {@link Repositories} configuration. * @param proxySelector - * The {@link ProxySelector}. + * The {@link ProxySelector}. * @param mirrorSelector - * The {@link MirrorSelector}. + * The {@link MirrorSelector}. * @return The list of configured {@link RemoteRepository}s. */ private List getRemoteRepositories(Repositories repositories, ProxySelector proxySelector, Optional mirrorSelector) { @@ -194,16 +194,16 @@ private List getRemoteRepositories(Repositories repositories, // Add configured remotes remotes.putAll(repositories.remotes()); return remotes.entrySet() - .stream() - .map(remoteEntry -> getRemoteRepository(remoteEntry.getKey(), remoteEntry.getValue(), proxySelector)) - // apply any configured mirrors to the remote repository - .map(remoteRepository -> mirrorSelector.map(selector -> selectMirror(remoteRepository, selector, repositories.mirrors(), proxySelector)) - .orElse(remoteRepository)) - .collect(toList()); + .stream() + .map(remoteEntry -> getRemoteRepository(remoteEntry.getKey(), remoteEntry.getValue(), proxySelector)) + // apply any configured mirrors to the remote repository + .map(remoteRepository -> mirrorSelector.map(selector -> selectMirror(remoteRepository, selector, repositories.mirrors(), proxySelector)) + .orElse(remoteRepository)) + .collect(toList()); } private static RemoteRepository selectMirror(RemoteRepository remoteRepository, MirrorSelector selector, Map mirrors, - ProxySelector proxySelector) { + ProxySelector proxySelector) { RemoteRepository mirrorRepository = selector.getMirror(remoteRepository); if (mirrorRepository == null) { return remoteRepository; @@ -214,9 +214,9 @@ private static RemoteRepository selectMirror(RemoteRepository remoteRepository, private static RemoteRepository getRemoteRepository(String id, Remote remote, ProxySelector proxySelector) { RemoteRepository remoteRepository = new RemoteRepository.Builder(id, REPOSITORY_LAYOUT_DEFAULT, remote.url()) // - .setReleasePolicy(getRepositoryPolicy(remote.releases())) - .setSnapshotPolicy(getRepositoryPolicy(remote.snapshots())) - .build(); + .setReleasePolicy(getRepositoryPolicy(remote.releases())) + .setSnapshotPolicy(getRepositoryPolicy(remote.snapshots())) + .build(); return getRemoteRepository(remoteRepository, proxySelector, remote.username(), remote.password()); } @@ -225,14 +225,14 @@ private static RepositoryPolicy getRepositoryPolicy(Policy policy) { } private static RemoteRepository getRemoteRepository(RemoteRepository remoteRepository, ProxySelector proxySelector, Optional optionalUsername, - Optional optionalPassword) { + Optional optionalPassword) { AuthenticationBuilder authBuilder = new AuthenticationBuilder(); optionalUsername.ifPresent(authBuilder::addUsername); optionalPassword.ifPresent(authBuilder::addPassword); org.eclipse.aether.repository.Proxy proxy = proxySelector.getProxy(remoteRepository); return new RemoteRepository.Builder(remoteRepository).setProxy(proxy) - .setAuthentication(authBuilder.build()) - .build(); + .setAuthentication(authBuilder.build()) + .build(); } /** @@ -252,17 +252,17 @@ private RepositorySystem newRepositorySystem() { * Creates a new {@link RepositorySystemSession}. * * @param repositories - * The {@link Repositories} + * The {@link Repositories} * @param system - * the {@link RepositorySystem} + * the {@link RepositorySystem} * @param mirrorSelector - * The optional {@link MirrorSelector}. + * The optional {@link MirrorSelector}. * @param proxySelector - * The {@link ProxySelector}. + * The {@link ProxySelector}. * @return a new {@link RepositorySystemSession}. */ private RepositorySystemSession newRepositorySystemSession(Repositories repositories, RepositorySystem system, File localDirectory, - Optional mirrorSelector, ProxySelector proxySelector) { + Optional mirrorSelector, ProxySelector proxySelector) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); session.setTransferListener(new TransferListener()); LocalRepository localRepo = new LocalRepository(localDirectory); @@ -270,18 +270,18 @@ private RepositorySystemSession newRepositorySystemSession(Repositories reposito session.setProxySelector(proxySelector); mirrorSelector.ifPresent(session::setMirrorSelector); session.setIgnoreArtifactDescriptorRepositories(repositories.ignoreTransitiveRepositories() - .orElse(true)); + .orElse(true)); return session; } private Optional getMirrorSelector(Repositories repositories) { if (repositories.mirrors() - .isEmpty()) { + .isEmpty()) { return empty(); } DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); for (Map.Entry entry : repositories.mirrors() - .entrySet()) { + .entrySet()) { String id = entry.getKey(); Mirror mirror = entry.getValue(); mirrorSelector.add(id, mirror.url(), null, false, false, mirror.mirrorOf(), null); @@ -296,15 +296,15 @@ private static class TransferListener extends AbstractTransferListener { @Override public void transferStarted(TransferEvent transferEvent) { log.info("Downloading '{}{}'.", transferEvent.getResource() - .getRepositoryUrl(), transferEvent.getResource() - .getResourceName()); + .getRepositoryUrl(), transferEvent.getResource() + .getResourceName()); } @Override public void transferSucceeded(TransferEvent transferEvent) { log.info("Finished download of '{}{}'.", transferEvent.getResource() - .getRepositoryUrl(), transferEvent.getResource() - .getResourceName()); + .getRepositoryUrl(), transferEvent.getResource() + .getResourceName()); } } } diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilder.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilder.java similarity index 75% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilder.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilder.java index 4521684119..2443511c5b 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilder.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilder.java @@ -1,40 +1,35 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.api; import java.io.File; import java.util.*; -import com.buschmais.jqassistant.commandline.CliConfigurationException; +import com.buschmais.jqassistant.core.resolver.configuration.ArtifactResolverConfiguration; +import com.buschmais.jqassistant.core.resolver.configuration.Policy; +import com.buschmais.jqassistant.core.resolver.configuration.Remote; +import com.buschmais.jqassistant.core.resolver.configuration.Repositories; import io.smallrye.config.PropertiesConfigSource; +import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.maven.settings.*; -import org.apache.maven.settings.Mirror; -import org.apache.maven.settings.Proxy; import org.apache.maven.settings.building.DefaultSettingsBuilderFactory; import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; import org.apache.maven.settings.building.SettingsBuildingException; import org.apache.maven.settings.building.SettingsBuildingRequest; import org.eclipse.microprofile.config.spi.ConfigSource; -import static com.buschmais.jqassistant.commandline.configuration.CliConfiguration.PROXY; -import static com.buschmais.jqassistant.commandline.configuration.Mirror.MIRROR_OF; -import static com.buschmais.jqassistant.commandline.configuration.Mirror.URL; -import static com.buschmais.jqassistant.commandline.configuration.Proxy.*; -import static com.buschmais.jqassistant.core.runtime.api.configuration.Configuration.PREFIX; import static java.util.stream.Collectors.toList; -import static lombok.AccessLevel.PRIVATE; @Slf4j -@NoArgsConstructor(access = PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class MavenSettingsConfigSourceBuilder { private static final String USER_MAVEN_SETTINGS = ".m2/settings.xml"; private static final String DEFAULT_LOCAL_REPOSITORY = ".m2/repository"; - public static ConfigSource createMavenSettingsConfigSource(File userHome, Optional mavenSettingsFile, List profiles) - throws CliConfigurationException { + public static ConfigSource createMavenSettingsConfigSource(File userHome, Optional mavenSettingsFile, List profiles) { Map properties = new HashMap<>(); File settingsFile = mavenSettingsFile.orElseGet(() -> new File(userHome, USER_MAVEN_SETTINGS)); @@ -69,10 +64,13 @@ private static void applyMirrors(Map properties, Settings settin for (Mirror mirror : settings.getMirrors()) { String id = mirror.getId(); if (id != null) { - put(mirror.getUrl(), properties, com.buschmais.jqassistant.commandline.configuration.Mirror.PREFIX, id, URL); - put(mirror.getMirrorOf(), properties, com.buschmais.jqassistant.commandline.configuration.Mirror.PREFIX, id, MIRROR_OF); - applyServerCredentials(id, settings, properties, com.buschmais.jqassistant.commandline.configuration.Mirror.PREFIX, - com.buschmais.jqassistant.commandline.configuration.Mirror.USERNAME, com.buschmais.jqassistant.commandline.configuration.Mirror.PASSWORD); + put(mirror.getUrl(), properties, com.buschmais.jqassistant.core.resolver.configuration.Mirror.PREFIX, id, + com.buschmais.jqassistant.core.resolver.configuration.Mirror.URL); + put(mirror.getMirrorOf(), properties, com.buschmais.jqassistant.core.resolver.configuration.Mirror.PREFIX, id, + com.buschmais.jqassistant.core.resolver.configuration.Mirror.MIRROR_OF); + applyServerCredentials(id, settings, properties, com.buschmais.jqassistant.core.resolver.configuration.Mirror.PREFIX, + com.buschmais.jqassistant.core.resolver.configuration.Mirror.USERNAME, + com.buschmais.jqassistant.core.resolver.configuration.Mirror.PASSWORD); } else { log.warn("Cannot configure mirror from Maven settings without id (url={}).", mirror.getUrl()); } @@ -85,12 +83,18 @@ private static void applyProxy(Map properties, Settings settings .filter(Proxy::isActive) .findFirst() .ifPresent(proxy -> { - put(proxy.getProtocol(), properties, PREFIX, PROXY, PROTOCOL); - put(proxy.getHost(), properties, PREFIX, PROXY, HOST); - put(Integer.toString(proxy.getPort()), properties, PREFIX, PROXY, PORT); - put(proxy.getUsername(), properties, PREFIX, PROXY, USERNAME); - put(proxy.getPassword(), properties, PREFIX, PROXY, PASSWORD); - put(proxy.getNonProxyHosts(), properties, PREFIX, PROXY, NON_PROXY_HOSTS); + put(proxy.getProtocol(), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.PROTOCOL); + put(proxy.getHost(), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.HOST); + put(Integer.toString(proxy.getPort()), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.PORT); + put(proxy.getUsername(), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.USERNAME); + put(proxy.getPassword(), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.PASSWORD); + put(proxy.getNonProxyHosts(), properties, ArtifactResolverConfiguration.PREFIX, ArtifactResolverConfiguration.PROXY, + com.buschmais.jqassistant.core.resolver.configuration.Proxy.NON_PROXY_HOSTS); }); } @@ -167,7 +171,7 @@ private static void applyServerCredentials(String serverId, Settings settings, M } } - private static Settings loadMavenSettings(File settingsFile) throws CliConfigurationException { + private static Settings loadMavenSettings(File settingsFile) throws IllegalStateException { log.info("Using Maven settings from '{}'.", settingsFile); SettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setUserSettingsFile(settingsFile); @@ -177,7 +181,7 @@ private static Settings loadMavenSettings(File settingsFile) throws CliConfigura .build(request) .getEffectiveSettings(); } catch (SettingsBuildingException ex) { - throw new CliConfigurationException("Failed to build settings from " + settingsFile, ex); + throw new IllegalStateException("Failed to build settings from " + settingsFile, ex); } } } diff --git a/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/ArtifactResolverConfiguration.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/ArtifactResolverConfiguration.java new file mode 100644 index 0000000000..432b7be55f --- /dev/null +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/ArtifactResolverConfiguration.java @@ -0,0 +1,23 @@ +package com.buschmais.jqassistant.core.resolver.configuration; + +import java.util.Optional; + +import com.buschmais.jqassistant.core.shared.annotation.Description; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; + +import io.smallrye.config.ConfigMapping; + +@ConfigMapping(prefix = ConfigurationMappingLoader.PREFIX) +public interface ArtifactResolverConfiguration { + + String PREFIX = "jqassistant"; + + String PROXY = "proxy"; + + @Description("The proxy to use for connecting to repositories.") + Optional proxy(); + + @Description("The repositories for resolving plugins and their dependencies.") + Repositories repositories(); + +} diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Mirror.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Mirror.java similarity index 93% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Mirror.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Mirror.java index 353a037af0..bd0a44e6e7 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Mirror.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Mirror.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.configuration; import java.util.Optional; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Policy.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Policy.java similarity index 88% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Policy.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Policy.java index 12cf450e7c..7922a5aeea 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Policy.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Policy.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.configuration; import com.buschmais.jqassistant.core.shared.annotation.Description; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Proxy.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Proxy.java similarity index 92% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Proxy.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Proxy.java index 7996cb862a..6f9e3e3416 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Proxy.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Proxy.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.configuration; import java.util.Optional; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Remote.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Remote.java similarity index 93% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Remote.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Remote.java index 6fe1ae9bc4..636a2bc307 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Remote.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Remote.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.configuration; import java.util.Optional; diff --git a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Repositories.java b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Repositories.java similarity index 93% rename from cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Repositories.java rename to core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Repositories.java index 4114e369fb..a8693d71f3 100644 --- a/cli/application/src/main/java/com/buschmais/jqassistant/commandline/configuration/Repositories.java +++ b/core/artifact-resolver/src/main/java/com/buschmais/jqassistant/core/resolver/configuration/Repositories.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.configuration; import java.io.File; import java.util.Map; diff --git a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactoryTest.java b/core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactoryTest.java similarity index 86% rename from cli/application/src/test/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactoryTest.java rename to core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactoryTest.java index d332126965..c4d32ccbc7 100644 --- a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/plugin/ArtifactProviderFactoryTest.java +++ b/core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/ArtifactProviderFactoryTest.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.plugin; +package com.buschmais.jqassistant.core.resolver.api; import java.io.File; import java.net.URL; @@ -6,11 +6,11 @@ import java.util.Map; import java.util.function.Consumer; -import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.commandline.configuration.Mirror; -import com.buschmais.jqassistant.commandline.configuration.Proxy; -import com.buschmais.jqassistant.commandline.configuration.Repositories; -import com.buschmais.jqassistant.core.runtime.impl.plugin.AetherArtifactProvider; +import com.buschmais.jqassistant.core.resolver.configuration.ArtifactResolverConfiguration; +import com.buschmais.jqassistant.core.resolver.configuration.Mirror; +import com.buschmais.jqassistant.core.resolver.configuration.Proxy; +import com.buschmais.jqassistant.core.resolver.configuration.Repositories; +import com.buschmais.jqassistant.core.shared.aether.AetherArtifactProvider; import org.eclipse.aether.repository.Authentication; import org.eclipse.aether.repository.RemoteRepository; @@ -20,8 +20,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory.MAVEN_CENTRAL_ID; -import static com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory.MAVEN_CENTRAL_URL; +import static com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory.MAVEN_CENTRAL_ID; +import static com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory.MAVEN_CENTRAL_URL; import static java.util.Optional.of; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; @@ -33,7 +33,7 @@ class ArtifactProviderFactoryTest { private ArtifactProviderFactory artifactProviderFactory; @Mock - private CliConfiguration configuration; + private ArtifactResolverConfiguration configuration; @Mock private Repositories repositories; diff --git a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilderTest.java b/core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilderTest.java similarity index 83% rename from cli/application/src/test/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilderTest.java rename to core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilderTest.java index 7eaa005d07..7c8751c102 100644 --- a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/configuration/MavenSettingsConfigSourceBuilderTest.java +++ b/core/artifact-resolver/src/test/java/com/buschmais/jqassistant/core/resolver/api/MavenSettingsConfigSourceBuilderTest.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.commandline.configuration; +package com.buschmais.jqassistant.core.resolver.api; import java.io.File; import java.net.URL; @@ -6,9 +6,11 @@ import java.util.Map; import java.util.Optional; -import com.buschmais.jqassistant.commandline.CliConfigurationException; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; +import com.buschmais.jqassistant.core.resolver.configuration.*; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; import org.eclipse.microprofile.config.spi.ConfigSource; import org.junit.jupiter.api.Test; @@ -19,17 +21,24 @@ class MavenSettingsConfigSourceBuilderTest { + @ConfigMapping(prefix = ArtifactResolverConfiguration.PREFIX) + interface MavenConfiguration extends ArtifactResolverConfiguration { + + @WithDefault("false") + boolean skip(); + + } + @Test - void defaultMavenSettings() throws CliConfigurationException { + void defaultMavenSettings() { URL userHomeUrl = MavenSettingsConfigSourceBuilderTest.class.getResource("/userhome"); File userHome = new File(userHomeUrl.getFile()); ConfigSource configSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(userHome, empty(), emptyList()); - CliConfiguration configuration = ConfigurationMappingLoader.builder(CliConfiguration.class) + MavenConfiguration configuration = ConfigurationMappingLoader.builder(MavenConfiguration.class) .load(configSource); - assertThat(configuration.skip()).isFalse(); Optional proxyOptional = configuration.proxy(); assertThat(proxyOptional).isPresent(); Proxy proxy = proxyOptional.get(); @@ -85,27 +94,27 @@ void defaultMavenSettings() throws CliConfigurationException { } @Test - void userProfile() throws CliConfigurationException { + void userProfile() { URL userHomeUrl = MavenSettingsConfigSourceBuilderTest.class.getResource("/userhome"); File userHome = new File(userHomeUrl.getFile()); ConfigSource configSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(userHome, empty(), List.of("user-profile")); - CliConfiguration configuration = ConfigurationMappingLoader.builder(CliConfiguration.class) + MavenConfiguration configuration = ConfigurationMappingLoader.builder(MavenConfiguration.class) .load(configSource); assertThat(configuration.skip()).isTrue(); } @Test - void customMavenSettings() throws CliConfigurationException { + void customMavenSettings() { URL userHomeUrl = MavenSettingsConfigSourceBuilderTest.class.getResource("/userhome"); File userHome = new File(userHomeUrl.getFile()); File customSettings = new File(userHome, "custom-maven-settings.xml"); ConfigSource configSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(userHome, of(customSettings), emptyList()); - CliConfiguration configuration = ConfigurationMappingLoader.builder(CliConfiguration.class) + MavenConfiguration configuration = ConfigurationMappingLoader.builder(MavenConfiguration.class) .load(configSource); Repositories repositories = configuration.repositories(); @@ -114,13 +123,13 @@ void customMavenSettings() throws CliConfigurationException { } @Test - void customMavenSettingsWithoutLocalRepo() throws CliConfigurationException { + void customMavenSettingsWithoutLocalRepo() { URL userHomeUrl = MavenSettingsConfigSourceBuilderTest.class.getResource("/userhome"); File userHome = new File(userHomeUrl.getFile()); File customSettings = new File(userHome, "custom-maven-settings-without-local-repo.xml"); ConfigSource configSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(userHome, of(customSettings), emptyList()); - CliConfiguration configuration = ConfigurationMappingLoader.builder(CliConfiguration.class) + MavenConfiguration configuration = ConfigurationMappingLoader.builder(MavenConfiguration.class) .load(configSource); Repositories repositories = configuration.repositories(); @@ -128,7 +137,7 @@ void customMavenSettingsWithoutLocalRepo() throws CliConfigurationException { } @Test - void withoutMavenSettings() throws CliConfigurationException { + void withoutMavenSettings() { File userHome = new File("invalid-userhome"); ConfigSource configSource = MavenSettingsConfigSourceBuilder.createMavenSettingsConfigSource(userHome, empty(), emptyList()); diff --git a/cli/application/src/test/resources/userhome/.m2/settings.xml b/core/artifact-resolver/src/test/resources/userhome/.m2/settings.xml similarity index 100% rename from cli/application/src/test/resources/userhome/.m2/settings.xml rename to core/artifact-resolver/src/test/resources/userhome/.m2/settings.xml diff --git a/cli/application/src/test/resources/userhome/custom-maven-settings-without-local-repo.xml b/core/artifact-resolver/src/test/resources/userhome/custom-maven-settings-without-local-repo.xml similarity index 100% rename from cli/application/src/test/resources/userhome/custom-maven-settings-without-local-repo.xml rename to core/artifact-resolver/src/test/resources/userhome/custom-maven-settings-without-local-repo.xml diff --git a/cli/application/src/test/resources/userhome/custom-maven-settings.xml b/core/artifact-resolver/src/test/resources/userhome/custom-maven-settings.xml similarity index 100% rename from cli/application/src/test/resources/userhome/custom-maven-settings.xml rename to core/artifact-resolver/src/test/resources/userhome/custom-maven-settings.xml diff --git a/core/pom.xml b/core/pom.xml index f7b40923fc..da7d7d7815 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -61,14 +61,15 @@ + analysis + artifact-resolver neo4j - schemata shared - rule - report - analysis scanner + schemata store + report + rule runtime test diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml index 9533a7f71b..df10227a66 100644 --- a/core/runtime/pom.xml +++ b/core/runtime/pom.xml @@ -25,24 +25,17 @@ com.buschmais.jqassistant.core report - - io.smallrye.config - smallrye-config-source-yaml - - - - jakarta.annotation - jakarta.annotation-api - - - org.apache.maven.resolver - maven-resolver-util - provided - org.projectlombok lombok + + + com.buschmais.jqassistant.core + artifact-resolver + ${project.version} + test + org.assertj assertj-core diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/Configuration.java b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/Configuration.java index c70f44f00c..03a0e412c7 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/Configuration.java +++ b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/Configuration.java @@ -4,8 +4,8 @@ import com.buschmais.jqassistant.core.analysis.api.configuration.Analyze; import com.buschmais.jqassistant.core.scanner.api.configuration.Scan; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import com.buschmais.jqassistant.core.shared.annotation.Description; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; import com.buschmais.jqassistant.core.store.api.configuration.Store; import com.buschmais.jqassistant.neo4j.embedded.api.configuration.Server; diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/PluginResolverImpl.java b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/PluginResolverImpl.java index afc1aa8eca..01545345dc 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/PluginResolverImpl.java +++ b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/PluginResolverImpl.java @@ -10,8 +10,8 @@ import com.buschmais.jqassistant.core.runtime.api.plugin.PluginClassLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepositoryException; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginResolver; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/CliPluginResolverIT.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/PluginResolverIT.java similarity index 66% rename from cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/CliPluginResolverIT.java rename to core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/PluginResolverIT.java index f88773b32e..1c7590cfe7 100644 --- a/cli/application/src/test/java/com/buschmais/jqassistant/commandline/task/CliPluginResolverIT.java +++ b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/PluginResolverIT.java @@ -1,40 +1,46 @@ -package com.buschmais.jqassistant.commandline.task; +package com.buschmais.jqassistant.core.runtime; import java.io.File; import java.util.HashMap; import java.util.Map; -import com.buschmais.jqassistant.commandline.configuration.CliConfiguration; -import com.buschmais.jqassistant.commandline.plugin.ArtifactProviderFactory; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; +import com.buschmais.jqassistant.core.resolver.api.ArtifactProviderFactory; +import com.buschmais.jqassistant.core.resolver.configuration.ArtifactResolverConfiguration; +import com.buschmais.jqassistant.core.runtime.api.configuration.Configuration; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginClassLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginResolver; import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginResolverImpl; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; +import io.smallrye.config.ConfigMapping; import io.smallrye.config.PropertiesConfigSource; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -public class CliPluginResolverIT { +class PluginResolverIT { + + @ConfigMapping(prefix = Configuration.PREFIX) + interface TestConfiguration extends Configuration, ArtifactResolverConfiguration { + } @Test void resolve() { Map configurationProperties = new HashMap<>(); - configurationProperties.put("jqassistant.plugins[0].group-id","org.jqassistant.plugin"); - configurationProperties.put("jqassistant.plugins[0].artifact-id","jqassistant-docker-plugin"); - configurationProperties.put("jqassistant.plugins[0].version","2.1.0"); + configurationProperties.put("jqassistant.plugins[0].group-id", "org.jqassistant.plugin"); + configurationProperties.put("jqassistant.plugins[0].artifact-id", "jqassistant-docker-plugin"); + configurationProperties.put("jqassistant.plugins[0].version", "2.1.0"); PropertiesConfigSource testConfigSource = new PropertiesConfigSource(configurationProperties, "TestConfigSource", 110); - CliConfiguration cliConfiguration = ConfigurationMappingLoader.builder(CliConfiguration.class) + TestConfiguration configuration = ConfigurationMappingLoader.builder(TestConfiguration.class) .load(testConfigSource); ArtifactProviderFactory artifactProviderFactory = new ArtifactProviderFactory(new File("target/it/userhome")); - ArtifactProvider artifactProvider = artifactProviderFactory.create(cliConfiguration); + ArtifactProvider artifactProvider = artifactProviderFactory.create(configuration); PluginResolver pluginResolver = new PluginResolverImpl(artifactProvider); - PluginClassLoader pluginClassLoader = pluginResolver.createClassLoader(ArtifactProviderFactory.class.getClassLoader(), cliConfiguration); + PluginClassLoader pluginClassLoader = pluginResolver.createClassLoader(ArtifactProviderFactory.class.getClassLoader(), configuration); assertThat(pluginClassLoader).isNotNull(); } diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoaderTest.java similarity index 70% rename from core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java rename to core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoaderTest.java index 041bb2d957..2c0be9f5cb 100644 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java +++ b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoaderTest.java @@ -1,16 +1,17 @@ -package com.buschmais.jqassistant.core.runtime.impl.configuration; +package com.buschmais.jqassistant.core.runtime.api.configuration; 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; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SysPropConfigSource; +import org.assertj.core.api.Assertions; import org.eclipse.microprofile.config.spi.ConfigSource; import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.SetEnvironmentVariable; @@ -24,16 +25,16 @@ */ class ConfigurationMappingLoaderTest { - public static final File USER_HOME = new File("src/test/resources/userhome"); + public static final File USER_HOME = new File("src/test/resources/configuration/userhome"); - public static final File WORKING_DIRECTORY = new File("src/test/resources/working directory"); + public static final File WORKING_DIRECTORY = new File("src/test/resources/configuration/working directory"); /** * Load all yaml/yml config files from the working directory. */ @Test void loadFromDefaultConfigLocations() { - TestConfiguration configuration = getConfiguration(emptyList()); + Configuration configuration = getConfiguration(emptyList()); assertThat(configuration).isNotNull(); @@ -57,7 +58,7 @@ void loadFromDefaultConfigLocations() { */ @Test void loadFromConfigLocation() { - TestConfiguration configuration = getConfiguration(singletonList(".jqassistant/scan/scan.yaml")); + Configuration configuration = getConfiguration(singletonList(".jqassistant/scan/scan.yaml")); assertThat(configuration).isNotNull(); @@ -75,17 +76,18 @@ void loadFromConfigLocation() { @Test void profile() { - TestConfiguration configuration = getConfiguration(singletonList(".jqassistant/profile.yml"), List.of("test-profile")); + Configuration configuration = getConfiguration(singletonList(".jqassistant/profile.yml"), List.of("test-profile")); - assertThat(configuration.scan() - .properties()).containsEntry("profile-user-value", "test-value"); + Assertions.assertThat(configuration.scan() + .properties()) + .containsEntry("profile-user-value", "test-value"); } @Test void ignoreProperty() { String unknownProperty = "jqassistant.unknown"; - TestConfiguration configuration = ConfigurationMappingLoader.builder(TestConfiguration.class, emptyList()) + Configuration configuration = ConfigurationMappingLoader.builder(Configuration.class, emptyList()) .withUserHome(USER_HOME) .withWorkingDirectory(WORKING_DIRECTORY) .withIgnoreProperties(Set.of(unknownProperty)) @@ -97,9 +99,10 @@ void ignoreProperty() { @Test @SetEnvironmentVariable(key = "jqassistant_scan_continue_on_error", value = "false") void overrideFromEnvVariable() { - TestConfiguration configuration = getConfiguration(emptyList()); - assertThat(configuration.scan() - .continueOnError()).isFalse(); + Configuration configuration = getConfiguration(emptyList()); + Assertions.assertThat(configuration.scan() + .continueOnError()) + .isFalse(); } @Test @@ -115,20 +118,21 @@ void useExpressionFromSystemProperty() { private void overrideFromSystemProperty(String continueOnError) { System.setProperty(continueOnError, "false"); try { - TestConfiguration configuration = getConfiguration(emptyList()); - assertThat(configuration.scan() - .continueOnError()).isFalse(); + Configuration configuration = getConfiguration(emptyList()); + Assertions.assertThat(configuration.scan() + .continueOnError()) + .isFalse(); } finally { System.clearProperty(continueOnError); } } - private TestConfiguration getConfiguration(List configLocations) { + private Configuration getConfiguration(List configLocations) { return getConfiguration(configLocations, emptyList()); } - private TestConfiguration getConfiguration(List configLocations, List profiles) { - return ConfigurationMappingLoader.builder(TestConfiguration.class, configLocations) + private Configuration getConfiguration(List configLocations, List profiles) { + return ConfigurationMappingLoader.builder(Configuration.class, configLocations) .withUserHome(USER_HOME) .withWorkingDirectory(WORKING_DIRECTORY) .withClasspath() diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationSerializerTest.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializerTest.java similarity index 63% rename from core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationSerializerTest.java rename to core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializerTest.java index 2f8b54fc72..c9daf77ff0 100644 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationSerializerTest.java +++ b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializerTest.java @@ -1,18 +1,19 @@ -package com.buschmais.jqassistant.core.runtime.impl.configuration; +package com.buschmais.jqassistant.core.runtime.api.configuration; import java.util.Properties; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationSerializer; import com.buschmais.jqassistant.core.scanner.api.configuration.Scan; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationSerializer; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.source.yaml.YamlConfigSource; import lombok.extern.slf4j.Slf4j; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import static com.buschmais.jqassistant.core.runtime.impl.configuration.ConfigurationMappingLoaderTest.USER_HOME; -import static com.buschmais.jqassistant.core.runtime.impl.configuration.ConfigurationMappingLoaderTest.WORKING_DIRECTORY; +import static com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoaderTest.USER_HOME; +import static com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoaderTest.WORKING_DIRECTORY; import static org.assertj.core.api.Assertions.assertThat; /** @@ -21,7 +22,7 @@ @Slf4j class ConfigurationSerializerTest { - private final ConfigurationSerializer configurationSerializer = new ConfigurationSerializer<>(); + private final ConfigurationSerializer configurationSerializer = new ConfigurationSerializer<>(); @Test void types() { @@ -33,7 +34,7 @@ void types() { properties.put("jqassistant.plugins[0].artifact-id", "test-plugin"); properties.put("jqassistant.plugins[0].version", "1.0.0"); PropertiesConfigSource configSource = new PropertiesConfigSource(properties, "test"); - TestConfiguration configuration = ConfigurationMappingLoader.builder(TestConfiguration.class) + Configuration configuration = ConfigurationMappingLoader.builder(Configuration.class) .load(configSource); String yaml = toYaml(configuration); @@ -47,7 +48,7 @@ void types() { @Test void serializeAndRestoreConfiguration() { - TestConfiguration configuration = ConfigurationMappingLoader.builder(TestConfiguration.class) + Configuration configuration = ConfigurationMappingLoader.builder(Configuration.class) .withUserHome(USER_HOME) .withWorkingDirectory(WORKING_DIRECTORY) .load(); @@ -56,14 +57,16 @@ void serializeAndRestoreConfiguration() { YamlConfigSource yamlConfigSource = new YamlConfigSource("yaml", yaml); assertThat(yamlConfigSource.getValue("jqassistant.analyze.execute-applied-concepts")).isEqualTo("false"); - TestConfiguration restoredConfiguration = ConfigurationMappingLoader.builder(TestConfiguration.class) + Configuration restoredConfiguration = ConfigurationMappingLoader.builder(Configuration.class) .load(yamlConfigSource); Scan scan = restoredConfiguration.scan(); - assertThat(scan.properties()).containsEntry("user-value", "default"); - assertThat(scan.properties()).containsEntry("overwritten-user-value", "overwritten"); + Assertions.assertThat(scan.properties()) + .containsEntry("user-value", "default"); + Assertions.assertThat(scan.properties()) + .containsEntry("overwritten-user-value", "overwritten"); } - private String toYaml(TestConfiguration configuration) { + private String toYaml(Configuration configuration) { String yaml = configurationSerializer.toYaml(configuration); log.info("\n{}", yaml); return yaml; diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/TestConfiguration.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/TestConfiguration.java deleted file mode 100644 index 19ba6b944d..0000000000 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/TestConfiguration.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.buschmais.jqassistant.core.runtime.impl.configuration; - -import com.buschmais.jqassistant.core.runtime.api.configuration.Configuration; - -import io.smallrye.config.ConfigMapping; - -@ConfigMapping(prefix = Configuration.PREFIX) -public interface TestConfiguration extends Configuration { -} diff --git a/core/runtime/src/test/resources/userhome/.jqassistant.yml b/core/runtime/src/test/resources/configuration/userhome/.jqassistant.yml similarity index 100% rename from core/runtime/src/test/resources/userhome/.jqassistant.yml rename to core/runtime/src/test/resources/configuration/userhome/.jqassistant.yml diff --git a/core/runtime/src/test/resources/working directory/.jqassistant/plugins.yml b/core/runtime/src/test/resources/configuration/working directory/.jqassistant/plugins.yml similarity index 100% rename from core/runtime/src/test/resources/working directory/.jqassistant/plugins.yml rename to core/runtime/src/test/resources/configuration/working directory/.jqassistant/plugins.yml diff --git a/core/runtime/src/test/resources/working directory/.jqassistant/profile.yml b/core/runtime/src/test/resources/configuration/working directory/.jqassistant/profile.yml similarity index 100% rename from core/runtime/src/test/resources/working directory/.jqassistant/profile.yml rename to core/runtime/src/test/resources/configuration/working directory/.jqassistant/profile.yml diff --git a/core/runtime/src/test/resources/working directory/.jqassistant/readme.txt b/core/runtime/src/test/resources/configuration/working directory/.jqassistant/readme.txt similarity index 100% rename from core/runtime/src/test/resources/working directory/.jqassistant/readme.txt rename to core/runtime/src/test/resources/configuration/working directory/.jqassistant/readme.txt diff --git a/core/runtime/src/test/resources/working directory/.jqassistant/scan/scan.yaml b/core/runtime/src/test/resources/configuration/working directory/.jqassistant/scan/scan.yaml similarity index 100% rename from core/runtime/src/test/resources/working directory/.jqassistant/scan/scan.yaml rename to core/runtime/src/test/resources/configuration/working directory/.jqassistant/scan/scan.yaml diff --git a/core/shared/pom.xml b/core/shared/pom.xml index f7a9d4b005..bbdb1fdc54 100644 --- a/core/shared/pom.xml +++ b/core/shared/pom.xml @@ -57,6 +57,20 @@ io.smallrye.config smallrye-config-core + + io.smallrye.config + smallrye-config-source-yaml + + + + jakarta.annotation + jakarta.annotation-api + + + org.apache.maven.resolver + maven-resolver-util + provided + javax.xml.bind jaxb-api @@ -100,6 +114,11 @@ junit-jupiter-engine test + + org.junit-pioneer + junit-pioneer + test + org.assertj assertj-core @@ -115,4 +134,4 @@ jaxb-runtime - \ No newline at end of file + diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/AetherArtifactProvider.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/AetherArtifactProvider.java similarity index 89% rename from core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/AetherArtifactProvider.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/AetherArtifactProvider.java index df3e43fee9..7700238fc7 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/impl/plugin/AetherArtifactProvider.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/AetherArtifactProvider.java @@ -1,12 +1,11 @@ -package com.buschmais.jqassistant.core.runtime.impl.plugin; +package com.buschmais.jqassistant.core.shared.aether; import java.io.File; import java.util.Collection; import java.util.List; -import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepositoryException; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -24,10 +23,10 @@ import org.eclipse.aether.resolution.DependencyRequest; import org.eclipse.aether.resolution.DependencyResolutionException; import org.eclipse.aether.resolution.DependencyResult; +import org.eclipse.aether.util.artifact.JavaScopes; import org.eclipse.aether.util.filter.DependencyFilterUtils; import static java.util.stream.Collectors.toList; -import static org.eclipse.aether.util.artifact.JavaScopes.RUNTIME; @Slf4j @Getter @@ -53,7 +52,7 @@ private List getDependencies(List plugins) { } private DependencyResult resolvePlugins(List dependencies) { - DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(RUNTIME); + DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyResult dependencyResult = resolveDependencies(classpathFilter, dependencies); if (log.isDebugEnabled()) { logDependencyTree(dependencyResult.getRoot(), 0); @@ -75,10 +74,10 @@ private List getPluginDependencies(Plugin plugin) { private static Dependency getDependency(Plugin plugin, String artifactId, List exlusions) { return new Dependency(new DefaultArtifact(plugin.groupId(), artifactId, plugin.classifier() - .orElse(null), plugin.type(), plugin.version()), RUNTIME, false, exlusions); + .orElse(null), plugin.type(), plugin.version()), JavaScopes.RUNTIME, false, exlusions); } - private static List getPluginExclusions(com.buschmais.jqassistant.core.shared.configuration.Exclusion exclusion) { + private static List getPluginExclusions(com.buschmais.jqassistant.core.shared.aether.configuration.Exclusion exclusion) { return exclusion.artifactId() .stream() .map(artifactId -> new Exclusion(exclusion.groupId(), artifactId.trim(), exclusion.classifier() @@ -94,7 +93,7 @@ private DependencyResult resolveDependencies(DependencyFilter classpathFilter, L try { return repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest); } catch (DependencyResolutionException e) { - throw new PluginRepositoryException("Cannot resolve plugin dependencies", e); + throw new IllegalStateException("Cannot resolve plugin dependencies", e); } } diff --git a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Exclusion.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Exclusion.java similarity index 90% rename from core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Exclusion.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Exclusion.java index 0eae217387..9edaf38ec8 100644 --- a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Exclusion.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Exclusion.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.shared.configuration; +package com.buschmais.jqassistant.core.shared.aether.configuration; import java.util.List; import java.util.Optional; diff --git a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Plugin.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Plugin.java similarity index 92% rename from core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Plugin.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Plugin.java index d2d8e75ed0..f716e4d2a7 100644 --- a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/Plugin.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/aether/configuration/Plugin.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.shared.configuration; +package com.buschmais.jqassistant.core.shared.aether.configuration; import java.util.List; import java.util.Optional; diff --git a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/artifact/ArtifactProvider.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/artifact/ArtifactProvider.java index 7b045c6dda..d91f4342fc 100644 --- a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/artifact/ArtifactProvider.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/artifact/ArtifactProvider.java @@ -3,7 +3,7 @@ import java.io.File; import java.util.List; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; public interface ArtifactProvider { diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilder.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilder.java similarity index 99% rename from core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilder.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilder.java index c9bf7cb901..3e78f1471b 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilder.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilder.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.runtime.api.configuration; +package com.buschmais.jqassistant.core.shared.configuration; import java.net.URI; import java.util.HashMap; diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java similarity index 93% rename from core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java index effb89df6f..56f847bae6 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationMappingLoader.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.runtime.api.configuration; +package com.buschmais.jqassistant.core.shared.configuration; import java.io.File; import java.io.IOException; @@ -35,12 +35,10 @@ public class ConfigurationMappingLoader { /** - * The default names of configuration files + * The config prefix for jQA. */ - public static final List DEFAULT_CONFIG_LOCATIONS = List.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant") - .stream() - .map(Paths::get) - .collect(toUnmodifiableList()); + public static final String PREFIX = "jqassistant"; + /** * The ordinal for config sources from the user home. @@ -60,31 +58,39 @@ public class ConfigurationMappingLoader { private static final String YAML = ".yaml"; private static final String YML = ".yml"; + /** + * The default names of configuration files + */ + private static final List DEFAULT_CONFIG_LOCATIONS = List.of(".jqassistant.yml", ".jqassistant.yaml", ".jqassistant") + .stream() + .map(Paths::get) + .collect(toUnmodifiableList()); + private static final String CLASSPATH_RESOURCE = ".jqassistant.yml"; /** - * Return a builder for creating a {@link Configuration}. + * Return a builder for creating a configuration mapping. * * @param configurationMapping - * The {@link Configuration} mapping. + * The configuration mapping mapping. */ - public static Builder builder(Class configurationMapping) { + public static Builder builder(Class configurationMapping) { return new Builder<>(configurationMapping, emptyList()); } /** - * Return a builder for creating a {@link Configuration}. + * Return a builder for creating a configuration mapping * * @param configurationMapping - * The {@link Configuration} mapping. + * The configuration mapping mapping. * @param configLocations * The names of the configuration locations. These may either be absolute paths or relative paths to the working directory. */ - public static Builder builder(Class configurationMapping, List configLocations) { + public static Builder builder(Class configurationMapping, List configLocations) { return new Builder<>(configurationMapping, configLocations); } - public static class Builder { + public static class Builder { private final ConfigurationSerializer configurationSerializer = new ConfigurationSerializer<>(); @@ -198,7 +204,7 @@ public Builder withIgnoreProperties(Collection ignoreProperties) { } /** - * Load the {@link Configuration} using the given directory including + * Load the configuration using the given directory including *

* - yml/yaml files present in the given configuration directory * - system properties @@ -206,7 +212,7 @@ public Builder withIgnoreProperties(Collection ignoreProperties) { * * @param additionalConfigSources * Additional {@link ConfigSource}s to consider, e.g. from a CLI or Maven Mojo. - * @return The {@link Configuration}. + * @return The configuration. */ public C load(ConfigSource... additionalConfigSources) { // Create intermediate configuration with applied profiles and interpolated properties (without validation) @@ -229,7 +235,7 @@ public C load(ConfigSource... additionalConfigSources) { private void logConfigProblems(SmallRyeConfig interpolatedConfig) { Map filteredProperties = stream(interpolatedConfig.getPropertyNames() - .spliterator(), false).filter(property -> property.startsWith(Configuration.PREFIX)) + .spliterator(), false).filter(property -> property.startsWith(PREFIX)) .filter(property -> !ignoreProperties.contains(property)) .collect(toMap(property -> property, interpolatedConfig::getRawValue, (s1, s2) -> null, () -> new TreeMap<>())); log.debug("jQAssistant config properties:"); diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializer.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationSerializer.java similarity index 96% rename from core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializer.java rename to core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationSerializer.java index 8404c5d212..2a854af271 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationSerializer.java +++ b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationSerializer.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.runtime.api.configuration; +package com.buschmais.jqassistant.core.shared.configuration; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; @@ -11,6 +11,7 @@ import io.smallrye.config.ConfigMappingInterface; import lombok.extern.slf4j.Slf4j; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.DumperOptions.FlowStyle; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.introspector.BeanAccess; import org.yaml.snakeyaml.introspector.MethodProperty; @@ -26,10 +27,9 @@ import static io.smallrye.config.ConfigMappingInterface.getConfigurationInterface; import static java.util.Arrays.stream; import static java.util.Collections.emptyMap; -import static org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK; @Slf4j -public class ConfigurationSerializer { +public class ConfigurationSerializer { public String toYaml(C configuration) { DumperOptions dumperOptions = getDumperOptions(); @@ -48,7 +48,7 @@ public String toYaml(C configuration) { private static DumperOptions getDumperOptions() { DumperOptions dumperOptions = new DumperOptions(); - dumperOptions.setDefaultFlowStyle(BLOCK); + dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK); dumperOptions.setPrettyFlow(true); dumperOptions.setIndent(2); dumperOptions.setAllowReadOnlyProperties(true); diff --git a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/option/OptionHelper.java b/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/option/OptionHelper.java deleted file mode 100644 index 1832f208fa..0000000000 --- a/core/shared/src/main/java/com/buschmais/jqassistant/core/shared/option/OptionHelper.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.buschmais.jqassistant.core.shared.option; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides shared functionality for working with options, e.g. from the command - * line. - */ -public final class OptionHelper { - - private static final Logger LOGGER = LoggerFactory.getLogger(OptionHelper.class); - - /** - * Determine the first non-null value from the given options. - * - * @param values - * The option that override the default value, the first non-null - * value will be accepted. - * @param - * The value type. - * @return The value. - */ - public static T coalesce(T... values) { - for (T override : values) { - if (override != null) { - return override; - } - } - return null; - } - - /** - * Verify if a deprecated option has been used and emit a warning. - * - * @param deprecatedOption - * The name of the deprecated option. - * @param value - * The provided value. - * @param option - * The option to use. - * @param - * The value type. - */ - public static void verifyDeprecatedOption(String deprecatedOption, T value, String option) { - if (value != null) { - LOGGER.warn("The option '" + deprecatedOption + "' is deprecated, use '" + option + "' instead."); - } - } - -} diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilderTest.java b/core/shared/src/test/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilderTest.java similarity index 96% rename from core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilderTest.java rename to core/shared/src/test/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilderTest.java index b91c9c3769..f223030742 100644 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationBuilderTest.java +++ b/core/shared/src/test/java/com/buschmais/jqassistant/core/shared/configuration/ConfigurationBuilderTest.java @@ -1,4 +1,4 @@ -package com.buschmais.jqassistant.core.runtime.api.configuration; +package com.buschmais.jqassistant.core.shared.configuration; import java.util.Map; diff --git a/core/store/src/main/java/com/buschmais/jqassistant/core/store/api/configuration/Embedded.java b/core/store/src/main/java/com/buschmais/jqassistant/core/store/api/configuration/Embedded.java index 4231afa30c..d7b7be4bbd 100644 --- a/core/store/src/main/java/com/buschmais/jqassistant/core/store/api/configuration/Embedded.java +++ b/core/store/src/main/java/com/buschmais/jqassistant/core/store/api/configuration/Embedded.java @@ -2,7 +2,7 @@ import java.util.List; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithDefault; diff --git a/core/store/src/main/java/com/buschmais/jqassistant/core/store/impl/EmbeddedGraphStore.java b/core/store/src/main/java/com/buschmais/jqassistant/core/store/impl/EmbeddedGraphStore.java index 31372845b0..e98871f598 100644 --- a/core/store/src/main/java/com/buschmais/jqassistant/core/store/impl/EmbeddedGraphStore.java +++ b/core/store/src/main/java/com/buschmais/jqassistant/core/store/impl/EmbeddedGraphStore.java @@ -5,8 +5,8 @@ import java.util.List; import java.util.Properties; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; -import com.buschmais.jqassistant.core.shared.configuration.Plugin; import com.buschmais.jqassistant.core.store.api.Store; import com.buschmais.jqassistant.core.store.api.configuration.Embedded; import com.buschmais.jqassistant.core.store.spi.StorePluginRepository; diff --git a/core/test/pom.xml b/core/test/pom.xml index d660d546cc..cd58bbf673 100644 --- a/core/test/pom.xml +++ b/core/test/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 com.buschmais.jqassistant.core @@ -9,11 +10,25 @@ test jQAssistant Test Framework + + + + ${project.basedir}/src/test/resources + true + + + + com.buschmais.jqassistant.core runtime + + com.buschmais.jqassistant.core + artifact-resolver + ${project.version} + org.projectlombok lombok @@ -59,4 +74,23 @@ runtime + + + + neo4jv5 + + [17,) + + + + + org.neo4j.procedure + apoc-core + core + ${neo4j_5x.version} + test + + + + 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 fc4e46d085..2d0d854dce 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 @@ -20,14 +20,13 @@ import com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin; 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.rule.api.model.*; import com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin; import com.buschmais.jqassistant.core.rule.api.source.FileRuleSource; import com.buschmais.jqassistant.core.rule.api.source.RuleSource; import com.buschmais.jqassistant.core.rule.impl.reader.RuleParser; import com.buschmais.jqassistant.core.runtime.api.configuration.Configuration; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginClassLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginConfigurationReader; import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginConfigurationReaderImpl; @@ -38,6 +37,9 @@ import com.buschmais.jqassistant.core.scanner.impl.ScannerContextImpl; import com.buschmais.jqassistant.core.scanner.impl.ScannerImpl; import com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository; +import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.store.api.Store; import com.buschmais.jqassistant.core.store.api.StoreFactory; import com.buschmais.xo.api.Query; @@ -48,7 +50,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; -import org.junit.jupiter.api.*; +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; @@ -60,22 +65,30 @@ */ public abstract class AbstractPluginIT { - public static final File TEST_STORE_DIRECTORY = new File("target/jqassistant/test-store"); + private static final File USER_HOME = new File(System.getProperty("user.home")); - protected static final String ARTIFACT_ID = "artifact"; + private static final File WORKING_DIRECTORY = new File("."); - private static PluginRepositoryImpl pluginRepository; + private static final File OUTPUT_DIRECTORY = new File(WORKING_DIRECTORY, "target/jqassistant"); - private File workingDirectory; + private static final File TEST_STORE_DIRECTORY = new File("target/jqassistant/test-store"); - private File outputDirectory; + protected static final String ARTIFACT_ID = "artifact"; + + private static ArtifactProviderFactory artifactProviderFactory; + + private static PluginRepositoryImpl pluginRepository; protected Store store; + protected InMemoryReportPlugin reportPlugin; + protected RuleSet ruleSet; @BeforeAll - public static void initPluginRepository() { + public static final void initPluginRepository() { + artifactProviderFactory = new ArtifactProviderFactory(USER_HOME); + OUTPUT_DIRECTORY.mkdirs(); PluginClassLoader pluginClassLoader = new PluginClassLoader(AbstractPluginIT.class.getClassLoader()); PluginConfigurationReader pluginConfigurationReader = new PluginConfigurationReaderImpl(pluginClassLoader); pluginRepository = new PluginRepositoryImpl(pluginConfigurationReader); @@ -83,7 +96,7 @@ public static void initPluginRepository() { } @AfterAll - public static void destroyPluginRepository() { + public static final void destroyPluginRepository() { if (pluginRepository != null) { pluginRepository.destroy(); } @@ -93,11 +106,8 @@ public static void destroyPluginRepository() { public void beforeEach() throws IOException, RuleException { ConfigurationBuilder configurationBuilder = createConfigurationBuilder(); configure(configurationBuilder); - Configuration configuration = createConfiguration(configurationBuilder); - workingDirectory = new File("."); - outputDirectory = new File(workingDirectory, "target/jqassistant"); - outputDirectory.mkdirs(); - startStore(configuration.store()); + ITConfiguration configuration = createConfiguration(configurationBuilder); + startStore(configuration); initializeRuleSet(configuration); initializeReportPlugin(configuration); } @@ -130,12 +140,12 @@ public void stopStore() { * * @return The configuration. */ - private Configuration createConfiguration(ConfigurationBuilder configurationBuilder) { - return ConfigurationMappingLoader.builder(Configuration.class) - .withClasspath() - .withProfiles(getConfigurationProfiles()) - .load(configurationBuilder.build(), new EnvConfigSource() { - }, new SysPropConfigSource()); + private ITConfiguration createConfiguration(ConfigurationBuilder configurationBuilder) { + return ConfigurationMappingLoader.builder(ITConfiguration.class) + .withClasspath() + .withProfiles(getConfigurationProfiles()) + .load(configurationBuilder.build(), new EnvConfigSource() { + }, new SysPropConfigSource()); } private void initializeRuleSet(Configuration configuration) throws RuleException, IOException { @@ -147,10 +157,10 @@ private void initializeRuleSet(Configuration configuration) throws RuleException } // read rules from plugins sources.addAll(pluginRepository.getRulePluginRepository() - .getRuleSources()); + .getRuleSources()); Collection ruleParserPlugins = pluginRepository.getRulePluginRepository() - .getRuleParserPlugins(configuration.analyze() - .rule()); + .getRuleParserPlugins(configuration.analyze() + .rule()); RuleParser ruleParser = new RuleParser(ruleParserPlugins); ruleSet = ruleParser.parse(sources); } @@ -160,10 +170,10 @@ private File getRulesDirectory() { } private void initializeReportPlugin(Configuration configuration) { - ReportContext reportContext = new ReportContextImpl(pluginRepository.getClassLoader(), store, outputDirectory); + ReportContext reportContext = new ReportContextImpl(pluginRepository.getClassLoader(), store, OUTPUT_DIRECTORY); Map reportPlugins = pluginRepository.getAnalyzerPluginRepository() - .getReportPlugins(configuration.analyze() - .report(), reportContext); + .getReportPlugins(configuration.analyze() + .report(), reportContext); this.reportPlugin = new InMemoryReportPlugin(new CompositeReportPlugin(reportPlugins)); } @@ -183,7 +193,7 @@ protected Map getReportProperties() { protected Map> getRuleInterpreterPlugins() { return pluginRepository.getAnalyzerPluginRepository() - .getRuleInterpreterPlugins(getRuleInterpreterProperties()); + .getRuleInterpreterPlugins(getRuleInterpreterProperties()); } protected Map getRuleInterpreterProperties() { @@ -193,10 +203,12 @@ protected Map getRuleInterpreterProperties() { /** * Initializes and resets the store. */ - private void startStore(com.buschmais.jqassistant.core.store.api.configuration.Store storeConfiguration) { - StoreFactory storeFactory = new StoreFactory(pluginRepository.getStorePluginRepository(), plugins -> emptyList()); - store = storeFactory.getStore(storeConfiguration, () -> TEST_STORE_DIRECTORY); + private void startStore(ITConfiguration configuration) { + ArtifactProvider artifactProvider = artifactProviderFactory.create(configuration); + StoreFactory storeFactory = new StoreFactory(pluginRepository.getStorePluginRepository(), artifactProvider); + store = storeFactory.getStore(configuration.store(), () -> TEST_STORE_DIRECTORY); store.start(); + store.reset(); } /** @@ -216,16 +228,16 @@ protected Scanner getScanner() { protected Scanner getScanner(Map properties) { ConfigurationBuilder configurationBuilder = createConfigurationBuilder().with(Scan.class, Scan.PROPERTIES, properties); Configuration configuration = createConfiguration(configurationBuilder); - ScannerContext scannerContext = new ScannerContextImpl(pluginRepository.getClassLoader(), store, workingDirectory, outputDirectory); + ScannerContext scannerContext = new ScannerContextImpl(pluginRepository.getClassLoader(), store, WORKING_DIRECTORY, OUTPUT_DIRECTORY); ScannerPluginRepository scannerPluginRepository = pluginRepository.getScannerPluginRepository(); return new ScannerImpl(configuration.scan(), scannerContext, scannerPluginRepository); } - private Analyzer getAnalyzer(Map parameters) throws RuleException { + private Analyzer getAnalyzer(Map parameters) { ConfigurationBuilder configurationBuilder = createConfigurationBuilder().with(Analyze.class, Analyze.RULE_PARAMETERS, parameters); Configuration configuration = createConfiguration(configurationBuilder); Baseline baselineConfiguration = configuration.analyze() - .baseline(); + .baseline(); BaselineRepository baselineRepository = new BaselineRepository(baselineConfiguration, getRulesDirectory()); BaselineManager baselineManager = new BaselineManager(baselineConfiguration, baselineRepository); return new AnalyzerImpl(configuration.analyze(), pluginRepository.getClassLoader(), store, getRuleInterpreterPlugins(), baselineManager, reportPlugin); @@ -235,16 +247,16 @@ private Analyzer getAnalyzer(Map parameters) throws RuleExceptio * Determines the directory a class is located in (e.g. target/test-classes). * * @param rootClass - * The class. + * The class. * @return The directory. */ protected File getClassesDirectory(Class rootClass) { String path = URLDecoder.decode(rootClass.getClassLoader() - .getResource(".") - .getPath(), Charset.defaultCharset()); + .getResource(".") + .getPath(), Charset.defaultCharset()); File directory = new File(path); assertThat(directory).isDirectory() - .describedAs("Expected %s to be a directory", directory.toString()); + .describedAs("Expected %s to be a directory", directory.toString()); return directory; } @@ -252,7 +264,7 @@ protected File getClassesDirectory(Class rootClass) { * Executes a CYPHER query and returns a {@link AbstractPluginIT.TestResult} . * * @param query - * The query. + * The query. * @return The {@link AbstractPluginIT.TestResult}. */ protected TestResult query(String query) { @@ -263,9 +275,9 @@ protected TestResult query(String query) { * Executes a CYPHER query and returns a {@link AbstractPluginIT.TestResult} . * * @param query - * The query. + * The query. * @param parameters - * The query parameters. + * The query parameters. * @return The {@link AbstractPluginIT.TestResult}. */ protected TestResult query(String query, Map parameters) { @@ -294,7 +306,7 @@ protected TestResult query(String query, Map parameters) { * Applies the concept identified by id. * * @param id - * The id. + * The id. * @return The result. */ protected Result applyConcept(String id) throws RuleException { @@ -305,30 +317,30 @@ protected Result applyConcept(String id) throws RuleException { * Applies the concept identified by id. * * @param id - * The id. + * The id. * @param parameters - * The rule parameters. + * The rule parameters. * @return The result. */ protected Result applyConcept(String id, Map parameters) throws RuleException { Analyzer analyzer = getAnalyzer(parameters); RuleSelection ruleSelection = RuleSelection.builder() - .conceptId(id) - .build(); + .conceptId(id) + .build(); Concept concept = ruleSet.getConceptBucket() - .getById(id); + .getById(id); assertThat(concept).describedAs("The requested concept cannot be found: " + id) - .isNotNull(); + .isNotNull(); analyzer.execute(ruleSet, ruleSelection); return reportPlugin.getConceptResults() - .get(id); + .get(id); } /** * Validates the constraint identified by id. * * @param id - * The id. + * The id. * @return The result. */ protected Result validateConstraint(String id) throws RuleException { @@ -339,29 +351,29 @@ protected Result validateConstraint(String id) throws RuleException * Validates the constraint identified by id. * * @param id - * The id. + * The id. * @param parameters - * The rule parameters. + * The rule parameters. * @return The result. */ protected Result validateConstraint(String id, Map parameters) throws RuleException { RuleSelection ruleSelection = RuleSelection.builder() - .constraintId(id) - .build(); + .constraintId(id) + .build(); Constraint constraint = ruleSet.getConstraintBucket() - .getById(id); + .getById(id); assertThat(constraint).describedAs("The requested constraint cannot be found: " + id) - .isNotNull(); + .isNotNull(); getAnalyzer(parameters).execute(ruleSet, ruleSelection); return reportPlugin.getConstraintResults() - .get(id); + .get(id); } /** * Executes the group identified by id. * * @param id - * The id. + * The id. */ protected void executeGroup(String id) throws RuleException { executeGroup(id, Collections.emptyMap()); @@ -371,18 +383,18 @@ protected void executeGroup(String id) throws RuleException { * Executes the group identified by id. * * @param id - * The id. + * The id. * @param parameters - * The rule parameters. + * The rule parameters. */ protected void executeGroup(String id, Map parameters) throws RuleException { RuleSelection ruleSelection = RuleSelection.builder() - .groupId(id) - .build(); + .groupId(id) + .build(); Group group = ruleSet.getGroupsBucket() - .getById(id); + .getById(id); assertThat(group).describedAs("The request group cannot be found: " + id) - .isNotNull(); + .isNotNull(); getAnalyzer(parameters).execute(ruleSet, ruleSelection); } @@ -401,7 +413,7 @@ protected class TestResult { * Return a column identified by its name. * * @param - * The expected type. + * The expected type. * @return All columns. */ public List getColumn(String name) { diff --git a/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractServerPluginIT.java b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractServerPluginIT.java index 1112b90e3a..7a81adf0ea 100644 --- a/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractServerPluginIT.java +++ b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/AbstractServerPluginIT.java @@ -1,6 +1,6 @@ package com.buschmais.jqassistant.core.test.plugin; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; import com.buschmais.jqassistant.core.store.api.configuration.Embedded; import com.buschmais.jqassistant.core.store.impl.EmbeddedGraphStore; import com.buschmais.jqassistant.neo4j.embedded.EmbeddedNeo4jServer; diff --git a/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/ITConfiguration.java b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/ITConfiguration.java new file mode 100644 index 0000000000..9ae45329e4 --- /dev/null +++ b/core/test/src/main/java/com/buschmais/jqassistant/core/test/plugin/ITConfiguration.java @@ -0,0 +1,10 @@ +package com.buschmais.jqassistant.core.test.plugin; + +import com.buschmais.jqassistant.core.resolver.configuration.ArtifactResolverConfiguration; +import com.buschmais.jqassistant.core.runtime.api.configuration.Configuration; + +import io.smallrye.config.ConfigMapping; + +@ConfigMapping(prefix = Configuration.PREFIX) +public interface ITConfiguration extends Configuration, ArtifactResolverConfiguration { +} diff --git a/core/test/src/test/java/com/buschmais/jqassistant/core/test/ApocIT.java b/core/test/src/test/java/com/buschmais/jqassistant/core/test/ApocIT.java new file mode 100644 index 0000000000..d6230da8c7 --- /dev/null +++ b/core/test/src/test/java/com/buschmais/jqassistant/core/test/ApocIT.java @@ -0,0 +1,29 @@ +package com.buschmais.jqassistant.core.test; + +import com.buschmais.jqassistant.core.test.plugin.AbstractPluginIT; +import com.buschmais.xo.api.Query; +import com.buschmais.xo.api.Query.Result.CompositeRowObject; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; + +class ApocIT extends AbstractPluginIT { + + @BeforeAll + static void setUp() { + assumeThat(Runtime.version() + .feature()).isGreaterThanOrEqualTo(17); + } + + @Test + void apocTest() { + store.beginTransaction(); + Query.Result rows = store.executeQuery("call apoc.help('apoc')"); + assertThat(rows).isNotEmpty(); + store.commitTransaction(); + } + +} diff --git a/core/test/src/test/resources/.jqassistant.yml b/core/test/src/test/resources/.jqassistant.yml new file mode 100644 index 0000000000..528f311439 --- /dev/null +++ b/core/test/src/test/resources/.jqassistant.yml @@ -0,0 +1,8 @@ +jqassistant: + store: + embedded: + neo4j-plugins: + - group-id: org.neo4j.procedure + artifact-id: apoc-core + classifier: core + version: ${neo4j_5x.version} 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 a6b09e2d4c..7fa7448b98 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 @@ -4,10 +4,10 @@ import java.util.*; import java.util.function.Supplier; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository; -import com.buschmais.jqassistant.core.runtime.impl.plugin.AetherArtifactProvider; +import com.buschmais.jqassistant.core.shared.aether.AetherArtifactProvider; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationBuilder; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationMappingLoader; import com.buschmais.jqassistant.core.store.api.Store; import com.buschmais.jqassistant.core.store.api.configuration.Embedded; import com.buschmais.jqassistant.scm.maven.configuration.Maven; @@ -277,7 +277,8 @@ private MavenConfiguration getConfiguration() { 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) + ConfigurationMappingLoader.Builder builder = ConfigurationMappingLoader.builder( + MavenConfiguration.class, configurationLocations) .withUserHome(userHome) .withDirectory(executionRootDirectory, CONFIGURATION_ORDINAL_EXECUTION_ROOT) .withEnvVariables() diff --git a/maven/src/main/java/com/buschmais/jqassistant/scm/maven/EffectiveConfigurationMojo.java b/maven/src/main/java/com/buschmais/jqassistant/scm/maven/EffectiveConfigurationMojo.java index 7c265ba7a2..f94a4e031a 100644 --- a/maven/src/main/java/com/buschmais/jqassistant/scm/maven/EffectiveConfigurationMojo.java +++ b/maven/src/main/java/com/buschmais/jqassistant/scm/maven/EffectiveConfigurationMojo.java @@ -1,14 +1,12 @@ package com.buschmais.jqassistant.scm.maven; -import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationSerializer; +import com.buschmais.jqassistant.core.shared.configuration.ConfigurationSerializer; import com.buschmais.jqassistant.scm.maven.configuration.MavenConfiguration; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Lists all effective rules. @@ -16,9 +14,7 @@ @Mojo(name = "effective-configuration", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) public class EffectiveConfigurationMojo extends AbstractRuleMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(EffectiveConfigurationMojo.class); - - private final ConfigurationSerializer configurationSerializer = new ConfigurationSerializer<>(); + private final com.buschmais.jqassistant.core.shared.configuration.ConfigurationSerializer configurationSerializer = new ConfigurationSerializer<>(); @Override public void aggregate(MojoExecutionContext mojoExecutionContext) throws MojoExecutionException, MojoFailureException { diff --git a/pom.xml b/pom.xml index 8b386e102a..821b6b336a 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ 2.3 2.8 2.0.1.Final - 2.3.0 + 2.4.1 2.0.0 3.6.0