Skip to content

Commit 0979892

Browse files
author
Greg Soltis
committed
Merge branch 'master' into enable_lru
2 parents 1e97139 + 5539d80 commit 0979892

File tree

43 files changed

+687
-523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+687
-523
lines changed

ci/fireci/fireci/commands.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,26 @@ def gradle_command(task, gradle_opts):
3737
help=
3838
'App build variant to use while running the smoke Tests. One of release|debug'
3939
)
40+
@click.option(
41+
'--test-apps-dir',
42+
'-d',
43+
multiple=True,
44+
type=click.Path(exists=True, file_okay=False, resolve_path=True),
45+
default=['test-apps'],
46+
help=
47+
'Directory that contains gradle build with apps to test against. Multiple values are allowed.'
48+
)
4049
@ci_command()
41-
def smoke_tests(app_build_variant):
50+
def smoke_tests(app_build_variant, test_apps_dir):
4251
"""Builds all SDKs in release mode and then tests test-apps against them."""
4352
gradle.run('publishAllToBuildDir')
4453

4554
cwd = os.getcwd()
46-
gradle.run(
47-
'connectedCheck',
48-
'-PtestBuildType=%s' % (app_build_variant),
49-
gradle_opts='-Dmaven.repo.local={}'.format(
50-
os.path.join(cwd, 'build', 'm2repository')),
51-
workdir=os.path.join(cwd, 'test-apps'),
52-
)
55+
for location in test_apps_dir:
56+
gradle.run(
57+
'connectedCheck',
58+
'-PtestBuildType=%s' % (app_build_variant),
59+
gradle_opts='-Dmaven.repo.local={}'.format(
60+
os.path.join(cwd, 'build', 'm2repository')),
61+
workdir=location,
62+
)

ci/fireci/fireci/emulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __enter__(self):
7474
stdout=self._stdout,
7575
stderr=self._stderr)
7676
try:
77-
self._wait_for_boot(datetime.timedelta(minutes=5))
77+
self._wait_for_boot(datetime.timedelta(minutes=10))
7878
except:
7979
self._kill(self._process)
8080
self._close_files()

ci/fireci/fireciplugins/copyright.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import fnmatch
16+
import click
17+
import contextlib
18+
import os
19+
import re
20+
21+
from fireci import ci_command
22+
23+
24+
@click.option(
25+
'--ignore-path',
26+
'-i',
27+
default=(),
28+
multiple=True,
29+
type=str,
30+
help='Unix path pattern to ignore when searching for matching files. '
31+
'Multiple values allowed.',
32+
)
33+
@click.option(
34+
'--include-extension',
35+
'-e',
36+
default=(),
37+
multiple=True,
38+
type=str,
39+
help='File extensions to scan for copyright violation. '
40+
'Multiple values allowed.',
41+
required=True,
42+
)
43+
@click.option(
44+
'--expected-regex',
45+
'-r',
46+
default='.*Copyright [0-9]{4} Google LLC',
47+
type=str,
48+
help='Regex expected to be present in the file.',
49+
)
50+
@click.argument(
51+
'dir_to_scan',
52+
type=click.Path(exists=True, file_okay=False),
53+
default='.',
54+
nargs=1,
55+
)
56+
@ci_command()
57+
def copyright_check(dir_to_scan, ignore_path, include_extension,
58+
expected_regex):
59+
"""Checks matching files' content for copyright information."""
60+
expression = re.compile(expected_regex)
61+
failed_files = []
62+
with chdir(dir_to_scan):
63+
for x in walk('.', ignore_path, include_extension):
64+
with open(x) as f:
65+
if not match_any(f, lambda line: expression.match(line)):
66+
failed_files.append(x)
67+
68+
if failed_files:
69+
raise click.ClickException(
70+
"The following files do not have valid copyright information:\n{}"
71+
.format('\n'.join(failed_files)))
72+
73+
74+
@contextlib.contextmanager
75+
def chdir(directory):
76+
original_dir = os.getcwd()
77+
os.chdir(directory)
78+
try:
79+
yield
80+
finally:
81+
os.chdir(original_dir)
82+
83+
84+
def match_any(iterable, predicate):
85+
"""Returns True if at least one item in the iterable matches the predicate."""
86+
for x in iterable:
87+
if predicate(x):
88+
return True
89+
return False
90+
91+
92+
def walk(dir_to_scan, ignore_paths, extensions_to_include):
93+
"""Recursively walk the provided directory and yield matching paths."""
94+
for root, dirs, filenames in os.walk(dir_to_scan):
95+
dirs[:] = (
96+
x for x in dirs if not matches(os.path.join(root, x), ignore_paths))
97+
98+
for f in filenames:
99+
filename = os.path.join(root, f)
100+
if os.path.splitext(f)[1][1:] in extensions_to_include and not matches(
101+
filename, ignore_paths):
102+
yield os.path.normpath(filename)
103+
104+
105+
def matches(path, paths):
106+
path = os.path.normpath(path)
107+
return match_any(paths, lambda p: fnmatch.fnmatch(path, p))

