Build target in IntelliJ.
Summary: Build specified target by running `buck build [target]`.
diff --git a/plugin/src/com/facebook/buck/plugin/intellij/BuckPluginComponent.java b/plugin/src/com/facebook/buck/plugin/intellij/BuckPluginComponent.java
index 5d383a6..afc1217 100644
--- a/plugin/src/com/facebook/buck/plugin/intellij/BuckPluginComponent.java
+++ b/plugin/src/com/facebook/buck/plugin/intellij/BuckPluginComponent.java
@@ -17,6 +17,7 @@
package com.facebook.buck.plugin.intellij;
import com.facebook.buck.plugin.intellij.commands.BuckRunner;
+import com.facebook.buck.plugin.intellij.commands.BuildCommand;
import com.facebook.buck.plugin.intellij.commands.CleanCommand;
import com.facebook.buck.plugin.intellij.commands.SocketClient.BuckPluginEventListener;
import com.facebook.buck.plugin.intellij.commands.TargetsCommand;
@@ -75,44 +76,73 @@
}
}
- private boolean checkBuckRunner() {
+ private BuckRunner getBuckRunner() throws NoBuckRunnerException {
if (buckRunner.isPresent()) {
- return true;
+ return buckRunner.get();
}
+ throw new NoBuckRunnerException();
+ }
+
+ private void reportBuckNotPresent() {
// TODO(user) Show error message to UI
- return false;
}
public void refreshTargetsList() {
- if (!checkBuckRunner()) {
- return;
+ try {
+ final BuckRunner buckRunner = getBuckRunner();
+ Task.Backgroundable task = new Task.Backgroundable(project,
+ "Retrieving targets",
+ true, /* canBeCanceled */
+ BackgroundFromStartOption.getInstance()) {
+ public void run(ProgressIndicator progressIndicator) {
+ ImmutableList<BuckTarget> targets = TargetsCommand.getTargets(buckRunner);
+ // TODO(user) Refresh UI to show targets
+ }
+ };
+ task.queue();
+ } catch (NoBuckRunnerException e) {
+ reportBuckNotPresent();
}
- Task.Backgroundable task = new Task.Backgroundable(project,
- "Retrieving targets",
- true, /* canBeCanceled */
- BackgroundFromStartOption.getInstance()) {
- public void run(ProgressIndicator progressIndicator) {
- ImmutableList<BuckTarget> targets = TargetsCommand.getTargets(buckRunner.get());
- // TODO(user) Refresh UI to show targets
- }
- };
- task.queue();
}
public void clean() {
- if (!checkBuckRunner()) {
- return;
+ try {
+ final BuckRunner buckRunner = getBuckRunner();
+ Task.Backgroundable task = new Task.Backgroundable(project,
+ "Cleaning",
+ true, /* canBeCanceled */
+ BackgroundFromStartOption.getInstance()) {
+ public void run(ProgressIndicator progressIndicator) {
+ CleanCommand.clean(buckRunner);
+ // TODO(user) Clear built targets on UI
+ }
+ };
+ task.queue();
+ } catch (NoBuckRunnerException e) {
+ reportBuckNotPresent();
}
- Task.Backgroundable task = new Task.Backgroundable(project,
- "Cleaning",
- true, /* canBeCanceled */
- BackgroundFromStartOption.getInstance()) {
- public void run(ProgressIndicator progressIndicator) {
- CleanCommand.clean(buckRunner.get());
- // TODO(user) Clear built targets on UI
- }
- };
- task.queue();
+ }
+
+ /**
+ * Build a specified target in a background thread, showing a indicator in status bar.
+ * @param target Specified target to build
+ */
+ public void buildTarget(final BuckTarget target) {
+ try {
+ final BuckRunner buckRunner = getBuckRunner();
+ Task.Backgroundable task = new Task.Backgroundable(project,
+ "Building",
+ true, /* canBeCanceled */
+ BackgroundFromStartOption.getInstance()) {
+ public void run(ProgressIndicator progressIndicator) {
+ // TODO (carbokuo) Update UI
+ BuildCommand.build(buckRunner, target);
+ }
+ };
+ task.queue();
+ } catch (NoBuckRunnerException e) {
+ reportBuckNotPresent();
+ }
}
private class EventListener implements BuckPluginEventListener {
@@ -121,4 +151,7 @@
public void onEvent(Event event) {
}
}
+
+ private class NoBuckRunnerException extends Exception {
+ }
}
diff --git a/plugin/src/com/facebook/buck/plugin/intellij/commands/BuildCommand.java b/plugin/src/com/facebook/buck/plugin/intellij/commands/BuildCommand.java
new file mode 100644
index 0000000..755d42a
--- /dev/null
+++ b/plugin/src/com/facebook/buck/plugin/intellij/commands/BuildCommand.java
@@ -0,0 +1,19 @@
+package com.facebook.buck.plugin.intellij.commands;
+
+import com.facebook.buck.plugin.intellij.BuckTarget;
+import com.intellij.openapi.diagnostic.Logger;
+
+public class BuildCommand {
+
+ private static final Logger LOG = Logger.getInstance(BuildCommand.class);
+
+ private BuildCommand() {}
+
+ public static void build(BuckRunner buckRunner, BuckTarget target) {
+ int exitCode = buckRunner.execute("build", target.getName());
+ if (exitCode != 0) {
+ LOG.error(buckRunner.getStderr());
+ return;
+ }
+ }
+}