Skip to content

Commit 5f02efc

Browse files
committed
Add CI and dependabot configuration, fix broken builds
Besides a few minor clippy lints, the documentation for this crate was completely stale and not compiling. By testing this in CI we ensure users will be able to run the code that we provide to them. Note that strangely most functions in the "builder pattern" `Intent` are suffixed `with_` (because they _move_ `Intent`) except `set_class_name()` and `into_chooser(_with_title)()`. Is this intended or an oversight?
1 parent 7c11519 commit 5f02efc

File tree

5 files changed

+76
-16
lines changed

5 files changed

+76
-16
lines changed

.github/dependabot.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
- package-ecosystem: github-actions
8+
directory: "/.github/workflows/"
9+
schedule:
10+
interval: weekly

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
push:
3+
pull_request:
4+
5+
jobs:
6+
rust:
7+
name: Lint Rust code
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- run: rustup target add aarch64-linux-android
12+
- name: Cargo fmt
13+
run: cargo fmt --all -- --check
14+
- name: Cargo clippy
15+
run: cargo clippy --workspace --all-targets --target aarch64-linux-android -- -D warnings
16+
- name: Cargo build-test docs
17+
# Must build _for_ the host as --target makes this a no-op
18+
run: cargo test --doc
19+
- name: Test documentation
20+
env:
21+
RUSTDOCFLAGS: -Dwarnings
22+
run: cargo doc --workspace --target aarch64-linux-android
23+
24+
rust-msrv:
25+
name: Build-test MSRV (1.80) with minimal crate dependencies
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: dtolnay/rust-toolchain@nightly
30+
- name: Generate minimal-version dependencies
31+
run: cargo -Zminimal-versions generate-lockfile
32+
- uses: dtolnay/rust-toolchain@1.80.0
33+
with:
34+
targets: aarch64-linux-android
35+
- name: Cargo check
36+
run: cargo check --workspace --exclude intent-example --all-targets --target aarch64-linux-android

.github/workflows/publish.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
paths: "/Cargo.toml"
7+
8+
jobs:
9+
Publish:
10+
if: github.repository_owner == 'Traverse-Research'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Publish
15+
run: cargo publish --token ${{ secrets.cratesio_token }}

src/intent.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use jni::{
2-
errors::Error,
3-
objects::{JObject, JString},
4-
JNIEnv,
5-
};
1+
use jni::{errors::Error, objects::JObject, JNIEnv};
62

73
struct Inner<'env> {
84
env: JNIEnv<'env>,
@@ -33,8 +29,7 @@ impl<'env> Intent<'env> {
3329
let action_view =
3430
env.get_static_field(intent_class, action.as_ref(), "Ljava/lang/String;")?;
3531

36-
let intent =
37-
env.new_object(intent_class, "(Ljava/lang/String;)V", &[action_view.into()])?;
32+
let intent = env.new_object(intent_class, "(Ljava/lang/String;)V", &[action_view])?;
3833

3934
Ok(Inner {
4035
env,
@@ -51,7 +46,7 @@ impl<'env> Intent<'env> {
5146
uri_class,
5247
"parse",
5348
"(Ljava/lang/String;)Landroid/net/Uri;",
54-
&[JString::from(url_string).into()],
49+
&[url_string.into()],
5550
)?;
5651

5752
let intent_class = env.find_class("android/content/Intent")?;
@@ -61,7 +56,7 @@ impl<'env> Intent<'env> {
6156
let intent = env.new_object(
6257
intent_class,
6358
"(Ljava/lang/String;Landroid/net/Uri;)V",
64-
&[action_view.into(), uri.into()],
59+
&[action_view, uri],
6560
)?;
6661

6762
Ok(Inner {
@@ -77,10 +72,14 @@ impl<'env> Intent<'env> {
7772
///
7873
/// # android_intent::with_current_env(|env| {
7974
/// let intent = Intent::new(env, Action::Send);
80-
/// intent.set_class_name("com.excample", "IntentTarget")
75+
/// let intent = intent.set_class_name("com.excample", "IntentTarget");
8176
/// # })
8277
/// ```
83-
pub fn set_class_name(self, package_name: impl AsRef<str>, class_name: impl AsRef<str>) -> Self {
78+
pub fn set_class_name(
79+
self,
80+
package_name: impl AsRef<str>,
81+
class_name: impl AsRef<str>,
82+
) -> Self {
8483
self.and_then(|inner| {
8584
let package_name = inner.env.new_string(package_name)?;
8685
let class_name = inner.env.new_string(class_name)?;
@@ -102,7 +101,7 @@ impl<'env> Intent<'env> {
102101
///
103102
/// # android_intent::with_current_env(|env| {
104103
/// let intent = Intent::new(env, Action::Send);
105-
/// intent.push_extra(Extra::Text, "Hello World!")
104+
/// let intent = intent.with_extra(Extra::Text, "Hello World!");
106105
/// # })
107106
/// ```
108107
pub fn with_extra(self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
@@ -121,12 +120,12 @@ impl<'env> Intent<'env> {
121120
})
122121
}
123122

124-
/// Builds a new [`Action::Chooser`] Intent that wraps the given target intent.
123+
/// Builds a new [`super::Action::Chooser`] Intent that wraps the given target intent.
125124
/// ```no_run
126125
/// use android_intent::{Action, Intent};
127126
///
128127
/// # android_intent::with_current_env(|env| {
129-
/// let intent = Intent::new(env, Action::Send).into_chhoser();
128+
/// let intent = Intent::new(env, Action::Send).into_chooser();
130129
/// # })
131130
/// ```
132131
pub fn into_chooser(self) -> Self {
@@ -161,7 +160,7 @@ impl<'env> Intent<'env> {
161160
///
162161
/// # android_intent::with_current_env(|env| {
163162
/// let intent = Intent::new(env, Action::Send);
164-
/// intent.set_type("text/plain");
163+
/// let intent = intent.with_type("text/plain");
165164
/// # })
166165
/// ```
167166
pub fn with_type(self, type_name: impl AsRef<str>) -> Self {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ pub fn with_current_env(f: impl FnOnce(JNIEnv)) {
1414
let vm = unsafe { JavaVM::from_raw(cx.vm().cast()) }.unwrap();
1515
let env = vm.attach_current_thread().unwrap();
1616

17-
f(env.clone());
17+
f(*env);
1818
}

0 commit comments

Comments
 (0)