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();
}
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();
}
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;
}
Aggregations