Search in sources :

Example 6 with Diff

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();
        }
    }
}
Also used : Diff(aQute.bnd.service.diff.Diff) Tree(aQute.bnd.service.diff.Tree) Instructions(aQute.bnd.osgi.Instructions) Tag(aQute.lib.tag.Tag) File(java.io.File) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 7 with Diff

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;
}
Also used : Diff(aQute.bnd.service.diff.Diff) Tag(aQute.lib.tag.Tag)

Example 8 with Diff

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];
}
Also used : Diff(aQute.bnd.service.diff.Diff) ArrayList(java.util.ArrayList) Tree(aQute.bnd.service.diff.Tree) List(java.util.List) ArrayList(java.util.ArrayList) Baseline(aQute.bnd.differ.Baseline)

Example 9 with Diff

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]);
}
Also used : Diff(aQute.bnd.service.diff.Diff) ArrayList(java.util.ArrayList)

Example 10 with Diff

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;
}
Also used : Diff(aQute.bnd.service.diff.Diff) Tree(aQute.bnd.service.diff.Tree) Baseline(aQute.bnd.differ.Baseline)

Aggregations

Diff (aQute.bnd.service.diff.Diff)28 Tree (aQute.bnd.service.diff.Tree)17 Jar (aQute.bnd.osgi.Jar)9 File (java.io.File)7 Baseline (aQute.bnd.differ.Baseline)6 Builder (aQute.bnd.osgi.Builder)6 Info (aQute.bnd.differ.Baseline.Info)4 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)4 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 Delta (aQute.bnd.service.diff.Delta)3 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)2 DiffImpl (aQute.bnd.differ.DiffImpl)2 Parameters (aQute.bnd.header.Parameters)2 Instructions (aQute.bnd.osgi.Instructions)2 Processor (aQute.bnd.osgi.Processor)2 Version (aQute.bnd.version.Version)2 Tag (aQute.lib.tag.Tag)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Attrs (aQute.bnd.header.Attrs)1