Skip to content

Commit

Permalink
Feature: "exclude directories from analysis"
Browse files Browse the repository at this point in the history
  • Loading branch information
KayWeinert committed Apr 12, 2021
1 parent 60ce144 commit afc137f
Show file tree
Hide file tree
Showing 11 changed files with 1,226 additions and 92 deletions.
97 changes: 95 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

<arch-unit-build-plugin-core.version>2.7.3</arch-unit-build-plugin-core.version>

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

<scm>
Expand All @@ -84,6 +84,7 @@
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<dependencies>

<dependency>
Expand Down Expand Up @@ -142,6 +143,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -159,10 +167,70 @@
-->
</dependency>

<!-- needed to generate test classes above java 8 -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>testXjc</id>
<goals>
<goal>testXjc</goal>
</goals>
<phase>generate-test-sources</phase>
</execution>
</executions>
<configuration>
<packageName>com.societegenerale.commons.plugin.maven.test.generated</packageName>
<outputDirectory>${generated.test.source.directory}</outputDirectory>
<testXjbSources>
<testXjbSource>${project.basedir}/src/test/resources/generate/book.xsd</testXjbSource>
</testXjbSources>
<testSources>
<testSource>${project.basedir}/src/test/resources/generate/book.xsd</testSource>
</testSources>
<clearOutputDir>true</clearOutputDir>
</configuration>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -171,6 +239,28 @@
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<executions>
<execution>
<id>default</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>compile-generated-test-source</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${generated.test.source.directory}</compileSourceRoot>
</compileSourceRoots>
<generatedTestSourcesDirectory>${generated.test.source.directory}</generatedTestSourcesDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
Expand All @@ -183,6 +273,9 @@
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/Abstract*Test.java</exclude>
</excludes>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

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

@Parameter(defaultValue = "${project.build.directory}")
private String projectBuildDir;

public MavenRules getRules() {
return rules;
}

private RuleInvokerService ruleInvokerService ;
private RuleInvokerService ruleInvokerService;

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

Expand All @@ -82,8 +87,10 @@ public void execute() throws MojoFailureException {
String ruleFailureMessage;
try {
configureContextClassLoader();
final MavenLogAdapter mavenLogAdapter = new MavenLogAdapter(getLog());

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

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

@VisibleForTesting
void setProjectBuildDir(final String projectBuildDir) {
this.projectBuildDir = projectBuildDir;
}
}
Loading

0 comments on commit afc137f

Please sign in to comment.