Skip to content

Commit

Permalink
Remove transitive dependencies on kotlin stdlib (via androidx)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlaver committed Jul 9, 2022
1 parent 556a90a commit a405295
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 119 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 {
implementation 'androidx.annotation:annotation:1.4.0'
implementation 'androidx.collection:collection:1.2.0'
compileOnly 'org.jetbrains:annotations:23.0.0'
testCompileOnly 'org.jetbrains:annotations:23.0.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,8 +9,7 @@
import android.content.pm.Signature;
import android.os.Build;

import androidx.annotation.NonNull;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;

Expand All @@ -30,7 +29,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(@NonNull PackageManager pm) {
public AndroidAppPackageVerifier(@NotNull PackageManager pm) {
mPackageManager = pm;
}

Expand All @@ -51,7 +50,7 @@ public AndroidAppPackageVerifier(@NonNull 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(@NonNull String packageName, @NonNull URI uri)
public boolean verify(@NotNull String packageName, @NotNull URI uri)
throws CouldNotVerifyPackageException {
if (!"https".equalsIgnoreCase(uri.getScheme())) {
throw new CouldNotVerifyPackageException(
Expand Down Expand Up @@ -145,9 +144,9 @@ public boolean verify(@NonNull String packageName, @NonNull URI uri)
return result;
}

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

@NonNull
@NotNull
private static byte[] convertSHA256CertFingerprintStringToByteArray(
@NonNull String sha256CertFingerprint) {
@NotNull 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 androidx.annotation.NonNull;
import org.jetbrains.annotations.NotNull;

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(@NonNull URI uri) {
public static boolean isValidSiteURI(@NotNull 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,9 +7,8 @@
import android.util.Log;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -46,7 +45,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.
*/
@NonNull
@NotNull
public List<URI> getURIs() {
return Collections.unmodifiableList(mURIs);
}
Expand Down Expand Up @@ -85,8 +84,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(@NonNull StatementMatcher statementMatcher,
@NonNull StatementMatcherCallback callback) {
public void addStatementMatcher(@NotNull StatementMatcher statementMatcher,
@NotNull StatementMatcherCallback callback) {
mStatementMatchers.add(Pair.create(statementMatcher, callback));
}

Expand All @@ -95,8 +94,8 @@ public void addStatementMatcher(@NonNull 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)}
*/
@NonNull
public URI start(@NonNull URI sourceURI) {
@NotNull
public URI start(@NotNull URI sourceURI) {
if (!sourceURI.isAbsolute()) {
throw new IllegalArgumentException("Source URI must be absolute");
}
Expand Down Expand Up @@ -127,7 +126,7 @@ public URI start(@NonNull URI sourceURI) {
* @throws MatcherException if any registered {@link StatementMatcher} throws an exception
*/
@Nullable
public URI onDocumentLoaded(@NonNull URI documentURI, @NonNull String document)
public URI onDocumentLoaded(@NotNull URI documentURI, @NotNull String document)
throws IllFormattedStatementException, TooManyIncludesException, MatcherException {
if (mIsError) {
throw new IllegalStateException("AssetLinksJSONParser already in the error state");
Expand Down Expand Up @@ -187,10 +186,10 @@ public URI onDocumentLoaded(@NonNull URI documentURI, @NonNull String document)
}
}

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

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

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

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

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

/** A callback to be invoked when a {@link StatementMatcher} match occurs */
public interface StatementMatcherCallback {
void onMatch(@NonNull StatementMatcher matcher, @NonNull JSONObject o) throws JSONException;
void onMatch(@NotNull StatementMatcher matcher, @NotNull 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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
import android.util.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;
@NonNull private final ArrayMap<String, Object> mTargetKeyValues;
@NotNull 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,
@NonNull ArrayMap<String, Object> targetKeyValues) {
@NotNull 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(@NonNull JSONObject o) {
public boolean compare(@NotNull 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(@NonNull JSONObject o) {
}

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

@NonNull
@NotNull
@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}
*/
@NonNull
@NotNull
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}
*/
@NonNull
@NotNull
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}
*/
@NonNull
public Builder setTargetKeyValue(@NonNull String key, @Nullable String value) {
@NotNull
public Builder setTargetKeyValue(@NotNull String key, @Nullable String value) {
return setTargetKeyValue(key, value, false);
}

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

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

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

0 comments on commit a405295

Please sign in to comment.