use of org.semver.Delta.Difference in project semantic-versioning by jeluard.
the class Dumper method dumpFullStats.
/**
* Dumps on <code>out</code> all differences separated by its type in the order
* <code>remove</code>, <code>change</code>, <code>deprecate</code> and <code>add</code>.
* <p>
* Prepends statistics per class regarding difference type.
* </p>
* @param delta the delta to be dumped
* @param iwidth the integer width for formated integer counter
* @param out the print output stream
*/
public static void dumpFullStats(final Delta delta, final int iwidth, final PrintStream out) {
final Set<Difference> diffs = delta.getDifferences();
final List<Difference> diffsAdd = new ArrayList<Difference>();
final List<Difference> diffsChange = new ArrayList<Difference>();
final List<Difference> diffsDeprecate = new ArrayList<Difference>();
final List<Difference> diffsRemove = new ArrayList<Difference>();
final Map<String, DiffCount> className2DiffCount = new HashMap<String, DiffCount>();
int maxClassNameLen = 0;
for (final Iterator<Difference> iter = diffs.iterator(); iter.hasNext(); ) {
final Difference diff = iter.next();
final String className = diff.getClassName();
maxClassNameLen = Math.max(maxClassNameLen, className.length());
DiffCount dc = className2DiffCount.get(className);
if (null == dc) {
dc = new DiffCount(className);
className2DiffCount.put(className, dc);
}
if (diff instanceof Delta.Add) {
diffsAdd.add(diff);
dc.additions++;
} else if (diff instanceof Delta.Change) {
diffsChange.add(diff);
dc.changes++;
} else if (diff instanceof Delta.Deprecate) {
diffsDeprecate.add(diff);
dc.deprecates++;
} else if (diff instanceof Delta.Remove) {
diffsRemove.add(diff);
dc.removes++;
}
}
Collections.sort(diffsAdd);
Collections.sort(diffsChange);
Collections.sort(diffsDeprecate);
Collections.sort(diffsRemove);
final List<String> classNames = new ArrayList<String>(className2DiffCount.keySet());
Collections.sort(classNames);
System.err.println("Summary: " + diffs.size() + " differences in " + classNames.size() + " classes:");
System.err.println(" Remove " + diffsRemove.size() + ", Change " + diffsChange.size() + ", Deprecate " + diffsDeprecate.size() + ", Add " + diffsAdd.size());
System.err.printf("%n");
int iterI = 0;
for (final Iterator<String> iter = classNames.iterator(); iter.hasNext(); iterI++) {
final String className = iter.next();
final DiffCount dc = className2DiffCount.get(className);
System.err.printf("%" + iwidth + "d/%" + iwidth + "d: %-" + maxClassNameLen + "s: %s%n", iterI, classNames.size(), className, dc.format(iwidth));
}
System.err.printf("%n%nRemoves%n%n");
dump(diffsRemove, System.err);
System.err.printf("%n%nChanges%n%n");
dump(diffsChange, System.err);
System.err.printf("%n%nDeprecates%n%n");
dump(diffsDeprecate, System.err);
System.err.printf("%n%nAdditions%n%n");
dump(diffsAdd, System.err);
System.err.printf("%n%n");
}
use of org.semver.Delta.Difference in project semantic-versioning by jeluard.
the class Dumper method dump.
/**
* Dumps on <code>out</code> all of the given sorted differences.
*
* @param sortedDifferences the sorted differences to be dumped
* @param out the print output stream
*/
public static void dump(final List<Difference> sortedDifferences, final PrintStream out) {
String currentClassName = "";
for (final Difference difference : sortedDifferences) {
if (!currentClassName.equals(difference.getClassName())) {
out.println("Class " + difference.getClassName());
}
out.println(" " + extractActionType(difference) + " " + extractInfoType(difference.getInfo()) + " " + extractDetails(difference));
currentClassName = difference.getClassName();
}
}
use of org.semver.Delta.Difference in project semantic-versioning by jeluard.
the class DeprecateDetectionTest method shouldInheritedMethodMatchImplementedMethod.
@Test
public void shouldInheritedMethodMatchImplementedMethod() throws Exception {
/**
* The situation we are testing is as follows:
* Abstract class InheritanceRoot is initially implemented directly by ClassA.
* ClassA is later modified to extend another implementation of InheritanceRoot
* and the methods required by InheritanceRoot are now removed from ClassA directly,
* and instead inherited from the new parent, DirectDescendant. For the purposes of
* this test, this new ClassA is represented by ClassB (as we can't have the same
* class declared twice in a test -- in real life, this would both be ClassA's,
* in different jars).
*/
Map<String, ClassInfo> oldClassInfoMap = new HashMap<String, ClassInfo>();
Map<String, ClassInfo> newClassInfoMap = new HashMap<String, ClassInfo>();
JarDiff jd = new JarDiff();
addClassInfo(oldClassInfoMap, ClassA.class, jd);
addClassInfo(oldClassInfoMap, DirectDescendant.class, jd);
addClassInfo(oldClassInfoMap, InheritanceRoot.class, jd);
addClassInfo(newClassInfoMap, ClassB.class, jd);
addClassInfo(newClassInfoMap, DirectDescendant.class, jd);
addClassInfo(newClassInfoMap, InheritanceRoot.class, jd);
// Make B look like A
newClassInfoMap.put("org/semver/jardiff/DeprecateDetectionTest$ClassA", newClassInfoMap.get("org/semver/jardiff/DeprecateDetectionTest$ClassB"));
newClassInfoMap.remove("org/semver/jardiff/DeprecateDetectionTest$ClassB");
DifferenceAccumulatingHandler handler = new DifferenceAccumulatingHandler();
jd.diff(handler, new SimpleDiffCriteria(), "0.1.0", "0.2.0", oldClassInfoMap, newClassInfoMap);
Dumper.dump(handler.getDelta());
Set<Difference> differences = handler.getDelta().getDifferences();
Assert.assertEquals("differences found", 3, differences.size());
// Naive search for Deprecate.
boolean hasDeprecate = false;
for (Difference d : differences) {
if (d instanceof Deprecate)
hasDeprecate = true;
}
Assert.assertTrue("No Delta.Deprecate found", hasDeprecate);
}
Aggregations