OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.debug.ui.launch; | 14 package com.google.dart.tools.debug.ui.launch; |
15 | 15 |
16 import com.google.dart.tools.core.DartCore; | 16 import com.google.dart.tools.core.DartCore; |
17 import com.google.dart.tools.core.MessageConsole; | 17 import com.google.dart.tools.core.analysis.model.PubFolder; |
18 import com.google.dart.tools.core.dart2js.ProcessRunner; | 18 import com.google.dart.tools.core.pub.RunPubJob; |
19 import com.google.dart.tools.core.model.DartSdkManager; | |
20 | 19 |
21 import org.eclipse.core.commands.AbstractHandler; | 20 import org.eclipse.core.commands.AbstractHandler; |
22 import org.eclipse.core.commands.ExecutionEvent; | 21 import org.eclipse.core.commands.ExecutionEvent; |
23 import org.eclipse.core.commands.ExecutionException; | 22 import org.eclipse.core.commands.ExecutionException; |
24 import org.eclipse.core.resources.IContainer; | |
25 import org.eclipse.core.resources.IResource; | 23 import org.eclipse.core.resources.IResource; |
26 import org.eclipse.core.runtime.CoreException; | |
27 import org.eclipse.core.runtime.NullProgressMonitor; | |
28 import org.eclipse.jface.viewers.ISelection; | 24 import org.eclipse.jface.viewers.ISelection; |
29 import org.eclipse.jface.viewers.IStructuredSelection; | 25 import org.eclipse.jface.viewers.IStructuredSelection; |
30 import org.eclipse.ui.handlers.HandlerUtil; | 26 import org.eclipse.ui.handlers.HandlerUtil; |
31 | 27 |
32 import java.io.File; | |
33 import java.io.IOException; | |
34 import java.util.ArrayList; | |
35 import java.util.List; | |
36 | |
37 /** | 28 /** |
38 * Run the build.dart with deploy option which compiles the Polymer app to JavaS
cript. | 29 * Run the build.dart with deploy option which compiles the Polymer app to JavaS
cript. |
39 */ | 30 */ |
40 public class DeployPolymerAppHandler extends AbstractHandler { | 31 public class DeployPolymerAppHandler extends AbstractHandler { |
41 | 32 |
42 public DeployPolymerAppHandler() { | 33 public DeployPolymerAppHandler() { |
43 | 34 |
44 } | 35 } |
45 | 36 |
46 @Override | 37 @Override |
47 public Object execute(ExecutionEvent event) throws ExecutionException { | 38 public Object execute(ExecutionEvent event) throws ExecutionException { |
48 ISelection selection = HandlerUtil.getActivePart(event).getSite().getSelecti
onProvider().getSelection(); | 39 ISelection selection = HandlerUtil.getActivePart(event).getSite().getSelecti
onProvider().getSelection(); |
49 if (!selection.isEmpty()) { | 40 if (!selection.isEmpty()) { |
50 if (selection instanceof IStructuredSelection) { | 41 if (selection instanceof IStructuredSelection) { |
51 Object selectedObject = ((IStructuredSelection) selection).getFirstEleme
nt(); | 42 Object selectedObject = ((IStructuredSelection) selection).getFirstEleme
nt(); |
52 if (selectedObject instanceof IResource) { | 43 if (selectedObject instanceof IResource) { |
53 IContainer parent = ((IResource) selectedObject).getParent(); | 44 PubFolder folder = DartCore.getProjectManager().getPubFolder((IResourc
e) selectedObject); |
54 while (parent != null) { | 45 if (folder != null) { |
55 IResource buildFile = parent.findMember("build.dart"); | 46 RunPubJob job = new RunPubJob(folder.getResource(), RunPubJob.BUILD_
NOMINIFY_COMMAND); |
56 if (buildFile != null) { | 47 job.schedule(0); |
57 runBuildFile(buildFile); | 48 return null; |
58 return null; | |
59 } | |
60 parent = parent.getParent(); | |
61 } | 49 } |
62 DartCore.getConsole().println( | 50 DartCore.getConsole().println( |
63 "Error: Could not find build.dart file for " + ((IResource) select
edObject).getName()); | 51 "Error: Could not run pub build. Use Run Tools > Pub Build to buil
d Polymer app"); |
64 } | 52 } |
65 } | 53 } |
66 } | 54 } |
67 return null; | 55 return null; |
68 } | 56 } |
69 | |
70 private void runBuildFile(IResource buildFile) { | |
71 | |
72 MessageConsole console = DartCore.getConsole(); | |
73 | |
74 ProcessBuilder builder = new ProcessBuilder(); | |
75 builder.redirectErrorStream(true); | |
76 List<String> args = new ArrayList<String>(); | |
77 | |
78 String vmExecPath = ""; | |
79 if (DartSdkManager.getManager().hasSdk()) { | |
80 File vmExec = DartSdkManager.getManager().getSdk().getVmExecutable(); | |
81 | |
82 if (vmExec != null) { | |
83 vmExecPath = vmExec.getAbsolutePath().toString(); | |
84 } | |
85 } | |
86 | |
87 if (vmExecPath.length() == 0) { | |
88 String message = "Could not find the Dart VM executable"; | |
89 console.print(message); | |
90 DartCore.logError("Deploy Polymer app - " + message); | |
91 } | |
92 | |
93 args.add(vmExecPath); | |
94 args.add(buildFile.getLocation().toFile().getAbsolutePath()); | |
95 args.add("--deploy"); | |
96 | |
97 builder.command(args); | |
98 builder.directory(buildFile.getParent().getLocation().toFile()); | |
99 | |
100 ProcessRunner runner = new ProcessRunner(builder); | |
101 | |
102 try { | |
103 runner.runSync(new NullProgressMonitor()); | |
104 } catch (IOException e) { | |
105 String message = "Failed to run " + buildFile.getLocation().toString() + e
.toString(); | |
106 console.print(message); | |
107 DartCore.logError(message, e); | |
108 } | |
109 | |
110 StringBuilder stringBuilder = new StringBuilder(); | |
111 | |
112 if (!runner.getStdOut().isEmpty()) { | |
113 stringBuilder.append(runner.getStdOut().trim() + "\n"); //$NON-NLS-1$ | |
114 } | |
115 | |
116 console.printSeparator("build.dart --deploy"); | |
117 console.print(stringBuilder.toString()); | |
118 try { | |
119 buildFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); | |
120 } catch (CoreException e) { | |
121 // do nothing | |
122 } | |
123 } | |
124 | |
125 } | 57 } |
OLD | NEW |