use of aQute.bnd.properties.IDocument in project bndtools by bndtools.
the class BndSourceEditorPage method refresh.
void refresh() {
IDocument document = getDocument();
editModel.saveChangesTo(document);
}
use of aQute.bnd.properties.IDocument in project intellij-plugins by JetBrains.
the class ResolveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
Project project = event.getProject();
if (virtualFile == null || project == null)
return;
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {
private Map<Resource, List<Wire>> resolveResult;
private String updatedText;
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
File file = new File(virtualFile.getPath());
try (Workspace workspace = Workspace.findWorkspace(file);
Run run = Run.createRun(workspace, file);
ProjectResolver projectResolver = new ProjectResolver(run)) {
resolveResult = projectResolver.resolve();
List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
return new VersionedClause(c.getBundleSymbolicName(), attrs);
}).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
BndEditModel editModel = new BndEditModel();
IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
editModel.loadFrom(bndDocument);
editModel.setRunBundles(versionedClauses);
editModel.saveChangesTo(bndDocument);
updatedText = bndDocument.get();
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
throw new WrappingException(e);
}
indicator.checkCanceled();
}
@Override
public void onSuccess() {
if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
}
}
@Override
public void onThrowable(@NotNull Throwable t) {
Throwable cause = t instanceof WrappingException ? t.getCause() : t;
LOG.warn("Resolution failed", cause);
if (cause instanceof ResolutionException) {
new ResolutionFailedDialog(project, (ResolutionException) cause).show();
} else {
OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
}
}
}.queue();
}
use of aQute.bnd.properties.IDocument in project bndtools by bndtools.
the class BndSourceEditorPage method commit.
void commit(@SuppressWarnings("unused") boolean onSave) {
try {
// Only commit changes to the model if the document text has
// actually changed since we switched to the page; this prevents us
// losing selection in the Components and Imports tabs.
// We can't use the dirty flag for this because "undo" will clear
// the dirty flag.
IDocument doc = getDocument();
String currentContent = doc.get();
if (!currentContent.equals(lastLoaded))
editModel.loadFrom(getDocument());
} catch (IOException e) {
logger.logError("Error loading model from document.", e);
}
}
Aggregations