Search in sources :

Example 1 with ResolutionResult

use of org.bndtools.core.resolve.ResolutionResult in project bndtools by bndtools.

the class ResolutionResultsWizardPage method setResult.

public void setResult(ResolutionResult result) {
    ResolutionResult oldValue = this.result;
    this.result = result;
    propertySupport.firePropertyChange(PROP_RESULT, oldValue, result);
    if (getControl() != null && !getControl().isDisposed())
        updateUi();
}
Also used : ResolutionResult(org.bndtools.core.resolve.ResolutionResult)

Example 2 with ResolutionResult

use of org.bndtools.core.resolve.ResolutionResult in project bndtools by bndtools.

the class BndEditor method doAutoResolveOnSave.

private void doAutoResolveOnSave(IProgressMonitor monitor) {
    final Shell shell = getEditorSite().getShell();
    final IFile file = ResourceUtil.getFile(getEditorInput());
    if (file == null) {
        MessageDialog.openError(shell, "Resolution Error", "Unable to run resolution because the file is not in the workspace. NB.: the file will still be saved.");
        reallySave(monitor);
        return;
    }
    // Create resolver job and pre-validate
    final ResolveJob job = new ResolveJob(model);
    IStatus validation = job.validateBeforeRun();
    if (!validation.isOK()) {
        String message = "Unable to run the resolver. NB.: the file will still be saved.";
        ErrorDialog.openError(shell, "Resolution Validation Problem", message, validation, IStatus.ERROR | IStatus.WARNING);
        reallySave(monitor);
        return;
    }
    // Add operation to perform at the end of resolution (i.e. display
    // results and actually save the file)
    final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            ResolutionResult result = job.getResolutionResult();
            ResolutionWizard wizard = new ResolutionWizard(model, file, result);
            if (result.getOutcome() != ResolutionResult.Outcome.Resolved) /*|| !result.getResolve().getOptionalResources().isEmpty() */
            {
                WizardDialog dialog = new WizardDialog(shell, wizard);
                if (dialog.open() != Window.OK) {
                    if (!wizard.performFinish()) {
                        MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                    }
                }
            } else {
                if (!wizard.performFinish()) {
                    MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
                }
            }
            reallySave(monitor);
            return Status.OK_STATUS;
        }
    };
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            completionJob.schedule();
        }
    });
    // Start job
    job.setUser(true);
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with ResolutionResult

use of org.bndtools.core.resolve.ResolutionResult in project bndtools by bndtools.

the class ResolutionWizard method performFinish.

@Override
public boolean performFinish() {
    Collection<Resource> resources;
    ResolutionResult result = resultsPage.getResult();
    if (result != null && result.getOutcome() == ResolutionResult.Outcome.Resolved)
        resources = result.getResourceWirings().keySet();
    else
        resources = Collections.emptyList();
    // Open stream for physical paths list in target dir
    PrintStream pathsStream = null;
    try {
        File targetDir;
        Project bndProject = model.getProject();
        targetDir = bndProject.getTargetDir();
        if (targetDir == null)
            targetDir = file.getLocation().toFile().getParentFile();
        if (!targetDir.exists() && !targetDir.mkdirs()) {
            throw new IOException("Could not create target directory " + targetDir);
        }
        File pathsFile = new File(targetDir, file.getName() + RESOLVED_PATHS_EXTENSION);
        pathsStream = new PrintStream(pathsFile, "UTF-8");
    } catch (Exception e) {
        logger.logError("Unable to write resolved path list in target directory for project " + file.getProject().getName(), e);
    }
    // Generate -runbundles and path list
    try {
        List<VersionedClause> runBundles = new ArrayList<VersionedClause>(resources.size());
        for (Resource resource : resources) {
            VersionedClause runBundle = resourceToRunBundle(resource);
            //[cs] Skip dups
            if (runBundles.contains(runBundle)) {
                continue;
            }
            runBundles.add(runBundle);
            if (pathsStream != null) {
                VersionedClause runBundleWithUri = runBundle.clone();
                URI uri = ResourceUtils.getURI(ResourceUtils.getContentCapability(resource));
                runBundleWithUri.getAttribs().put(BndConstants.RESOLUTION_URI_ATTRIBUTE, uri.toString());
                StringBuilder builder = new StringBuilder();
                runBundleWithUri.formatTo(builder, clauseAttributeSorter);
                pathsStream.println(builder.toString());
            }
        }
        Collections.sort(runBundles, new Comparator<VersionedClause>() {

            @Override
            public int compare(VersionedClause vc1, VersionedClause vc2) {
                int diff = vc1.getName().compareTo(vc2.getName());
                if (diff != 0)
                    return diff;
                String r1 = vc1.getVersionRange();
                if (r1 == null)
                    r1 = "";
                String r2 = vc2.getVersionRange();
                if (r2 == null)
                    r2 = "";
                return r1.compareTo(r2);
            }
        });
        // Do not change the order of existing runbundles because they migh have been ordered manually
        List<VersionedClause> diffAddBundles = new ArrayList<>(runBundles);
        List<VersionedClause> oldRunBundles = model.getRunBundles();
        if (oldRunBundles == null)
            oldRunBundles = Collections.emptyList();
        else
            diffAddBundles.removeAll(oldRunBundles);
        List<VersionedClause> diffRemvedBundles = new ArrayList<>(oldRunBundles);
        diffRemvedBundles.removeAll(runBundles);
        List<VersionedClause> updatedRunBundles = new ArrayList<>(oldRunBundles);
        updatedRunBundles.addAll(diffAddBundles);
        updatedRunBundles.removeAll(diffRemvedBundles);
        // do not use getRunBundles().addAll, because it will not reflect in UI or File
        model.setRunBundles(updatedRunBundles);
    } finally {
        if (pathsStream != null) {
            IO.close(pathsStream);
        }
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) Project(aQute.bnd.build.Project) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

ResolutionResult (org.bndtools.core.resolve.ResolutionResult)3 IFile (org.eclipse.core.resources.IFile)2 Project (aQute.bnd.build.Project)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ResolveJob (org.bndtools.core.resolve.ResolveJob)1 ResolutionWizard (org.bndtools.core.resolve.ui.ResolutionWizard)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 UIJob (org.eclipse.ui.progress.UIJob)1 Resource (org.osgi.resource.Resource)1