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

Unified Diff: components/cronet/PRESUBMIT.py

Issue 2320413002: [Cronet] Add presubmit check to verify Cronet package division. (Closed)
Patch Set: don't check for imports Created 4 years, 3 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: components/cronet/PRESUBMIT.py
diff --git a/components/cronet/PRESUBMIT.py b/components/cronet/PRESUBMIT.py
index 57cb261d6034d22d604a1c63ed3a9570cf1bec7a..327e334c81a08205e8f37ee9e471bd9c7c6f7056 100644
--- a/components/cronet/PRESUBMIT.py
+++ b/components/cronet/PRESUBMIT.py
@@ -31,9 +31,44 @@ def _GetPathsToPrepend(input_api):
'third_party', 'catapult', 'devil'),
]
+def _PackageChecks(input_api, output_api):
+ """Verify API classes are in org.chromium.net package, and implementation
+ classes are not in org.chromium.net package."""
+ api_file_pattern = input_api.re.compile(
+ r'^components/cronet/android/api/.*\.(java|template)$')
+ impl_file_pattern = input_api.re.compile(
+ r'^components/cronet/android/java/.*\.(java|template)$')
+ api_package_pattern = input_api.re.compile(r'^package (?!org.chromium.net;)')
+ impl_package_pattern = input_api.re.compile(r'^package org.chromium.net;')
+
+ source_filter = lambda path: input_api.FilterSourceFile(path,
+ white_list=[r'^components/cronet/android/.*\.(java|template)$'])
+
+ problems = []
+ for f in input_api.AffectedSourceFiles(source_filter):
+ local_path = f.LocalPath()
+ for line_number, line in f.ChangedContents():
+ if (api_file_pattern.search(local_path)):
+ if (api_package_pattern.search(line)):
+ problems.append(
+ '%s:%d\n %s' % (local_path, line_number, line.strip()))
+ elif (impl_file_pattern.search(local_path)):
+ if (impl_package_pattern.search(line)):
+ problems.append(
+ '%s:%d\n %s' % (local_path, line_number, line.strip()))
+
+ if problems:
+ return [output_api.PresubmitError(
+ 'API classes must be in org.chromium.net package, and implementation\n'
+ 'classes must not be in org.chromium.net package.',
+ problems)]
+ else:
+ return []
+
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_PyLintChecks(input_api, output_api))
results.extend(
input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
+ results.extend(_PackageChecks(input_api, output_api))
return results
« 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