Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
428eedb
Initial code migration:
Apr 6, 2017
cfbbd6a
Reformatting code according to check-style plugin conventions
hiranya911 Apr 6, 2017
59842b8
Code reformatting: Fixing javadoc indentation
hiranya911 Apr 6, 2017
fef4ecf
More reformatting: Added google check style config
hiranya911 Apr 6, 2017
a606833
Code formatting continued
hiranya911 Apr 6, 2017
1d2ed82
Code formatting continued
hiranya911 Apr 6, 2017
8972b1b
Reformatting
hiranya911 Apr 6, 2017
e5509c3
Fixed all checkstyle violations; Build configured to fail on lint errors
Apr 6, 2017
0587d52
Updated checkstyle config
Apr 6, 2017
7f2f470
Working on re-enabling the integration tests
Apr 7, 2017
8ee5cfc
Temporarily removing IT test cases
Apr 7, 2017
dbc6ee6
Extending checkstyle coverage to test sourcesw
Apr 7, 2017
c66f35b
Cleaned up verbose test output
Apr 7, 2017
f7cbdc2
Adding 2 integration tests to verify the maven integration test support
Apr 7, 2017
7715b90
Moving test only trampolines to the test/ subtree; Adding a removed m…
Apr 10, 2017
c3591ed
Fixing integration tests
hiranya911 Apr 11, 2017
bc54329
Added event test
hiranya911 Apr 11, 2017
75df20f
Added the real time test
hiranya911 Apr 11, 2017
471d0a9
Adding data test back
hiranya911 Apr 11, 2017
f692bb6
Fixed the object serialization test
hiranya911 Apr 11, 2017
c368248
Adding a factory method to MapBuilder
hiranya911 Apr 11, 2017
a30ae95
Added transaction integration test
hiranya911 Apr 11, 2017
7714024
Added transaction test
hiranya911 Apr 11, 2017
2da7955
Added rules integration test
hiranya911 Apr 11, 2017
094d756
Updated rules test
hiranya911 Apr 11, 2017
f446c79
Merge branch 'hkj-initial-code-migration' into hkj-db-integration-tests
hiranya911 Apr 11, 2017
952c6b0
Cleaning up the test code; Removed unnecessary utils and constants
hiranya911 Apr 12, 2017
594bfbb
Added more factory methods for MapBuilder; Removed unused legacy depe…
hiranya911 Apr 12, 2017
5dc413f
Dropped the jackson test dependency
hiranya911 Apr 12, 2017
738c75e
Adding release profile
Apr 12, 2017
5e81a8b
Ignoring some maven specific temp files
Apr 12, 2017
922054d
Updated pom to use release + nexus plugin combo
Apr 12, 2017
337299f
Loading the version numbner from a Maven-filtered resource
Apr 12, 2017
aa88398
Adding the initial version of contribution guide
Apr 12, 2017
a0ef544
Merge branch 'hkj-db-integration-tests' into hkj-release-process
Apr 12, 2017
8b2ff85
Inferring the DB URL from project ID
Apr 12, 2017
2da5b03
Fixed test race condition
Apr 13, 2017
a24340c
Merge branch 'hkj-db-integration-tests' into hkj-release-process
Apr 13, 2017
7d39734
Fixing some race conditions in ITs
Apr 13, 2017
5f8e82a
Merge branch 'hkj-db-integration-tests' into hkj-release-process
Apr 13, 2017
4b0361c
Cleaning up EventHelper instances after use
hiranya911 Apr 13, 2017
e5eca5c
Merge branch 'hkj-db-integration-tests' into hkj-release-process
Apr 13, 2017
3d3be22
Adding back some logging code; Dropping fblocal URLs
Apr 13, 2017
eefc4ce
Dropping all references to fblocal
Apr 13, 2017
d13b1ec
Merge branch 'hkj-db-integration-tests' into hkj-release-process
Apr 13, 2017
e911387
Removing port numbers from test URLs
Apr 14, 2017
3c7f98f
Separated conjunctive assertions into separate ones for better error …
hiranya911 Apr 14, 2017
7efbd53
Merge branch 'hkj-db-integration-tests' into hkj-release-process
hiranya911 Apr 14, 2017
59d1689
Merge branch 'hkj-release-process' of github.com:firebase/firebase-ad…
Apr 14, 2017
0dc979c
Fixing merge conflict
Apr 14, 2017
b47dbf6
Allowing snapshot versions in database
Apr 14, 2017
78fdef7
Updated contributing guide
Apr 14, 2017
f5883d7
Updated titles and links
Apr 14, 2017
21e14d6
Fixing SCM URL
Apr 14, 2017
4bb3923
Removed Base64 and Preconditions
Apr 14, 2017
36b334f
Removed Objects
Apr 14, 2017
ca5af15
Implemented a mechanism to capture async errors and fail during integ…
Apr 14, 2017
e0757cd
Downgrading guava version to 20.0 since 21.0 only works on Java 8 (ht…
Apr 17, 2017
d6de43d
Merge branch 'hkj-release-process' into hkj-remove-utils
Apr 17, 2017
5517d00
Merge branch 'master' of github.com:firebase/firebase-admin-java into…
Apr 17, 2017
2cdff1f
Updated all test URLs to https; Documented TestHelpers
Apr 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/main/java/com/google/firebase/FirebaseApp.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.google.firebase;

import static com.google.firebase.internal.Base64Utils.encodeUrlSafeNoPadding;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.io.BaseEncoding;
import com.google.firebase.internal.AuthStateListener;
import com.google.firebase.internal.FirebaseAppStore;
import com.google.firebase.internal.FirebaseExecutors;
Expand All @@ -13,8 +18,6 @@
import com.google.firebase.internal.Joiner;
import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Nullable;
import com.google.firebase.internal.Objects;
import com.google.firebase.internal.Preconditions;
import com.google.firebase.tasks.Continuation;
import com.google.firebase.tasks.Task;

Expand Down Expand Up @@ -69,9 +72,10 @@ public class FirebaseApp {

/** Default constructor. */
private FirebaseApp(String name, FirebaseOptions options, TokenRefresher.Factory factory) {
this.name = Preconditions.checkNotEmpty(name);
this.options = Preconditions.checkNotNull(options);
tokenRefresher = Preconditions.checkNotNull(factory).create(this);
checkArgument(!Strings.isNullOrEmpty(name));
this.name = name;
this.options = checkNotNull(options);
tokenRefresher = checkNotNull(factory).create(this);
}

/** Returns a mutable list of all FirebaseApps. */
Expand Down Expand Up @@ -177,7 +181,7 @@ static void clearInstancesForTest() {
* the app has been deleted.
*/
static String getPersistenceKey(String name, FirebaseOptions options) {
return encodeUrlSafeNoPadding(name.getBytes(UTF_8));
return BaseEncoding.base64Url().omitPadding().encode(name.getBytes(UTF_8));
}

/** Use this key to store data per FirebaseApp. */
Expand All @@ -203,7 +207,7 @@ private static List<String> getAllAppNames() {

/** Normalizes the app name. */
private static String normalize(@NonNull String name) {
return name.trim();
return checkNotNull(name).trim();
}

/** Returns the unique name of this app. */
Expand Down Expand Up @@ -237,7 +241,7 @@ public int hashCode() {

@Override
public String toString() {
return Objects.toStringHelper(this).add("name", name).add("options", options).toString();
return MoreObjects.toStringHelper(this).add("name", name).add("options", options).toString();
}

/**
Expand Down Expand Up @@ -321,19 +325,17 @@ boolean isDefaultApp() {
// initialized using reflection when an app is deleted (for v5).
void addLifecycleEventListener(@NonNull FirebaseAppLifecycleListener listener) {
checkNotDeleted();
Preconditions.checkNotNull(listener);
lifecycleListeners.add(listener);
lifecycleListeners.add(checkNotNull(listener));
}

void removeLifecycleEventListener(@NonNull FirebaseAppLifecycleListener listener) {
checkNotDeleted();
Preconditions.checkNotNull(listener);
lifecycleListeners.remove(listener);
lifecycleListeners.remove(checkNotNull(listener));
}

void addAuthStateListener(@NonNull final AuthStateListener listener) {
checkNotDeleted();
Preconditions.checkNotNull(listener);
checkNotNull(listener);

GetTokenResult currentToken;
synchronized (authStateListeners) {
Expand All @@ -350,7 +352,7 @@ void addAuthStateListener(@NonNull final AuthStateListener listener) {

void removeAuthStateListener(@NonNull AuthStateListener listener) {
checkNotDeleted();
Preconditions.checkNotNull(listener);
checkNotNull(listener);
synchronized (authStateListeners) {
authStateListeners.remove(listener);
}
Expand All @@ -371,7 +373,7 @@ static class TokenRefresher {
private ScheduledFuture<Task<GetTokenResult>> future;

TokenRefresher(FirebaseApp app) {
this.firebaseApp = Preconditions.checkNotNull(app);
this.firebaseApp = checkNotNull(app);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/google/firebase/FirebaseException.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.google.firebase;

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.base.Strings;
import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Preconditions;

/** Base class for all Firebase exceptions. */
public class FirebaseException extends Exception {
Expand All @@ -11,10 +13,12 @@ public class FirebaseException extends Exception {
protected FirebaseException() {}

public FirebaseException(@NonNull String detailMessage) {
super(Preconditions.checkNotEmpty(detailMessage, "Detail message must not be empty"));
super(detailMessage);
checkArgument(!Strings.isNullOrEmpty(detailMessage), "Detail message must not be empty");
}

public FirebaseException(@NonNull String detailMessage, Throwable cause) {
super(Preconditions.checkNotEmpty(detailMessage, "Detail message must not be empty"), cause);
super(detailMessage, cause);
checkArgument(!Strings.isNullOrEmpty(detailMessage), "Detail message must not be empty");
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/google/firebase/FirebaseOptions.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.google.firebase;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.firebase.auth.FirebaseCredential;
import com.google.firebase.auth.FirebaseCredentials;
import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Nullable;
import com.google.firebase.internal.Objects;
import com.google.firebase.internal.Preconditions;

import java.io.InputStream;
import java.util.HashMap;
Expand All @@ -24,10 +26,9 @@ private FirebaseOptions(
@Nullable String databaseUrl,
@NonNull FirebaseCredential firebaseCredential,
@Nullable Map<String, Object> databaseAuthVariableOverride) {
Preconditions.checkArgument(firebaseCredential != null, "Service Account must be provided.");

this.databaseUrl = databaseUrl;
this.firebaseCredential = firebaseCredential;
this.firebaseCredential = checkNotNull(firebaseCredential, "Service Account must be provided.");
this.databaseAuthVariableOverride = databaseAuthVariableOverride;
}

Expand Down Expand Up @@ -72,7 +73,7 @@ public int hashCode() {

@Override
public String toString() {
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.add("databaseUrl", databaseUrl)
.add("credential", firebaseCredential)
.add("databaseAuthVariableOverride", databaseAuthVariableOverride)
Expand Down Expand Up @@ -148,8 +149,7 @@ public Builder setServiceAccount(@NonNull InputStream stream) {
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setCredential(@NonNull FirebaseCredential credential) {
Preconditions.checkArgument(credential != null);
firebaseCredential = credential;
firebaseCredential = checkNotNull(credential);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// TODO(rahulrav/isachen): Decide if changing this not enforcing an error code. Need to align
// with the decision in http://b/27677218. Also, need to turn this into abstract later.

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.base.Strings;
import com.google.firebase.FirebaseException;
import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Preconditions;

/**
* Generic exception related to Firebase Authentication. Check the error code and message for more
Expand All @@ -20,7 +22,8 @@ public class FirebaseAuthException extends FirebaseException {

public FirebaseAuthException(@NonNull String errorCode, @NonNull String detailMessage) {
super(detailMessage);
this.errorCode = Preconditions.checkNotEmpty(errorCode);
checkArgument(!Strings.isNullOrEmpty(errorCode));
this.errorCode = errorCode;
}

/** Returns an error code that may provide more information about the error. */
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/google/firebase/auth/FirebaseCredentials.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.google.firebase.auth;

import static com.google.firebase.internal.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.util.Utils;
Expand Down Expand Up @@ -87,9 +87,8 @@ static FirebaseCredential applicationDefault(HttpTransport transport, JsonFactor
*/
@NonNull
public static FirebaseCredential fromCertificate(InputStream serviceAccount) {
checkNotNull(serviceAccount);
return fromCertificate(
serviceAccount, Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
return fromCertificate(serviceAccount,
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
}

@VisibleForTesting
Expand All @@ -112,7 +111,6 @@ static FirebaseCredential fromCertificate(
*/
@NonNull
public static FirebaseCredential fromRefreshToken(InputStream refreshToken) {
checkNotNull(refreshToken);
return fromRefreshToken(
refreshToken, Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
}
Expand Down Expand Up @@ -232,7 +230,7 @@ static class CertCredential extends BaseCredential {
CertCredential(InputStream inputStream, HttpTransport transport, JsonFactory jsonFactory) {
super(transport, jsonFactory);
try {
jsonData = streamToString(inputStream);
jsonData = streamToString(checkNotNull(inputStream));
JSONObject jsonObject = new JSONObject(jsonData);
projectId = jsonObject.getString("project_id");
} catch (IOException e) {
Expand Down Expand Up @@ -309,7 +307,7 @@ static class RefreshTokenCredential extends BaseCredential {
InputStream inputStream, HttpTransport transport, JsonFactory jsonFactory) {
super(transport, jsonFactory);
try {
jsonData = streamToString(inputStream);
jsonData = streamToString(checkNotNull(inputStream));
} catch (IOException e) {
streamException = new IOException("Failed to read refresh token", e);
}
Expand Down Expand Up @@ -366,12 +364,12 @@ static class FirebaseAccessToken {

FirebaseAccessToken(GoogleCredential credential, Clock clock) {
checkNotNull(credential, "Google credential is required");
checkNotNull(clock, "Clock is required");

token =
checkNotNull(
credential.getAccessToken(), "Access token should not be null after refresh.");
expirationTime = credential.getExpirationTimeMilliseconds();
this.clock = clock;
this.clock = checkNotNull(clock, "Clock is required");
}

String getToken() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.google.firebase.database;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.ImplFirebaseTrampolines;
Expand All @@ -12,7 +14,6 @@
import com.google.firebase.database.utilities.Utilities;
import com.google.firebase.database.utilities.Validation;

import com.google.firebase.internal.Preconditions;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
Expand Down Expand Up @@ -332,9 +333,8 @@ DatabaseConfig getConfig() {
private static String loadSdkVersion() {
try (InputStream in = FirebaseDatabase.class.getClassLoader()
.getResourceAsStream(ADMIN_SDK_PROPERTIES)) {
Preconditions.checkNotNull(in, "Failed to load: " + ADMIN_SDK_PROPERTIES);
Properties properties = new Properties();
properties.load(in);
properties.load(checkNotNull(in, "Failed to load: " + ADMIN_SDK_PROPERTIES));
return properties.getProperty("sdk.version");
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.google.firebase.database.core;

import static com.google.common.base.Preconditions.checkState;

import com.google.firebase.FirebaseApp;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.connection.ConnectionContext;
Expand All @@ -13,7 +15,6 @@
import com.google.firebase.database.tubesock.WebSocket;
import com.google.firebase.database.utilities.DefaultRunLoop;
import com.google.firebase.internal.GaeThreadFactory;
import com.google.firebase.internal.Preconditions;
import com.google.firebase.internal.RevivingScheduledExecutor;

import java.util.List;
Expand Down Expand Up @@ -47,8 +48,7 @@ public Logger newLogger(Context ctx, Logger.Level level, List<String> components

private ThreadFactory getGaeThreadFactory() {
GaeThreadFactory threadFactory = GaeThreadFactory.getInstance();
Preconditions.checkState(
threadFactory.isUsingBackgroundThreads(),
checkState(threadFactory.isUsingBackgroundThreads(),
"Failed to initialize a GAE background thread factory");
return threadFactory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.google.firebase.database.core;

import static com.google.firebase.internal.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.firebase.FirebaseApp;
import com.google.firebase.ImplFirebaseTrampolines;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.google.firebase.database.core;

import com.google.firebase.internal.Preconditions;
import static com.google.common.base.Preconditions.checkNotNull;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/** ThreadPoolEventTarget is an event target using a configurable threadpool. */
class ThreadPoolEventTarget implements EventTarget {
class ThreadPoolEventTarget implements EventTarget, UncaughtExceptionHandler {

private final ThreadPoolExecutor executor;
private UncaughtExceptionHandler exceptionHandler;

public ThreadPoolEventTarget(
final ThreadFactory wrappedFactory, final ThreadInitializer threadInitializer) {
Expand All @@ -25,17 +27,14 @@ public Thread newThread(Runnable r) {
Thread thread = wrappedFactory.newThread(r);
threadInitializer.setName(thread, "FirebaseDatabaseEventTarget");
threadInitializer.setDaemon(thread, true);
// TODO: should we set an uncaught exception handler here? Probably want
// to let
// exceptions happen...
threadInitializer.setUncaughtExceptionHandler(thread, ThreadPoolEventTarget.this);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! For future reference, it'd be nice to keep unrelated changes like this in a separate PR for easier reviewing... especially since the rest of this PR is pretty mechanical... but now that I've seen a non-mechanical change, I'm paranoid there may be others I should watch out for (in other words, it's usually better to keep "pure refactoring" PRs separate from "behavior change" PRs)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

return thread;
}
});
}

public ThreadPoolEventTarget(final ThreadPoolExecutor executor) {
Preconditions.checkNotNull(executor);
this.executor = executor;
this.executor = checkNotNull(executor);
}

@Override
Expand All @@ -62,4 +61,23 @@ public void shutdown() {
public void restart() {
executor.setCorePoolSize(1);
}

synchronized UncaughtExceptionHandler getExceptionHandler() {
return exceptionHandler;
}

synchronized void setExceptionHandler(UncaughtExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}

@Override
public void uncaughtException(Thread t, Throwable e) {
UncaughtExceptionHandler delegate;
synchronized (this) {
delegate = exceptionHandler;
}
if (delegate != null) {
delegate.uncaughtException(t, e);
}
}
}
Loading