Search in sources :

Example 1 with Diff

use of aQute.bnd.service.diff.Diff in project felix by apache.

the class AbstractBaselinePlugin method doDiff.

private void doDiff(Object context, Diff diff, int depth) {
    String type = StringUtils.lowerCase(String.valueOf(diff.getType()));
    String shortDelta = getShortDelta(diff.getDelta());
    String delta = StringUtils.lowerCase(String.valueOf(diff.getDelta()));
    String name = diff.getName();
    startDiff(context, depth, type, name, delta, shortDelta);
    for (Diff curDiff : diff.getChildren()) {
        if (Delta.UNCHANGED != curDiff.getDelta()) {
            doDiff(context, curDiff, depth + 1);
        }
    }
    endDiff(context, depth);
}
Also used : Diff(aQute.bnd.service.diff.Diff)

Example 2 with Diff

use of aQute.bnd.service.diff.Diff 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());
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Diff(aQute.bnd.service.diff.Diff) Tree(aQute.bnd.service.diff.Tree) Jar(aQute.bnd.osgi.Jar)

Example 3 with Diff

use of aQute.bnd.service.diff.Diff 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);
                    }
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Diff(aQute.bnd.service.diff.Diff) Attrs(aQute.bnd.header.Attrs) Tree(aQute.bnd.service.diff.Tree) File(java.io.File)

Example 4 with Diff

use of aQute.bnd.service.diff.Diff in project bnd by bndtools.

the class Builder method show.

/**
	 * Show the diff recursively
	 * 
	 * @param p
	 * @param i
	 */
private void show(Diff p, String indent, boolean warning) {
    Delta d = p.getDelta();
    if (d == Delta.UNCHANGED)
        return;
    if (warning)
        warning("%s%s", indent, p).header("-diff");
    else
        error("%s%s", indent, p).header("-diff");
    indent = indent + " ";
    switch(d) {
        case CHANGED:
        case MAJOR:
        case MINOR:
        case MICRO:
            break;
        default:
            return;
    }
    for (Diff c : p.getChildren()) show(c, indent, warning);
}
Also used : Delta(aQute.bnd.service.diff.Delta) Diff(aQute.bnd.service.diff.Diff)

Example 5 with Diff

use of aQute.bnd.service.diff.Diff 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)

Aggregations

Diff (aQute.bnd.service.diff.Diff)29 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