|
1 | 1 | # How to become a contributor and submit your own code |
2 | 2 |
|
3 | 3 | * [Contributor License Agreements](#Contributor-License-Agreements) |
4 | | -* [Contributing a Patch](#Contributing-a-Patch) |
5 | | -* [Contributing a new sample](#Contributing-a-new-sample) |
| 4 | +* [Contributing a Patch or New Sample](#Contributing-a-Patch) |
6 | 5 | * [Build Tools](#build-tools) |
7 | 6 | * [Integration Testing](#testing) |
8 | 7 | * [Style](#Style) |
@@ -26,32 +25,37 @@ Follow either of the two links above to access the appropriate CLA and |
26 | 25 | instructions for how to sign and return it. Once we receive it, we'll be able to |
27 | 26 | accept your pull requests. |
28 | 27 |
|
29 | | -## Contributing a Patch |
| 28 | +## Contributing a Patch or New Sample |
30 | 29 |
|
31 | | -1. Submit an issue describing your proposed change to the repo in question. |
32 | | -1. The repo owner will respond to your issue promptly. |
33 | | -1. If your proposed change is accepted, and you haven't already done so, sign a |
34 | | - Contributor License Agreement (see details above). |
35 | | -1. Fork the desired repo, develop and test your code changes. |
36 | | -1. Ensure that your code adheres to the existing style in the sample to which |
37 | | - you are contributing. |
| 30 | +1. Sign a [Contributor License Agreement](#Contributor-License-Agreements). |
| 31 | +1. Set up your [Java Developer Environment](https://cloud.google.com/java/docs/setup). |
| 32 | +1. Fork the repo. |
| 33 | +1. Develop and test your code. |
| 34 | +1. Ensure that your code adheres to the [SAMPLE_FORMAT.md](SAMPLE_FORMAT.md) |
| 35 | +guidelines. |
38 | 36 | 1. Ensure that your code has an appropriate set of unit tests which all pass. |
39 | 37 | 1. Submit a pull request. |
| 38 | +1. A maintainer will review the pull request and make comments. |
40 | 39 |
|
41 | | -## Contributing a new sample |
| 40 | +## Build Tools |
42 | 41 |
|
43 | | -1. See the [SAMPLE_FORMAT.md](SAMPLE_FORMAT.md) for guidelines on the preferred sample format. |
| 42 | + All new samples should build and run integration tests with both [Maven](https://maven.apache.org/) and [Gradle](https://gradle.org/). |
44 | 43 |
|
| 44 | +## Integration Testing |
45 | 45 |
|
46 | | -## Build Tools |
| 46 | +All samples must have Integration Tests that run with Maven and Gradle |
47 | 47 |
|
48 | | -For instructions regarding development environment setup, please visit [the documentation](https://cloud.google.com/java/docs/setup). All new samples should build and run integration tests with both [Maven](https://maven.apache.org/) and [Gradle](https://gradle.org/). |
| 48 | +* Test Library: [JUnit4](https://junit.org/junit4/) |
| 49 | +* Test Runner: [Maven Failsafe plugin](https://maven.apache.org/surefire/maven-failsafe-plugin/) and [Maven Surefire plugin](https://maven.apache.org/surefire/maven-surefire-plugin/). |
49 | 50 |
|
50 | | -## Testing |
| 51 | +### Running Tests Locally |
51 | 52 |
|
52 | | -All samples must have Integration Tests (ie. They need to run against a real service) that run with |
53 | | -`mvn verify` & `gradle build test`. If we need to enable an API, let us know. |
| 53 | +Run tests locally with commands: |
| 54 | +* Maven: `mvn verify` |
| 55 | +* Gradle: `gradle build test` |
54 | 56 |
|
| 57 | + |
| 58 | +### Gradle Specifcs |
55 | 59 | Your `build.gradle` should have the following section: |
56 | 60 |
|
57 | 61 | ```groovy |
@@ -72,9 +76,34 @@ test { |
72 | 76 | } |
73 | 77 | ``` |
74 | 78 |
|
75 | | -### Keys and Secrets |
| 79 | +### Other Testing Set Up |
| 80 | + |
| 81 | +Most samples require a GCP project and billing account. Keep the following in |
| 82 | +mind when setting up tests. |
| 83 | + |
| 84 | +* **Environment variables** |
| 85 | + Minimize additional environment variables that need to be set to run the tests. |
| 86 | + If you do require additional environment variables, they should be added to |
| 87 | + `run_tests.sh`. |
| 88 | + |
| 89 | + Existing environment variables include: |
| 90 | + * `GOOGLE_APPLICATION_CREDENTIALS` |
| 91 | + * `GOOGLE_CLOUD_PROJECT` |
| 92 | + * `PROJECT_ID` |
| 93 | + |
| 94 | + |
| 95 | +* **API library** |
| 96 | + Add a note in the pull request, if an API needs to be enable in the testing |
| 97 | + project. |
76 | 98 |
|
77 | | -Please contact a Java DPE for instructions before adding to Travis. |
| 99 | +* **Cloud resources** |
| 100 | + Most Java samples create the Cloud resources that they need to run. If this |
| 101 | + is resource intensive or not possible, add a note in the pull request for the |
| 102 | + resource to be added to the testing project. |
| 103 | + |
| 104 | +* **Keys and Secrets** |
| 105 | + Add a note in the pull request, in order for a Java maintainer to assist you |
| 106 | + in adding keys and secrets to the testing project. |
78 | 107 |
|
79 | 108 | ## Style |
80 | 109 |
|
@@ -90,34 +119,37 @@ tool or IntelliJ plugin. |
90 | 119 |
|
91 | 120 | [google-java-format]: https://github.com/google/google-java-format |
92 | 121 |
|
93 | | -### Running the Linter |
94 | | - |
95 | | -To run the checkstyle & ErrorProne plugins on an existing sample, run |
96 | | - |
97 | | -```shell |
98 | | -mvn clean verify -DskipTests |
99 | | -``` |
100 | | - |
101 | | -The `-DskipTests` is optional. It is useful if you want to verify that your code |
102 | | -builds and adheres to the style guide without waiting for tests to complete. |
103 | | - |
104 | 122 | ### Adding the Checkstyle Plugin to New Samples |
105 | 123 |
|
106 | 124 | The samples in this repository use a common parent POM to define plugins used |
107 | 125 | for linting and testing. Add the following to your sample POM to ensure that it |
108 | | -uses the common Checkstyle configuration. |
| 126 | +uses the common Checkstyle configuration. For more information, see the |
| 127 | +[java-repo-tools](https://github.com/GoogleCloudPlatform/java-repo-tools) |
| 128 | +repository. |
109 | 129 |
|
110 | 130 | ```xml |
| 131 | +<!-- |
| 132 | + The parent pom defines common style checks and testing strategies for our samples. |
| 133 | + Removing or replacing it should not affect the execution of the samples in anyway. |
| 134 | + --> |
111 | 135 | <parent> |
112 | 136 | <groupId>com.google.cloud</groupId> |
113 | 137 | <artifactId>doc-samples</artifactId> |
114 | | - <version>1.0.0</version> |
115 | | - <!-- Change relativePath to point to the root directory. --> |
116 | | - <relativePath>../..</relativePath> |
| 138 | + <version>1.0.11</version> |
117 | 139 | </parent> |
118 | 140 | ``` |
119 | 141 |
|
120 | | -This is just used for testing. The sample should build without a parent defined. |
| 142 | +### Running the Linter |
| 143 | + |
| 144 | +To run the checkstyle & ErrorProne plugins on an existing sample, run |
| 145 | + |
| 146 | +```shell |
| 147 | +mvn clean verify -DskipTests |
| 148 | +``` |
| 149 | + |
| 150 | +The `-DskipTests` is optional. It is useful if you want to verify that your code |
| 151 | +builds and adheres to the style guide without waiting for tests to complete. |
| 152 | + |
121 | 153 |
|
122 | 154 | ### Parsing Command-Line Arguments in Samples |
123 | 155 |
|
@@ -128,5 +160,4 @@ CLI](https://commons.apache.org/proper/commons-cli/index.html) library. |
128 | 160 |
|
129 | 161 | Dataflow samples are an exception to this rule, since Dataflow has [its own |
130 | 162 | method for setting custom |
131 | | -options](https://cloud.google.com/dataflow/pipelines/specifying-exec-params) |
132 | | - |
| 163 | +options](https://cloud.google.com/dataflow/pipelines/specifying-exec-params). |