Skip to content

Commit 8128eca

Browse files
authored
Removed old deprecated APIs (#383)
1 parent d1e21f3 commit 8128eca

Some content is hidden

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

46 files changed

+204
-196
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.google.common.base.Joiner;
3535
import com.google.common.base.MoreObjects;
3636
import com.google.common.base.Strings;
37-
import com.google.common.base.Supplier;
3837
import com.google.common.collect.ImmutableList;
3938
import com.google.firebase.internal.FirebaseAppStore;
4039
import com.google.firebase.internal.FirebaseScheduledExecutor;
@@ -121,7 +120,6 @@ private FirebaseApp(String name, FirebaseOptions options, TokenRefresher.Factory
121120

122121
/** Returns a list of all FirebaseApps. */
123122
public static List<FirebaseApp> getApps() {
124-
// TODO: reenable persistence. See b/28158809.
125123
synchronized (appsLock) {
126124
return ImmutableList.copyOf(instances.values());
127125
}
@@ -582,18 +580,17 @@ enum State {
582580
private static FirebaseOptions getOptionsFromEnvironment() throws IOException {
583581
String defaultConfig = System.getenv(FIREBASE_CONFIG_ENV_VAR);
584582
if (Strings.isNullOrEmpty(defaultConfig)) {
585-
return new FirebaseOptions.Builder()
583+
return FirebaseOptions.builder()
586584
.setCredentials(APPLICATION_DEFAULT_CREDENTIALS)
587585
.build();
588586
}
589587
JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
590-
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
588+
FirebaseOptions.Builder builder = FirebaseOptions.builder();
591589
JsonParser parser;
592590
if (defaultConfig.startsWith("{")) {
593591
parser = jsonFactory.createJsonParser(defaultConfig);
594592
} else {
595-
FileReader reader;
596-
reader = new FileReader(defaultConfig);
593+
FileReader reader = new FileReader(defaultConfig);
597594
parser = jsonFactory.createJsonParser(reader);
598595
}
599596
parser.parseAndClose(builder);

src/main/java/com/google/firebase/FirebaseAppLifecycleListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* A listener which gets notified when {@link com.google.firebase.FirebaseApp} gets deleted.
2121
*/
22-
// TODO: consider making it public in a future release.
22+
@Deprecated
2323
interface FirebaseAppLifecycleListener {
2424

2525
/**

src/main/java/com/google/firebase/FirebaseOptions.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ public static Builder builder() {
223223
return new Builder();
224224
}
225225

226+
/**
227+
* Creates a new Builder from the options object.
228+
*
229+
* <p>The new builder is not backed by this object's values, that is changes made to the new
230+
* builder don't change the values of the origin object.
231+
*/
232+
public Builder toBuilder() {
233+
return new Builder(this);
234+
}
235+
226236
/**
227237
* Builder for constructing {@link FirebaseOptions}.
228238
*/
@@ -249,15 +259,23 @@ public static final class Builder {
249259
private int connectTimeout;
250260
private int readTimeout;
251261

252-
/** Constructs an empty builder. */
262+
/**
263+
* Constructs an empty builder.
264+
*
265+
* @deprecated Use {@link FirebaseOptions#builder()} instead.
266+
*/
267+
@Deprecated
253268
public Builder() {}
254269

255270
/**
256271
* Initializes the builder's values from the options object.
257272
*
258273
* <p>The new builder is not backed by this object's values, that is changes made to the new
259274
* builder don't change the values of the origin object.
275+
*
276+
* @deprecated Use {@link FirebaseOptions#toBuilder()} instead.
260277
*/
278+
@Deprecated
261279
public Builder(FirebaseOptions options) {
262280
databaseUrl = options.databaseUrl;
263281
storageBucket = options.storageBucket;

src/main/java/com/google/firebase/auth/FirebaseAuth.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,6 @@ public void setCustomUserClaims(@NonNull String uid,
758758
setCustomUserClaimsOp(uid, claims).call();
759759
}
760760

761-
/**
762-
* @deprecated Use {@link #setCustomUserClaims(String, Map)} instead.
763-
*/
764-
public void setCustomClaims(@NonNull String uid,
765-
@Nullable Map<String, Object> claims) throws FirebaseAuthException {
766-
setCustomUserClaims(uid, claims);
767-
}
768-
769761
/**
770762
* Similar to {@link #setCustomUserClaims(String, Map)} but performs the operation asynchronously.
771763
*

src/main/java/com/google/firebase/database/core/JvmAuthTokenProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private static class TokenChangeListenerWrapper implements CredentialsChangedLis
112112
}
113113

114114
@Override
115-
public void onChanged(OAuth2Credentials credentials) throws IOException {
115+
public void onChanged(OAuth2Credentials credentials) {
116116
// When this event fires, it is guaranteed that credentials.getAccessToken() will return a
117117
// valid OAuth2 token.
118118
final AccessToken accessToken = credentials.getAccessToken();

src/main/java/com/google/firebase/messaging/Notification.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,6 @@ public class Notification {
3333
@Key("image")
3434
private final String image;
3535

36-
/**
37-
* Creates a new {@code Notification} using the given title and body.
38-
*
39-
* @param title Title of the notification.
40-
* @param body Body of the notification.
41-
*
42-
* @deprecated Use {@link #Notification(Builder)} instead.
43-
*/
44-
public Notification(String title, String body) {
45-
this(title, body, null);
46-
}
47-
48-
/**
49-
* Creates a new {@code Notification} using the given title, body, and image.
50-
*
51-
* @param title Title of the notification.
52-
* @param body Body of the notification.
53-
* @param imageUrl URL of the image that is going to be displayed in the notification.
54-
*
55-
* @deprecated Use {@link #Notification(Builder)} instead.
56-
*/
57-
public Notification(String title, String body, String imageUrl) {
58-
this.title = title;
59-
this.body = body;
60-
this.image = imageUrl;
61-
}
62-
6336
private Notification(Builder builder) {
6437
this.title = builder.title;
6538
this.body = builder.body;

src/test/java/com/google/firebase/FirebaseAppTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535
import com.google.auth.oauth2.OAuth2Credentials.CredentialsChangedListener;
3636
import com.google.common.base.Defaults;
3737
import com.google.common.base.Strings;
38-
import com.google.common.base.Supplier;
3938
import com.google.common.base.Suppliers;
4039
import com.google.common.collect.ImmutableList;
4140
import com.google.common.collect.ImmutableMap;
4241
import com.google.common.collect.ImmutableSet;
4342
import com.google.firebase.FirebaseApp.TokenRefresher;
44-
import com.google.firebase.FirebaseOptions.Builder;
4543
import com.google.firebase.database.FirebaseDatabase;
4644
import com.google.firebase.testing.FirebaseAppRule;
4745
import com.google.firebase.testing.ServiceAccount;
@@ -74,7 +72,7 @@
7472
public class FirebaseAppTest {
7573

7674
private static final FirebaseOptions OPTIONS =
77-
new FirebaseOptions.Builder()
75+
FirebaseOptions.builder()
7876
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
7977
.build();
8078

@@ -110,7 +108,7 @@ public void testGetInstancePersistedNotInitialized() {
110108

111109
@Test
112110
public void testGetProjectIdFromOptions() {
113-
FirebaseOptions options = new FirebaseOptions.Builder(OPTIONS)
111+
FirebaseOptions options = OPTIONS.toBuilder()
114112
.setProjectId("explicit-project-id")
115113
.build();
116114
FirebaseApp app = FirebaseApp.initializeApp(options, "myApp");
@@ -131,7 +129,7 @@ public void testGetProjectIdFromEnvironment() {
131129
for (String variable : variables) {
132130
String gcloudProject = System.getenv(variable);
133131
TestUtils.setEnvironmentVariables(ImmutableMap.of(variable, "project-id-1"));
134-
FirebaseOptions options = new FirebaseOptions.Builder()
132+
FirebaseOptions options = FirebaseOptions.builder()
135133
.setCredentials(new MockGoogleCredentials())
136134
.build();
137135
try {
@@ -155,7 +153,7 @@ public void testProjectIdEnvironmentVariablePrecedence() {
155153

156154
TestUtils.setEnvironmentVariables(ImmutableMap.of(
157155
"GCLOUD_PROJECT", "project-id-1", "GOOGLE_CLOUD_PROJECT", "project-id-2"));
158-
FirebaseOptions options = new FirebaseOptions.Builder()
156+
FirebaseOptions options = FirebaseOptions.builder()
159157
.setCredentials(new MockGoogleCredentials())
160158
.build();
161159
try {
@@ -239,7 +237,7 @@ public void testGetNullApp() {
239237
@Test
240238
public void testToString() throws IOException {
241239
FirebaseOptions options =
242-
new FirebaseOptions.Builder()
240+
FirebaseOptions.builder()
243241
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
244242
.build();
245243
FirebaseApp app = FirebaseApp.initializeApp(options, "app");
@@ -461,14 +459,13 @@ public void testTokenRefresherStateMachine() {
461459
@Test
462460
public void testAppWithAuthVariableOverrides() {
463461
Map<String, Object> authVariableOverrides = ImmutableMap.<String, Object>of("uid", "uid1");
464-
FirebaseOptions options =
465-
new FirebaseOptions.Builder(getMockCredentialOptions())
466-
.setDatabaseAuthVariableOverride(authVariableOverrides)
467-
.build();
462+
FirebaseOptions options = getMockCredentialOptions().toBuilder()
463+
.setDatabaseAuthVariableOverride(authVariableOverrides)
464+
.build();
468465
FirebaseApp app = FirebaseApp.initializeApp(options, "testGetAppWithUid");
469466
assertEquals("uid1", app.getOptions().getDatabaseAuthVariableOverride().get("uid"));
470467
String token = TestOnlyImplFirebaseTrampolines.getToken(app, false);
471-
Assert.assertTrue(!token.isEmpty());
468+
Assert.assertFalse(token.isEmpty());
472469
}
473470

474471
@Test(expected = IllegalArgumentException.class)
@@ -599,7 +596,7 @@ private static void setFirebaseConfigEnvironmentVariable(String configJSON) {
599596
}
600597

601598
private static FirebaseOptions getMockCredentialOptions() {
602-
return new Builder().setCredentials(new MockGoogleCredentials()).build();
599+
return FirebaseOptions.builder().setCredentials(new MockGoogleCredentials()).build();
603600
}
604601

605602
private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)

src/test/java/com/google/firebase/FirebaseOptionsTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class FirebaseOptionsTest {
4848
private static final String FIREBASE_PROJECT_ID = "explicit-project-id";
4949

5050
private static final FirebaseOptions ALL_VALUES_OPTIONS =
51-
new FirebaseOptions.Builder()
51+
FirebaseOptions.builder()
5252
.setDatabaseUrl(FIREBASE_DB_URL)
5353
.setStorageBucket(FIREBASE_STORAGE_BUCKET)
5454
.setProjectId(FIREBASE_PROJECT_ID)
@@ -77,7 +77,7 @@ public void createOptionsWithAllValuesSet() throws IOException {
7777
NetHttpTransport httpTransport = new NetHttpTransport();
7878
FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder().build();
7979
FirebaseOptions firebaseOptions =
80-
new FirebaseOptions.Builder()
80+
FirebaseOptions.builder()
8181
.setDatabaseUrl(FIREBASE_DB_URL)
8282
.setStorageBucket(FIREBASE_STORAGE_BUCKET)
8383
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
@@ -110,7 +110,7 @@ public void createOptionsWithAllValuesSet() throws IOException {
110110
@Test
111111
public void createOptionsWithOnlyMandatoryValuesSet() throws IOException {
112112
FirebaseOptions firebaseOptions =
113-
new FirebaseOptions.Builder()
113+
FirebaseOptions.builder()
114114
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
115115
.build();
116116
assertNotNull(firebaseOptions.getJsonFactory());
@@ -133,7 +133,7 @@ public void createOptionsWithOnlyMandatoryValuesSet() throws IOException {
133133
@Test
134134
public void createOptionsWithCustomFirebaseCredential() {
135135
FirebaseOptions firebaseOptions =
136-
new FirebaseOptions.Builder()
136+
FirebaseOptions.builder()
137137
.setCredentials(new GoogleCredentials() {
138138
@Override
139139
public AccessToken refreshAccessToken() {
@@ -153,33 +153,33 @@ public AccessToken refreshAccessToken() {
153153

154154
@Test(expected = NullPointerException.class)
155155
public void createOptionsWithCredentialMissing() {
156-
new FirebaseOptions.Builder().build().getCredentials();
156+
FirebaseOptions.builder().build().getCredentials();
157157
}
158158

159159
@Test(expected = NullPointerException.class)
160160
public void createOptionsWithNullCredentials() {
161-
new FirebaseOptions.Builder().setCredentials((GoogleCredentials) null).build();
161+
FirebaseOptions.builder().setCredentials((GoogleCredentials) null).build();
162162
}
163163

164164
@Test(expected = IllegalArgumentException.class)
165165
public void createOptionsWithStorageBucketUrl() throws IOException {
166-
new FirebaseOptions.Builder()
166+
FirebaseOptions.builder()
167167
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
168168
.setStorageBucket("gs://mock-storage-bucket")
169169
.build();
170170
}
171171

172172
@Test(expected = NullPointerException.class)
173173
public void createOptionsWithNullThreadManager() {
174-
new FirebaseOptions.Builder()
174+
FirebaseOptions.builder()
175175
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
176176
.setThreadManager(null)
177177
.build();
178178
}
179179

180180
@Test
181181
public void checkToBuilderCreatesNewEquivalentInstance() {
182-
FirebaseOptions allValuesOptionsCopy = new FirebaseOptions.Builder(ALL_VALUES_OPTIONS).build();
182+
FirebaseOptions allValuesOptionsCopy = ALL_VALUES_OPTIONS.toBuilder().build();
183183
assertNotSame(ALL_VALUES_OPTIONS, allValuesOptionsCopy);
184184
assertEquals(ALL_VALUES_OPTIONS.getCredentials(), allValuesOptionsCopy.getCredentials());
185185
assertEquals(ALL_VALUES_OPTIONS.getDatabaseUrl(), allValuesOptionsCopy.getDatabaseUrl());
@@ -195,15 +195,15 @@ public void checkToBuilderCreatesNewEquivalentInstance() {
195195

196196
@Test(expected = IllegalArgumentException.class)
197197
public void createOptionsWithInvalidConnectTimeout() {
198-
new FirebaseOptions.Builder()
198+
FirebaseOptions.builder()
199199
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
200200
.setConnectTimeout(-1)
201201
.build();
202202
}
203203

204204
@Test(expected = IllegalArgumentException.class)
205205
public void createOptionsWithInvalidReadTimeout() {
206-
new FirebaseOptions.Builder()
206+
FirebaseOptions.builder()
207207
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
208208
.setReadTimeout(-1)
209209
.build();
@@ -213,11 +213,11 @@ public void createOptionsWithInvalidReadTimeout() {
213213
public void testNotEquals() throws IOException {
214214
GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream());
215215
FirebaseOptions options1 =
216-
new FirebaseOptions.Builder()
216+
FirebaseOptions.builder()
217217
.setCredentials(credentials)
218218
.build();
219219
FirebaseOptions options2 =
220-
new FirebaseOptions.Builder()
220+
FirebaseOptions.builder()
221221
.setCredentials(credentials)
222222
.setDatabaseUrl("https://test.firebaseio.com")
223223
.build();

src/test/java/com/google/firebase/ThreadManagerTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public void testAppLifecycleWithServiceCall() {
187187
}
188188

189189
@Test
190-
public void testAppLifecycleWithMultipleServiceCalls()
191-
throws ExecutionException, InterruptedException {
190+
public void testAppLifecycleWithMultipleServiceCalls() {
192191
MockThreadManager threadManager = new MockThreadManager(executor);
193192

194193
// Initializing an app should initialize the executor.
@@ -235,7 +234,7 @@ public void testAppLifecycleWithMultipleServiceCalls()
235234
}
236235

237236
private FirebaseOptions buildOptions(ThreadManager threadManager) {
238-
return new FirebaseOptions.Builder()
237+
return FirebaseOptions.builder()
239238
.setCredentials(new MockGoogleCredentials())
240239
.setProjectId("mock-project-id")
241240
.setThreadManager(threadManager)
@@ -278,7 +277,7 @@ private static class Event {
278277
private final FirebaseApp app;
279278
private ExecutorService executor;
280279

281-
public Event(int type, @Nullable FirebaseApp app, @Nullable ExecutorService executor) {
280+
Event(int type, @Nullable FirebaseApp app, @Nullable ExecutorService executor) {
282281
this.type = type;
283282
this.app = app;
284283
this.executor = executor;

src/test/java/com/google/firebase/auth/FirebaseAuthIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public void testCustomTokenWithIAM() throws Exception {
405405
if (token == null) {
406406
token = credentials.refreshAccessToken();
407407
}
408-
FirebaseOptions options = new FirebaseOptions.Builder()
408+
FirebaseOptions options = FirebaseOptions.builder()
409409
.setCredentials(GoogleCredentials.create(token))
410410
.setServiceAccountId(((ServiceAccountSigner) credentials).getAccount())
411411
.setProjectId(IntegrationTestUtils.getProjectId())

src/test/java/com/google/firebase/auth/FirebaseAuthTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class FirebaseAuthTest {
6060
private static final FirebaseAuthException testException = new FirebaseAuthException(
6161
ErrorCode.INVALID_ARGUMENT, "Test error message", null, null, null);
6262
private static final long VALID_SINCE = 1494364393;
63-
public static final String TEST_USER = "testUser";
63+
private static final String TEST_USER = "testUser";
6464

6565
@After
6666
public void cleanup() {
@@ -539,7 +539,7 @@ private FirebaseApp getFirebaseAppForUserRetrieval() {
539539
MockHttpTransport transport = new MockHttpTransport.Builder()
540540
.setLowLevelHttpResponse(new MockLowLevelHttpResponse().setContent(getUserResponse))
541541
.build();
542-
return FirebaseApp.initializeApp(new FirebaseOptions.Builder()
542+
return FirebaseApp.initializeApp(FirebaseOptions.builder()
543543
.setCredentials(new MockGoogleCredentials("test-token"))
544544
.setHttpTransport(transport)
545545
.setProjectId("test-project-id")

0 commit comments

Comments
 (0)