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

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/DartCore.java

Issue 334853002: merge cl for mobile support fixes and features in editor (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.core; 14 package com.google.dart.tools.core;
15 15
16 import com.google.dart.engine.AnalysisEngine; 16 import com.google.dart.engine.AnalysisEngine;
17 import com.google.dart.engine.error.ErrorCode; 17 import com.google.dart.engine.error.ErrorCode;
18 import com.google.dart.engine.index.Index; 18 import com.google.dart.engine.index.Index;
19 import com.google.dart.engine.index.IndexFactory; 19 import com.google.dart.engine.index.IndexFactory;
20 import com.google.dart.engine.index.MemoryIndexStore; 20 import com.google.dart.engine.index.IndexStore;
21 import com.google.dart.engine.sdk.DirectoryBasedDartSdk; 21 import com.google.dart.engine.sdk.DirectoryBasedDartSdk;
22 import com.google.dart.engine.utilities.instrumentation.Instrumentation; 22 import com.google.dart.engine.utilities.instrumentation.Instrumentation;
23 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; 23 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder;
24 import com.google.dart.engine.utilities.logging.Logger; 24 import com.google.dart.engine.utilities.logging.Logger;
25 import com.google.dart.server.AnalysisServer; 25 import com.google.dart.server.AnalysisServer;
26 import com.google.dart.server.internal.remote.StdioServerSocket; 26 import com.google.dart.server.internal.remote.StdioServerSocket;
27 import com.google.dart.tools.core.analysis.model.AnalysisServerData; 27 import com.google.dart.tools.core.analysis.model.AnalysisServerData;
28 import com.google.dart.tools.core.analysis.model.ProjectManager; 28 import com.google.dart.tools.core.analysis.model.ProjectManager;
29 import com.google.dart.tools.core.analysis.model.PubFolder; 29 import com.google.dart.tools.core.analysis.model.PubFolder;
30 import com.google.dart.tools.core.internal.MessageConsoleImpl; 30 import com.google.dart.tools.core.internal.MessageConsoleImpl;
(...skipping 14 matching lines...) Expand all
45 import com.google.dart.tools.core.model.DartModel; 45 import com.google.dart.tools.core.model.DartModel;
46 import com.google.dart.tools.core.model.DartModelException; 46 import com.google.dart.tools.core.model.DartModelException;
47 import com.google.dart.tools.core.model.DartProject; 47 import com.google.dart.tools.core.model.DartProject;
48 import com.google.dart.tools.core.model.DartSdkListener; 48 import com.google.dart.tools.core.model.DartSdkListener;
49 import com.google.dart.tools.core.model.DartSdkManager; 49 import com.google.dart.tools.core.model.DartSdkManager;
50 import com.google.dart.tools.core.utilities.general.StringUtilities; 50 import com.google.dart.tools.core.utilities.general.StringUtilities;
51 import com.google.dart.tools.core.utilities.io.FileUtilities; 51 import com.google.dart.tools.core.utilities.io.FileUtilities;
52 import com.google.dart.tools.core.utilities.performance.PerformanceManager; 52 import com.google.dart.tools.core.utilities.performance.PerformanceManager;
53 import com.google.dart.tools.core.utilities.yaml.PubYamlUtils; 53 import com.google.dart.tools.core.utilities.yaml.PubYamlUtils;
54 54
55 import org.apache.commons.lang3.StringUtils;
55 import org.eclipse.core.resources.IContainer; 56 import org.eclipse.core.resources.IContainer;
56 import org.eclipse.core.resources.IFile; 57 import org.eclipse.core.resources.IFile;
57 import org.eclipse.core.resources.IFolder; 58 import org.eclipse.core.resources.IFolder;
58 import org.eclipse.core.resources.IMarker; 59 import org.eclipse.core.resources.IMarker;
59 import org.eclipse.core.resources.IProject; 60 import org.eclipse.core.resources.IProject;
60 import org.eclipse.core.resources.IResource; 61 import org.eclipse.core.resources.IResource;
61 import org.eclipse.core.resources.IResourceVisitor; 62 import org.eclipse.core.resources.IResourceVisitor;
62 import org.eclipse.core.resources.IWorkspaceRoot; 63 import org.eclipse.core.resources.IWorkspaceRoot;
63 import org.eclipse.core.resources.ProjectScope; 64 import org.eclipse.core.resources.ProjectScope;
64 import org.eclipse.core.resources.ResourcesPlugin; 65 import org.eclipse.core.resources.ResourcesPlugin;
(...skipping 13 matching lines...) Expand all
78 import org.eclipse.core.runtime.preferences.InstanceScope; 79 import org.eclipse.core.runtime.preferences.InstanceScope;
79 import org.osgi.framework.BundleContext; 80 import org.osgi.framework.BundleContext;
80 import org.osgi.framework.Version; 81 import org.osgi.framework.Version;
81 import org.osgi.service.prefs.BackingStoreException; 82 import org.osgi.service.prefs.BackingStoreException;
82 83
83 import java.io.File; 84 import java.io.File;
84 import java.io.FileNotFoundException; 85 import java.io.FileNotFoundException;
85 import java.io.FileReader; 86 import java.io.FileReader;
86 import java.io.FileWriter; 87 import java.io.FileWriter;
87 import java.io.IOException; 88 import java.io.IOException;
89 import java.io.PrintStream;
88 import java.io.PrintWriter; 90 import java.io.PrintWriter;
89 import java.io.StringWriter; 91 import java.io.StringWriter;
90 import java.lang.management.ManagementFactory; 92 import java.lang.management.ManagementFactory;
91 import java.text.SimpleDateFormat; 93 import java.text.SimpleDateFormat;
92 import java.util.ArrayList; 94 import java.util.ArrayList;
93 import java.util.Arrays; 95 import java.util.Arrays;
94 import java.util.Date; 96 import java.util.Date;
95 import java.util.HashMap; 97 import java.util.HashMap;
96 import java.util.HashSet; 98 import java.util.HashSet;
97 import java.util.Hashtable; 99 import java.util.Hashtable;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 * Eclipse problem marker type used to Angular warning markers 168 * Eclipse problem marker type used to Angular warning markers
167 */ 169 */
168 public static final String ANGULAR_WARNING_MARKER_TYPE = PLUGIN_ID + ".angular _warning"; 170 public static final String ANGULAR_WARNING_MARKER_TYPE = PLUGIN_ID + ".angular _warning";
169 171
170 /** 172 /**
171 * Extension for single unit compiled into JavaScript. 173 * Extension for single unit compiled into JavaScript.
172 */ 174 */
173 public static final String EXTENSION_JS = "js"; 175 public static final String EXTENSION_JS = "js";
174 176
175 /** 177 /**
178 * Preference for enabling Angular analysis.
179 */
180 public static final String ENABLE_ANGULAR_ANALYSIS_PREFERENCE = "enableAngular Analysis";
181
182 /**
176 * Preference for the automatically running pub. 183 * Preference for the automatically running pub.
177 */ 184 */
178 public static final String PUB_AUTO_RUN_PREFERENCE = "pubAutoRun"; 185 public static final String PUB_AUTO_RUN_PREFERENCE = "pubAutoRun";
179 186
180 /** 187 /**
181 * Preference for enabling hints. 188 * Preference for enabling hints.
182 */ 189 */
183 public static final String ENABLE_HINTS_PREFERENCE = "enableHints"; 190 public static final String ENABLE_HINTS_PREFERENCE = "enableHints";
184 191
185 /** 192 /**
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 * Name of special pubspec lock file 286 * Name of special pubspec lock file
280 */ 287 */
281 public static final String PUBSPEC_LOCK_FILE_NAME = "pubspec.lock"; 288 public static final String PUBSPEC_LOCK_FILE_NAME = "pubspec.lock";
282 289
283 /** 290 /**
284 * The name of the build.dart special file. 291 * The name of the build.dart special file.
285 */ 292 */
286 public static final String BUILD_DART_FILE_NAME = "build.dart"; 293 public static final String BUILD_DART_FILE_NAME = "build.dart";
287 294
288 /** 295 /**
296 * Used by the {@link DartDebugUserAgentManager} to indicate whether the
297 * allow remote connection dialog is open.
298 */
299 public static boolean allowConnectionDialogOpen = false;
300
301 /**
289 * The shared message console instance. 302 * The shared message console instance.
290 */ 303 */
291 private static final MessageConsole CONSOLE = new MessageConsoleImpl(); 304 private static final MessageConsole CONSOLE = new MessageConsoleImpl();
292 305
293 /** 306 /**
294 * The QualifiedName for a resource remapping (a.foo ==> a.bar). 307 * The QualifiedName for a resource remapping (a.foo ==> a.bar).
295 */ 308 */
296 private static final QualifiedName RESOURCE_REMAP_NAME = new QualifiedName( 309 private static final QualifiedName RESOURCE_REMAP_NAME = new QualifiedName(
297 PLUGIN_ID, 310 PLUGIN_ID,
298 "resourceRemap"); 311 "resourceRemap");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 */ 349 */
337 private static WorkspaceAnalysisServerListener analysisServerListener = new Wo rkspaceAnalysisServerListener( 350 private static WorkspaceAnalysisServerListener analysisServerListener = new Wo rkspaceAnalysisServerListener(
338 analysisServerDataImpl); 351 analysisServerDataImpl);
339 352
340 /** 353 /**
341 * Used to synchronize access to {@link #analysisServer}. 354 * Used to synchronize access to {@link #analysisServer}.
342 */ 355 */
343 private static final Object analysisServerLock = new Object(); 356 private static final Object analysisServerLock = new Object();
344 357
345 /** 358 /**
359 * The socket and process manager used by {@link #analysisServer}.
360 */
361 private static StdioServerSocket analysisServerSocket;
362
363 /**
346 * Add the given listener for dart ignore changes to the Dart Model. Has no ef fect if an identical 364 * Add the given listener for dart ignore changes to the Dart Model. Has no ef fect if an identical
347 * listener is already registered. 365 * listener is already registered.
348 * 366 *
349 * @param listener the listener to add 367 * @param listener the listener to add
350 */ 368 */
351 public static void addIgnoreListener(DartIgnoreListener listener) { 369 public static void addIgnoreListener(DartIgnoreListener listener) {
352 getProjectManager().getIgnoreManager().addListener(listener); 370 getProjectManager().getIgnoreManager().addListener(listener);
353 } 371 }
354 372
355 /** 373 /**
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 * Answer the unique {@link AnalysisServer} used for analysis of anything in t he workspace. 474 * Answer the unique {@link AnalysisServer} used for analysis of anything in t he workspace.
457 * 475 *
458 * @return the {@link AnalysisServer} (not {@code null}) 476 * @return the {@link AnalysisServer} (not {@code null})
459 */ 477 */
460 @SuppressWarnings("restriction") 478 @SuppressWarnings("restriction")
461 public static AnalysisServer getAnalysisServer() { 479 public static AnalysisServer getAnalysisServer() {
462 synchronized (analysisServerLock) { 480 synchronized (analysisServerLock) {
463 if (analysisServer == null) { 481 if (analysisServer == null) {
464 // TODO(scheglov) remove local analysis server 482 // TODO(scheglov) remove local analysis server
465 // analysisServer = new com.google.dart.server.internal.local.LocalAnalys isServerImpl(); 483 // analysisServer = new com.google.dart.server.internal.local.LocalAnalys isServerImpl();
466 File sdkDirectory = DirectoryBasedDartSdk.getDefaultSdkDirectory(); 484 DartSdkManager sdkManager = DartSdkManager.getManager();
467 if (sdkDirectory == null) { 485 if (!sdkManager.hasSdk()) {
468 DartCore.logError("Add the dart sdk (com.google.dart.sdk) as a JVM arg ument"); 486 DartCore.logError("Add the dart sdk (com.google.dart.sdk) as a JVM arg ument");
469 System.exit(1); 487 System.exit(1);
470 } 488 }
471 String svnRoot = System.getProperty("com.google.dart.svnRoot"); 489 String svnRoot = System.getProperty("com.google.dart.svnRoot");
472 if (svnRoot == null) { 490 if (svnRoot == null) {
473 DartCore.logError("Add the dart svnRoot (com.google.dart.svnRoot) as a JVM argument"); 491 DartCore.logError("Add the dart svnRoot (com.google.dart.svnRoot) as a JVM argument");
474 System.exit(1); 492 System.exit(1);
475 } 493 }
476 String runtimePath = sdkDirectory.getAbsolutePath() + "/bin/dart"; 494 String runtimePath = sdkManager.getSdk().getVmExecutable().getAbsolutePa th();
477 String analysisServerPath = svnRoot + "/pkg/analysis_server/bin/server.d art"; 495 String analysisServerPath = svnRoot + "/pkg/analysis_server/bin/server.d art";
478 try { 496 try {
479 StdioServerSocket socket = new StdioServerSocket(runtimePath, analysis ServerPath); 497 // prepare debug stream
480 socket.start(); 498 PrintStream debugStream;
499 {
500 String logPath = DartCoreDebug.ANALYSIS_SERVER_LOG_FILE;
501 if (StringUtils.isBlank(logPath)) {
502 debugStream = null;
503 } else if ("console".equals(logPath)) {
504 debugStream = System.out;
505 } else {
506 debugStream = new PrintStream(logPath);
507 }
508 }
509 // start server
510 analysisServerSocket = new StdioServerSocket(runtimePath, analysisServ erPath, debugStream);
511 analysisServerSocket.start();
481 analysisServer = new com.google.dart.server.internal.remote.RemoteAnal ysisServerImpl( 512 analysisServer = new com.google.dart.server.internal.remote.RemoteAnal ysisServerImpl(
482 socket.getRequestSink(), 513 analysisServerSocket.getRequestSink(),
483 socket.getResponseStream()); 514 analysisServerSocket.getResponseStream(),
515 analysisServerSocket.getErrorStream());
484 analysisServerDataImpl.setServer(analysisServer); 516 analysisServerDataImpl.setServer(analysisServer);
485 analysisServer.addAnalysisServerListener(analysisServerListener); 517 analysisServer.addAnalysisServerListener(analysisServerListener);
486 } catch (Throwable e) { 518 } catch (Throwable e) {
487 DartCore.logError("Enable to start stdio server", e); 519 DartCore.logError("Enable to start stdio server", e);
488 System.exit(1); 520 System.exit(1);
489 } 521 }
490 } 522 }
491 } 523 }
492 return analysisServer; 524 return analysisServer;
493 } 525 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 * Answer the unique project manager used for analysis of anything in the work space. 745 * Answer the unique project manager used for analysis of anything in the work space.
714 * 746 *
715 * @return the manager (not {@code null}) 747 * @return the manager (not {@code null})
716 */ 748 */
717 public static ProjectManager getProjectManager() { 749 public static ProjectManager getProjectManager() {
718 synchronized (projectManagerLock) { 750 synchronized (projectManagerLock) {
719 if (projectManager == null) { 751 if (projectManager == null) {
720 // start index 752 // start index
721 final Index index; 753 final Index index;
722 { 754 {
723 MemoryIndexStore indexStore = IndexFactory.newMemoryIndexStore(); 755 File stateDir = getPlugin().getStateLocation().toFile();
756 File indexDir = new File(stateDir, "index");
757 indexDir.mkdirs();
758 IndexStore indexStore = IndexFactory.newFileIndexStore(indexDir);
724 index = IndexFactory.newIndex(indexStore); 759 index = IndexFactory.newIndex(indexStore);
725 Thread thread = new Thread() { 760 Thread thread = new Thread() {
726 @Override 761 @Override
727 public void run() { 762 public void run() {
728 index.run(); 763 index.run();
729 } 764 }
730 }; 765 };
731 thread.setName("Index Thread"); 766 thread.setName("Index Thread");
732 thread.setDaemon(true); 767 thread.setDaemon(true);
733 thread.start(); 768 thread.start();
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 1650
1616 return prefs; 1651 return prefs;
1617 } 1652 }
1618 1653
1619 public IEclipsePreferences getProjectPreferences(IProject project) { 1654 public IEclipsePreferences getProjectPreferences(IProject project) {
1620 ProjectScope projectScope = new ProjectScope(project); 1655 ProjectScope projectScope = new ProjectScope(project);
1621 1656
1622 return projectScope.getNode(PLUGIN_ID); 1657 return projectScope.getNode(PLUGIN_ID);
1623 } 1658 }
1624 1659
1660 public boolean isAngularAnalysisEnabled() {
1661 return DartCore.getPlugin().getPrefs().getBoolean(ENABLE_ANGULAR_ANALYSIS_PR EFERENCE, true);
1662 }
1663
1625 public boolean isAutoRunPubEnabled() { 1664 public boolean isAutoRunPubEnabled() {
1626 return DartCore.getPlugin().getPrefs().getBoolean(PUB_AUTO_RUN_PREFERENCE, t rue); 1665 return DartCore.getPlugin().getPrefs().getBoolean(PUB_AUTO_RUN_PREFERENCE, t rue);
1627 } 1666 }
1628 1667
1629 public boolean isHintsDart2JSEnabled() { 1668 public boolean isHintsDart2JSEnabled() {
1630 return DartCore.getPlugin().getPrefs().getBoolean(ENABLE_HINTS_DART2JS_PREFE RENCE, true); 1669 return DartCore.getPlugin().getPrefs().getBoolean(ENABLE_HINTS_DART2JS_PREFE RENCE, true);
1631 } 1670 }
1632 1671
1633 public boolean isHintsEnabled() { 1672 public boolean isHintsEnabled() {
1634 return DartCore.getPlugin().getPrefs().getBoolean(ENABLE_HINTS_PREFERENCE, t rue); 1673 return DartCore.getPlugin().getPrefs().getBoolean(ENABLE_HINTS_PREFERENCE, t rue);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 @Override 1769 @Override
1731 public void stop(BundleContext context) throws Exception { 1770 public void stop(BundleContext context) throws Exception {
1732 DartSdkManager.getManager().removeSdkListener(this); 1771 DartSdkManager.getManager().removeSdkListener(this);
1733 1772
1734 try { 1773 try {
1735 getProjectManager().stop(); 1774 getProjectManager().stop();
1736 1775
1737 synchronized (analysisServerLock) { 1776 synchronized (analysisServerLock) {
1738 if (analysisServer != null) { 1777 if (analysisServer != null) {
1739 analysisServer.shutdown(); 1778 analysisServer.shutdown();
1779 analysisServerSocket.stop();
1740 } 1780 }
1741 } 1781 }
1742 1782
1743 if (DartCoreDebug.METRICS) { 1783 if (DartCoreDebug.METRICS) {
1744 StringWriter writer = new StringWriter(); 1784 StringWriter writer = new StringWriter();
1745 PerformanceManager.getInstance().printMetrics(new PrintWriter(writer)); 1785 PerformanceManager.getInstance().printMetrics(new PrintWriter(writer));
1746 String metricsInfo = writer.toString(); 1786 String metricsInfo = writer.toString();
1747 if (metricsInfo.length() > 0) { 1787 if (metricsInfo.length() > 0) {
1748 getLog().log(new Status(Status.INFO, PLUGIN_ID, metricsInfo, null)); 1788 getLog().log(new Status(Status.INFO, PLUGIN_ID, metricsInfo, null));
1749 } 1789 }
1750 } 1790 }
1751 } finally { 1791 } finally {
1752 super.stop(context); 1792 super.stop(context);
1753 } 1793 }
1754 } 1794 }
1755 } 1795 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698