Search in sources :

Example 1 with WorkspaceReleaseDialog

use of bndtools.release.ui.WorkspaceReleaseDialog in project bndtools by bndtools.

the class WorkspaceAnalyserJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    IProgressMonitor mon = monitor;
    if (mon == null) {
        mon = new NullProgressMonitor();
    }
    try {
        Collection<Project> projects = Activator.getWorkspace().getAllProjects();
        mon.beginTask(Messages.workspaceReleaseJob, projects.size() * 2);
        List<Project> orderedProjects = getBuildOrder(mon, Activator.getWorkspace());
        if (mon.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        final List<ProjectDiff> projectDiffs = new ArrayList<ProjectDiff>();
        mon.setTaskName(Messages.processingProjects);
        for (Project project : orderedProjects) {
            IProject eProject = ReleaseUtils.getProject(project);
            if (!isIncluded(eProject)) {
                mon.worked(1);
                continue;
            }
            if ("".equals(project.getProperty(Constants.RELEASEREPO, null))) {
                mon.worked(1);
                continue;
            }
            if (eProject == null || !eProject.isOpen() || !eProject.isAccessible()) {
                mon.worked(1);
                continue;
            }
            List<Baseline> jarDiffs = null;
            try (ProjectBuilder pb = project.getBuilder(null)) {
                for (Builder b : pb.getSubBuilders()) {
                    mon.subTask(String.format(Messages.processingProject, b.getBsn()));
                    Baseline jarDiff = DiffHelper.createBaseline(b);
                    if (jarDiff != null) {
                        if (jarDiffs == null) {
                            jarDiffs = new ArrayList<Baseline>();
                        }
                        jarDiffs.add(jarDiff);
                    }
                }
            }
            if (jarDiffs != null && jarDiffs.size() > 0) {
                projectDiffs.add(new ProjectDiff(project, jarDiffs));
            }
            if (mon.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            mon.worked(1);
        }
        if (projectDiffs.size() == 0) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(shell, Messages.releaseWorkspaceBundles, Messages.noBundlesRequireRelease);
                }
            };
            if (Display.getCurrent() == null) {
                Display.getDefault().syncExec(runnable);
            } else {
                runnable.run();
            }
            return Status.OK_STATUS;
        }
        ReleaseHelper.initializeProjectDiffs(projectDiffs);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                WorkspaceReleaseDialog dialog = new WorkspaceReleaseDialog(shell, projectDiffs, false);
                int ret = dialog.open();
                if (ret == Window.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();
        }
    } catch (Exception e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) WorkspaceReleaseDialog(bndtools.release.ui.WorkspaceReleaseDialog) Baseline(aQute.bnd.differ.Baseline) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectBuilder(aQute.bnd.build.ProjectBuilder)

Example 2 with WorkspaceReleaseDialog

use of bndtools.release.ui.WorkspaceReleaseDialog 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>();
        try (ProjectBuilder pb = project.getBuilder(null)) {
            for (Builder builder : pb.getSubBuilders()) {
                if (subBundles != null) {
                    if (!subBundles.contains(builder.getPropertiesFile())) {
                        continue;
                    }
                }
                Baseline diff = DiffHelper.createBaseline(builder);
                if (diff != null) {
                    diffs.add(diff);
                }
            }
        }
        if (diffs.size() == 0) {
            // TODO: message
            return Status.OK_STATUS;
        }
        monitor.worked(33);
        Runnable runnable = new Runnable() {

            @Override
            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() == Window.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(IStatus.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) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) WorkspaceReleaseDialog(bndtools.release.ui.WorkspaceReleaseDialog) Baseline(aQute.bnd.differ.Baseline) ProjectBuilder(aQute.bnd.build.ProjectBuilder)

Aggregations

ProjectBuilder (aQute.bnd.build.ProjectBuilder)2 Baseline (aQute.bnd.differ.Baseline)2 Builder (aQute.bnd.osgi.Builder)2 WorkspaceReleaseDialog (bndtools.release.ui.WorkspaceReleaseDialog)2 ArrayList (java.util.ArrayList)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Project (aQute.bnd.build.Project)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1