Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/Stagehand.java

Issue 658743004: Move the Editor and Eclipse plugins over to using stagehand for the new project templates. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/Stagehand.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/Stagehand.java (revision 0)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/Stagehand.java (working copy)
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2014, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.dart.tools.core.generator;
+
+import com.google.dart.tools.core.DartCore;
+import com.google.dart.tools.core.dart2js.ProcessRunner;
+import com.google.dart.tools.core.model.DartSdkManager;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A wrapper around the Stagehand CLI tool.
+ */
+public class Stagehand {
+ public static class StagehandTuple {
+ public String id;
+ public String description;
+ public String entrypoint;
+
+ public StagehandTuple(String id, String description) {
+ this.id = id;
+ this.description = description;
+ }
+
+ public StagehandTuple(String id, String description, String entrypoint) {
+ this.id = id;
+ this.description = description;
+ this.entrypoint = entrypoint;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + id + "," + description + "]";
+ }
+ }
+
+ private static final List<StagehandTuple> EMPTY = new ArrayList<Stagehand.StagehandTuple>();
+
+ public Stagehand() {
+
+ }
+
+ /**
+ * Generate the given sample id into the given directory. Return the main (launchable) file, if
+ * any.
+ */
+ public void generateInto(File projectDirectory, String sampleId) throws StagehandException {
+ // pub global run stagehand sample
+ ProcessRunner runner = createPubRunner(
+ new String[] {"global", "run", "stagehand", sampleId},
+ projectDirectory);
+
+ try {
+ int retValue = runner.runSync(null);
+
+ if (retValue != 0) {
+ throw new StagehandException(runner.getStdErr());
+ }
+ } catch (IOException e) {
+ throw new StagehandException(e);
+ }
+ }
+
+ public List<StagehandTuple> getAvailableSamples() {
+ // pub global run stagehand --machine
+ ProcessRunner runner = createPubRunner(new String[] {"global", "run", "stagehand", "--machine"});
+
+ try {
+ int exitCode = runner.runSync(null);
+
+ if (exitCode != 0) {
+ return EMPTY;
+ }
+
+ // [{"name":"consoleapp","description":"A minimal command-line application."},{"name",...
+ JSONArray arr = new JSONArray(runner.getStdOut());
+ List<StagehandTuple> result = new ArrayList<Stagehand.StagehandTuple>();
+
+ for (int i = 0; i < arr.length(); i++) {
+ JSONObject obj = arr.getJSONObject(i);
+
+ result.add(new StagehandTuple(
+ obj.getString("name"),
+ obj.getString("description"),
+ obj.optString("entrypoint")));
+ }
+
+ return result;
+ } catch (IOException e) {
+ DartCore.logError(e);
+ return EMPTY;
+ } catch (JSONException e) {
+ DartCore.logError(e);
+ return EMPTY;
+ }
+ }
+
+ public void install() {
+ // pub global activate stagehand
+ DartSdkManager.getManager().getSdk().getVmExecutable().getPath();
+ ProcessRunner runner = createPubRunner(new String[] {"global", "activate", "stagehand"});
+
+ try {
+ runner.runSync(null);
+ } catch (IOException e) {
+
+ }
+ }
+
+ public boolean isInstalled() {
+ // pub global list
+ ProcessRunner runner = createPubRunner(new String[] {"global", "list"});
+
+ try {
+ int exitCode = runner.runSync(null);
+
+ if (exitCode != 0) {
+ return false;
+ }
+
+ String[] lines = runner.getStdOut().split("\n");
+
+ for (String line : lines) {
+ if (line.startsWith("stagehand ")) {
+ return true;
+ }
+ }
+
+ return false;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ public void upgrade() {
+ // pub global activate stagehand
+ install();
+ }
+
+ private ProcessRunner createPubRunner(String[] args) {
+ return createPubRunner(args, null);
+ }
+
+ private ProcessRunner createPubRunner(String[] args, File cwd) {
+ String vmPath = DartSdkManager.getManager().getSdk().getPubExecutable().getPath();
+ List<String> list = new ArrayList<String>();
+ list.add(vmPath);
+ for (String str : args) {
+ list.add(str);
+ }
+ ProcessBuilder builder = new ProcessBuilder(list);
+ if (cwd != null) {
+ builder.directory(cwd);
+ }
+ return new ProcessRunner(builder);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698