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());
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class Baseline method baseline.
public Set<Info> baseline(Tree n, Parameters nExports, Tree o, Parameters oExports, Instructions packageFilters) throws Exception {
diff = n.diff(o);
Diff apiDiff = diff.get("<api>");
infos = Create.set();
bsn = getBsn(n);
newerVersion = getVersion(n);
olderVersion = getVersion(o);
boolean firstRelease = false;
if (o.get("<manifest>") == null) {
firstRelease = true;
if (newerVersion.equals(Version.emptyVersion)) {
newerVersion = Version.ONE;
}
}
Delta highestDelta = Delta.UNCHANGED;
for (Diff pdiff : apiDiff.getChildren()) {
if (// Just packages
pdiff.getType() != Type.PACKAGE)
continue;
if (pdiff.getName().startsWith("java."))
continue;
if (!packageFilters.matches(pdiff.getName()))
continue;
final Info info = new Info();
infos.add(info);
info.reason = getRootCauses(pdiff);
info.packageDiff = pdiff;
info.packageName = pdiff.getName();
info.attributes = nExports.get(info.packageName);
logger.debug("attrs for {} {}", info.packageName, info.attributes);
info.newerVersion = getVersion(info.attributes);
info.olderVersion = getVersion(oExports.get(info.packageName));
if (pdiff.getDelta() == Delta.UNCHANGED) {
info.suggestedVersion = info.olderVersion;
// Fix previously released package containing version qualifier
if (info.olderVersion.getQualifier() != null) {
info.suggestedVersion = bump(Delta.MICRO, info.olderVersion, 1, 0);
info.warning += "Found package version with qualifier. Bumping micro version";
} else if (!info.newerVersion.equals(info.olderVersion)) {
info.warning += "No difference but versions are not equal";
}
} else if (pdiff.getDelta() == Delta.REMOVED) {
info.suggestedVersion = null;
} else if (pdiff.getDelta() == Delta.ADDED) {
info.suggestedVersion = info.newerVersion;
} else {
// We have an API change
info.suggestedVersion = bump(pdiff.getDelta(), info.olderVersion, 1, 0);
if (info.newerVersion.compareTo(info.suggestedVersion) < 0) {
// our suggested version is smaller
info.mismatch = true;
// that an interface is a provider interface
if (pdiff.getDelta() == Delta.MAJOR) {
info.providers = Create.set();
if (info.attributes != null)
info.providers.addAll(Processor.split(info.attributes.get(Constants.PROVIDER_TYPE_DIRECTIVE)));
// Calculate the new delta assuming we fix all the major
// interfaces
// by making them providers
Delta tryDelta = pdiff.getDelta(new Ignore() {
public boolean contains(Diff diff) {
if (diff.getType() == Type.INTERFACE && diff.getDelta() == Delta.MAJOR) {
info.providers.add(Descriptors.getShortName(diff.getName()));
return true;
}
return false;
}
});
if (tryDelta != Delta.MAJOR) {
info.suggestedIfProviders = bump(tryDelta, info.olderVersion, 1, 0);
}
}
}
}
Delta content;
switch(pdiff.getDelta()) {
case IGNORED:
case UNCHANGED:
content = Delta.UNCHANGED;
break;
case ADDED:
content = Delta.MINOR;
break;
case // cannot happen
CHANGED:
content = Delta.MICRO;
break;
case MICRO:
content = pdiff.getDelta();
break;
case MINOR:
content = pdiff.getDelta();
break;
case MAJOR:
content = pdiff.getDelta();
break;
case REMOVED:
default:
content = Delta.MAJOR;
break;
}
if (content.compareTo(highestDelta) > 0) {
highestDelta = content;
}
}
// biggest semantic change
if (firstRelease || !bsn.equals(getBsn(o))) {
suggestedVersion = newerVersion;
} else {
suggestedVersion = bumpBundle(highestDelta, olderVersion, 1, 0);
if (suggestedVersion.compareTo(newerVersion) < 0)
suggestedVersion = newerVersion;
}
binfo.bsn = bsn;
binfo.suggestedVersion = suggestedVersion;
binfo.version = binfo.olderVersion = olderVersion;
binfo.newerVersion = newerVersion;
if (newerVersion.getWithoutQualifier().equals(olderVersion.getWithoutQualifier())) {
if (getDiff().getDelta() == Delta.UNCHANGED)
return infos;
}
// Ok, now our bundle version must be >= the suggestedVersion
if (newerVersion.getWithoutQualifier().compareTo(getSuggestedVersion()) < 0) {
binfo.mismatch = true;
binfo.reason = getRootCauses(apiDiff);
}
return infos;
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class DiffImpl method serialize.
public Data serialize() {
Data data = new Data();
data.type = getType();
data.delta = delta;
data.name = getName();
data.children = new Data[children.size()];
int i = 0;
for (Diff d : children) data.children[i++] = d.serialize();
return data;
}
use of aQute.bnd.service.diff.Diff 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();
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class BaselineTest method testCutOffInheritance.
// This tests the scenario where a super type is injected into the class
// hierarchy but the super class comes from outside the bundle so that the
// baseline cannot find it. Since the class hierarchy was cut off, the
// baseline would _forget_ that every class inherits from Object, and _lose_
// Object's methods if not directly implemented.
public void testCutOffInheritance() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("jar/baseline/inheritance-change-1.0.0.jar"));
Jar newer = new Jar(IO.getFile("jar/baseline/inheritance-change-1.1.0.jar"))) {
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertFalse(bundleInfo.mismatch);
assertEquals("1.1.0", bundleInfo.suggestedVersion.toString());
Set<Info> packageInfos = baseline.getPackageInfos();
assertEquals(1, packageInfos.size());
Info change = packageInfos.iterator().next();
assertFalse(change.mismatch);
assertEquals("example", change.packageName);
assertEquals("1.1.0", change.suggestedVersion.toString());
Diff packageDiff = change.packageDiff;
Collection<? extends Diff> children = packageDiff.getChildren();
assertEquals(5, children.size());
Iterator<? extends Diff> iterator = children.iterator();
Diff diff = iterator.next();
assertEquals(Delta.MICRO, diff.getDelta());
diff = iterator.next();
assertEquals(Delta.MICRO, diff.getDelta());
diff = iterator.next();
assertEquals(Delta.MINOR, diff.getDelta());
}
}
Aggregations