| Index: chrome/android/java/src/PRESUBMIT.py
|
| diff --git a/chrome/android/java/src/PRESUBMIT.py b/chrome/android/java/src/PRESUBMIT.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c1f96e30ef6c113bc39deb4ca5190ca39146825a
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/PRESUBMIT.py
|
| @@ -0,0 +1,63 @@
|
| +# Copyright (c) 2017 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""Presubmit script for Android Java code.
|
| +
|
| +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
| +for more details about the presubmit API built into depot_tools.
|
| +
|
| +This presubmit checks for the following:
|
| + - No new calls to Notification.Builder or NotificationCompat.Builder
|
| + constructors. Callers should use ChromeNotificationBuilder instead.
|
| +"""
|
| +
|
| +import re
|
| +
|
| +NEW_NOTIFICATION_BUILDER_RE = re.compile(
|
| + r'new\sNotification(Compat)?\.Builder')
|
| +
|
| +def CheckChangeOnUpload(input_api, output_api):
|
| + return _CommonChecks(input_api, output_api)
|
| +
|
| +
|
| +def CheckChangeOnCommit(input_api, output_api):
|
| + return _CommonChecks(input_api, output_api)
|
| +
|
| +def _CommonChecks(input_api, output_api):
|
| + """Checks common to both upload and commit."""
|
| + result = []
|
| + result.extend(_CheckNotificationConstructors(input_api, output_api))
|
| + # Add more checks here
|
| + return result
|
| +
|
| +def _CheckNotificationConstructors(input_api, output_api):
|
| + whitelist = [
|
| + 'chrome/android/java/src/org/chromium/chrome/browser/notifications/'
|
| + 'NotificationBuilder.java',
|
| + 'chrome/android/java/src/org/chromium/chrome/browser/notifications/'
|
| + 'NotificationCompatBuilder.java'
|
| + ]
|
| + problems = []
|
| + for f in input_api.AffectedFiles():
|
| + if f.LocalPath() in whitelist:
|
| + continue
|
| + for line_number, line in f.ChangedContents():
|
| + if NEW_NOTIFICATION_BUILDER_RE.search(line):
|
| + problems.append(
|
| + ' %s:%d\n \t%s' % (f.LocalPath(), line_number, line.strip()))
|
| + if problems:
|
| + return [output_api.PresubmitError(
|
| +'''
|
| +Android Notification Construction Check failed:
|
| + Your new code added one or more calls to the Notification.Builder and/or
|
| + NotificationCompat.Builder constructors, listed below.
|
| +
|
| + This is banned, please construct notifications using
|
| + NotificationBuilderFactory.createChromeNotificationBuilder instead,
|
| + specifying a channel for use on Android O.
|
| +
|
| + See https://crbug.com/678670 for more information.
|
| +''',
|
| + problems)]
|
| + return []
|
|
|