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());
}
use of aQute.bnd.service.diff.Tree in project bnd by bndtools.
the class DiffCommand method diff.
private void diff(diffOptions options, DiffPluginImpl di, Jar newer, Jar older) throws Exception {
if (newer == null) {
bnd.error("No newer file specified");
return;
}
if (older == null) {
bnd.error("No older file specified");
return;
}
PrintWriter pw = null;
try {
File fout = options.output();
if (fout == null)
pw = IO.writer(bnd.out);
else
pw = IO.writer(fout, UTF_8);
Instructions packageFilters = new Instructions(options.pack());
if (options.ignore() != null)
di.setIgnore(Processor.join(options.ignore()));
Tree n = di.tree(newer);
Tree o = di.tree(older);
Diff diff = n.diff(o);
boolean all = options.api() == false && options.resources() == false && options.manifest() == false;
if (!options.xml()) {
if (all || options.api())
for (Diff packageDiff : diff.get("<api>").getChildren()) {
if (packageFilters.matches(packageDiff.getName()))
show(pw, packageDiff, 0, !options.full());
}
if (all || options.manifest())
show(pw, diff.get("<manifest>"), 0, !options.full());
if (all || options.resources())
show(pw, diff.get("<resources>"), 0, !options.full());
} else {
Tag tag = new Tag("diff");
tag.addAttribute("date", new Date());
tag.addContent(getTagFrom("newer", newer));
tag.addContent(getTagFrom("older", older));
if (all || options.api())
tag.addContent(getTagFrom(diff.get("<api>"), !options.full()));
if (all || options.manifest())
tag.addContent(getTagFrom(diff.get("<manifest>"), !options.full()));
if (all || options.resources())
tag.addContent(getTagFrom(diff.get("<resources>"), !options.full()));
pw.print("<?xml version='1.0' encoding='UTF-8'?>\n");
tag.print(0, pw);
}
} finally {
if (older != null) {
older.close();
}
if (newer != null) {
newer.close();
}
if (pw != null) {
pw.close();
}
}
}
use of aQute.bnd.service.diff.Tree in project bnd by bndtools.
the class DiffCommand method showTree.
/**
* Just show the single tree
*
* @param bnd
* @param options
* @throws Exception
*/
private static void showTree(bnd bnd, diffOptions options) throws Exception {
File fout = options.output();
PrintWriter pw;
if (fout == null)
pw = IO.writer(bnd.out);
else
pw = IO.writer(fout, UTF_8);
Instructions packageFilters = new Instructions(options.pack());
try (Jar newer = new Jar(bnd.getFile(options._arguments().get(0)))) {
Differ di = new DiffPluginImpl();
Tree n = di.tree(newer);
boolean all = options.api() == false && options.resources() == false && options.manifest() == false;
if (all || options.api())
for (Tree packageDiff : n.get("<api>").getChildren()) {
if (packageFilters.matches(packageDiff.getName()))
show(pw, packageDiff, 0);
}
if (all || options.manifest())
show(pw, n.get("<manifest>"), 0);
if (all || options.resources())
show(pw, n.get("<resources>"), 0);
} finally {
pw.close();
}
}
use of aQute.bnd.service.diff.Tree in project bndtools by bndtools.
the class TreeContentProvider method getChildren.
@Override
public Object[] getChildren(Object parent) {
if (parent instanceof List) {
return ((List<?>) parent).toArray();
}
if (parent instanceof Baseline) {
Collection<? extends Diff> diffs = ((Baseline) parent).getDiff().getChildren();
List<Diff> filteredDiffs = new ArrayList<Diff>();
for (Diff diff : diffs) {
switch(diff.getType()) {
case API:
case MANIFEST:
case RESOURCES:
if (getChildren(diff).length == 0)
continue;
break;
default:
break;
}
filteredDiffs.add(diff);
}
return filteredDiffs.toArray(new Diff[0]);
}
if (parent instanceof Tree) {
return ((Tree) parent).getChildren();
}
if (parent instanceof Diff) {
return getChildren((Diff) parent);
}
return new Object[0];
}
use of aQute.bnd.service.diff.Tree in project bndtools by bndtools.
the class TreeLabelProvider method getImage.
@Override
public Image getImage(Object element) {
if (element instanceof Baseline) {
//$NON-NLS-1$
return BundleTreeImages.resolveImage("bundle", ((Baseline) element).getDiff().getDelta().toString().toLowerCase(), null, null);
}
if (element instanceof Diff) {
Diff tree = (Diff) element;
String type = tree.getType().toString().toLowerCase();
String strDelta = getDeltaString(tree);
String impExp = null;
if (tree.getType() == Type.PACKAGE) {
//$NON-NLS-1$
impExp = "export";
} else if (tree.getType() == Type.RESOURCE) {
String name = tree.getName();
int idx = name.lastIndexOf('.');
if (idx > -1) {
//$NON-NLS-1$
type = "dot_" + name.substring(idx + 1);
}
}
return BundleTreeImages.resolveImage(type, strDelta, impExp, null);
}
if (element instanceof Tree) {
Tree tree = (Tree) element;
String type = tree.getType().toString().toLowerCase();
String impExp = null;
if (tree.getType() == Type.PACKAGE) {
//$NON-NLS-1$
impExp = "export";
} else if (tree.getType() == Type.RESOURCE) {
String name = tree.getName();
int idx = name.lastIndexOf('.');
if (idx > 0) {
//$NON-NLS-1$
type = "dot_" + name.substring(idx + 1);
}
}
return BundleTreeImages.resolveImage(type, null, impExp, null);
}
return null;
}
Aggregations