Search in sources :

Example 21 with Baseline

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);
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Diff(aQute.bnd.service.diff.Diff) Formatter(java.util.Formatter) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Instructions(aQute.bnd.osgi.Instructions) Baseline(aQute.bnd.differ.Baseline) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info) InfoRepository(aQute.bnd.service.repository.InfoRepository) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 22 with Baseline

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();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) WorkspaceReleaseDialog(bndtools.release.ui.WorkspaceReleaseDialog) Baseline(aQute.bnd.differ.Baseline)

Example 23 with Baseline

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);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn)

Example 24 with Baseline

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];
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info)

Example 25 with Baseline

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());
            }
        }
    }
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info)

Aggregations

Baseline (aQute.bnd.differ.Baseline)27 Info (aQute.bnd.differ.Baseline.Info)15 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)15 Jar (aQute.bnd.osgi.Jar)15 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)13 Processor (aQute.bnd.osgi.Processor)11 Builder (aQute.bnd.osgi.Builder)9 Diff (aQute.bnd.service.diff.Diff)6 ArrayList (java.util.ArrayList)5 ProjectBuilder (aQute.bnd.build.ProjectBuilder)4 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 Tree (aQute.bnd.service.diff.Tree)2 Version (aQute.bnd.version.Version)2 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)2 WorkspaceReleaseDialog (bndtools.release.ui.WorkspaceReleaseDialog)2 IOException (java.io.IOException)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Project (aQute.bnd.build.Project)1