Skip to content

Commit c29cafb

Browse files
committed
Feature: "exclude directories from analysis"
1 parent 0d0f668 commit c29cafb

File tree

11 files changed

+1227
-93
lines changed

11 files changed

+1227
-93
lines changed

pom.xml

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
<jacoco.version>0.8.3</jacoco.version>
5555
<mockito.version>3.1.0</mockito.version>
5656

57-
<arch-unit-build-plugin-core.version>2.7.2</arch-unit-build-plugin-core.version>
57+
<arch-unit-build-plugin-core.version>2.7.3-SNAPSHOT</arch-unit-build-plugin-core.version>
5858

59-
<project.testresult.directory>${project.build.directory}/test-results
60-
</project.testresult.directory>
59+
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
60+
<generated.test.source.directory>${project.basedir}/target/generated-test-sources/test-annotations</generated.test.source.directory>
6161
</properties>
6262

6363
<scm>
@@ -84,6 +84,7 @@
8484
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
8585
</repository>
8686
</distributionManagement>
87+
8788
<dependencies>
8889

8990
<dependency>
@@ -142,6 +143,13 @@
142143
<scope>test</scope>
143144
</dependency>
144145

146+
<dependency>
147+
<groupId>junit</groupId>
148+
<artifactId>junit</artifactId>
149+
<version>4.13.1</version>
150+
<scope>test</scope>
151+
</dependency>
152+
145153
<dependency>
146154
<groupId>org.assertj</groupId>
147155
<artifactId>assertj-core</artifactId>
@@ -159,10 +167,70 @@
159167
-->
160168
</dependency>
161169

170+
<!-- needed to generate test classes above java 8 -->
171+
<dependency>
172+
<groupId>jakarta.xml.bind</groupId>
173+
<artifactId>jakarta.xml.bind-api</artifactId>
174+
<version>2.3.3</version>
175+
<scope>compile</scope>
176+
</dependency>
177+
<dependency>
178+
<groupId>com.sun.xml.bind</groupId>
179+
<artifactId>jaxb-impl</artifactId>
180+
<version>2.3.3</version>
181+
<scope>compile</scope>
182+
</dependency>
162183

163184
</dependencies>
185+
164186
<build>
165187
<plugins>
188+
<plugin>
189+
<groupId>org.codehaus.mojo</groupId>
190+
<artifactId>jaxb2-maven-plugin</artifactId>
191+
<version>2.5.0</version>
192+
<executions>
193+
<execution>
194+
<id>testXjc</id>
195+
<goals>
196+
<goal>testXjc</goal>
197+
</goals>
198+
<phase>generate-test-sources</phase>
199+
</execution>
200+
</executions>
201+
<configuration>
202+
<packageName>com.societegenerale.commons.plugin.maven.test.generated</packageName>
203+
<outputDirectory>${generated.test.source.directory}</outputDirectory>
204+
<testXjbSources>
205+
<testXjbSource>${project.basedir}/src/test/resources/generate/book.xsd</testXjbSource>
206+
</testXjbSources>
207+
<testSources>
208+
<testSource>${project.basedir}/src/test/resources/generate/book.xsd</testSource>
209+
</testSources>
210+
<clearOutputDir>true</clearOutputDir>
211+
</configuration>
212+
<dependencies>
213+
<dependency>
214+
<groupId>org.glassfish.jaxb</groupId>
215+
<artifactId>jaxb-xjc</artifactId>
216+
<version>2.3.2</version>
217+
<scope>compile</scope>
218+
</dependency>
219+
<dependency>
220+
<groupId>jakarta.xml.bind</groupId>
221+
<artifactId>jakarta.xml.bind-api</artifactId>
222+
<version>2.3.3</version>
223+
<scope>compile</scope>
224+
</dependency>
225+
<dependency>
226+
<groupId>com.sun.xml.bind</groupId>
227+
<artifactId>jaxb-impl</artifactId>
228+
<version>2.3.3</version>
229+
<scope>compile</scope>
230+
</dependency>
231+
</dependencies>
232+
</plugin>
233+
166234
<plugin>
167235
<groupId>org.apache.maven.plugins</groupId>
168236
<artifactId>maven-compiler-plugin</artifactId>
@@ -171,6 +239,28 @@
171239
<source>${maven.compiler.source}</source>
172240
<target>${maven.compiler.target}</target>
173241
</configuration>
242+
<executions>
243+
<execution>
244+
<id>default</id>
245+
<phase>compile</phase>
246+
<goals>
247+
<goal>compile</goal>
248+
</goals>
249+
</execution>
250+
<execution>
251+
<id>compile-generated-test-source</id>
252+
<phase>test-compile</phase>
253+
<goals>
254+
<goal>testCompile</goal>
255+
</goals>
256+
<configuration>
257+
<compileSourceRoots>
258+
<compileSourceRoot>${generated.test.source.directory}</compileSourceRoot>
259+
</compileSourceRoots>
260+
<generatedTestSourcesDirectory>${generated.test.source.directory}</generatedTestSourcesDirectory>
261+
</configuration>
262+
</execution>
263+
</executions>
174264
</plugin>
175265

