aboutsummaryrefslogtreecommitdiff
path: root/CONTRIBUTING.md
blob: 73b0b8f7db2c787795a3efd4bcfc229c935c1a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Jni-rs Contribution Guide

Jni-rs is open to any contributions, whether
it is a feedback on existing features, a request for a new one, a bug report
or a pull request. This document describes how to work with this project:

* how to [build](#how-to-build) it
* how to [test](#tests) it
* the [code style guidelines](#the-code-style)
* how to [submit an issue](#submitting-issues)
* how to [submit a PR](#submitting-pull-requests).

## How to Build

### System Dependencies

You need to install the following dependencies:

* [JDK 1.8+](http://jdk.java.net/10/).
* [Rust (latest stable)](https://www.rust-lang.org/).

### Building

To build `jni-rs`, simply run

```$sh
cargo build
```

inside project root directory. You can also build the library in release mode by
adding `--release` flag.

## Tests

### Categories of Tests

* Unit tests are typically placed at the bottom of their module file.
  E.g. [unit tests of signature module](src/wrapper/signature.rs). Tests are wrapped
  in private module with `test` attribute:

  ```rust
  #[cfg(test)]
  mod test {
    use super::*;

    #[test]
    fn first_test() { /* ... */ }

    // More tests...
  }
  ```

* Integration tests are in [tests directory](tests). They use the same pattern as
  unit tests, but split into several files instead of private modules.
  Integration tests use `jni-rs` as every other Rust application — by importing
  library using `extern crate` keyword.

  ```rust
    extern crate jni;
    use jni::*;
  ```

  Integration tests typically require running a JVM, so you should add
  `#![cfg(feature = "invocation")]` at the top of the file. You can use helper
  methods from [util module](tests/util/mod.rs) to run JVM.

  Keep in mind, that only one JVM can be run per process. Therefore, tests that
  need to launch it with different parameters have to be placed in different
  source files. `Cargo` runs tests from different modules in parallel.

* Benchmarks are in [benches](benches) directory. As integration tests, they
  require launching a JVM from native.

* Doc tests are rarely used, but they allow to efficiently test some functionality
  by providing an example of its usage. Consult
  [Rust documentation](https://doc.rust-lang.org/beta/rustdoc/documentation-tests.html)
  for more info about writing these tests.

### Running Tests

#### Setup Environment

As some tests need to launch a JVM, add a directory with JVM library that you want
to use to `LD_LIBRARY_PATH` on Linux/Mac or `PATH` environment variable on Windows.
On Linux/Mac, you can use the following script for this purpose:

```$sh
source test_profile
```

#### Run Tests

To run all tests, execute the following command:

```$sh
cargo test --features=invocation
```

This command will run all tests, including unit, integration and documentation
tests.

#### Run Benchmarks

To run all benchmarks, execute the following command (nightly Rust required):

```$sh
cargo +nightly bench --features=invocation
```

They might help you to see the performance differences between
two [API flavours][checked-unchecked]: checked and unchecked, and
pick the right one for your application.

[checked-unchecked]: https://docs.rs/jni/0.19.0/jni/struct.JNIEnv.html#checked-and-unchecked-methods

## The Code Style

Rust code follows the [Rust style guide](https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md).
[`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) enforces the code style.

After installation, you can run it with

```$sh
cargo fmt --all -- --check
```

Every public entry of the API must be thoroughly documented and covered with tests if it is possible.
You can use [JNI specification](https://docs.oracle.com/javase/10/docs/specs/jni/index.html) as
a reference for how to write detailed documentation.

Do not forget to update project guides and tutorials along with documentation.

To open local documentation of the project, you can use the following command:

```$sh
cargo doc --open
```

## Submitting Issues

Use Github Issues to submit an issue, whether it is a question, some feedback, a bug or a feature request: <https://github.com/jni-rs/jni-rs/issues/new>

## Submitting Pull Requests

Before starting to work on a PR, please submit an issue describing the intended changes.
Chances are — we are already working on something similar. If not — we can then offer some
help with the requirements, design, implementation or documentation.

It’s fine to open a PR as soon as you need any feedback — ask any questions in the description.

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
  <http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
  at your option.

### Contributor License Agreement

Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion is the work by you, as defined in the
Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.