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

Unified Diff: chrome/android/java/src/PRESUBMIT.py

Issue 2894643002: [Android] Presubmit check for banned Notification construction (Closed)
Patch Set: Simplifying regex as it only runs on single lines 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..bc77c030557b1a07b1cd6a1bbefe7148b9aa5a22
--- /dev/null
+++ b/chrome/android/java/src/PRESUBMIT.py
@@ -0,0 +1,67 @@
+# 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')
nyquist 2017/05/18 20:32:36 I don't know if that's even OK, but does the \s he
awdf 2017/05/19 14:16:53 I took out the '\s+'s from the regex when I realis
awdf 2017/05/19 14:48:44 Dismissing that idea (& the more straightforward o
+
+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/
nyquist 2017/05/18 20:32:37 Why so many 's?
awdf 2017/05/19 14:16:53 Ah you caught a bug, thank you! (Triple quotes mea
+ 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 []
+
+
+
+
« 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