Search in sources :

Example 1 with DiffImpl

use of aQute.bnd.differ.DiffImpl 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());
}
Also used : Version(aQute.bnd.version.Version) Diff(aQute.bnd.service.diff.Diff) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Tree(aQute.bnd.service.diff.Tree) DiffImpl(aQute.bnd.differ.DiffImpl)

Example 2 with DiffImpl

use of aQute.bnd.differ.DiffImpl in project bnd by bndtools.

the class RepoCommand method _diff.

@Description("Diff jars (or show tree)")
public void _diff(diffOptions options) throws UnsupportedEncodingException, IOException, Exception {
    List<String> args = options._arguments();
    String newer = args.remove(0);
    String older = args.size() > 0 ? args.remove(0) : null;
    RepositoryPlugin rnewer = findRepo(newer);
    RepositoryPlugin rolder = older == null ? null : findRepo(older);
    if (rnewer == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    if (older != null && rolder == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    PrintWriter pw = IO.writer(bnd.out, UTF_8);
    Tree tNewer = RepositoryElement.getTree(rnewer);
    if (rolder == null) {
        if (options.json())
            codec.enc().to(pw).put(tNewer.serialize()).flush();
        else
            DiffCommand.show(pw, tNewer, 0);
    } else {
        Tree tOlder = RepositoryElement.getTree(rolder);
        Diff diff = new DiffImpl(tNewer, tOlder);
        MultiMap<String, String> map = new MultiMap<String, String>();
        for (Diff bsn : diff.getChildren()) {
            for (Diff version : bsn.getChildren()) {
                if (version.getDelta() == Delta.UNCHANGED)
                    continue;
                if (options.remove() == false && options.added() == false || (//
                options.remove() && version.getDelta() == Delta.REMOVED) || (options.added() && version.getDelta() == Delta.ADDED)) {
                    map.add(bsn.getName(), version.getName());
                }
            }
        }
        if (options.json())
            codec.enc().to(pw).put(map).flush();
        else if (!options.diff())
            bnd.printMultiMap(map);
        else
            DiffCommand.show(pw, diff, 0, !options.full());
    }
    pw.flush();
}
Also used : MultiMap(aQute.lib.collections.MultiMap) Diff(aQute.bnd.service.diff.Diff) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Tree(aQute.bnd.service.diff.Tree) DiffImpl(aQute.bnd.differ.DiffImpl) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

Aggregations

DiffImpl (aQute.bnd.differ.DiffImpl)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 Diff (aQute.bnd.service.diff.Diff)2 Tree (aQute.bnd.service.diff.Tree)2 Version (aQute.bnd.version.Version)1 MultiMap (aQute.lib.collections.MultiMap)1 Description (aQute.lib.getopt.Description)1 PrintWriter (java.io.PrintWriter)1