finalize = function(opt_error) {
    testServer.stopServer();
    var exitCode = 0;
    if (opt_error) {
      var message = opt_error.message || opt_error.toString();
      log('Error detected:', message);
      exitCode = 1;
    }
  }
/*.js',
  ]).pipe(gjslint()).
      pipe(gjslint['reporter']('console'), {fail: true});
});


gulp.task('build', function() {
  var knownOpts = {
    'filter': [Array, String, null],
    'mode': [String, null],
    'target': [String]
  };
  var options = nopt(knownOpts);

  if (options.target == 'lib') {
    return builder.buildLib(options);
  } else {
    return builder.buildAllTests(options).then(function() {
      log('Everything built');
    });
  }
});


gulp.task('debug', function() {
  var knownOpts = {
    'target': [String, null],
    'port': [Number, null]
  };

  var options = nopt(knownOpts);
  options.target = options.target || 'tests';
  var port = options.port || 8000;

  // The test server cannot callback. It is terminated by Ctrl-C.
  if (options.target == 'perf') {
    testServer.runPerfTestServer(port);
  } else if (options.target != 'spac') {
    testServer.runUnitTestServer(port);
  }
});


gulp.task('test', function() {
  var knownOpts = {
    'browser': [Array, String, null],
    'filter': [Array, String, null],
    'target': [String]
  };
  var options = nopt(knownOpts);
  var browsers = options.browser instanceof Array ?
      options.browser :
      [options.browser || process.env['SELENIUM_BROWSER'] || 'chrome'];
  /** @param {*=} opt_error