Skip to content

Commit a0e199d

Browse files
chore: merge main into generate-libraries-main
2 parents 223a513 + 502b807 commit a0e199d

File tree

19 files changed

+128
-52
lines changed

19 files changed

+128
-52
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: java-development
3+
description: General guidance on Java development practices, building, testing, and style in the monorepo. Use this skill when working on Java code across the repository.
4+
---
5+
6+
# Java Development Guide
7+
8+
This skill provides general guidelines for Java development inside the monorepo. It covers building, formatting, testing, and style conventions to ensure consistency across modules.
9+
10+
## Workflow
11+
12+
### 1. Building the Project
13+
14+
The repository uses Maven as its primary build system.
15+
16+
* **Build All Modules**: To build all modules from the root of the repository, run:
17+
```bash
18+
mvn install -T 1C -P quick-build
19+
```
20+
> [!TIP]
21+
> Use `-T 1C` to build modules in parallel (one thread per CPU core) and `-P quick-build` to skip unnecessary plugins for faster builds.
22+
* **Build a Specific Module**: You can also run Maven commands within a specific module directory (e.g., `java-bigquery`) to build only that module.
23+
24+
### 2. Code Formatting
25+
26+
Code formatting is enforced using the `fmt-maven-plugin`.
27+
28+
* **Check Formatting**: To check for formatting issues without modifying files, run:
29+
```bash
30+
mvn fmt:check -T 1C
31+
```
32+
* **Apply Formatting**: To automatically format the code according to the project style, run:
33+
```bash
34+
mvn fmt:format -T 1C
35+
```
36+
> [!TIP]
37+
> To save time, run `mvn fmt:format` within the specific module directory you are working on, rather than at the root.
38+
> [!NOTE]
39+
> Always run `mvn fmt:format` before committing changes to avoid build failures due to formatting.
40+
41+
### 3. Testing Strategy
42+
43+
* **Unit Tests**: Traditional unit tests should be added for individual classes and methods. Run them using:
44+
```bash
45+
mvn test -T 1C
46+
```
47+
* **Integration Tests**: Many modules have integration tests that run against live services or emulators. These may require specific profiles or environment variables. Refer to the specific module's README for details.
48+
49+
### 4. Style Guide
50+
51+
Follow these general rules to maintain code quality and consistency:
52+
53+
1. **Minimize Visibility**: Default to the most restrictive access level possible. Avoid using `public` unless the class or method is intended to be part of the public API.
54+
2. Avoid Fully Qualified Names: Use imports to keep class names short and readable, rather than using fully qualified names in the code.
55+
3. **Avoid Obsolete APIs**: Do not call methods marked with `@ObsoleteApi` or `@Deprecated` unless there are no viable alternatives.
56+
4. **Clean Diffs**: Avoid unnecessary formatting changes or whitespace modifications to keep diffs clean and easy to review.
57+
58+
### 5. Dependency Management
59+
60+
* **Version Bumps**: Try not to bump any external dependency versions unless there is a known security vulnerability (CVE) or a critical bug fix.
61+
* **New Dependencies**: Avoid introducing new external dependencies. If a new dependency is required, provide a strong justification in the pull request.
62+
* **Standard Library First**: Prefer to use features from the Java standard library, followed by existing dependencies in the project (preferably Google-managed dependencies).
63+
64+
### 6. Contribution Guidelines
65+
66+
* **Commit Messages**: Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. Include the module as the scope (e.g., `feat(spanner): ...`, `fix(bigquery): ...`).
67+
* **Pull Requests**: All code changes must be submitted via a pull request and require review. Ensure you pull the latest changes from `main` and resolve any conflicts before submitting.

.github/workflows/sdk-platform-java-create_additional_release_tag.yaml renamed to .github/workflows/create_additional_release_tag.yaml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
name: sdk-platform-java Create additional tags for each release
1+
name: Create additional tags for each release
22

33
on:
44
release:
55
types: [published]
66
workflow_dispatch:
7-
8-
env:
9-
BUILD_SUBDIR: sdk-platform-java
107
jobs:
11-
filter:
12-
runs-on: ubuntu-latest
13-
outputs:
14-
library: ${{ steps.filter.outputs.library }}
15-
steps:
16-
- uses: actions/checkout@v4
17-
- uses: dorny/paths-filter@v3
18-
id: filter
19-
with:
20-
filters: |
21-
library:
22-
- 'sdk-platform-java/**'
238
build:
24-
needs: filter
25-
if: ${{ needs.filter.outputs.library == 'true' }}
269
runs-on: ubuntu-latest
2710
permissions:
2811
# Permission to create tag
@@ -32,7 +15,7 @@ jobs:
3215
- name: Checkout code
3316
uses: actions/checkout@v4
3417
with:
35-
token: ${{ secrets.GITHUB_TOKEN }}
18+
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
3619
- name: Set up Git
3720
run: |
3821
git config --local user.email "action@github.com"

