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