Search in sources :

Example 1 with IDocument

use of aQute.bnd.properties.IDocument in project bndtools by bndtools.

the class BndSourceEditorPage method refresh.

void refresh() {
    IDocument document = getDocument();
    editModel.saveChangesTo(document);
}
Also used : IDocument(aQute.bnd.properties.IDocument)

Example 2 with IDocument

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction.writeCommandAction(com.intellij.openapi.command.WriteCommandAction.writeCommandAction) Constants(aQute.bnd.osgi.Constants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) Workspace(aQute.bnd.build.Workspace) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) BndEditModel(aQute.bnd.build.model.BndEditModel) OsmorcBundle(org.osmorc.i18n.OsmorcBundle) ProjectResolver(biz.aQute.resolve.ProjectResolver) FileModificationService(com.intellij.codeInsight.FileModificationService) Resource(org.osgi.resource.Resource) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Run(aQute.bnd.build.Run) Collectors(java.util.stream.Collectors) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) BndFileType(org.jetbrains.osgi.bnd.BndFileType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IDocument(aQute.bnd.properties.IDocument) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Wire(org.osgi.resource.Wire) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ResolutionException(org.osgi.service.resolver.ResolutionException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ProjectResolver(biz.aQute.resolve.ProjectResolver) Attrs(aQute.bnd.header.Attrs) Document(com.intellij.openapi.editor.Document) IDocument(aQute.bnd.properties.IDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IDocument(aQute.bnd.properties.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 3 with IDocument

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);
    }
}
Also used : IOException(java.io.IOException) IDocument(aQute.bnd.properties.IDocument)

Aggregations

IDocument (aQute.bnd.properties.IDocument)3 Run (aQute.bnd.build.Run)1 Workspace (aQute.bnd.build.Workspace)1 BndEditModel (aQute.bnd.build.model.BndEditModel)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 Attrs (aQute.bnd.header.Attrs)1 Constants (aQute.bnd.osgi.Constants)1 ProjectResolver (biz.aQute.resolve.ProjectResolver)1 FileModificationService (com.intellij.codeInsight.FileModificationService)1 NotificationType (com.intellij.notification.NotificationType)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 WriteCommandAction.writeCommandAction (com.intellij.openapi.command.WriteCommandAction.writeCommandAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1