OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Presubmit script for Android Java code. |
| 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into depot_tools. |
| 9 |
| 10 This presubmit checks for the following: |
| 11 - No new calls to Notification.Builder or NotificationCompat.Builder |
| 12 constructors. Callers should use ChromeNotificationBuilder instead. |
| 13 """ |
| 14 |
| 15 import re |
| 16 |
| 17 NEW_NOTIFICATION_BUILDER_RE = re.compile( |
| 18 r'new\sNotification(Compat)?\.Builder') |
| 19 |
| 20 def CheckChangeOnUpload(input_api, output_api): |
| 21 return _CommonChecks(input_api, output_api) |
| 22 |
| 23 |
| 24 def CheckChangeOnCommit(input_api, output_api): |
| 25 return _CommonChecks(input_api, output_api) |
| 26 |
| 27 def _CommonChecks(input_api, output_api): |
| 28 """Checks common to both upload and commit.""" |
| 29 result = [] |
| 30 result.extend(_CheckNotificationConstructors(input_api, output_api)) |
| 31 # Add more checks here |
| 32 return result |
| 33 |
| 34 def _CheckNotificationConstructors(input_api, output_api): |
| 35 whitelist = [ |
| 36 'chrome/android/java/src/org/chromium/chrome/browser/notifications/' |
| 37 'NotificationBuilder.java', |
| 38 'chrome/android/java/src/org/chromium/chrome/browser/notifications/' |
| 39 'NotificationCompatBuilder.java' |
| 40 ] |
| 41 problems = [] |
| 42 for f in input_api.AffectedFiles(): |
| 43 if f.LocalPath() in whitelist: |
| 44 continue |
| 45 for line_number, line in f.ChangedContents(): |
| 46 if NEW_NOTIFICATION_BUILDER_RE.search(line): |
| 47 problems.append( |
| 48 ' %s:%d\n \t%s' % (f.LocalPath(), line_number, line.strip())) |
| 49 if problems: |
| 50 return [output_api.PresubmitError( |
| 51 ''' |
| 52 Android Notification Construction Check failed: |
| 53 Your new code added one or more calls to the Notification.Builder and/or |
| 54 NotificationCompat.Builder constructors, listed below. |
| 55 |
| 56 This is banned, please construct notifications using |
| 57 NotificationBuilderFactory.createChromeNotificationBuilder instead, |
| 58 specifying a channel for use on Android O. |
| 59 |
| 60 See https://crbug.com/678670 for more information. |
| 61 ''', |
| 62 problems)] |
| 63 return [] |
OLD | NEW |