From de83ee6f0d32d75913ee93a9d71013b4d3914956 Mon Sep 17 00:00:00 2001
From: Alice Li
Date: Wed, 3 Apr 2024 18:01:57 -0400
Subject: [PATCH 1/3] feat: refactor Version selection
---
.../com/google/docfx/doclet/RepoMetadata.java | 7 +
.../com/microsoft/build/PackageBuilder.java | 4 +-
.../microsoft/build/PackageOverviewFile.java | 64 ++---
.../com/microsoft/build/YmlFilesBuilder.java | 28 +-
.../microsoft/model/LibraryOverviewFile.java | 243 ++++++++++--------
.../com.microsoft.samples.agreements.md | 12 +-
...om.microsoft.samples.commentinheritance.md | 22 +-
.../com.microsoft.samples.google.md | 24 +-
.../com.microsoft.samples.google.v1.md | 2 +-
.../com.microsoft.samples.google.v1.stub.md | 16 +-
.../com.microsoft.samples.google.v1beta.md | 14 +-
.../com.microsoft.samples.google.v1p1alpha.md | 14 +-
.../com.microsoft.samples.md | 26 +-
.../com.microsoft.samples.offers.md | 6 +-
.../com.microsoft.samples.subpackage.md | 16 +-
.../expected-generated-files/overview.md | 30 ++-
16 files changed, 297 insertions(+), 231 deletions(-)
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/google/docfx/doclet/RepoMetadata.java b/third_party/docfx-doclet-143274/src/main/java/com/google/docfx/doclet/RepoMetadata.java
index a2c378b9..c9408fea 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/google/docfx/doclet/RepoMetadata.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/google/docfx/doclet/RepoMetadata.java
@@ -46,6 +46,9 @@ public class RepoMetadata {
@SerializedName("api_id")
private String apiId;
+ @SerializedName("recommended_package")
+ private String recommendedPackage;
+
private String artifactId;
public String getNamePretty() {
@@ -80,6 +83,10 @@ public void setProductDocumentationUri(String productDocumentationUri) {
this.productDocumentationUri = productDocumentationUri;
}
+ public Optional getRecommendedPackage() {
+ return Optional.ofNullable(this.recommendedPackage);
+ }
+
public String getApiDescription() {
return this.apiDescription;
}
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageBuilder.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageBuilder.java
index bba0e5b6..d5f89216 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageBuilder.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageBuilder.java
@@ -35,7 +35,7 @@ PackageOverviewFile buildPackageOverviewFile(
PackageElement packageElement,
RepoMetadata repoMetadata,
String artifactVersion,
- String recommendedApiVersion) {
+ String recommendedPackage) {
String status = packageLookup.extractStatus(packageElement);
String fileName = packageElement.getQualifiedName() + ".md";
PackageOverviewFile packageOverviewFile =
@@ -48,7 +48,7 @@ PackageOverviewFile buildPackageOverviewFile(
packageLookup,
referenceBuilder,
artifactVersion,
- recommendedApiVersion);
+ recommendedPackage);
return packageOverviewFile;
}
}
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
index 19758662..0b91459c 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
@@ -55,9 +55,12 @@ public class PackageOverviewFile {
// This is only set if the package is not a GA package
private String PRERELEASE_IMPLICATIONS = "";
- private String recommendedApiVersion;
+ // Uses the `recommended_package` field set in the RepoMetadata file if set; otherwise computes it.
+ private String recommendedPackage;
- // This is only set if the package is not the latest GA package
+ private String recommendedPackageLink;
+
+ // This is only set if the package is not the recommended package
private String RECOMMENDED_VERSION = "";
// This is only set if the package is a stub package
@@ -81,19 +84,18 @@ public PackageOverviewFile(
PackageLookup packageLookup,
ReferenceBuilder referenceBuilder,
String artifactVersion,
- String recommendedApiVersion) {
+ String recommendedPackage) {
this.outputPath = outputPath;
this.fileName = fileName;
this.packageElement = packageElement;
- this.recommendedApiVersion = recommendedApiVersion;
+ this.recommendedPackage = recommendedPackage;
String packageURIPath = fileName.replace(".md", "");
this.PACKAGE_HEADER = "# Package " + packageURIPath + " (" + artifactVersion + ")\n";
- // This will always link to the latest version of the package classes
String cloudRADChildElementLinkPrefix =
- "https://cloud.google.com/java/docs/reference/" + repoMetadata.getArtifactId() + "/latest/";
+ "https://cloud.google.com/java/docs/reference/" + repoMetadata.getArtifactId() + "/" + artifactVersion + "/";
String packageURIPathGithub = packageURIPath.replace('.', '/');
String githubSourcePackageLink =
@@ -103,56 +105,40 @@ public PackageOverviewFile(
+ "/src/main/java/"
+ packageURIPathGithub;
+ String cgcRootUri = "https://cloud.google.com/java/docs/reference/";
+ this.recommendedPackageLink = cgcRootUri + repoMetadata.getArtifactId() + "/" + artifactVersion + "/" + this.recommendedPackage;
// If the package status is not a GA version, then add a disclaimer around prerelease
// implications
if (status != null) {
this.PRERELEASE_IMPLICATIONS =
"## Prerelease Implications\n\n"
- + "This package is a prerelease version! Use with caution.\n"
- + "Prerelease versions are considered unstable as they may be shut down. You can read more about [Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).\n"
- + "Each Cloud Java client library may contain multiple packages. Each package containing a version number in its name corresponds to a published version of the service.\n"
- + "We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.\n"
- + "For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.\n"
- + "If you use an unstable release, breaking changes may be introduced when upgrading.\n\n";
+ + "This package is a prerelease version! Use with caution.\n\n"
+ + "Prerelease versions are considered unstable as they may be shut down and/or subject to breaking changes when upgrading.\n"
+ + "Use them only for testing or if you specifically need their experimental features.\n\n";
}
- // This regex captures the package path before the version (if it exists) and the version
- Pattern pattern = Pattern.compile("(.*?)(v\\d+.*?)(?:\\.|$)");
- ImmutableList
\n\n"
- + "### SBT\n"
- + "SBT [doesn't support BOMs](https://github.com/sbt/sbt/issues/4531). You can find\n"
- + "recommended versions of libraries from a particular BOM version on the\n"
- + "[dashboard](https://storage.googleapis.com/cloud-opensource-java-dashboard/com.google.cloud/libraries-bom/index.html)\n"
- + "and set the versions manually.\n"
- + "To use the latest version of this library, add this to your dependencies:\n"
- + "
\n\n";
-
- // Some client libraries do not have an underlying API service (e.g.
- // google-cloud-logging-logback, google-cloud-storage-nio, google-cloud-spanner-jdbc), hence
- // there is no recommended API version.
- if (this.recommendedApiVersion.isEmpty()) {
+ this.LIBRARY_OVERVIEW_CLIENT_INSTALLATION_HEADER =
+ "## Use the "
+ + repoMetadata.getNamePretty()
+ + " for Java\n"
+ + "To ensure that your project uses compatible versions of the libraries\n"
+ + "and their component artifacts, import `com.google.cloud:libraries-bom` and use\n"
+ + "the BOM to specify dependency versions. Be sure to remove any versions that you\n"
+ + "set previously. For more information about\n"
+ + "BOMs, see [Google Cloud Platform Libraries BOM](https://cloud.google.com/java/docs/bom).\n\n";
+
+ // When b/312765900 is implemented, then refactor this section to use the devsite-selector
+ // format. Current format is a workaround so the sanitizer doesn't remove the content.
+ this.LIBRARY_OVERVIEW_CLIENT_INSTALLATION_SECTION =
+ "### Maven\n"
+ + "Import the BOM in the dependencyManagement section of your pom.xml file.\n"
+ + "Include specific artifacts you depend on in the dependencies section, but don't\n"
+ + "specify the artifacts' versions in the dependencies section.\n"
+ + "\n"
+ + "The example below demonstrates how you would import the BOM and include the "
+ + repoMetadata.getArtifactId()
+ + " artifact.\n"
+ + "
\n\n"
+ + "### Gradle\n"
+ + "BOMs are supported by default in Gradle 5.x or later. Add a platform\n"
+ + "dependency on com.google.cloud:libraries-bom and remove the version from the\n"
+ + "dependency declarations in the artifact's build.gradle file.\n"
+ + "\n"
+ + "The example below demonstrates how you would import the BOM and include the "
+ + repoMetadata.getArtifactId()
+ + " artifact.\n"
+ + "
\n\n"
+ + "The platform and enforcedPlatform keywords supply dependency versions\n"
+ + "declared in a BOM. The enforcedPlatform keyword enforces the dependency\n"
+ + "versions declared in the BOM and thus overrides what you specified.\n\n"
+ + "For more details of the platform and enforcedPlatform keywords Gradle 5.x or higher, see\n"
+ + "[Gradle: Importing Maven BOMs](https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import).\n"
+ + "\n"
+ + "If you're using Gradle 4.6 or later, add\n"
+ + "enableFeaturePreview('IMPROVED_POM_SUPPORT') to your settings.gradle file. For details, see\n"
+ + "[Gradle 4.6 Release Notes: BOM import](https://docs.gradle.org/4.6/release-notes.html#bom-import).\n"
+ + "Versions of Gradle earlier than 4.6 don't support BOMs.\n\n"
+ + "### SBT\n"
+ + "SBT [doesn't support BOMs](https://github.com/sbt/sbt/issues/4531). You can find\n"
+ + "recommended versions of libraries from a particular BOM version on the\n"
+ + "[dashboard](https://storage.googleapis.com/cloud-opensource-java-dashboard/com.google.cloud/libraries-bom/index.html)\n"
+ + "and set the versions manually.\n"
+ + "To use the latest version of this library, add this to your dependencies:\n"
+ + "
\n\n";
+
+ }
+ // It should be very rare that a client library does not have a recommended package
+ if (this.recommendedPackage.isEmpty()) {
this.LIBRARY_OVERVIEW_PACKAGE_SELECTION_SECTION = "";
} else {
this.LIBRARY_OVERVIEW_PACKAGE_SELECTION_SECTION =
- "## Which version should I use?\n"
- + "For this library, we recommend using API version "
- + this.recommendedApiVersion
- + " for new applications.\n"
- + "\n"
- + "Each Cloud Java client library may contain multiple packages. Each package containing a version number in its name corresponds to a published version of the service.\n"
- + "We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.\n"
- + "For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.\n"
- + "If you use an unstable release, breaking changes may be introduced when upgrading.\n"
- + "You can read more about [Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).\n\n";
+ "## Which version ID should I get started with?\n"
+ + "For this library, we recommend using "
+ + "["
+ + this.recommendedPackage
+ + "]("
+ + this.recommendedPackageLink
+ + ") for new applications.\n\n"
+ + "### Understanding Version ID and Library Versions\n"
+ + "When using a Cloud client library, it's important to distinguish between two types of versions:\n"
+ + "- **Library Version**: The version of the software package (the client library) that helps you interact with the Cloud service. These libraries are\n"
+ + "released and updated frequently with bug fixes, improvements, and support for new service features and versions. The version selector at\n"
+ + "the top of this page represents the client library version.\n"
+ + "- **Version ID**: The version of the Cloud service itself (e.g. "
+ + repoMetadata.getNamePretty()
+ + "). New Version IDs are introduced infrequently, and often involve\n"
+ + "changes to the core functionality and structure of the Cloud service itself. The packages in the lefthand navigation represent packages tied\n"
+ + "to a specific Version ID of the Cloud service.\n\n"
+ + "### Managing Library Versions\n"
+ + "We recommend using the com.google.cloud:libraries-bom installation method detailed above to streamline dependency management\n"
+ + "across multiple Cloud Java client libraries. This ensures compatibility and simplifies updates.\n\n"
+ + "### Choosing the Right Version ID\n"
+ + "Each Cloud Java client library may contain packages tied to specific Version IDs (e.g., v1, v2alpha). For new production applications, use\n"
+ + "the latest stable Version ID. This is identified by the highest version number **without** a suffix (like \"alpha\" or \"beta\"). You can read more about\n"
+ + "[Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).\n\n"
+ + "**Important**: Unstable Version ID releases (those _with_ suffixes) are subject to breaking changes when upgrading. Use them only for testing or if you specifically need their experimental features.\n\n";
}
}
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.md
index 37ee1cb2..9618adae 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.md
@@ -7,6 +7,10 @@
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Classes
Deprecated.This one is deprecated :(
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.commentinheritance.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.commentinheritance.md
index 31a00725..f07675a6 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.commentinheritance.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.commentinheritance.md
@@ -7,6 +7,10 @@
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Classes
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Client Classes
Client classes are the main entry point to using a package.
They contain several variations of Java methods for each of the API's methods.
@@ -17,7 +21,7 @@ Client
Indicates a public API that can change at any time, and has no guarantee of API stability and
backward-compatibility.
@@ -95,7 +99,7 @@ Indicates a public API that can change at any time, and has no guarantee of API
Exception thrown if there is a validation problem with a path template, http config, or related
framework methods. Comes as an illegal argument exception subclass. Allows to globally set a
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.md
index 7ad4133c..cb50fddf 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.md
@@ -17,7 +17,7 @@ Client
Service Description: Service that implements Google Cloud Speech API.
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.stub.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.stub.md
index b6943d51..f6f5094c 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.stub.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1.stub.md
@@ -7,10 +7,14 @@
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Stub Package Implications
This package is a a base stub class. It is for advanced usage and reflects the underlying API directly.
-We generally recommend using non-stub, latest GA package, such as [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.google.v1). Use with caution.
+We generally recommend using the non-stub, latest GA package, such as [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1). Use with caution.
## Stub Classes
-## This package is not the latest GA version!
+## This package is not the recommended entry point to using this client library!
- For this library, we recommend using the [package](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.google.v1) associated with API version v1 for new applications.
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
## Prerelease Implications
This package is a prerelease version! Use with caution.
-Prerelease versions are considered unstable as they may be shut down. You can read more about [Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).
-Each Cloud Java client library may contain multiple packages. Each package containing a version number in its name corresponds to a published version of the service.
-We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.
-For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.
-If you use an unstable release, breaking changes may be introduced when upgrading.
+
+Prerelease versions are considered unstable as they may be shut down and/or subject to breaking changes when upgrading.
+Use them only for testing or if you specifically need their experimental features.
## Client Classes
Client classes are the main entry point to using a package.
@@ -30,7 +28,7 @@ Client
Service Description: Service that implements Google Cloud Speech API.
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.md
index d019536d..0001294b 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.md
@@ -7,18 +7,16 @@
-## This package is not the latest GA version!
+## This package is not the recommended entry point to using this client library!
- For this library, we recommend using the [package](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.google.v1) associated with API version v1 for new applications.
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
## Prerelease Implications
This package is a prerelease version! Use with caution.
-Prerelease versions are considered unstable as they may be shut down. You can read more about [Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).
-Each Cloud Java client library may contain multiple packages. Each package containing a version number in its name corresponds to a published version of the service.
-We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.
-For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.
-If you use an unstable release, breaking changes may be introduced when upgrading.
+
+Prerelease versions are considered unstable as they may be shut down and/or subject to breaking changes when upgrading.
+Use them only for testing or if you specifically need their experimental features.
## Client Classes
Client classes are the main entry point to using a package.
@@ -30,7 +28,7 @@ Client
Service Description: Service that implements Google Cloud Speech API.
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.md
index f3e3e013..0b3bab6e 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.md
@@ -7,6 +7,10 @@
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Classes
The main entry point into using the partner SDK functionality. Represents a partner and
encapsulates all the behavior attached to partners. Use this interface to get to the partner's
@@ -86,7 +90,7 @@ Enum
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Classes
+## This package is not the recommended entry point to using this client library!
+
+ For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
## Classes
diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/overview.md b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/overview.md
index 9ae046d5..df45ffd4 100644
--- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/overview.md
+++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/overview.md
@@ -87,12 +87,26 @@ To use the latest version of this library, add this to your dependencies:
libraryDependencies += "com.google.cloud" % "google-cloud-apikeys" % "0.18.0"
-## Which version should I use?
-For this library, we recommend using API version v1 for new applications.
-
-Each Cloud Java client library may contain multiple packages. Each package containing a version number in its name corresponds to a published version of the service.
-We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.
-For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.
-If you use an unstable release, breaking changes may be introduced when upgrading.
-You can read more about [Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).
+## Which version ID should I get started with?
+For this library, we recommend using [com.microsoft.samples.google.v1](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/0.18.0/com.microsoft.samples.google.v1) for new applications.
+
+### Understanding Version ID and Library Versions
+When using a Cloud client library, it's important to distinguish between two types of versions:
+- **Library Version**: The version of the software package (the client library) that helps you interact with the Cloud service. These libraries are
+released and updated frequently with bug fixes, improvements, and support for new service features and versions. The version selector at
+the top of this page represents the client library version.
+- **Version ID**: The version of the Cloud service itself (e.g. API Keys API). New Version IDs are introduced infrequently, and often involve
+changes to the core functionality and structure of the Cloud service itself. The packages in the lefthand navigation represent packages tied
+to a specific Version ID of the Cloud service.
+
+### Managing Library Versions
+We recommend using the com.google.cloud:libraries-bom installation method detailed above to streamline dependency management
+across multiple Cloud Java client libraries. This ensures compatibility and simplifies updates.
+
+### Choosing the Right Version ID
+Each Cloud Java client library may contain packages tied to specific Version IDs (e.g., v1, v2alpha). For new production applications, use
+the latest stable Version ID. This is identified by the highest version number **without** a suffix (like "alpha" or "beta"). You can read more about
+[Cloud API versioning strategy here](https://cloud.google.com/apis/design/versioning).
+
+**Important**: Unstable Version ID releases (those _with_ suffixes) are subject to breaking changes when upgrading. Use them only for testing or if you specifically need their experimental features.
From 10337273764c32f7e91bbe907b540d937102a062 Mon Sep 17 00:00:00 2001
From: Alice Li
Date: Thu, 4 Apr 2024 12:26:31 -0400
Subject: [PATCH 2/3] update fmt-maven-plugin and lint
---
third_party/docfx-doclet-143274/pom.xml | 4 +-
.../microsoft/build/PackageOverviewFile.java | 44 ++++++++++++-------
.../com/microsoft/build/YmlFilesBuilder.java | 12 ++---
.../microsoft/model/LibraryOverviewFile.java | 14 ++++--
4 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/third_party/docfx-doclet-143274/pom.xml b/third_party/docfx-doclet-143274/pom.xml
index a6263964..0b702e4a 100644
--- a/third_party/docfx-doclet-143274/pom.xml
+++ b/third_party/docfx-doclet-143274/pom.xml
@@ -94,9 +94,9 @@
- com.coveo
+ com.spotify.fmtfmt-maven-plugin
- 2.13
+ 2.23true
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
index 0b91459c..862f5cb3 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java
@@ -55,7 +55,8 @@ public class PackageOverviewFile {
// This is only set if the package is not a GA package
private String PRERELEASE_IMPLICATIONS = "";
- // Uses the `recommended_package` field set in the RepoMetadata file if set; otherwise computes it.
+ // Uses the `recommended_package` field set in the RepoMetadata file if set; otherwise computes
+ // it.
private String recommendedPackage;
private String recommendedPackageLink;
@@ -95,7 +96,11 @@ public PackageOverviewFile(
this.PACKAGE_HEADER = "# Package " + packageURIPath + " (" + artifactVersion + ")\n";
String cloudRADChildElementLinkPrefix =
- "https://cloud.google.com/java/docs/reference/" + repoMetadata.getArtifactId() + "/" + artifactVersion + "/";
+ "https://cloud.google.com/java/docs/reference/"
+ + repoMetadata.getArtifactId()
+ + "/"
+ + artifactVersion
+ + "/";
String packageURIPathGithub = packageURIPath.replace('.', '/');
String githubSourcePackageLink =
@@ -106,7 +111,13 @@ public PackageOverviewFile(
+ packageURIPathGithub;
String cgcRootUri = "https://cloud.google.com/java/docs/reference/";
- this.recommendedPackageLink = cgcRootUri + repoMetadata.getArtifactId() + "/" + artifactVersion + "/" + this.recommendedPackage;
+ this.recommendedPackageLink =
+ cgcRootUri
+ + repoMetadata.getArtifactId()
+ + "/"
+ + artifactVersion
+ + "/"
+ + this.recommendedPackage;
// If the package status is not a GA version, then add a disclaimer around prerelease
// implications
if (status != null) {
@@ -117,21 +128,24 @@ public PackageOverviewFile(
+ "Use them only for testing or if you specifically need their experimental features.\n\n";
}
- // If a package is not the same as the recommended package, add a disclaimer. If the recommended package does not exist, then do not set the disclaimer.
- if (!this.recommendedPackage.isEmpty() && !packageElement.getQualifiedName().toString().equals(this.recommendedPackage)) {
- this.RECOMMENDED_VERSION =
- "## This package is not the recommended entry point to using this client library!\n\n"
- + " For this library, we recommend using ["
- + recommendedPackage
- + "]("
- + recommendedPackageLink
- + ")"
- + " for new applications.\n"
- + "\n";
+ // If a package is not the same as the recommended package, add a disclaimer. If the recommended
+ // package does not exist, then do not set the disclaimer.
+ if (!this.recommendedPackage.isEmpty()
+ && !packageElement.getQualifiedName().toString().equals(this.recommendedPackage)) {
+ this.RECOMMENDED_VERSION =
+ "## This package is not the recommended entry point to using this client library!\n\n"
+ + " For this library, we recommend using ["
+ + recommendedPackage
+ + "]("
+ + recommendedPackageLink
+ + ")"
+ + " for new applications.\n"
+ + "\n";
}
// Link to recommended package (if it exists) for the Stub class as well
- if (!this.recommendedPackage.isEmpty() && String.valueOf(this.packageElement.getQualifiedName()).contains("stub")) {
+ if (!this.recommendedPackage.isEmpty()
+ && String.valueOf(this.packageElement.getQualifiedName()).contains("stub")) {
this.STUB_IMPLICATIONS =
"## Stub Package Implications\n\n"
+ "This package is a a base stub class. It is for advanced usage and reflects the underlying API directly.\n"
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
index da2ba6ba..bc15c793 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
@@ -20,7 +20,6 @@
import com.microsoft.util.FileUtil;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -148,19 +147,20 @@ void process() {
.filter(pkg -> !packageLookup.isApiVersionStubPackage(pkg))
.collect(Collectors.toList()));
- // Calculate the recommended package based on the latest stable Version ID. This will be overridden by the recommended_package in the RepoMetadata, if set
+ // Calculate the recommended package based on the latest stable Version ID. This will be
+ // overridden by the recommended_package in the RepoMetadata, if set
HashMap packageVersions = new HashMap<>();
for (PackageElement pkg : allPackages) {
Optional apiVersion = packageLookup.extractApiVersion(pkg);
- apiVersion.ifPresent(version -> packageVersions.put(version, String.valueOf(pkg.getQualifiedName())));
+ apiVersion.ifPresent(
+ version -> packageVersions.put(version, String.valueOf(pkg.getQualifiedName())));
}
// If repoMetadata contains a recommended package, use that instead of the calculated package
Optional inputRecommendedPackage = repoMetadata.getRecommendedPackage();
- if(inputRecommendedPackage.isPresent()){
+ if (inputRecommendedPackage.isPresent()) {
recommendedPackage = repoMetadata.getRecommendedPackage().get();
- }
- else if(!packageVersions.keySet().isEmpty()){
+ } else if (!packageVersions.keySet().isEmpty()) {
recommendedApiVersion = ApiVersion.getRecommended(packageVersions.keySet());
recommendedPackage = packageVersions.get(recommendedApiVersion).toString();
}
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/model/LibraryOverviewFile.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/model/LibraryOverviewFile.java
index a104ffee..1495a24d 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/model/LibraryOverviewFile.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/model/LibraryOverviewFile.java
@@ -55,9 +55,15 @@ public LibraryOverviewFile(
this.recommendedPackageLink = "";
// Compute the link to the recommended package if it exists
- if(!this.recommendedPackage.isEmpty()){
+ if (!this.recommendedPackage.isEmpty()) {
String cgcRootUri = "https://cloud.google.com/java/docs/reference/";
- this.recommendedPackageLink = cgcRootUri + repoMetadata.getArtifactId() + "/" + artifactVersion + "/" + this.recommendedPackage;
+ this.recommendedPackageLink =
+ cgcRootUri
+ + repoMetadata.getArtifactId()
+ + "/"
+ + artifactVersion
+ + "/"
+ + this.recommendedPackage;
}
this.LIBRARY_OVERVIEW_FILE_HEADER =
@@ -90,7 +96,8 @@ public LibraryOverviewFile(
+ "\n\n";
// For non-service libraries, these steps are not necessary
- // TODO: https://github.com/googleapis/java-docfx-doclet/issues/253 : Ideally we can refactor for custom modules to copy from their README sections
+ // TODO: https://github.com/googleapis/java-docfx-doclet/issues/253 : Ideally we can refactor
+ // for custom modules to copy from their README sections
String[] runtimeLibraries = {"gax", "api-common", "common-protos", "google-cloud-core"};
if (Arrays.asList(runtimeLibraries).contains(repoMetadata.getApiShortName())) {
@@ -195,7 +202,6 @@ public LibraryOverviewFile(
+ artifactVersion
+ ""\n"
+ "\n\n";
-
}
// It should be very rare that a client library does not have a recommended package
if (this.recommendedPackage.isEmpty()) {
From ad76dd328a5a97c3cdf474c605433c150a4888a3 Mon Sep 17 00:00:00 2001
From: Alice Li
Date: Thu, 4 Apr 2024 16:31:26 -0400
Subject: [PATCH 3/3] refactor to not pre-calculate the version unnecessarily
---
.../com/microsoft/build/YmlFilesBuilder.java | 36 ++++++++++---------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
index bc15c793..f0ddb1e8 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/YmlFilesBuilder.java
@@ -147,23 +147,25 @@ void process() {
.filter(pkg -> !packageLookup.isApiVersionStubPackage(pkg))
.collect(Collectors.toList()));
- // Calculate the recommended package based on the latest stable Version ID. This will be
- // overridden by the recommended_package in the RepoMetadata, if set
- HashMap packageVersions = new HashMap<>();
- for (PackageElement pkg : allPackages) {
- Optional apiVersion = packageLookup.extractApiVersion(pkg);
- apiVersion.ifPresent(
- version -> packageVersions.put(version, String.valueOf(pkg.getQualifiedName())));
- }
-
- // If repoMetadata contains a recommended package, use that instead of the calculated package
- Optional inputRecommendedPackage = repoMetadata.getRecommendedPackage();
- if (inputRecommendedPackage.isPresent()) {
- recommendedPackage = repoMetadata.getRecommendedPackage().get();
- } else if (!packageVersions.keySet().isEmpty()) {
- recommendedApiVersion = ApiVersion.getRecommended(packageVersions.keySet());
- recommendedPackage = packageVersions.get(recommendedApiVersion).toString();
- }
+ // Use the provided recommended package in the .repo-metadata.json file, if set
+ recommendedPackage =
+ repoMetadata
+ .getRecommendedPackage()
+ .orElseGet(
+ () -> {
+ // Calculate the recommended package based on the latest stable Version ID.
+ HashMap packageVersions = new HashMap<>();
+ for (PackageElement pkg : allPackages) {
+ Optional apiVersion = packageLookup.extractApiVersion(pkg);
+ apiVersion.ifPresent(
+ version ->
+ packageVersions.put(version, String.valueOf(pkg.getQualifiedName())));
+ }
+ if (packageVersions.isEmpty()) return "";
+
+ ApiVersion recommended = ApiVersion.getRecommended(packageVersions.keySet());
+ return packageVersions.get(recommended).toString();
+ });
for (PackageElement element : organizedPackagesWithoutStubs.get(PackageGroup.VISIBLE)) {
tocFile.addTocItem(buildPackage(element));