use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class ProjectBuilder method doBaseline.
/**
* Compare this builder's JAR with a baseline
*
* @throws Exception
*/
@Override
public void doBaseline(Jar dot) throws Exception {
String diffignore = project.getProperty(Constants.DIFFIGNORE);
logger.debug("ignore headers & paths {}", diffignore);
differ.setIgnore(diffignore);
Instructions diffpackages = new Instructions(new Parameters(project.getProperty(Constants.DIFFPACKAGES), this));
logger.debug("diffpackages {}", diffpackages);
try (Jar fromRepo = getBaselineJar()) {
if (fromRepo == null) {
logger.debug("No baseline jar {}", getProperty(Constants.BASELINE));
return;
}
Version newer = new Version(getVersion());
Version older = new Version(fromRepo.getVersion());
if (!getBsn().equals(fromRepo.getBsn())) {
error("The symbolic name of this project (%s) is not the same as the baseline: %s", getBsn(), fromRepo.getBsn());
return;
}
if (newer.getWithoutQualifier().equals(older.getWithoutQualifier())) {
RepositoryPlugin rr = getBaselineRepo();
if (rr instanceof InfoRepository) {
ResourceDescriptor descriptor = ((InfoRepository) rr).getDescriptor(getBsn(), older);
if (descriptor != null && descriptor.phase != Phase.STAGING) {
error("Baselining %s against same version %s but the repository says the older repository version is not the required %s but is instead %s", getBsn(), getVersion(), Phase.STAGING, descriptor.phase);
return;
}
}
}
logger.debug("baseline {}-{} against: {}", getBsn(), getVersion(), fromRepo.getName());
Baseline baseliner = new Baseline(this, differ);
Set<Info> infos = baseliner.baseline(dot, fromRepo, diffpackages);
if (infos.isEmpty())
logger.debug("no deltas");
StringBuffer sb = new StringBuffer();
try (Formatter f = new Formatter(sb, Locale.US)) {
for (Info info : infos) {
if (!info.mismatch) {
continue;
}
sb.setLength(0);
Diff packageDiff = info.packageDiff;
f.format("Baseline mismatch for package %s, %s change. Current is %s, repo is %s, suggest %s or %s%n%#S", packageDiff.getName(), packageDiff.getDelta(), info.newerVersion, ((info.olderVersion != null) && info.olderVersion.equals(Version.LOWEST)) ? '-' : info.olderVersion, ((info.suggestedVersion != null) && info.suggestedVersion.compareTo(info.newerVersion) <= 0) ? "ok" : info.suggestedVersion, (info.suggestedIfProviders == null) ? "-" : info.suggestedIfProviders, packageDiff);
SetLocation l = error("%s", f.toString());
l.header(Constants.BASELINE);
fillInLocationForPackageInfo(l.location(), packageDiff.getName());
if (getPropertiesFile() != null)
l.file(getPropertiesFile().getAbsolutePath());
l.details(info);
}
BundleInfo binfo = baseliner.getBundleInfo();
if (binfo.mismatch) {
sb.setLength(0);
f.format("The bundle version (%s/%s) is too low, must be at least %s%n%#S", binfo.olderVersion, binfo.newerVersion, binfo.suggestedVersion, baseliner.getDiff());
SetLocation error = error("%s", f.toString());
error.context("Baselining");
error.header(Constants.BUNDLE_VERSION);
error.details(binfo);
FileLine fl = getHeader(Pattern.compile("^" + Constants.BUNDLE_VERSION, Pattern.MULTILINE));
if (fl != null) {
error.file(fl.file.getAbsolutePath());
error.line(fl.line);
error.length(fl.length);
}
}
}
}
}
use of aQute.bnd.service.diff.Diff in project bnd by bndtools.
the class DiffImpl method format.
private static void format(final Formatter formatter, final Diff diff, final List<String> formats, final Set<Delta> deltas, final int indent, final int depth) {
if (depth == formats.size()) {
StringBuilder sb = new StringBuilder();
if (depth > 0) {
sb.append("%n");
}
int width = depth * 2;
for (int leading = width + indent; leading > 0; leading--) {
sb.append(' ');
}
sb.append("%-");
sb.append(Math.max(20 - width, 1));
sb.append("s %-10s %s");
formats.add(sb.toString());
}
String format = formats.get(depth);
formatter.format(format, diff.getDelta(), diff.getType(), diff.getName());
for (Diff childDiff : diff.getChildren()) {
if (deltas.contains(childDiff.getDelta())) {
format(formatter, childDiff, formats, deltas, indent, depth + 1);
}
}
}
use of aQute.bnd.service.diff.Diff in project bndtools by bndtools.
the class InfoLabelProvider method getImage.
@Override
public Image getImage(Object element) {
if (element instanceof Baseline) {
//$NON-NLS-1$
Diff apiDiff = ((Baseline) element).getDiff() != null ? ((Baseline) element).getDiff().get("<api>") : null;
if (apiDiff == null) {
apiDiff = ((Baseline) element).getDiff();
}
//$NON-NLS-1$
return BundleTreeImages.resolveImage("bundle", apiDiff.getDelta().toString().toLowerCase(), null, null);
}
if (element instanceof Info) {
Info tree = (Info) element;
//$NON-NLS-1$
String type = "package";
//$NON-NLS-1$
String delta = "changed" + '_' + tree.packageDiff.getDelta().toString().toLowerCase();
//$NON-NLS-1$
String impExp = "export";
return BundleTreeImages.resolveImage(type, delta, impExp, null);
}
return null;
}
Aggregations