use of aQute.bnd.service.diff.Diff in project felix by apache.
the class AbstractBaselinePlugin method doDiff.
private void doDiff(Object context, Diff diff, int depth) {
String type = StringUtils.lowerCase(String.valueOf(diff.getType()));
String shortDelta = getShortDelta(diff.getDelta());
String delta = StringUtils.lowerCase(String.valueOf(diff.getDelta()));
String name = diff.getName();
startDiff(context, depth, type, name, delta, shortDelta);
for (Diff curDiff : diff.getChildren()) {
if (Delta.UNCHANGED != curDiff.getDelta()) {
doDiff(context, curDiff, depth + 1);
}
}
endDiff(context, depth);
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class BaselineTest method testCompilerEnumDifference.
/**
* Test 2 jars compiled with different compilers
*/
public void testCompilerEnumDifference() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar ecj = new Jar(IO.getFile("jar/baseline/com.example.baseline.ecj.jar"));
Jar javac = new Jar(IO.getFile("jar/baseline/com.example.baseline.javac.jar"))) {
Tree tecj = diff.tree(ecj);
Tree tjavac = diff.tree(javac);
Diff d = tecj.diff(tjavac);
assertEquals(Delta.UNCHANGED, d.getDelta());
}
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class Builder method doDiff.
/**
* Diff this bundle to another bundle for the given packages.
*
* @throws Exception
*/
public void doDiff(@SuppressWarnings("unused") Jar dot) throws Exception {
Parameters diffs = parseHeader(getProperty("-diff"));
if (diffs.isEmpty())
return;
logger.debug("diff {}", diffs);
if (tree == null)
tree = differ.tree(this);
for (Entry<String, Attrs> entry : diffs.entrySet()) {
String path = entry.getKey();
File file = getFile(path);
if (!file.isFile()) {
error("Diffing against %s that is not a file", file).header("-diff").context(path);
continue;
}
boolean full = entry.getValue().get("--full") != null;
boolean warning = entry.getValue().get("--warning") != null;
Tree other = differ.tree(file);
Diff api = tree.diff(other).get("<api>");
Instructions instructions = new Instructions(entry.getValue().get("--pack"));
logger.debug("diff against {} --full={} --pack={} --warning={}", file, full, instructions);
for (Diff p : api.getChildren()) {
String pname = p.getName();
if (p.getType() == Type.PACKAGE && instructions.matches(pname)) {
if (p.getDelta() != Delta.UNCHANGED) {
if (!full)
if (warning)
warning("Differ %s", p).header("-diff").context(path);
else
error("Differ %s", p).header("-diff").context(path);
else {
if (warning)
warning("Diff found a difference in %s for packages %s", file, instructions).header("-diff").context(path);
else
error("Diff found a difference in %s for packages %s", file, instructions).header("-diff").context(path);
show(p, "", warning);
}
}
}
}
}
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class Builder method show.
/**
* Show the diff recursively
*
* @param p
* @param i
*/
private void show(Diff p, String indent, boolean warning) {
Delta d = p.getDelta();
if (d == Delta.UNCHANGED)
return;
if (warning)
warning("%s%s", indent, p).header("-diff");
else
error("%s%s", indent, p).header("-diff");
indent = indent + " ";
switch(d) {
case CHANGED:
case MAJOR:
case MINOR:
case MICRO:
break;
default:
return;
}
for (Diff c : p.getChildren()) show(c, indent, warning);
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class RepoTreeTest method testSimple.
public static void testSimple() throws Exception {
RepositoryPlugin a = mock(RepositoryPlugin.class);
RepositoryPlugin b = mock(RepositoryPlugin.class);
when(a.getName()).thenReturn("a");
when(a.list(null)).thenReturn(Arrays.asList("a", "b"));
when(a.versions("a")).thenReturn(new SortedList<Version>(new Version("1"), new Version("2")));
when(a.versions("b")).thenReturn(new SortedList<Version>(new Version("2"), new Version("3")));
when(b.getName()).thenReturn("b");
when(b.list(null)).thenReturn(Arrays.asList("b", "c"));
when(b.versions("b")).thenReturn(new SortedList<Version>(new Version("1"), new Version("2")));
when(b.versions("c")).thenReturn(new SortedList<Version>(new Version("2"), new Version("3")));
Tree ta = RepositoryElement.getTree(a);
Tree tb = RepositoryElement.getTree(b);
Diff diff = new DiffImpl(ta, tb);
print(diff, 0);
assertEquals(Delta.MAJOR, diff.getDelta());
assertEquals(Type.PROGRAM, diff.get("a").getType());
assertEquals(Type.VERSION, diff.get("a").get("1.0.0").getType());
assertEquals(Delta.ADDED, diff.get("a").get("1.0.0").getDelta());
assertEquals(Delta.ADDED, diff.get("a").get("2.0.0").getDelta());
assertEquals(Delta.REMOVED, diff.get("b").get("1.0.0").getDelta());
assertEquals(Delta.UNCHANGED, diff.get("b").get("2.0.0").getDelta());
assertEquals(Delta.ADDED, diff.get("b").get("3.0.0").getDelta());
assertEquals(Delta.REMOVED, diff.get("c").getDelta());
assertEquals(Delta.REMOVED, diff.get("c").get("2.0.0").getDelta());
assertEquals(Delta.REMOVED, diff.get("c").get("3.0.0").getDelta());
}
Aggregations