.github/workflows/sdk-platform-java-ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
library:
1919
- 'sdk-platform-java/**'
2020
- 'google-auth-library-java/**'
21+
- '.github/workflows/ci.yaml'
2122
build:
2223
needs: filter
2324
if: ${{ needs.filter.outputs.library == 'true' }}

.github/workflows/unmanaged_dependency_check.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ jobs:
1010
with:
1111
distribution: temurin
1212
java-version: 11
13-
- name: Install modules
13+
- name: Install all modules first
1414
shell: bash
15-
run: mvn install -B -ntp -T 1C -DskipTests -Pquick-build
15+
run: .kokoro/build.sh
16+
env:
17+
BUILD_SUBDIR: sdk-platform-java
18+
JOB_TYPE: install
1619
- name: Unmanaged dependency check
1720
uses: ./sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check
1821
with:

generation_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ libraries:
235235
library_name: asset
236236
release_level: stable
237237
api_reference: https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview
238-
issue_tracker: https://issuetracker.google.com/issues/new?component=187210&template=0
238+
issue_tracker: https://issuetracker.google.com/issues/new?component=187210
239239
GAPICs:
240240
- proto_path: google/cloud/asset/v1
241241
- proto_path: google/cloud/asset/v1p1beta1
@@ -1331,7 +1331,7 @@ libraries:
13311331
accounts.
13321332
release_level: stable
13331333
requires_billing: false
1334-
issue_tracker: https://issuetracker.google.com/issues/new?component=187161&template=0
1334+
issue_tracker: https://issuetracker.google.com/issues/new?component=187161
13351335
GAPICs:
13361336
- proto_path: google/iam/credentials/v1
13371337
- api_shortname: iap
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
java_library(
2+
name = "credentials",
3+
srcs = glob(["java/**/*.java"]),
4+
visibility = ["//visibility:public"],
5+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
java_library(
2+
name = "oauth2_http",
3+
srcs = glob(["java/**/*.java"]),
4+
deps = [
5+
"@com_google_guava_guava//jar",
6+
"@com_google_guava_failureaccess//jar",
7+
"//google-auth-library-java/credentials:credentials",
8+
"@com_google_http_client_google_http_client//jar",
9+
"@com_google_http_client_google_http_client_gson//jar",
10+
"@com_google_api_api_common//jar",
11+
"@com_google_code_gson_gson//jar",
12+
"@com_google_errorprone_error_prone_annotations//jar",
13+
"@com_google_code_findbugs_jsr305//jar",
14+
"@com_google_auto_value_auto_value_annotations//jar",
15+
"@com_google_auto_value_auto_value//jar",
16+
"@org_slf4j_slf4j_api//jar",
17+
],
18+
plugins = ["@com_google_api_gax_java//:auto_value_plugin"],
19+
visibility = ["//visibility:public"],
20+
)

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/InternalAwsSecurityCredentialsSupplier.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ Map<String, Object> createMetadataRequestHeaders(AwsCredentialSource awsCredenti
235235
// Both flows work for IDMS v1 and v2. But if IDMSv2 is enabled, then if
236236
// session token is not present, Unauthorized exception will be thrown.
237237
if (awsCredentialSource.imdsv2SessionTokenUrl != null) {
238-
Map<String, Object> tokenRequestHeaders =
239-
new HashMap<String, Object>() {
240-
{
241-
put(AWS_IMDSV2_SESSION_TOKEN_TTL_HEADER, AWS_IMDSV2_SESSION_TOKEN_TTL);
242-
}
243-
};
238+
Map<String, Object> tokenRequestHeaders = new HashMap<>();
239+
tokenRequestHeaders.put(AWS_IMDSV2_SESSION_TOKEN_TTL_HEADER, AWS_IMDSV2_SESSION_TOKEN_TTL);
244240

245241
String imdsv2SessionToken =
246242
retrieveResource(

java-asset/.repo-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"library_type": "GAPIC_AUTO",
1515
"requires_billing": true,
1616
"api_reference": "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview",
17-
"issue_tracker": "https://issuetracker.google.com/issues/new?component=187210&template=0"
17+
"issue_tracker": "https://issuetracker.google.com/issues/new?component=187210"
1818
}

java-iamcredentials/.repo-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"api_id": "iamcredentials.googleapis.com",
1414
"library_type": "GAPIC_AUTO",
1515
"requires_billing": false,
16-
"issue_tracker": "https://issuetracker.google.com/issues/new?component=187161&template=0"
16+
"issue_tracker": "https://issuetracker.google.com/issues/new?component=187161"
1717
}

0 commit comments

Comments
 (0)