Skip to content

Commit

Permalink
Revert "Remove transitive dependencies on kotlin stdlib (via androidx)"
Browse files Browse the repository at this point in the history
This reverts commit a405295.
  • Loading branch information
sdlaver committed Jul 9, 2022
1 parent a405295 commit 3b65937
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 114 deletions.
4 changes: 2 additions & 2 deletions digitalassetlinks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ tasks.whenTaskAdded { task ->
}

dependencies {
compileOnly 'org.jetbrains:annotations:23.0.0'
testCompileOnly 'org.jetbrains:annotations:23.0.0'
implementation 'androidx.annotation:annotation:1.4.0'
implementation 'androidx.collection:collection:1.2.0'
testImplementation 'com.google.protobuf:protobuf-java:3.21.2'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import android.content.pm.Signature;
import android.os.Build;

import org.jetbrains.annotations.NotNull;
import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONObject;

Expand All @@ -29,7 +30,7 @@ public class AndroidAppPackageVerifier extends URISourceVerifier {
* Construct a new {@link AndroidAppPackageVerifier}
* @param pm the {@link PackageManager} from which to look up app package details
*/
public AndroidAppPackageVerifier(@NotNull PackageManager pm) {
public AndroidAppPackageVerifier(@NonNull PackageManager pm) {
mPackageManager = pm;
}

Expand All @@ -50,7 +51,7 @@ public AndroidAppPackageVerifier(@NotNull PackageManager pm) {
* successful. Note that this doesn't necessarily imply that the package was not verified,
* but rather that a relationship could not be established.
*/
public boolean verify(@NotNull String packageName, @NotNull URI uri)
public boolean verify(@NonNull String packageName, @NonNull URI uri)
throws CouldNotVerifyPackageException {
if (!"https".equalsIgnoreCase(uri.getScheme())) {
throw new CouldNotVerifyPackageException(
Expand Down Expand Up @@ -144,9 +145,9 @@ public boolean verify(@NotNull String packageName, @NotNull URI uri)
return result;
}

@NotNull
@NonNull
private static byte[][] convertDEREncodedCertificatesToSHA256Fingerprints(
@NotNull Signature[] derEncodedCerts) {
@NonNull Signature[] derEncodedCerts) {
final MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
Expand All @@ -160,9 +161,9 @@ private static byte[][] convertDEREncodedCertificatesToSHA256Fingerprints(
return sha256CertFingerprints;
}

@NotNull
@NonNull
private static byte[] convertSHA256CertFingerprintStringToByteArray(
@NotNull String sha256CertFingerprint) {
@NonNull String sha256CertFingerprint) {
// NOTE: the format of the certificate fingerprint string is already checked against
// AssetLinksGrammer.SHA256_CERT_FINGERPRINT_PATTERN by AssetLinksJSONParser
final byte[] fp = new byte[32];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package com.solana.digitalassetlinks;

import org.jetbrains.annotations.NotNull;
import androidx.annotation.NonNull;

import java.net.URI;

Expand Down Expand Up @@ -36,7 +36,7 @@ public final class AssetLinksGrammar {
public static final String SHA256_CERT_FINGERPRINT_PATTERN = "^(?:[0-9A-F]{2}:){31}[0-9A-F]{2}$";

/** Tests if the specified URI is valid for {@link #GRAMMAR_WEB_SITE} */
public static boolean isValidSiteURI(@NotNull URI uri) {
public static boolean isValidSiteURI(@NonNull URI uri) {
return (uri.isAbsolute() &&
("http".equalsIgnoreCase(uri.getScheme()) ||
"https".equalsIgnoreCase(uri.getScheme())) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import android.util.Log;
import android.util.Pair;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -45,7 +46,7 @@ public AssetLinksJSONParser() {}
* @return a {@link List} of {@link URI}s in the order discovered. The first entry is the source
* {@link URI} for this Asset Links tree.
*/
@NotNull
@NonNull
public List<URI> getURIs() {
return Collections.unmodifiableList(mURIs);
}
Expand Down Expand Up @@ -84,8 +85,8 @@ public boolean isError() {
* @param statementMatcher the {@link StatementMatcher} to add
* @param callback the {@link StatementMatcherCallback} to invoke when a match occurs
*/
public void addStatementMatcher(@NotNull StatementMatcher statementMatcher,
@NotNull StatementMatcherCallback callback) {
public void addStatementMatcher(@NonNull StatementMatcher statementMatcher,
@NonNull StatementMatcherCallback callback) {
mStatementMatchers.add(Pair.create(statementMatcher, callback));
}

Expand All @@ -94,8 +95,8 @@ public void addStatementMatcher(@NotNull StatementMatcher statementMatcher,
* @param sourceURI the initial Asset Links {@link URI}. It must be an absolute {@link URI}.
* @return the first {@link URI} to fetch for {@link #onDocumentLoaded(URI, String)}
*/
@NotNull
public URI start(@NotNull URI sourceURI) {
@NonNull
public URI start(@NonNull URI sourceURI) {
if (!sourceURI.isAbsolute()) {
throw new IllegalArgumentException("Source URI must be absolute");
}
Expand Down Expand Up @@ -126,7 +127,7 @@ public URI start(@NotNull URI sourceURI) {
* @throws MatcherException if any registered {@link StatementMatcher} throws an exception
*/
@Nullable
public URI onDocumentLoaded(@NotNull URI documentURI, @NotNull String document)
public URI onDocumentLoaded(@NonNull URI documentURI, @NonNull String document)
throws IllFormattedStatementException, TooManyIncludesException, MatcherException {
if (mIsError) {
throw new IllegalStateException("AssetLinksJSONParser already in the error state");
Expand Down Expand Up @@ -186,10 +187,10 @@ public URI onDocumentLoaded(@NotNull URI documentURI, @NotNull String document)
}
}

private void parseAssetLinksDocument(@NotNull URI documentURI,
@NotNull String document,
@NotNull ArrayList<JSONObject> statementList,
@NotNull ArrayList<URI> includeList)
private void parseAssetLinksDocument(@NonNull URI documentURI,
@NonNull String document,
@NonNull ArrayList<JSONObject> statementList,
@NonNull ArrayList<URI> includeList)
throws IllFormattedStatementException {
try {
final JSONArray statements = new JSONArray(document); // mandatory top-level array
Expand All @@ -215,9 +216,9 @@ private void parseAssetLinksDocument(@NotNull URI documentURI,
}
}

private void parseIncludeStatement(@NotNull URI documentURI,
@NotNull JSONObject statement,
@NotNull ArrayList<URI> includeList)
private void parseIncludeStatement(@NonNull URI documentURI,
@NonNull JSONObject statement,
@NonNull ArrayList<URI> includeList)
throws JSONException, IllFormattedStatementException {
if (statement.has(AssetLinksGrammar.GRAMMAR_RELATION) ||
statement.has(AssetLinksGrammar.GRAMMAR_TARGET)) {
Expand All @@ -239,8 +240,8 @@ private void parseIncludeStatement(@NotNull URI documentURI,
includeList.add(resolvedURI);
}

private void parseAssetLinkStatement(@NotNull JSONObject statement,
@NotNull ArrayList<JSONObject> statementList)
private void parseAssetLinkStatement(@NonNull JSONObject statement,
@NonNull ArrayList<JSONObject> statementList)
throws JSONException, IllFormattedStatementException {
final JSONArray relations = statement.getJSONArray(AssetLinksGrammar.GRAMMAR_RELATION);
if (relations.length() == 0) {
Expand All @@ -263,7 +264,7 @@ private void parseAssetLinkStatement(@NotNull JSONObject statement,
statementList.add(statement);
}

private void validateWebTarget(@NotNull JSONObject webTarget)
private void validateWebTarget(@NonNull JSONObject webTarget)
throws JSONException, IllFormattedStatementException {
final String site = webTarget.getString(AssetLinksGrammar.GRAMMAR_WEB_SITE);
final URI uri;
Expand All @@ -278,7 +279,7 @@ private void validateWebTarget(@NotNull JSONObject webTarget)
}
}

private void validateAndroidAppTarget(@NotNull JSONObject androidAppTarget)
private void validateAndroidAppTarget(@NonNull JSONObject androidAppTarget)
throws JSONException, IllFormattedStatementException {
final String packageName = androidAppTarget.getString("package_name");
if (!packageName.matches(AssetLinksGrammar.PACKAGE_NAME_PATTERN)) {
Expand All @@ -300,7 +301,7 @@ private void validateAndroidAppTarget(@NotNull JSONObject androidAppTarget)

/** A callback to be invoked when a {@link StatementMatcher} match occurs */
public interface StatementMatcherCallback {
void onMatch(@NotNull StatementMatcher matcher, @NotNull JSONObject o) throws JSONException;
void onMatch(@NonNull StatementMatcher matcher, @NonNull JSONObject o) throws JSONException;
}

/** The base type for all {@link AssetLinksJSONParser} exceptions */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

package com.solana.digitalassetlinks;

import android.util.ArrayMap;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -24,7 +24,7 @@
public class StatementMatcher {
@Nullable private final String mRelation;
@Nullable private final String mTargetNamespace;
@NotNull private final ArrayMap<String, Object> mTargetKeyValues;
@NonNull private final ArrayMap<String, Object> mTargetKeyValues;

/**
* Construct a new {@link StatementMatcher}
Expand All @@ -35,7 +35,7 @@ public class StatementMatcher {
*/
protected StatementMatcher(@Nullable String relation,
@Nullable String targetNamespace,
@NotNull ArrayMap<String, Object> targetKeyValues) {
@NonNull ArrayMap<String, Object> targetKeyValues) {
if (relation != null && !relation.matches(AssetLinksGrammar.RELATION_PATTERN)) {
throw new IllegalArgumentException("relation does not match the expected format");
}
Expand All @@ -51,7 +51,7 @@ protected StatementMatcher(@Nullable String relation,
* @return true if all conditions of this {@link StatementMatcher} are satisfied, else false
* @throws IllegalArgumentException if o is not a well-formed Asset Links statement object
*/
public boolean compare(@NotNull JSONObject o) {
public boolean compare(@NonNull JSONObject o) {
try {
if (mRelation != null) {
final JSONArray relations = o.getJSONArray(AssetLinksGrammar.GRAMMAR_RELATION); // mandatory field
Expand Down Expand Up @@ -138,8 +138,8 @@ public boolean compare(@NotNull JSONObject o) {
}

// Removes default port numbers and the trailing FQDN '.' for comparison purposes
@NotNull
private URI canonicalizeURI(@NotNull URI uri) {
@NonNull
private URI canonicalizeURI(@NonNull URI uri) {
final boolean hasExplicitDefaultPort;
final String scheme = uri.getScheme();
final int port = uri.getPort();
Expand Down Expand Up @@ -181,7 +181,7 @@ private URI canonicalizeURI(@NotNull URI uri) {
* @return a {@link StatementMatcher}
* @throws IllegalArgumentException if site is non-null and fails validation
*/
public static StatementMatcher createWebStatementMatcher(@NotNull String relation,
public static StatementMatcher createWebStatementMatcher(@NonNull String relation,
@Nullable URI site) {
final Builder builder = StatementMatcher.newBuilder()
.setRelation(relation)
Expand Down Expand Up @@ -209,7 +209,7 @@ public static StatementMatcher createWebStatementMatcher(@NotNull String relatio
* @throws IllegalArgumentException if packageName is non-null and fails validation, or if
* sha256CertFingerprint is non-null and fails validation.
*/
public static StatementMatcher createAndroidAppStatementMatcher(@NotNull String relation,
public static StatementMatcher createAndroidAppStatementMatcher(@NonNull String relation,
@Nullable String packageName,
@Nullable String sha256CertFingerprint) {
final Builder builder = StatementMatcher.newBuilder()
Expand Down Expand Up @@ -237,7 +237,7 @@ public static StatementMatcher createAndroidAppStatementMatcher(@NotNull String
* Create a new {@link Builder}
* @return a new {@link Builder}
*/
@NotNull
@NonNull
public static Builder newBuilder() {
return new Builder();
}
Expand All @@ -257,7 +257,7 @@ public int hashCode() {
return Objects.hash(mRelation, mTargetNamespace, mTargetKeyValues);
}

@NotNull
@NonNull
@Override
public String toString() {
return "StatementMatcher{" +
Expand Down Expand Up @@ -285,7 +285,7 @@ public Builder() {}
* @param relation the relation condition for the {@link StatementMatcher}
* @return this {@link Builder}
*/
@NotNull
@NonNull
public Builder setRelation(@Nullable String relation) {
mRelation = relation;
return this;
Expand All @@ -296,7 +296,7 @@ public Builder setRelation(@Nullable String relation) {
* @param targetNamespace the target namespace condition for the {@link StatementMatcher}
* @return this {@link Builder}
*/
@NotNull
@NonNull
public Builder setTargetNamespace(@Nullable String targetNamespace) {
mTargetNamespace = targetNamespace;
return this;
Expand All @@ -308,8 +308,8 @@ public Builder setTargetNamespace(@Nullable String targetNamespace) {
* @param value the target String value of this condition
* @return this {@link Builder}
*/
@NotNull
public Builder setTargetKeyValue(@NotNull String key, @Nullable String value) {
@NonNull
public Builder setTargetKeyValue(@NonNull String key, @Nullable String value) {
return setTargetKeyValue(key, value, false);
}

Expand All @@ -321,8 +321,8 @@ public Builder setTargetKeyValue(@NotNull String key, @Nullable String value) {
* for key
* @return this {@link Builder}
*/
@NotNull
public Builder setTargetKeyValue(@NotNull String key,
@NonNull
public Builder setTargetKeyValue(@NonNull String key,
@Nullable String value,
boolean allowMatchInArray) {
if (value != null) {
Expand All @@ -343,8 +343,8 @@ public Builder setTargetKeyValue(@NotNull String key,
* @param value the target {@link URI} value of this condition
* @return this {@link Builder}
*/
@NotNull
public Builder setTargetKeyValue(@NotNull String key, @Nullable URI value) {
@NonNull
public Builder setTargetKeyValue(@NonNull String key, @Nullable URI value) {
if (value != null) {
mKeyValues.put(key, value);
} else {
Expand All @@ -357,17 +357,17 @@ public Builder setTargetKeyValue(@NotNull String key, @Nullable URI value) {
* Construct a new {@link StatementMatcher} from the current state of this {@link Builder}
* @return a new {@link StatementMatcher}
*/
@NotNull
@NonNull
public StatementMatcher build() {
return new StatementMatcher(mRelation, mTargetNamespace, mKeyValues);
}
}

private static final class AllowMatchInArray {
@NotNull
@NonNull
public final String value;

public AllowMatchInArray(@NotNull String value) {
public AllowMatchInArray(@NonNull String value) {
this.value = value;
}
}
Expand Down
Loading

0 comments on commit 3b65937

Please sign in to comment.