Skip to content

Commit

Permalink
77 plugins should be executed using pluginclassloader as tccl 1 (#85)
Browse files Browse the repository at this point in the history
Added dedicated support for Neo4j plugins to embedded store
  • Loading branch information
DirkMahler authored Feb 27, 2024
1 parent 9dcab94 commit a443f35
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 16 deletions.
11 changes: 11 additions & 0 deletions maven/src/it/neo4j-plugin/.jqassistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
jqassistant:
store:
embedded:
neo4j-plugins:
- group-id: org.neo4j.procedure
artifact-id: apoc-core
classifier: core
version: ${apoc.version}
analyze:
groups:
- it
2 changes: 2 additions & 0 deletions maven/src/it/neo4j-plugin/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals.1 = verify -e
invoker.goals.2 = verify -e -Djqassistant.store.embedded.neo4j-plugin-directory=target/jqassistant/plugins
14 changes: 14 additions & 0 deletions maven/src/it/neo4j-plugin/jqassistant/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<jqa:jqassistant-rules xmlns:jqa="http://www.buschmais.com/jqassistant/core/analysis/rules/schema/v1.0">

<group id="it">
<includeConcept refId="it:*" />
</group>

<concept id="it:APOCHelp">
<description>Calls APOC Help</description>
<cypher>
call apoc.help('apoc')
</cypher>
</concept>

</jqa:jqassistant-rules>
15 changes: 15 additions & 0 deletions maven/src/it/neo4j-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>@project.groupId@</groupId>
<artifactId>@[email protected]</artifactId>
<version>@project.version@</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>@[email protected]</artifactId>

<properties>
<apoc.version>@neo4j_5x_apoc.version@</apoc.version>
</properties>

</project>
10 changes: 10 additions & 0 deletions maven/src/it/neo4j-plugin/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def reportFile1 = new File(basedir, 'target/jqassistant/jqassistant-report.xml')
assert reportFile1.exists()
def jqassistantReport = new XmlSlurper().parse(reportFile1)
def itGroup = jqassistantReport.group.find { it.@id = 'it' }
def concept = itGroup.concept.find { it.@id == 'it:APOCHelp' }
assert concept.status == 'success'

def pluginDir = new File(basedir, 'target/jqassistant/plugins')
assert pluginDir.exists();
assert pluginDir.isDirectory();
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import com.buschmais.jqassistant.core.runtime.api.configuration.ConfigurationBuilder;
import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository;
import com.buschmais.jqassistant.core.runtime.impl.plugin.AetherArtifactProvider;
import com.buschmais.jqassistant.core.store.api.Store;
import com.buschmais.jqassistant.neo4j.embedded.configuration.Embedded;
import com.buschmais.jqassistant.core.store.api.configuration.Embedded;
import com.buschmais.jqassistant.scm.maven.configuration.Maven;
import com.buschmais.jqassistant.scm.maven.configuration.MavenConfiguration;
import com.buschmais.jqassistant.scm.maven.configuration.source.EmptyConfigSource;
Expand Down Expand Up @@ -113,8 +114,8 @@ public final void execute() throws MojoExecutionException, MojoFailureException
if (configuration.skip()) {
getLog().info("Skipping execution.");
} else {
PluginRepository pluginRepository = pluginRepositoryProvider.getPluginRepository(repositorySystem, repositorySystemSession, repositories,
configuration);
AetherArtifactProvider artifactResolver = new AetherArtifactProvider(repositorySystem, repositorySystemSession, repositories);
PluginRepository pluginRepository = pluginRepositoryProvider.getPluginRepository(configuration, artifactResolver);
MojoExecutionContext mojoExecutionContext = new MojoExecutionContext(session, currentProject, execution, configuration, pluginRepository);
MavenProject rootModule = mojoExecutionContext.getRootModule();
Set<MavenProject> executedModules = getExecutedModules(rootModule);
Expand Down Expand Up @@ -223,7 +224,8 @@ private Set<MavenProject> getExecutedModules(MavenProject rootModule) {
*/
private Store getStore(MojoExecutionContext mojoExecutionContext, Supplier<File> storeDirectorySupplier) throws MojoExecutionException {
Object existingStore = cachingStoreProvider.getStore(mojoExecutionContext.getConfiguration()
.store(), storeDirectorySupplier, mojoExecutionContext.getPluginRepository());
.store(), storeDirectorySupplier, mojoExecutionContext.getPluginRepository(),
new AetherArtifactProvider(repositorySystem, repositorySystemSession, repositories));
if (!Store.class.isAssignableFrom(existingStore.getClass())) {
throw new MojoExecutionException(
"Cannot re-use store instance from reactor. Either declare the plugin as extension or execute Maven using the property -D" + Maven.REUSE_STORE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.function.Supplier;

import com.buschmais.jqassistant.core.runtime.api.plugin.PluginRepository;
import com.buschmais.jqassistant.core.shared.artifact.ArtifactProvider;
import com.buschmais.jqassistant.core.store.api.Store;
import com.buschmais.jqassistant.core.store.api.StoreFactory;

Expand Down Expand Up @@ -54,7 +55,7 @@ private static class StoreKey {
* @return The store.
*/
public Store getStore(com.buschmais.jqassistant.core.store.api.configuration.Store storeConfiguration, Supplier<File> storeDirectorySupplier,
PluginRepository pluginRepository) {
PluginRepository pluginRepository, ArtifactProvider artifactProvider) {
URI uri = storeConfiguration.uri()
.orElseGet(() -> {
File storeDirectory = storeDirectorySupplier.get();
Expand All @@ -70,7 +71,7 @@ public Store getStore(com.buschmais.jqassistant.core.store.api.configuration.Sto
StoreKey key = storeKeyBuilder.build();
Store store = storesByKey.get(key);
if (store == null) {
store = StoreFactory.getStore(storeConfiguration, storeDirectorySupplier, pluginRepository.getStorePluginRepository());
store = StoreFactory.getStore(storeConfiguration, storeDirectorySupplier, pluginRepository.getStorePluginRepository(), artifactProvider);
store.start();
storesByKey.put(key, store);
keysByStore.put(store, key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.buschmais.jqassistant.scm.maven.provider;

import java.util.List;

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;
import com.buschmais.jqassistant.core.runtime.api.plugin.PluginResolver;
import com.buschmais.jqassistant.core.runtime.impl.plugin.AetherPluginResolverImpl;
import com.buschmais.jqassistant.core.runtime.impl.plugin.PluginConfigurationReaderImpl;
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.scm.maven.configuration.MavenConfiguration;

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;

@Component(role = PluginRepositoryProvider.class, instantiationStrategy = "singleton")
public class PluginRepositoryProvider implements Disposable {
Expand All @@ -29,11 +25,9 @@ public void dispose() {
}
}

public PluginRepository getPluginRepository(RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession,
List<RemoteRepository> repositories, MavenConfiguration configuration) {
public PluginRepository getPluginRepository(MavenConfiguration configuration, ArtifactProvider artifactProvider) {
if (pluginRepository == null) {

PluginResolver pluginResolver = new AetherPluginResolverImpl(repositorySystem, repositorySystemSession, repositories);
PluginResolver pluginResolver = new PluginResolverImpl(artifactProvider);
PluginClassLoader pluginClassLoader = pluginResolver.createClassLoader(Thread.currentThread().getContextClassLoader(), configuration);

// do a lazy init of the plugin repo to speed-up if the plugin execution shall be skipped
Expand Down

0 comments on commit a443f35

Please sign in to comment.