Search in sources :

Example 1 with Tree

use of aQute.bnd.service.diff.Tree 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 2 with Tree

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

the class BaselineTest method testClassesDiffWithoutSource.

public void testClassesDiffWithoutSource() throws Exception {
    DiffPluginImpl diff = new DiffPluginImpl();
    try (Jar jar = new Jar(IO.getFile("jar/osgi.jar"));
        Jar out = new Jar(".")) {
        for (String path : jar.getResources().keySet()) {
            if (!path.startsWith("OSGI-OPT/src/"))
                out.putResource(path, jar.getResource(path));
        }
        Tree tree = diff.tree(out);
        assertNull(tree.get("<resources>").get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
        assertNotNull(tree.get("<resources>").get("org/osgi/application/ApplicationContext.class"));
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Tree(aQute.bnd.service.diff.Tree) Jar(aQute.bnd.osgi.Jar) Matchers.anyString(org.mockito.Matchers.anyString)

Example 3 with Tree

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

the class BaselineTest method testClassesDiffWithSource.

/**
	 * Test skipping classes when there is source
	 */
public void testClassesDiffWithSource() throws Exception {
    DiffPluginImpl diff = new DiffPluginImpl();
    try (Jar jar = new Jar(IO.getFile("jar/osgi.jar"));
        Jar out = new Jar(".")) {
        out.putResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java", jar.getResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
        out.putResource("org/osgi/application/ApplicationContext.class", jar.getResource("org/osgi/application/ApplicationContext.class"));
        Tree tree = diff.tree(out);
        Tree src = tree.get("<resources>").get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java").getChildren()[0];
        assertNotNull(src);
        assertNull(tree.get("<resources>").get("org/osgi/application/ApplicationContext.class"));
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Tree(aQute.bnd.service.diff.Tree) Jar(aQute.bnd.osgi.Jar)

Example 4 with Tree

use of aQute.bnd.service.diff.Tree 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 5 with Tree

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());
}
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

Tree (aQute.bnd.service.diff.Tree)24 Diff (aQute.bnd.service.diff.Diff)17 Jar (aQute.bnd.osgi.Jar)10 File (java.io.File)9 Builder (aQute.bnd.osgi.Builder)6 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)5 Instructions (aQute.bnd.osgi.Instructions)4 PrintWriter (java.io.PrintWriter)4 Parameters (aQute.bnd.header.Parameters)3 Baseline (aQute.bnd.differ.Baseline)2 DiffImpl (aQute.bnd.differ.DiffImpl)2 Attrs (aQute.bnd.header.Attrs)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 Version (aQute.bnd.version.Version)2 MultiMap (aQute.lib.collections.MultiMap)2 Tag (aQute.lib.tag.Tag)2 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)1 Info (aQute.bnd.differ.Baseline.Info)1 Analyzer (aQute.bnd.osgi.Analyzer)1 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)1