Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sharing-rules-between-projects/project/.jqassistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jqassistant:
plugins:
#<1>
- group-id: my.organization
artifact-id: rules
version: 1.0.0-SNAPSHOT

analyze:
#<2>
groups:
- my-organization:Default
- project:Default
#<3>
rule-parameters:
rootPackage: my.organization
9 changes: 0 additions & 9 deletions sharing-rules-between-projects/project/jqassistant/index.adoc

This file was deleted.

10 changes: 10 additions & 0 deletions sharing-rules-between-projects/project/jqassistant/index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<jqassistant-rules
xmlns="http://schema.jqassistant.org/rule/v2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.0 https://schema.jqassistant.org/rule/jqassistant-rule-v2.0.xsd">

<group id="project:Default">
<includeGroup refId="module:Default"/>
</group>

</jqassistant-rules>
32 changes: 4 additions & 28 deletions sharing-rules-between-projects/project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<jqassistant.version>1.8.0</jqassistant.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>${jqassistant.version}</version>
<version>2.0.6</version>
<executions>
<execution>
<id>default</id>
Expand All @@ -36,26 +32,6 @@
</goals>
</execution>
</executions>
<configuration>
<groups>
<!-- shared rules -->
<group>my-organization:Default</group>
<!-- project specific rules -->
<group>project:Default</group>
</groups>
<ruleParameters>
<!-- parameter required by the shared constraint "package:RootPackage" -->
<rootPackage>my.organization</rootPackage>
</ruleParameters>
</configuration>
<dependencies>
<!-- plugin providing the shared rules -->
<dependency>
<groupId>my.organization</groupId>
<artifactId>rules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
<!-- end::plugin[] -->
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Dirk Mahler <dirk.mahler@jqassistant.org>

[.lead]
// tag::lead[]
Create a plugin containing shared rules for using them in different projects.
This tutorial is about sharing rules between different projects. Specifically a plugin containing shared rules will be created that can be used in several different projects.
// end::lead[]

NOTE: This tutorial is written for version 1.8.0 of jQAssistant.
NOTE: This tutorial is written for version 2.0.6 of jQAssistant.

== Overview

Expand All @@ -34,6 +34,8 @@ For convenience reasons the rules are bundled into groups to ease execution and

== Providing Rules As Plugin

IMPORTANT: The following part of the tutorial refers to the `rules` directory. This directory itself represents a maven project, which creates a plugin that defines jQAssistant-rules. These can later be shared to other projects. (The plugin will be implemented into another project in section <<Using Shared Rules In A Maven Project>>)

=== The Plugin Structure

The standard approach of sharing rules is by distributing them as a jQAssistant plugin.
Expand All @@ -47,7 +49,7 @@ include::rules/pom.xml[indent=0]

The file mainly declares test dependencies that will be used later for verifying the rules.

jQAssistant expects a plugin descriptor `/META-INF/jqassistant-plugin.xml` as classpath resource.
jQAssistant expects a plugin descriptor `resources/META-INF/jqassistant-plugin.xml` as classpath resource.
It declares files containing rules that shall be shared:

[source,xml]
Expand All @@ -56,7 +58,7 @@ It declares files containing rules that shall be shared:
include::rules/src/main/resources/META-INF/jqassistant-plugin.xml[]
----

The referenced files are expected as classpath resources located in the folder `/META-INF/jqassistant-rules`.
The referenced files are expected as classpath resources located in the folder `resources/META-INF/jqassistant-rules`.
This tutorial uses XML documents to declare the rules.
Thus the following folder structure is expected:

Expand All @@ -70,9 +72,6 @@ META-INF/
└── my-organization.xml
----

NOTE: Asciidoc files are supported as well but take longer time to load at startup.
Therefore the recommended format is XML to not negatively affect the build process of other projects.

The next sections describe the shared rules in detail.

=== Maven Related Rules
Expand Down Expand Up @@ -121,7 +120,7 @@ include::rules/src/test/java/my/organization/rules/PackageTest.java[tags=Test]

=== Grouping Rules For Execution

The file `my-organization.xml` contains defines a group:
The file `my-organization.xml` defines a group:

