Search in sources :

Example 1 with Project

use of com.intellij.openapi.project.Project in project buck by facebook.

the class BuckClientTest method hasBuckDisconnectedThenWeReconnectIfSoSpecified.

@Test
public void hasBuckDisconnectedThenWeReconnectIfSoSpecified() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    Project project = new MockProjectEx(new MockDisposable());
    TestBuckEventHandler handler = new TestBuckEventHandler();
    BuckSocket buckSocket = new BuckSocket(handler);
    BuckClientManager.getOrCreateClient(project, handler).setBuckSocket(buckSocket);
    BuckClientManager.getOrCreateClient(project, handler).connect();
    buckSocket.onConnect(new MockSession());
    BuckClientManager.getOrCreateClient(project, handler).disconnectWithRetry();
    buckSocket.onClose(0, "FOO");
    buckSocket.onConnect(new MockSession());
    assertTrue(BuckClientManager.getOrCreateClient(project, handler).isConnected());
}
Also used : Project(com.intellij.openapi.project.Project) MockApplicationEx(com.intellij.mock.MockApplicationEx) MockSession(com.facebook.buck.intellij.ideabuck.test.util.MockSession) MockApplication(com.intellij.mock.MockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) MockProjectEx(com.intellij.mock.MockProjectEx) Test(org.junit.Test)

Example 2 with Project

use of com.intellij.openapi.project.Project in project buck by facebook.

the class BuckClientTest method testMessages.

@Test
public void testMessages() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    Project project = new MockProjectEx(new MockDisposable());
    TestBuckEventHandler handler = new TestBuckEventHandler();
    BuckClient client = BuckClientManager.getOrCreateClient(project, handler);
    // Set the socket we control
    BuckSocket socket = new BuckSocket(handler);
    client.setBuckSocket(socket);
    client.connect();
    assertEquals("", handler.getLastMessage());
    socket.onMessage("some text");
    assertEquals("some text", handler.getLastMessage());
    socket.onMessage("some text 1");
    socket.onMessage("some text 2");
    socket.onMessage("some text 3");
    socket.onMessage("some text 4");
    assertEquals("some text 4", handler.getLastMessage());
}
Also used : Project(com.intellij.openapi.project.Project) MockApplicationEx(com.intellij.mock.MockApplicationEx) MockApplication(com.intellij.mock.MockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) MockProjectEx(com.intellij.mock.MockProjectEx) Test(org.junit.Test)

Example 3 with Project

use of com.intellij.openapi.project.Project in project buck by facebook.

the class BuckAnnotator method annotateErrors.

private void annotateErrors(PsiElement psiElement, AnnotationHolder annotationHolder) {
    BuckValue value = PsiTreeUtil.getParentOfType(psiElement, BuckValue.class);
    if (value == null) {
        return;
    }
    final Project project = psiElement.getProject();
    if (project == null) {
        return;
    }
    String target = psiElement.getText();
    if (target.matches("\".*\"") || target.matches("'.*'")) {
        target = target.substring(1, target.length() - 1);
    } else {
        return;
    }
    if (!BuckBuildUtil.isValidAbsoluteTarget(target)) {
        return;
    }
    VirtualFile buckDir = project.getBaseDir().findFileByRelativePath(BuckBuildUtil.extractAbsoluteTarget(target));
    VirtualFile targetBuckFile = buckDir != null ? buckDir.findChild("BUCK") : null;
    if (targetBuckFile == null) {
        TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset());
        annotationHolder.createErrorAnnotation(range, ANNOTATOR_ERROR_CANNOT_LOCATE_TARGET);
        project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuckValue(com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue) Project(com.intellij.openapi.project.Project) TextRange(com.intellij.openapi.util.TextRange)

Example 4 with Project

use of com.intellij.openapi.project.Project in project buck by facebook.

the class BuckBuildManager method showNoTargetMessage.

/**
   * Print "no selected target" error message to console window.
   * Also provide a hyperlink which can directly jump to "Choose Target" GUI window.
   */
public void showNoTargetMessage(Project project) {
    BuckModule buckModule = project.getComponent(BuckModule.class);
    buckModule.getBuckEventsConsumer().consumeConsoleEvent("Please choose a build target!");
    BuckToolWindowFactory.outputConsoleMessage(project, "Please ", ConsoleViewContentType.ERROR_OUTPUT);
    BuckToolWindowFactory.outputConsoleHyperlink(project, "choose a build target!\n", new HyperlinkInfo() {

        @Override
        public void navigate(Project project) {
            JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
            AnAction action = ActionManager.getInstance().getAction("buck.ChooseTarget");
            action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) JComponent(javax.swing.JComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 5 with Project

use of com.intellij.openapi.project.Project in project buck by facebook.

the class BuckBuildManager method runBuckCommand.

/**
   * Execute simple process asynchronously with progress.
   *
   * @param handler        a handler
   * @param operationTitle an operation title shown in progress dialog
   */
public synchronized void runBuckCommand(final BuckCommandHandler handler, final String operationTitle) {
    if (!(handler instanceof BuckKillCommandHandler)) {
        currentRunningBuckCommandHandler = handler;
        // Save files for anything besides buck kill
        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

            @Override
            public void run() {
                FileDocumentManager.getInstance().saveAllDocuments();
            }
        }, ModalityState.NON_MODAL);
    }
    Project project = handler.project();
    String exec = BuckSettingsProvider.getInstance().getState().buckExecutable;
    if (exec == null) {
        BuckToolWindowFactory.outputConsoleMessage(project, "Please specify the buck executable path!\n", ConsoleViewContentType.ERROR_OUTPUT);
        BuckToolWindowFactory.outputConsoleMessage(project, "Preference -> Tools -> Buck -> Path to Buck executable\n", ConsoleViewContentType.NORMAL_OUTPUT);
        return;
    }
    final ProgressManager manager = ProgressManager.getInstance();
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            manager.run(new Task.Backgroundable(handler.project(), operationTitle, true) {

                public void run(final ProgressIndicator indicator) {
                    runInCurrentThread(handler, indicator, true, operationTitle);
                }
            });
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90