use of aQute.bnd.service.diff.Tree 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.Tree in project bnd by bndtools.
the class BaselineTest method testClassesDiffWithoutSource.
public void testClassesDiffWithoutSource() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar jar = new Jar(IO.getFile("jar/osgi.jar"));
Jar out = new Jar(".")) {
for (String path : jar.getResources().keySet()) {
if (!path.startsWith("OSGI-OPT/src/"))
out.putResource(path, jar.getResource(path));
}
Tree tree = diff.tree(out);
assertNull(tree.get("<resources>").get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
assertNotNull(tree.get("<resources>").get("org/osgi/application/ApplicationContext.class"));
}
}
use of aQute.bnd.service.diff.Tree in project bnd by bndtools.
the class BaselineTest method testClassesDiffWithSource.
/**
* Test skipping classes when there is source
*/
public void testClassesDiffWithSource() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar jar = new Jar(IO.getFile("jar/osgi.jar"));
Jar out = new Jar(".")) {
out.putResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java", jar.getResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
out.putResource("org/osgi/application/ApplicationContext.class", jar.getResource("org/osgi/application/ApplicationContext.class"));
Tree tree = diff.tree(out);
Tree src = tree.get("<resources>").get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java").getChildren()[0];
assertNotNull(src);
assertNull(tree.get("<resources>").get("org/osgi/application/ApplicationContext.class"));
}
}
use of aQute.bnd.service.diff.Tree 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.Tree 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