176266
<plugin>
@@ -183,6 +273,9 @@
183273
<includes>
184274
<include>**/*Test.java</include>
185275
</includes>
276+
<excludes>
277+
<exclude>**/Abstract*Test.java</exclude>
278+
</excludes>
186279
</configuration>
187280
</plugin>
188281

src/main/java/com/societegenerale/commons/plugin/maven/ArchUnitMojo.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import java.net.URL;
66
import java.util.ArrayList;
77
import java.util.List;
8+
import java.util.Set;
89

910
import com.societegenerale.commons.plugin.maven.model.MavenRules;
1011
import com.societegenerale.commons.plugin.model.Rules;
1112
import com.societegenerale.commons.plugin.service.RuleInvokerService;
13+
import com.tngtech.archunit.thirdparty.com.google.common.annotations.VisibleForTesting;
1214
import org.apache.commons.lang3.StringUtils;
1315
import org.apache.maven.artifact.DependencyResolutionRequiredException;
1416
import org.apache.maven.plugin.AbstractMojo;
@@ -54,11 +56,14 @@ public class ArchUnitMojo extends AbstractMojo {
5456
@Parameter(defaultValue = "${project}", required = true, readonly = true)
5557
private MavenProject mavenProject;
5658

59+
@Parameter(defaultValue = "${project.build.directory}")
60+
private String projectBuildDir;
61+
5762
public MavenRules getRules() {
5863
return rules;
5964
}
6065

61-
private RuleInvokerService ruleInvokerService ;
66+
private RuleInvokerService ruleInvokerService;
6267

6368
private static final String PREFIX_ARCH_VIOLATION_MESSAGE = "ArchUnit Maven plugin reported architecture failures listed below :";
6469

@@ -82,8 +87,10 @@ public void execute() throws MojoFailureException {
8287
String ruleFailureMessage;
8388
try {
8489
configureContextClassLoader();
90+
final MavenLogAdapter mavenLogAdapter = new MavenLogAdapter(getLog());
8591

86-
ruleInvokerService = new RuleInvokerService(new MavenLogAdapter(getLog()), new MavenScopePathProvider(mavenProject), excludedPaths);
92+
final Set<String> excludes = new ExcludedPathsPreProcessor().processExcludedPaths(getLog(), projectBuildDir, excludedPaths);
93+
ruleInvokerService = new RuleInvokerService(mavenLogAdapter, new MavenScopePathProvider(mavenProject), excludes);
8794

8895
ruleFailureMessage = ruleInvokerService.invokeRules(coreRules);
8996
} catch (final Exception e) {
@@ -107,4 +114,8 @@ private void configureContextClassLoader() throws DependencyResolutionRequiredEx
107114
Thread.currentThread().setContextClassLoader(contextClassLoader);
108115
}
109116

117+
@VisibleForTesting
118+
void setProjectBuildDir(final String projectBuildDir) {
119+
this.projectBuildDir = projectBuildDir;
120+
}
110121
}

0 commit comments

Comments
 (0)