use of aQute.bnd.differ.Baseline 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.differ.Baseline in project bndtools by bndtools.
the class ReleaseDialogJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
monitor.beginTask(Messages.cleaningProject, 100);
monitor.setTaskName(Messages.releasing);
monitor.worked(33);
monitor.subTask(Messages.checkingExported);
final List<Baseline> diffs = new ArrayList<Baseline>();
List<Builder> builders = project.getBuilder(null).getSubBuilders();
for (Builder builder : builders) {
if (subBundles != null) {
if (!subBundles.contains(builder.getPropertiesFile())) {
continue;
}
}
Baseline diff = DiffHelper.createBaseline(project, builder.getBsn());
if (diff != null) {
diffs.add(diff);
}
}
if (diffs.size() == 0) {
//TODO: message
return Status.OK_STATUS;
}
monitor.worked(33);
Runnable runnable = new Runnable() {
public void run() {
List<ProjectDiff> projectDiffs = new ArrayList<ProjectDiff>();
projectDiffs.add(new ProjectDiff(project, diffs));
ReleaseHelper.initializeProjectDiffs(projectDiffs);
WorkspaceReleaseDialog dialog = new WorkspaceReleaseDialog(shell, projectDiffs, true);
if (dialog.open() == WorkspaceReleaseDialog.OK) {
boolean runJob = false;
for (ProjectDiff diff : projectDiffs) {
if (diff.isRelease()) {
runJob = true;
break;
}
}
if (!runJob) {
return;
}
WorkspaceReleaseJob releaseJob = new WorkspaceReleaseJob(projectDiffs, dialog.getReleaseOption(), dialog.isShowMessage());
releaseJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
releaseJob.schedule();
}
}
};
if (Display.getCurrent() == null) {
Display.getDefault().asyncExec(runnable);
} else {
runnable.run();
}
monitor.worked(33);
return Status.OK_STATUS;
} catch (Exception e) {
return new Status(Status.ERROR, Activator.PLUGIN_ID, "Error : " + e.getMessage(), e);
} finally {
monitor.done();
}
}
use of aQute.bnd.differ.Baseline in project bndtools by bndtools.
the class BundleTree method createInfoViewer.
private void createInfoViewer(Composite container) {
infoViewerComposite = new Composite(container, SWT.NONE);
infoViewerComposite.setLayoutData(createFillGridData());
TreeColumnLayout layout = new TreeColumnLayout();
infoViewerComposite.setLayout(layout);
infoViewer = new TreeViewer(infoViewerComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
infoViewer.setUseHashlookup(true);
infoViewer.getTree().setHeaderVisible(true);
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
TreeColumn treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(450, 180, true));
treeColumn.setText(Messages.bundleAndPackageName);
treeViewerColumn.setLabelProvider(new InfoLabelProvider());
treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(80, 80, true));
treeColumn.setText(Messages.version2);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Baseline) {
return ((Baseline) element).getOlderVersion().getWithoutQualifier().toString();
}
if (element instanceof Info) {
return ((Info) element).olderVersion.toString();
}
//$NON-NLS-1$
return "";
}
});
treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(80, 80, true));
treeColumn.setText(Messages.newVersion);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Baseline) {
return ((Baseline) element).getSuggestedVersion().toString();
}
if (element instanceof Info) {
//$NON-NLS-1$
return ((Info) element).suggestedVersion != null ? ((Info) element).suggestedVersion.toString() : "";
}
//$NON-NLS-1$
return "";
}
});
treeViewerColumn.setEditingSupport(new InlineComboEditingSupport(infoViewer));
infoViewer.setContentProvider(infoTreeViewerProvider);
infoViewer.setAutoExpandLevel(2);
}
use of aQute.bnd.differ.Baseline in project bndtools by bndtools.
the class InfoContentProvider method getChildren.
@Override
public Object[] getChildren(Object parent) {
if (parent instanceof List) {
return ((List<?>) parent).toArray();
}
if (parent instanceof Baseline) {
if (isShowAll()) {
return ((Baseline) parent).getPackageInfos().toArray();
}
Set<Info> infos = ((Baseline) parent).getPackageInfos();
List<Info> filteredDiffs = new ArrayList<Info>();
for (Info info : infos) {
if (info.packageDiff.getDelta() == Delta.IGNORED || (info.packageDiff.getDelta() == Delta.UNCHANGED && info.olderVersion.equals(info.suggestedVersion))) {
continue;
}
filteredDiffs.add(info);
}
return filteredDiffs.toArray(new Info[0]);
}
return new Object[0];
}
use of aQute.bnd.differ.Baseline in project bndtools by bndtools.
the class ReleaseHelper method initializeProjectDiffs.
public static void initializeProjectDiffs(List<ProjectDiff> projects) {
String[] repos = getReleaseRepositories();
for (ProjectDiff projectDiff : projects) {
RepositoryPlugin repoPlugin = ReleaseHelper.getReleaseRepo(projectDiff.getProject());
String repo;
if (repoPlugin != null) {
repo = repoPlugin.getName();
} else {
repo = null;
}
if (repo == null) {
if (repos.length > 0) {
repo = repos[0];
} else {
repo = "";
}
}
projectDiff.setReleaseRepository(repo);
projectDiff.setDefaultReleaseRepository(repo);
for (Baseline baseline : projectDiff.getBaselines()) {
if (ReleaseUtils.needsRelease(baseline)) {
projectDiff.setRelease(true);
projectDiff.setReleaseRequired(true);
if (!baseline.getNewerVersion().equals(baseline.getSuggestedVersion())) {
projectDiff.setVersionUpdateRequired(true);
continue;
}
for (Info info : baseline.getPackageInfos()) {
if (!info.newerVersion.equals(info.suggestedVersion)) {
projectDiff.setVersionUpdateRequired(true);
break;
}
}
} else {
baseline.setSuggestedVersion(baseline.getOlderVersion());
}
}
}
}
Aggregations