Skip to content

Commit 3d76e6a

Browse files
authored
Merge pull request #72 from google/closure
Add Closure JS implementation
2 parents 13c805e + 8a0939e commit 3d76e6a

File tree

15 files changed

+1303
-102
lines changed

15 files changed

+1303
-102
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore backup and swap files.
2+
*~
3+
.*.swp
4+
# Ignore all bazel-* links.
5+
/bazel-*
6+
# Ignore outputs generated during Bazel bootstrapping.
7+
/output/

CONTRIBUTING.md

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,72 @@
1-
Want to contribute? Great! First, read this page (including the small print at the end).
2-
3-
## Before you contribute
4-
Before we can use your code, you must sign the
5-
[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
6-
(CLA), which you can do online.
7-
8-
The CLA is necessary mainly because you own the
9-
copyright to your changes, even after your contribution becomes part of our
10-
codebase, so we need your permission to use and distribute your code. We also
11-
need to be sure of various other things—for instance that you'll tell us if you
12-
know that your code infringes on other people's patents.
13-
14-
You don't have to sign
15-
the CLA until after you've submitted your code for review and a member has
16-
approved it, but you must do it before we can put your code into our codebase.
17-
Before you start working on a larger contribution, you should get in touch with
18-
us first through the issue tracker with your idea so that we can help out and
19-
possibly guide you. Coordinating up front makes it much easier to avoid
20-
frustration later on.
21-
22-
## Writing a new implementation
23-
24-
Before you start writing a new implementation, look at some of the existing ones. If you copy the
25-
code structure from them, you are more likely to have fewer bugs and an easier review cycle.
26-
27-
If you create new algorithms to encode or decode, then your reviewer will have to spend more time
28-
trying to understand your code in a language they may not be familiar with, and the review cycle
29-
will take longer.
30-
31-
The reason we say this is because once code is accepted into our repository, we have the responsibility
32-
to maintain and look after it. You are not writing the code for you, but for the OLC project team.
33-
34-
## Code reviews
35-
All submissions, including submissions by project members, require review. We
36-
use Github pull requests for this purpose.
37-
38-
## Code Style
39-
Programs written in Go must be formatted with `gofmt`. For other languages, we use the
40-
[Google style guides](https://google.github.io/styleguide/) for code styling. Specifically, this means:
41-
42-
* Line length: 80 chars (Java 100)
43-
* No extra whitespace around arguments `(code)` not `( code )`
44-
* K & R style braces:
45-
```java
46-
if (condition()) {
47-
something();
48-
} else {
49-
somethingElse();
50-
}
51-
```
52-
53-
## The small print
54-
Contributions made by corporations are covered by a different agreement than
55-
the one above, the Software Grant and Corporate Contributor License Agreement.
1+
# Contributing to Open Location Code
2+
3+
The Open Location Code project strongly encourages technical contributions.
4+
5+
We hope you'll become an ongoing participant in our open source community but we also welcome one-off contributions for the issues you're particularly passionate about.
6+
7+
- [Filing issues](#filing-issues)
8+
* [Bugs](#bugs)
9+
* [Suggestions](#suggestions)
10+
- [Contributing code](#contributing-code)
11+
- [Contributing a new implementation](#contributing-a-new-implementation)
12+
- [Contributor License Agreement](#contributor-license-agreement)
13+
- [Ongoing participation](#ongoing-participation)
14+
* [Discussion channels](#discussion-channels)
15+
16+
## Filing issues
17+
18+
### Bugs
19+
20+
If you find a bug in an Open Location Code library, please [file an issue](https://github.com/google/open-location-code/issues/new). Members of the community are regularly monitoring issues and will try to fix open bugs quickly.
21+
22+
The best bug reports provide a detailed description of the issue, step-by-step instructions for predictably reproducing the issue, and possibly even a working example that demonstrates the issue.
23+
24+
Please note that questions about how to use Open Location Code or other general questions should be asked on the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code)<!-- Uncomment if this becomes sensible --><!-- or [Stack Overflow under the Open Location Code tag](http://stackoverflow.com/questions/tagged/open-location-code) -->
25+
instead of filing an issue here.
26+
27+
### Suggestions
28+
29+
The Open Location Code project is meant to evolve with feedback. The project and its users appreciate your thoughts on ways to improve the design or features or creative ways to use the codes.
30+
31+
To make a suggestion [file an issue](https://github.com/google/open-location-code/issues/new).
32+
33+
If you are intending to implement, please see the [Contributing code](#contributing-code) section below for next steps.
34+
35+
If you are adding Open Location Codes to your project, please contact the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code) so we can suggest how you can make the most of the codes.
36+
37+
## Contributing code
38+
39+
The Open Location Code project accepts and greatly appreciates code contributions!
40+
41+
If you are contributing code to the project consider [joining the Open Location Code project on GitHub](https://goo.gl/forms/T65peVtfQfEoDWeD3).
42+
43+
A few things to note:
44+
45+
* The Open Location Code project follows the [fork & pull](https://help.github.com/articles/using-pull-requests/#fork--pull) model for accepting contributions.
46+
* We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html). More generally make sure to follow the same comment and coding style as the rest of the project.
47+
* Include [tests](TESTING.md) when contributing code. There are tests that you can use as examples.
48+
49+
## Contributing a new implementation
50+
51+
Follow this process for contributing a new implementation:
52+
53+
* Look at the existing implementations, to get an idea of the usage and how much work is involved.
54+
* If you copy the code structure and algorithms from an existing implementation, you'll have a much shorter review cycle.
55+
* [Create a new GitHub issue](https://github.com/google/open-location-code/issues/new) to start discussion of the new feature.
56+
* Follow the guidelines for [Contributing code](#contributing-code) described above.
57+
58+
## Contributor License Agreement
59+
60+
The Open Location Code project hosted at GitHub requires all contributors to sign a Contributor License Agreement ([individual](https://developers.google.com/open-source/cla/individual) or [corporation](https://developers.google.com/open-source/cla/corporate)) in order to protect contributors, users and Google in issues of intellectual property.
61+
62+
When you create a Pull Request a check will be run to ensure that you have signed the CLA. Make sure that you sign the CLA with the same email address you associate with your commits (likely via the `user.email` Git config as described on GitHub's [Set up Git](https://help.github.com/articles/set-up-git/) page).
63+
64+
## Ongoing participation
65+
66+
We actively encourage ongoing participation by community members.
67+
68+
### Discussion channels
69+
70+
Technical issues, designs, etc. are discussed on [GitHub issues](https://github.com/google/open-location-code/issues) and [pull requests](https://github.com/google/open-location-code/pulls),
71+
or the [Open Location Code Google Group](https://groups.google.com/forum/#!forum/open-location-code)<!-- Uncomment if this becomes sensible --><!-- and [Stack Overflow under the Open Location Code tag](http://stackoverflow.com/questions/tagged/open-location-code) -->.
72+

TESTING.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
# Automated Integration Testing
1+
# Testing
2+
The preferred mechanism for testing is using the [Bazel](https://bazel.build/)
3+
build system. This uses files called `BUILD` ([example](https://github.com/google/open-location-code/blob/master/BUILD)
4+
to provide rules to build code and run tests.
5+
6+
Create a `BUILD` file in your code directory with a [test rule](https://bazel.build/versions/master/docs/test-encyclopedia.html).
7+
You can then test your code by running:
8+
9+
```sh
10+
blaze test <dir>:<rule>
11+
```
12+
13+
All tests can be run with:
14+
15+
```sh
16+
blaze test ...:all
17+
```
18+
19+
## Automated Integration Testing
220
Changes are sent to [Travis CI](https://travis-ci.org)
321
for integration testing after pushes, and you can see the current test status
422
[here](https://travis-ci.org/google/open-location-code).
523

624
The testing configuration is controlled by two files:
725
[`travis.yml`](.travis.yml) and [`run_tests.sh`](run_tests.sh).
826

9-
## [.travis.yml](.travis.yml)
27+
### [.travis.yml](.travis.yml)
1028
This file defines the prerequisites required for testing, and the list of
1129
directories to be tested. (The directories listed are tested in parallel.)
1230

1331
The same script ([run_tests.sh](run_tests.sh)) is executed for all directories.
1432

15-
## [run_tests.sh](run_tests.sh)
33+
### [run_tests.sh](run_tests.sh)
1634
This file is run once for _each_ directory defined in
1735
`.travis.yml`. The directory name being tested is passed in the environment
1836
variable `TEST_DIR`.)
@@ -23,7 +41,7 @@ commands to test the relevant implementation. The commands that do the testing
2341
return zero, even if they output error messages, will be considered by the
2442
testing framework as a success_.
2543

26-
## Adding Your Tests
44+
### Adding Your Tests
2745
Add your directory to the [`.travis.yml`](.travis.yml) file:
2846
```
2947
# Define the list of directories to execute tests in.
@@ -49,7 +67,7 @@ the script will return the same status as the tests. If this status is zero,
4967
the test will be marked successful. If not, the test will be marked as a
5068
failure.
5169

52-
## Testing Multiple Languages
70+
### Testing Multiple Languages
5371
[Travis CI](https://travis-ci.org) assumes that each github project has only
5472
a single language. That language is specified in the [.travis.yml](.travis.yml)
5573
file (`language: node_js`).

WORKSPACE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
workspace(name = "openlocationcode")
2+
3+
# Include the Google Test framework for C++ testing.
4+
# See https://github.com/google/googletest
5+
new_http_archive(
6+
name = "gtest",
7+
url = "https://github.com/google/googletest/archive/release-1.8.0.zip",
8+
sha256 = "f3ed3b58511efd272eb074a3a6d6fb79d7c2e6a0e374323d1e6bcbcc1ef141bf",
9+
build_file = "cpp/gtest.BUILD",
10+
strip_prefix = "googletest-release-1.8.0/googletest",
11+
)
12+
13+
# Include the Bazel Closure rules for javascript testing..
14+
# See https://github.com/bazelbuild/rules_closure
15+
http_archive(
16+
name = "io_bazel_rules_closure",
17+
url = "http://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.4.1.tar.gz",
18+
sha256 = "ba5e2e10cdc4027702f96e9bdc536c6595decafa94847d08ae28c6cb48225124",
19+
strip_prefix = "rules_closure-0.4.1",
20+
)
21+
22+
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
23+
24+
closure_repositories()
25+

cpp/WORKSPACE

Lines changed: 0 additions & 9 deletions
This file was deleted.

java/BUILD

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
java_library(
3+
name = "openlocationcode",
4+
srcs = [
5+
"com/google/openlocationcode/OpenLocationCode.java",
6+
],
7+
)
8+
9+
java_test(
10+
name = "encoding_Test",
11+
srcs = [
12+
"com/google/openlocationcode/tests/EncodingTest.java",
13+
],
14+
test_class = "com.google.openlocationcode.tests.EncodingTest",
15+
size = "small",
16+
deps = [
17+
":openlocationcode",
18+
],
19+
data = [
20+
"//test_data:test_data"
21+
],
22+
)
23+
24+
java_test(
25+
name = "precision_test",
26+
srcs = [
27+
"com/google/openlocationcode/tests/PrecisionTest.java",
28+
],
29+
test_class = "com.google.openlocationcode.tests.PrecisionTest",
30+
size = "small",
31+
deps = [
32+
":openlocationcode",
33+
],
34+
data = [
35+
"//test_data:test_data"
36+
],
37+
)
38+
39+
java_test(
40+
name = "shortening_test",
41+
srcs = [
42+
"com/google/openlocationcode/tests/ShorteningTest.java",
43+
],
44+
test_class = "com.google.openlocationcode.tests.ShorteningTest",
45+
size = "small",
46+
deps = [
47+
":openlocationcode",
48+
],
49+
data = [
50+
"//test_data:test_data"
51+
],
52+
)
53+
54+
java_test(
55+
name = "validity_test",
56+
srcs = [
57+
"com/google/openlocationcode/tests/ValidityTest.java",
58+
],
59+
test_class = "com.google.openlocationcode.tests.ValidityTest",
60+
size = "small",
61+
deps = [
62+
":openlocationcode",
63+
],
64+
data = [
65+
"//test_data:test_data"
66+
],
67+
)

java/README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
# Java Open Location Code library
22

3-
## Building
3+
## Building and Testing
44

5-
Create an empty `build` directory:
5+
Included is a `BUILD` file that uses the [Bazel](https://bazel.build/) build system to produce a JAR file and to run tests. You will need to install Bazel on your system to run the tests.
66

7-
```shell
8-
mkdir build
9-
```
7+
### Building the JAR file
108

11-
Compile the `com/google/openlocationcode/OpenLocationCode.java` file and then
12-
package it as a jar file:
9+
To build a JAR file, run:
1310

14-
```shell
15-
javac -d build com/google/openlocationcode/OpenLocationCode.java
16-
cd build
17-
jar cvf OpenLocationCode.jar com/google/openlocationcode/OpenLocationCode*.class
18-
cd ..
1911
```
20-
That's it - you'll have a jar file in `build/OpenLocationCode.jar`.
12+
$ bazel build java:openlocationcode
13+
INFO: Found 1 target...
14+
Target //java:openlocationcode up-to-date:
15+
bazel-bin/java/libopenlocationcode.jar
16+
INFO: Elapsed time: 3.107s, Critical Path: 0.22s
17+
$
18+
```
2119

22-
## Testing
20+
The JAR file is accessable using the path shown in the output.
2321

24-
Download the `junit` and `hamcrest` jar files from [their repository](https://github.com/junit-team/junit4/wiki/Download-and-Install)
25-
and place them somewhere.
22+
If you cannot install Bazel, you can build the JAR file manually with:
2623

27-
(This will assume you downloaded `junit-41.2.jar` and `hamcrest-core-1.3.jar`)
24+
```
25+
mkdir build
26+
javac -d build com/google/openlocationcode/OpenLocationCode.java
27+
```
2828

29-
Build the `OpenLocationCode.jar` file as above.
29+
This will create a JAR file in the `build` directory. Change that to a suitable location.
3030

31-
Add all three files to your `CLASSPATH` variable (obviously use the real paths to the files):
31+
### Running tests
3232

33-
```shell
34-
CLASSPATH=$CLASSPATH:build/OpenLocationCode.jar:/path/to/junit-4.12.jar:/path/to/hamcrest-core-1.3.jar
35-
```
33+
The tests read their data from the [`test_data`](https://github.com/google/open-location-code/tree/master/test_data) directory.
3634

37-
Compile the test classes:
35+
Run the tests from the top-level github directory. This command will build the JAR file and test classes, and execute them:
3836

39-
```shell
40-
javac -cp $CLASSPATH -d build com/google/openlocationcode/tests/*java
4137
```
42-
43-
Run the tests. Note that we need to use the `-cp` argument to give the location of the test classes and the test data files:
44-
45-
```shell
46-
java -cp $CLASSPATH:build:../test_data: org.junit.runner.JUnitCore com.google.openlocationcode.tests.EncodingTest com.google.openlocationcode.tests.PrecisionTest com.google.openlocationcode.tests.ShorteningTest com.google.openlocationcode.tests.ValidityTest
38+
$ bazel test java:all
39+
INFO: Found 1 target and 4 test targets...
40+
INFO: Elapsed time: 0.657s, Critical Path: 0.46s
41+
//java:encoding_Test PASSED in 0.4s
42+
//java:precision_test PASSED in 0.4s
43+
//java:shortening_test PASSED in 0.4s
44+
//java:validity_test PASSED in 0.4s
45+
46+
Executed 4 out of 4 tests: 4 tests pass.
47+
$
4748
```
49+

java/com/google/openlocationcode/tests/EncodingTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.junit.Test;
88

99
import java.io.BufferedReader;
10+
import java.io.File;
11+
import java.io.FileInputStream;
1012
import java.io.InputStream;
1113
import java.io.InputStreamReader;
1214
import java.util.ArrayList;
@@ -46,7 +48,8 @@ public TestData(String line) {
4648

4749
@Before
4850
public void setUp() throws Exception {
49-
InputStream testDataStream = ClassLoader.getSystemResourceAsStream("encodingTests.csv");
51+
File testFile = new File(System.getenv("JAVA_RUNFILES"), "openlocationcode/test_data/encodingTests.csv");
52+
InputStream testDataStream = new FileInputStream(testFile);
5053
BufferedReader reader = new BufferedReader(new InputStreamReader(testDataStream));
5154
String line;
5255
while ((line = reader.readLine()) != null) {

0 commit comments

Comments
 (0)