JDepend misses Cycles
We have a JUnit test based on JDepend 2.9.1 in order to find illegal dependencies and cycles.
Today we found that JDepend is missing dependencies. It doesn't seem to consider A depending on B in the following piece of code:
public class A {
@SomeAnotation(value = B.class)
public String someMethod() {
...
}
}
Our test looks like开发者_Python百科 this:
private JDepend setupJDepend() {
JDepend jdepend = null;
try {
jdepend = new JDepend();
jdepend.addDirectory("target/classes");
jdepend.addDirectory("target/test-classes");
} catch (final IOException ioException) {
fail("An IOException occured: " + ioException.getMessage());
}
jdepend.analyzeInnerClasses(true);
return jdepend;
}
@Test
public final void testNoCyclesOnPackageLevel() {
final JDepend jdepend = setupJDepend();
final Collection<?> packages = analyzeDependencies();
assertTrue(packages.size() > 0);
assertFalse("The code contains dependency cycles on package level!",
jdepend.containsCycles());
if (ignorePackageCycle) {
return;
}
java.util.List<String> packagesWithCycle = new ArrayList<String>();
for (Object pObject : packages) {
JavaPackage javaPackage = (JavaPackage) pObject;
if (javaPackage.containsCycle()) {
packagesWithCycle.add(javaPackage.getName());
}
}
assertTrue(packagesWithCycle.toString(), packagesWithCycle.isEmpty());
}
The JDepend4Eclipse plugin sees the dependency and reports the resulting cycle.
Is this a Bug? Is there a Workaround? Are we doing something wrong?
On a related note: jdepend.containsCycles() always returns false.
This is a missing feature!
For a @Retention(SOURCE)
declared @SomeAnotation
, no tool can find B
in the compiled class file.
For other policies, the annotations is included in the class file but the ClassFileParser
of JDepend does not support annotations of any kind, this is a missing feature so far.
EDIT: The source code checked in, support java 5 annotations and is used in the eclipse plugin. Maybe the 2.9.1 is not based on this. Not found the release notes of JDepend and its release date. The Code has been checked in 2010-05-19. The "latest" release seems to be from 2008.
精彩评论