Another bnd code refresh

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1360983 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/bnd/differ/Baseline.java b/bundleplugin/src/main/java/aQute/bnd/differ/Baseline.java
index fd27e41..4319b6b 100644
--- a/bundleplugin/src/main/java/aQute/bnd/differ/Baseline.java
+++ b/bundleplugin/src/main/java/aQute/bnd/differ/Baseline.java
@@ -34,6 +34,12 @@
 	final Differ	differ;
 	final Reporter	bnd;
 	Diff			diff;
+	Set<Info>		infos;
+	String 			bsn;
+	Version			newerVersion;
+	Version			olderVersion;
+	Version			suggestedVersion;
+	String			releaseRepository;
 
 	public Baseline(Reporter bnd, Differ differ) throws IOException {
 		this.differ = differ;
@@ -66,8 +72,14 @@
 			throws Exception {
 		diff = n.diff(o);
 		Diff apiDiff = diff.get("<api>");
-		Set<Info> infos = Create.set();
+		infos = Create.set();
 
+		bsn = getBsn(n);
+
+		newerVersion = getVersion(n);
+		olderVersion = getVersion(o);
+		
+		Delta highestDelta = Delta.MICRO;
 		for (Diff pdiff : apiDiff.getChildren()) {
 			if (pdiff.getType() != Type.PACKAGE) // Just packages
 				continue;
@@ -91,7 +103,7 @@
 			if (pdiff.getDelta() == Delta.UNCHANGED) {
 				info.suggestedVersion = info.olderVersion;
 				if (!info.newerVersion.equals(info.olderVersion)) {
-					info.warning += "No difference but versions are equal";
+					info.warning += "No difference but versions are not equal";
 				}
 			} else if (pdiff.getDelta() == Delta.REMOVED) {
 				info.suggestedVersion = null;
@@ -135,6 +147,13 @@
 					}
 				}
 			}
+			if (pdiff.getDelta().compareTo(highestDelta) > 0) {
+				highestDelta = pdiff.getDelta();
+			}
+		}
+		suggestedVersion = bumpBundle(highestDelta, olderVersion, 1, 0);
+		if (suggestedVersion.getMajor() == 0) {
+			suggestedVersion = Version.ONE;
 		}
 		return infos;
 	}
@@ -148,6 +167,40 @@
 		return diff;
 	}
 
+	public Set<Info> getPackageInfos() {
+		if (infos == null)
+			return Collections.emptySet();
+		return infos;
+	}
+
+	public String getBsn() {
+		return bsn;
+	}
+
+	public Version getSuggestedVersion() {
+		return suggestedVersion;
+	}
+
+	public void setSuggestedVersion(Version suggestedVersion) {
+		this.suggestedVersion = suggestedVersion;
+	}
+
+	public Version getNewerVersion() {
+		return newerVersion;
+	}
+
+	public Version getOlderVersion() {
+		return olderVersion;
+	}
+
+	public String getReleaseRepository() {
+		return releaseRepository;
+	}
+
+	public void setReleaseRepository(String releaseRepository) {
+		this.releaseRepository = releaseRepository;
+	}
+
 	private Version bump(Delta delta, Version last, int offset, int base) {
 		switch (delta) {
 			case UNCHANGED :
@@ -177,5 +230,43 @@
 
 		return OSGiHeader.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
 	}
+	
+	private Version getVersion(Tree top) {
+		Tree manifest = top.get("<manifest>");
+		if (manifest == null) {
+			return Version.emptyVersion;
+		}
+		for (Tree tree : manifest.getChildren()) {
+			if (tree.getName().startsWith(Constants.BUNDLE_VERSION)) {
+				return Version.parseVersion(tree.getName().substring(15));
+			}
+		}
+		return Version.emptyVersion;
+	}
 
+	private String getBsn(Tree top) {
+		Tree manifest = top.get("<manifest>");
+		if (manifest == null) {
+			return "";
+		}
+		for (Tree tree : manifest.getChildren()) {
+			if (tree.getName().startsWith(Constants.BUNDLE_SYMBOLICNAME) && tree.getChildren().length > 0) {
+				return tree.getChildren()[0].getName();
+			}
+		}
+		return "";
+	}
+
+	private Version bumpBundle(Delta delta, Version last, int offset, int base) {
+		switch (delta) {
+			case MINOR :
+				return new Version(last.getMajor(), last.getMinor() + offset, base);
+			case MAJOR :
+				return new Version(last.getMajor() + 1, base, base);
+			case ADDED :
+				return new Version(last.getMajor(), last.getMinor() + offset, base);
+			default :
+				return new Version(last.getMajor(), last.getMinor(), last.getMicro() + offset);
+		}
+	}
 }