<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library spark;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:html' hide File;

import 'package:bootjack/bootjack.dart' as bootjack;
import 'package:chrome/chrome_app.dart' as chrome;
import 'package:dquery/dquery.dart';
import 'package:logging/logging.dart';

// BUG(ussuri): https://github.com/dart-lang/spark/issues/500
import 'packages/spark_widgets/spark_status/spark_status.dart';

import 'lib/ace.dart';
import 'lib/actions.dart';
import 'lib/analytics.dart' as analytics;
import 'lib/app.dart';
import 'lib/builder.dart';
import 'lib/dart/dart_builder.dart';
import 'lib/editors.dart';
import 'lib/editor_area.dart';
import 'lib/event_bus.dart';
import 'lib/jobs.dart';
import 'lib/launch.dart';
import 'lib/preferences.dart' as preferences;
import 'lib/scm.dart';
import 'lib/tests.dart';
import 'lib/services/services.dart';
import 'lib/ui/files_controller.dart';
import 'lib/ui/files_controller_delegate.dart';
import 'lib/ui/widgets/splitview.dart';
import 'lib/utils.dart' as utils;
import 'lib/workspace.dart' as ws;
import 'test/all.dart' as all_tests;

import 'spark_model.dart';

analytics.Tracker _analyticsTracker = new analytics.NullTracker();

void main() {
  isTestMode().then((testMode) {
    createSparkZone().runGuarded(() {
      Spark spark = new Spark(testMode);
      spark.start();
    });
  });
}

/**
 * Returns true if app.json contains a test-mode entry set to true. If app.json
 * does not exit, it returns true.
 */
Future<bool> isTestMode() {
  String url = chrome.runtime.getURL('app.json');
  return HttpRequest.getString(url).then((String contents) {
    bool result = true;
    try {
      Map info = JSON.decode(contents);
      result = info['test-mode'];
    } catch (exception, stackTrace) {
      // If JSON is invalid, assume test mode.
      result = true;
    }
    return result;
  }).catchError((e) {
    return true;
  });
}

/**
 * Create a [Zone] that logs uncaught exceptions.
 */
Zone createSparkZone() {
  var errorHandler = (self, parent, zone, error, stackTrace) {
    _handleUncaughtException(error, stackTrace);
  };
  var specification = new ZoneSpecification(handleUncaughtError: errorHandler);
  return Zone.current.fork(specification: specification);
}

class Spark extends SparkModel implements FilesControllerDelegate {
  /// The Google Analytics app ID for Spark.
  static final _ANALYTICS_ID = 'UA-45578231-1';

  final bool developerMode;

  Services services;
  final JobManager jobManager = new JobManager();
  SparkStatus statusComponent;

  AceManager _aceManager;
  ThemeManager _aceThemeManager;
  KeyBindingManager _aceKeysManager;
  ws.Workspace _workspace;
  ScmManager scmManager;
  EditorManager _editorManager;
  EditorArea _editorArea;
  LaunchManager _launchManager;

  final EventBus eventBus = new EventBus();

  preferences.PreferenceStore _localPrefs;
  preferences.PreferenceStore _syncPrefs;

  ActionManager _actionManager;

  SplitView _splitView;
  FilesController _filesController;
  PlatformInfo _platformInfo;
  TestDriver _testDriver;
  ProjectLocationManager projectLocationManager;

  Spark(this.developerMode) {
    services = new Services();
    services.ping().then((result) => print(result));

    document.title = appName;

    _localPrefs = preferences.localStore;
    _syncPrefs = preferences.syncStore;

    initAnalytics();

    addParticipant(new _SparkSetupParticipant(this));

    // TODO: this event is not being fired. A bug with chrome apps / Dartium?
    // Possibly this: https://github.com/dart-gde/chrome.dart/issues/115
    chrome.app.window.onClosed.listen((_) {
      close();
    });

    initWorkspace();
    initScmManager();

    createEditorComponents();
    initEditorArea();
    initEditorManager();

    initFilesController();

    initLookAndFeel();

    createActions();
    initToolbar();
    buildMenu();

    initSplitView();
    initSaveStatusListener();

    initLaunchManager();

    window.onFocus.listen((Event e) {
      // When the user switch to an other application, he might change the
      // content of the workspace from other applications.
      // For that reason, when the user switch back to Spark, we want to check
      // whether the content of the workspace changed.
      // TODO(devoncarew): This is causing workspace corruption issues. Our
      // refresh method really needs to weave deltas back into the existing
      // workspace model.
      //workspace.refresh();
    });

    // Add a Dart builder.
    addBuilder(new DartBuilder());
  }

  //
  // SparkModel interface:
  //

