@CompileStatic class ClassesWithSameName extends Object
Represents one or more class files that have the same exact name.
In this case the class name is a relative, file system path to the
class file. For example: org/apache/maven/Stuff.class
Example of how we can have two of the same class:
- mockito-core-1.9.5.jar contains org/mockito/Mockito.class
- mockito-all-1.9.5.jar contains org/mockito/Mockito.class
With that example you're not supposed to have both on the classpath. Typically
you'd choose the maven way (mockito-core) or the convenient-for-non-maven-users
way (mockito-all) but not both.
Adapted from org.apache.maven.plugins.enforcer.ClassesWithSameName
.
Constructor and description |
---|
ClassesWithSameName
(EnforcerContext context, ClassFile initialClassFile, ClassFile[] additionalClassFiles)
|
Type Params | Return Type | Name and description |
---|---|---|
|
void |
add(ClassFile classFile) Add a new .class file with the same exact path and name as the other classes this file represents (though the artifact can be different). |
|
Set<ResolvedArtifact> |
getAllArtifactsThisClassWasFoundIn()
|
|
boolean |
hasDuplicates(boolean ignoreWhenIdentical) Main logic to determine if this object represents more than one of the exact same class on the classpath. |
|
ClassFile |
previous()
|
|
String |
toOutputString(boolean ignoreWhenIdentical)
|
context
- (required) the enforcer contextinitialClassFile
- (required) we require at least one class file. Splitting this param from the
next one lets us require at least one at compile time (instead of runtime).additionalClassFiles
- (optional) additional class filesAdd a new .class file with the same exact path and name as the other classes this file represents (though the artifact can be different).
classFile
- The path to the .class file. Example: org/apache/maven/Stuff.class
Main logic to determine if this object represents more than one of the exact same class on the classpath.
ignoreWhenIdentical
- True if we should ignore two or more classes when they have the
exact same bytecode false means fail whenever there's more than
one of the same class, regardless of bytecode.
ignoreWhenIdentical
- True if we should ignore two or more classes when they have the
exact same bytecode false means fail whenever there's more than
one of the same class, regardless of bytecode.