-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added target/test-classes directory to check for cycles
This enables package cycle check between test and src folder. To add test folder the maven phase has to be changed to test-compile
- Loading branch information
1 parent
8051a76
commit 696dcaf
Showing
6 changed files
with
129 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
[![Build Status](https://buildhive.cloudbees.com/job/andrena/job/no-package-cycles-enforcer-rule/badge/icon)](https://buildhive.cloudbees.com/job/andrena/job/no-package-cycles-enforcer-rule/) | ||
|
||
This Maven Enforcer Rule checks your project for package cycles. It fails the build if any package cycle is found, showing you the packages and classes involved in the cycle. | ||
|
||
Usage: Add the following plugin to your POM: | ||
|
||
``` | ||
<plugin> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>1.2</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>de.andrena.tools.nopackagecycles</groupId> | ||
<artifactId>no-package-cycles-enforcer-rule</artifactId> | ||
<version>1.0.4</version> | ||
</dependency> | ||
</dependencies> | ||
<executions> | ||
<execution> | ||
<id>enforce-no-package-cycles</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<phase>compile</phase> | ||
<configuration> | ||
<rules> | ||
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule" /> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
``` | ||
|
||
See also: | ||
* The original version by Daniel Seidewitz on [Stackoverflow](http://stackoverflow.com/questions/3416547/maven-jdepend-fail-build-with-cycles). Improved by showing all packages afflicted with cycles and the corresponding classes importing the conflicting packages. | ||
* [JDepend](https://github.com/clarkware/jdepend), the library being used to detect package cycles. | ||
* For more information about package cycles, see ["The Acyclic Dependencies Principle" by Robert C. Martin (Page 6)](http://www.objectmentor.com/resources/articles/granularity.pdf). | ||
[![Build Status](https://buildhive.cloudbees.com/job/andrena/job/no-package-cycles-enforcer-rule/badge/icon)](https://buildhive.cloudbees.com/job/andrena/job/no-package-cycles-enforcer-rule/) | ||
|
||
This Maven Enforcer Rule checks your project for package cycles. It fails the build if any package cycle is found, showing you the packages and classes involved in the cycle. | ||
|
||
Usage: Add the following plugin to your POM: | ||
|
||
``` | ||
<plugin> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>1.2</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>de.andrena.tools.nopackagecycles</groupId> | ||
<artifactId>no-package-cycles-enforcer-rule</artifactId> | ||
<version>1.0.4</version> | ||
</dependency> | ||
</dependencies> | ||
<executions> | ||
<execution> | ||
<id>enforce-no-package-cycles</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<phase>test-compile</phase> | ||
<configuration> | ||
<rules> | ||
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule" /> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
``` | ||
|
||
See also: | ||
* The original version by Daniel Seidewitz on [Stackoverflow](http://stackoverflow.com/questions/3416547/maven-jdepend-fail-build-with-cycles). Improved by showing all packages afflicted with cycles and the corresponding classes importing the conflicting packages. | ||
* [JDepend](https://github.com/clarkware/jdepend), the library being used to detect package cycles. | ||
* For more information about package cycles, see ["The Acyclic Dependencies Principle" by Robert C. Martin (Page 6)](http://www.objectmentor.com/resources/articles/granularity.pdf). |
43 changes: 43 additions & 0 deletions
43
src/main/java/de/andrena/tools/nopackagecycles/DirectoriesWithClasses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.andrena.tools.nopackagecycles; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
|
||
import java.io.File; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; | ||
|
||
public class DirectoriesWithClasses implements Iterable<File>{ | ||
|
||
public static final String MAVEN_PROJECT_BUILD_OUTPUT_DIRECTORY_VAR = "${project.build.outputDirectory}"; | ||
public static final String MAVEN_PROJECT_BUILD_TEST_OUTPUT_DIRECTORY_VAR = "${project.build.testOutputDirectory}"; | ||
|
||
private final List<File> directories = new LinkedList<File>(); | ||
|
||
public DirectoriesWithClasses(EnforcerRuleHelper helper) throws ExpressionEvaluationException { | ||
addDirectoryIfExists(helper, MAVEN_PROJECT_BUILD_OUTPUT_DIRECTORY_VAR); | ||
addDirectoryIfExists(helper, MAVEN_PROJECT_BUILD_TEST_OUTPUT_DIRECTORY_VAR); | ||
} | ||
|
||
private void addDirectoryIfExists(EnforcerRuleHelper helper, String variable) | ||
throws ExpressionEvaluationException { | ||
File directory = new File((String) helper.evaluate(variable)); | ||
if(directory.exists()) { | ||
helper.getLog().info("Adding directory " + directory.getAbsolutePath() + " for package cycles search."); | ||
directories.add(directory); | ||
} else { | ||
helper.getLog().info("Directory " + directory.getAbsolutePath() + " could not be found."); | ||
} | ||
} | ||
|
||
public boolean directoriesWithClassesFound() { | ||
return !directories.isEmpty(); | ||
} | ||
|
||
public Iterator<File> iterator() { | ||
return unmodifiableList(directories).iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters