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

Side by Side Diff: chrome/android/java/src/PRESUBMIT.py

Issue 2894643002: [Android] Presubmit check for banned Notification construction (Closed)
Patch Set: remove blank lines for peter Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 []
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698