ci/fireci/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
name='fireci',
2626
version='0.1',
2727
install_requires=[
28-
'click==6.7',
28+
'click==7.0',
2929
],
3030
packages=find_packages(exclude=['tests']),
3131
entry_points={

ci/fireci/tests/copyright_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from fireciplugins.copyright import (
18+
match_any,
19+
matches,
20+
walk,
21+
)
22+
from .fileutil import (
23+
Artifact,
24+
create_artifacts,
25+
in_tempdir,
26+
)
27+
28+
29+
class CopyrightCheckTest(unittest.TestCase):
30+
31+
def test_match_any(self):
32+
test_data = (
33+
((1, 2, 3), lambda x: x == 2, True),
34+
((1, 2, 3), lambda x: x == 5, False),
35+
((), lambda x: x == 1, False),
36+
)
37+
for iterable, predicate, expected_result in test_data:
38+
with self.subTest():
39+
self.assertEqual(match_any(iterable, predicate), expected_result)
40+
41+
def test_matches(self):
42+
test_data = (
43+
('file.py', '*.py', True),
44+
('file.xml', '*.py', False),
45+
('hello/file.py', '*.py', True),
46+
('hello/file.xml', 'hello/**', True),
47+
('some/file.xml', 'hello/**', False),
48+
)
49+
50+
for path, path_to_match, expected_result in test_data:
51+
pass
52+
with self.subTest("'{}' matches '{}' must be {}".format(
53+
path, path_to_match, expected_result)):
54+
self.assertEqual(matches(path, [path_to_match]), expected_result)
55+
56+
@in_tempdir
57+
def test_walk_in_empty_dir(self):
58+
paths = walk('.', [], ['py', 'xml'])
59+
self.assertTrue(len(list(paths)) == 0)
60+
61+
@in_tempdir
62+
def test_walk_should_filter_out_non_matching_files(self):
63+
create_artifacts(
64+
Artifact('hello/world/foo.py'), Artifact('dir1/subdir2/file.py'),
65+
Artifact('hello/world.py'), Artifact('dir1/subdir2/file.py'),
66+
Artifact('dir1/subdir2/file.gradle'), Artifact('dir1/subdir2/file.xml'))
67+
paths = walk('.', ['hello/**'], ['py', 'xml'])
68+
69+
self.assertEqual(
70+
set(paths), {'dir1/subdir2/file.py', 'dir1/subdir2/file.xml'})

ci/fireci/tests/fileutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_artifacts(*artifacts):
3838
else:
3939
dirname = os.path.dirname(artifact.path)
4040
if dirname:
41-
os.makedirs(os.path.dirname(artifact.path))
41+
os.makedirs(os.path.dirname(artifact.path), exist_ok=True)
4242
with open(artifact.path, 'w') as opened_file:
4343
opened_file.write(artifact.content)
4444
os.chmod(artifact.path, artifact.mode)

ci/fireci/tests/integ_tests.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,65 @@ def test_smoke_test_with_buildType_should_invoke_gradle_with_release_build_type(
132132
result = self.runner.invoke(cli,
133133
['smoke_tests', '--app-build-variant', 'debug'])
134134
self.assertEqual(result.exit_code, 0)
135+
136+
@in_tempdir
137+
def test_copyright_check_when_no_violating_files_should_succeed(self):
138+
create_artifacts(
139+
Artifact('dir/file.py', content='# Copyright 2018 Google LLC'))
140+
141+
result = self.runner.invoke(cli, ['copyright_check', '-e', 'py'])
142+
self.assertEqual(result.exit_code, 0)
143+
144+
@in_tempdir
145+
def test_copyright_check_when_violating_files_exist_should_fail(self):
146+
create_artifacts(
147+
Artifact('dir/file.py', content='# Copyright 2018 Google LLC'),
148+
Artifact('dir/file2.py', content='# hello'),
149+
Artifact('dir2/file3.xml', content='# hello'),
150+
)
151+
152+
result = self.runner.invoke(cli,
153+
['copyright_check', '-e', 'py', '-e'
154+
'xml'])
155+
self.assertEqual(result.exit_code, 1)
156+
self.assertFalse('dir/file.py' in result.output)
157+
self.assertTrue('dir/file2.py' in result.output)
158+
self.assertTrue('dir2/file3.xml' in result.output)
159+
160+
@in_tempdir
161+
def test_copyright_check_when_violating_files_exist_should_fail2(self):
162+
create_artifacts(
163+
Artifact('dir/file.py', content='# Copyright 2018 Google LLC'),
164+
Artifact('dir/file2.py', content='# hello'),
165+
Artifact('dir2/file3.xml', content='# hello'),
166+
Artifact('dir2/subdir/file4.xml', content='# hello'),
167+
)
168+
169+
result = self.runner.invoke(
170+
cli, ['copyright_check', '-e', 'py', '-e'
171+
'xml', '-i', 'dir2/**'])
172+
173+
self.assertEqual(result.exit_code, 1)
174+
self.assertFalse('dir/file.py' in result.output)
175+
self.assertTrue('dir/file2.py' in result.output)
176+
self.assertFalse('dir2/file3.xml' in result.output)
177+
self.assertFalse('dir2/subdir/file4.xml' in result.output)
178+
179+
@in_tempdir
180+
def test_copyright_check_when_violating_files_exist_should_fail3(self):
181+
create_artifacts(
182+
Artifact('dir/subdir/file.py', content='# Copyright 2018 Google LLC'),
183+
Artifact('dir/subdir/file2.py', content='# hello'),
184+
Artifact('dir/subdir2/file3.xml', content='# hello'),
185+
Artifact('dir/subdir4/file4.xml', content='# hello'),
186+
)
187+
188+
result = self.runner.invoke(
189+
cli,
190+
['copyright_check', '-e', 'py', '-e'
191+
'xml', '-i', 'subdir2/**', 'dir'])
192+
193+
self.assertEqual(result.exit_code, 1)
194+
self.assertFalse('subdir/file.py' in result.output)
195+
self.assertTrue('subdir/file2.py' in result.output)
196+
self.assertTrue('subdir4/file4.xml' in result.output)

firebase-common/firebase-common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies {
5959
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
6060

6161
testImplementation 'com.android.support.test:runner:1.0.2'
62-
testImplementation 'org.robolectric:robolectric:4.0-alpha-3'
62+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
6363
testImplementation 'junit:junit:4.12'
6464
testImplementation "com.google.truth:truth:$googleTruthVersion"
6565
testImplementation 'org.mockito:mockito-core:2.21.0'
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.google.firebase">
4-
<application>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
package="com.google.firebase">
5+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
6+
<uses-sdk android:minSdkVersion="14"/>
7+
<application>
58

6-
<provider
7-
android:authorities="${applicationId}.firebaseinitprovider"
8-
android:name="com.google.firebase.provider.FirebaseInitProvider"
9-
android:exported="false"
10-
android:initOrder="100" />
11-
</application>
9+
<provider
10+
android:name="com.google.firebase.provider.FirebaseInitProvider"
11+
android:authorities="${applicationId}.firebaseinitprovider"
12+
android:exported="false"
13+
android:initOrder="100"/>
14+
</application>
1215
</manifest>

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class FirebaseApp {
104104

105105
public static final String DEFAULT_APP_NAME = "[DEFAULT]";
106106

107-
@VisibleForTesting static final String FIREBASE_APP_PREFS = "com.google.firebase.common.prefs";
107+
private static final String FIREBASE_APP_PREFS = "com.google.firebase.common.prefs:";
108108

109109
@VisibleForTesting
110110
static final String DATA_COLLECTION_DEFAULT_ENABLED = "firebase_data_collection_default_enabled";
@@ -525,7 +525,7 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
525525
idTokenListenersCountChangedListener = new DefaultIdTokenListenersCountChangedListener();
526526

527527
sharedPreferences =
528-
applicationContext.getSharedPreferences(FIREBASE_APP_PREFS, Context.MODE_PRIVATE);
528+
applicationContext.getSharedPreferences(getSharedPrefsName(name), Context.MODE_PRIVATE);
529529
dataCollectionDefaultEnabled = new AtomicBoolean(readAutoDataCollectionEnabled());
530530

531531
List<ComponentRegistrar> registrars =
@@ -540,6 +540,10 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
540540
publisher = componentRuntime.get(Publisher.class);
541541
}
542542

543+
private static String getSharedPrefsName(String appName) {
544+
return FIREBASE_APP_PREFS + appName;
545+
}
546+
543547
private boolean readAutoDataCollectionEnabled() {
544548
if (sharedPreferences.contains(DATA_COLLECTION_DEFAULT_ENABLED)) {
545549
return sharedPreferences.getBoolean(DATA_COLLECTION_DEFAULT_ENABLED, true);

0 commit comments

Comments
 (0)