[source,xml]
.src/main/resources/META-INF/jqassistant-rules/my-organization.xml
Expand All @@ -139,59 +138,45 @@ After validation they can be moved to `my-organization:Default` (or groups inclu

== Using Shared Rules In A Maven Project

IMPORTANT: The following part of the tutorial refers to the `project` directory. This directory itself represents a maven project, which uses the rules from the plugin. (More precise the plugin that was created in section <<Providing Rules As Plugin>>)

This section demonstrates how the set of shared rules may be activated in a Maven based project.
The latter defines its own set of specific rules.
These are bundled in the group `project:Default` which is declared in the file `jqassistant/index.adoc`

[source,asciidoc]
[source,xml]
.jqassistant/index.adoc
....
include::project/jqassistant/index.adoc[]
include::project/jqassistant/index.xml[]
....

The Maven build descriptor `pom.xml` contains the declaration for the jQAssistant plugin:
The Maven build descriptor `pom.xml` enables jQAssistant and configures it to execute the goals "scan" and "analyze":

[source,xml]
.pom.xml
----
include::project/pom.xml[tags=plugin,indent=0]
----

- The plugin containing the shared rules is declared as dependency.
- The configuration section selects the groups `my-organization:Default` and `project:Default` for execution.
- Furthermore a value for the parameter `rootPackage` required by the constraint `package:RootPackage` is defined.

The project can now be built as usual and all required rules will be executed:

[source,raw]
[source,yml]
..jqassistant.yml
----
mvn install
include::project/.jqassistant.yml[indent=0]
----

== Using Shared Rules With The Command Line Utility
<1> JQAssistant is told to use the plugin containing the shared rules.
<2> The configuration section selects the groups `my-organization:Default` and `project:Default` for execution.
<3> Furthermore, a value for the parameter `rootPackage` required by the constraint `package:RootPackage` is defined.

For using shared rules the plugin JAR file must be copied to the folder `plugins/` of the command line utility.

Furthermore a properties file must be created providing rule parameters, i.e. `rootPackage` required by the constraint `package:RootPackage`:

[source,properties]
.ruleParameters.properties
----
rootPackage=my.organization
----

Now the analysis can be executed using the following command:
The project can now be built as usual and all required rules will be executed:

[source,raw]
----
# Unix
jqassistant.sh analyze -groups my-organization:Default,project:Default -ruleParameters ruleParameters.properties

# Windows
jqassistant.cmd analyze -groups my-organization:Default,project:Default -ruleParameters ruleParameters.properties
mvn install
----

== Resources

1. link:tutorial.zip[ZIP archive including a Maven example for sharing rules]
1. link:https://jqassistant.github.io/jqassistant/doc/2.0.0/manual/[jQAssistant manual]


46 changes: 21 additions & 25 deletions sharing-rules-between-projects/rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,78 +12,74 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>bom</artifactId>
<version>2.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Test dependencies -->
<dependency>
<groupId>com.buschmais.jqassistant.core</groupId>
<artifactId>store</artifactId>
<version>1.8.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.buschmais.jqassistant.core</groupId>
<artifactId>plugin</artifactId>
<version>1.8.0</version>
<artifactId>test</artifactId>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.buschmais.jqassistant.plugin</groupId>
<artifactId>common</artifactId>
<type>test-jar</type>
<version>1.8.0</version>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.buschmais.jqassistant.plugin</groupId>
<artifactId>java</artifactId>
<type>test-jar</type>
<version>1.8.0</version>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.buschmais.jqassistant.plugin</groupId>
<artifactId>java</artifactId>
<version>1.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.buschmais.jqassistant.neo4jserver</groupId>
<artifactId>neo4jv3</artifactId>
<version>1.8.0</version>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<jqassistant-plugin xmlns="http://schema.jqassistant.org/plugin/v1.8"
<jqassistant-plugin xmlns="http://schema.jqassistant.org/plugin/v2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/plugin/v1.8 https://schema.jqassistant.org/plugin/jqassistant-plugin-v1.8.xsd"
xsi:schemaLocation="http://schema.jqassistant.org/plugin/v2.0 https://schema.jqassistant.org/plugin/jqassistant-plugin-v2.0.xsd"
name="Shared Rules">
<description>Provides shared rules for my organization.</description>
<rules>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<jqassistant-rules
xmlns="http://schema.jqassistant.org/rule/v1.8"
xmlns="http://schema.jqassistant.org/rule/v2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v1.8 https://schema.jqassistant.org/rule/jqassistant-rule-v1.8.xsd">
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.0 https://schema.jqassistant.org/rule/jqassistant-rule-v2.0.xsd">

<group id="maven:Default">
<includeConstraint refId="maven:GroupId"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<jqassistant-rules
xmlns="http://schema.jqassistant.org/rule/v1.8"
xmlns="http://schema.jqassistant.org/rule/v2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v1.8 https://schema.jqassistant.org/rule/jqassistant-rule-v1.8.xsd">
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.0 https://schema.jqassistant.org/rule/jqassistant-rule-v2.0.xsd">

<group id="my-organization:Default">
<includeGroup refId="maven:Default"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<jqassistant-rules
xmlns="http://schema.jqassistant.org/rule/v1.8"
xmlns="http://schema.jqassistant.org/rule/v2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v1.8 https://schema.jqassistant.org/rule/jqassistant-rule-v1.8.xsd">
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.0 https://schema.jqassistant.org/rule/jqassistant-rule-v2.0.xsd">

<group id="package:Default">
<includeConstraint refId="package:RootPackage"/>
Expand All @@ -14,7 +14,7 @@
MATCH
(package:Package)-[:CONTAINS]->(type:Type)
WHERE NOT
package.fqn starts with {rootPackage}
package.fqn starts with $rootPackage
RETURN
type as TypeOutsideRootPackage
]]></cypher>
Expand Down
Loading