  AceManager get aceManager => _aceManager;<commit_msg>Review fixes (restored separate init statement for services)<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library spark;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:html' hide File;

import 'package:bootjack/bootjack.dart' as bootjack;
import 'package:chrome/chrome_app.dart' as chrome;
import 'package:dquery/dquery.dart';
import 'package:logging/logging.dart';

// BUG(ussuri): https://github.com/dart-lang/spark/issues/500
import 'packages/spark_widgets/spark_status/spark_status.dart';

import 'lib/ace.dart';
import 'lib/actions.dart';
import 'lib/analytics.dart' as analytics;
import 'lib/app.dart';
import 'lib/builder.dart';
import 'lib/dart/dart_builder.dart';
import 'lib/editors.dart';
import 'lib/editor_area.dart';
import 'lib/event_bus.dart';
import 'lib/jobs.dart';
import 'lib/launch.dart';
import 'lib/preferences.dart' as preferences;
import 'lib/scm.dart';
import 'lib/tests.dart';
import 'lib/services/services.dart';
import 'lib/ui/files_controller.dart';
import 'lib/ui/files_controller_delegate.dart';
import 'lib/ui/widgets/splitview.dart';
import 'lib/utils.dart' as utils;
import 'lib/workspace.dart' as ws;
import 'test/all.dart' as all_tests;

import 'spark_model.dart';

analytics.Tracker _analyticsTracker = new analytics.NullTracker();

void main() {
  isTestMode().then((testMode) {
    createSparkZone().runGuarded(() {
      Spark spark = new Spark(testMode);
      spark.start();
    });
  });
}

/**
 * Returns true if app.json contains a test-mode entry set to true. If app.json
 * does not exit, it returns true.
 */
Future<bool> isTestMode() {
  String url = chrome.runtime.getURL('app.json');
  return HttpRequest.getString(url).then((String contents) {
    bool result = true;
    try {
      Map info = JSON.decode(contents);
      result = info['test-mode'];
    } catch (exception, stackTrace) {
      // If JSON is invalid, assume test mode.
      result = true;
    }
    return result;
  }).catchError((e) {
    return true;
  });
}

/**
 * Create a [Zone] that logs uncaught exceptions.
 */
Zone createSparkZone() {
  var errorHandler = (self, parent, zone, error, stackTrace) {
    _handleUncaughtException(error, stackTrace);
  };
  var specification = new ZoneSpecification(handleUncaughtError: errorHandler);
  return Zone.current.fork(specification: specification);
}

class Spark extends SparkModel implements FilesControllerDelegate {
  /// The Google Analytics app ID for Spark.
  static final _ANALYTICS_ID = 'UA-45578231-1';

  final bool developerMode;

  Services services;
  final JobManager jobManager = new JobManager();
  SparkStatus statusComponent;

  AceManager _aceManager;
  ThemeManager _aceThemeManager;
  KeyBindingManager _aceKeysManager;
  ws.Workspace _workspace;
  ScmManager scmManager;
  EditorManager _editorManager;
  EditorArea _editorArea;
  LaunchManager _launchManager;

  final EventBus eventBus = new EventBus();

  preferences.PreferenceStore _localPrefs;
  preferences.PreferenceStore _syncPrefs;

  ActionManager _actionManager;

  SplitView _splitView;
  FilesController _filesController;
  PlatformInfo _platformInfo;
  TestDriver _testDriver;
  ProjectLocationManager projectLocationManager;

  Spark(this.developerMode) {
    initServices();

    document.title = appName;

    _localPrefs = preferences.localStore;
    _syncPrefs = preferences.syncStore;

    initAnalytics();

    addParticipant(new _SparkSetupParticipant(this));

    // TODO: this event is not being fired. A bug with chrome apps / Dartium?
    // Possibly this: https://github.com/dart-gde/chrome.dart/issues/115
    chrome.app.window.onClosed.listen((_) {
      close();
    });

    initWorkspace();
    initScmManager();

    createEditorComponents();
    initEditorArea();
    initEditorManager();

    initFilesController();

    initLookAndFeel();

    createActions();
    initToolbar();
    buildMenu();

    initSplitView();
    initSaveStatusListener();

    initLaunchManager();

    window.onFocus.listen((Event e) {
      // When the user switch to an other application, he might change the
      // content of the workspace from other applications.
      // For that reason, when the user switch back to Spark, we want to check
      // whether the content of the workspace changed.
      // TODO(devoncarew): This is causing workspace corruption issues. Our
      // refresh method really needs to weave deltas back into the existing
      // workspace model.
      //workspace.refresh();
    });

    // Add a Dart builder.
    addBuilder(new DartBuilder());
  }

  initServices() {
    services = new Services();
    services.ping().then((result) => print(result));
  }

  //
  // SparkModel interface:
  //

  AceManager get aceManager => _aceManager;
{'fraction_non_alphanumeric': 0.11356886840757809, 'fraction_numerical': 0.0038914490527393753, 'mean_word_length': 3.841844323252355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258796', 'n_tokens_mistral': 3059, 'n_tokens_neox': 2920, 'n_words': 802}