use of aQute.bnd.service.diff.Diff 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.Diff in project bnd by bndtools.
the class DiffCommand method getTagFrom.
private static Tag getTagFrom(Diff diff, boolean limited) {
if (limited && (diff.getDelta() == Delta.UNCHANGED || diff.getDelta() == Delta.IGNORED))
return null;
Tag tag = new Tag("diff");
tag.addAttribute("name", diff.getName());
tag.addAttribute("delta", diff.getDelta());
tag.addAttribute("type", diff.getType());
if (limited && (diff.getDelta() == Delta.ADDED || diff.getDelta() == Delta.REMOVED))
return tag;
for (Diff c : diff.getChildren()) {
Tag child = getTagFrom(c, limited);
if (child != null)
tag.addContent(child);
}
return tag;
}
use of aQute.bnd.service.diff.Diff 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.Diff in project bndtools by bndtools.
the class TreeContentProvider method getChildren.
private Object[] getChildren(Diff parent) {
Collection<? extends Diff> diffs = parent.getChildren();
List<Diff> filteredDiffs = new ArrayList<Diff>();
for (Diff diff : diffs) {
if (!showAll && (diff.getDelta() == Delta.IGNORED || diff.getDelta() == Delta.UNCHANGED)) {
continue;
}
if (diff.getType() == Type.SHA) {
continue;
}
if ("META-INF/MANIFEST.MF".equals(diff.getName())) {
//$NON-NLS-1$
continue;
}
if (diff.getType() == Type.HEADER && diff.getName().startsWith(Constants.BUNDLE_VERSION)) {
continue;
}
filteredDiffs.add(diff);
}
return filteredDiffs.toArray(new Diff[0]);
}
use of aQute.bnd.service.diff.Diff 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