Skip to content

Commit

Permalink
Fix issues with minify and ProGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Dec 23, 2023
1 parent d410429 commit 1594355
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
3 changes: 1 addition & 2 deletions demo/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,5 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("androidx.lifecycle:lifecycle-extensions:2.1.0")
implementation("androidx.preference:preference:1.1.1")
implementation("junit:junit:4.12")
implementation("org.hamcrest:hamcrest-library:2.2")
implementation("junit:junit:4.13.2")
}
54 changes: 54 additions & 0 deletions product/runtime/src/test/java/com/chaquo/java/MatchesPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.chaquo.java;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import java.util.regex.Pattern;


/** Copied from Hamcrest 2, which doesn't interact well with JUnit 4 and ProGuard
* ("Missing class org.hamcrest.Factory"). */
public class MatchesPattern extends TypeSafeMatcher<String> {

private final Pattern pattern;

public MatchesPattern(Pattern pattern) {
this.pattern = pattern;
}

@Override
protected boolean matchesSafely(String item) {
return pattern.matcher(item).matches();
}

@Override
public void describeTo(Description description) {
description.appendText("a string matching the pattern '" + pattern + "'");
}

/**
* Creates a matcher of {@link java.lang.String} that matches when the examined string
* exactly matches the given {@link java.util.regex.Pattern}.
*
* @param pattern
* the text pattern to match.
* @return The matcher.
*/
public static Matcher<String> matchesPattern(Pattern pattern) {
return new MatchesPattern(pattern);
}

/**
* Creates a matcher of {@link java.lang.String} that matches when the examined string
* exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}.
*
* @param regex
* the regex to match.
* @return The matcher.
*/
public static Matcher<String> matchesPattern(String regex) {
return new MatchesPattern(Pattern.compile(regex));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.junit.rules.*;
import org.junit.runners.*;

import static com.chaquo.java.MatchesPattern.matchesPattern;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsInstanceOf.any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ def test_catch(self):


def trace_line(method):
# In AGP 8.2, ProGuard renames all Java source files to "SourceFile".
return (r"\s*at com.chaquo.python.TestException." + method +
r"\(TestException.java:[0-9]+\)\s*")
r"\(.+:[0-9]+\)\s*")
4 changes: 3 additions & 1 deletion product/runtime/src/test/python/chaquopy/test/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ def fnf(self):
fnf_frames = [
("<python>.chaquopy.test.test_proxy", "fnf", "test_proxy.py", ref_line_no + 3),
("com.chaquo.python.PyObject", "callAttrThrows", None, None),
("com.chaquo.python.PyInvocationHandler", "invoke", "PyInvocationHandler.java", None)]

# In AGP 8.2, ProGuard renames all Java source files to "SourceFile".
("com.chaquo.python.PyInvocationHandler", "invoke", None, None)]

def assertFnfThrows(message, throw_cls, catch_cls=None, check_cause=False):
if catch_cls is None:
Expand Down

0 comments on commit 1594355

Please sign in to comment.