Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90c4f38
fix: support non-name fields with res-refs in resname def parsing
miraleung Oct 27, 2020
a74be70
fix: add workaround for missing default_host and oauth_scopes annotation
miraleung Oct 27, 2020
aef9843
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
miraleung Oct 29, 2020
fdb1ffb
fix: clarify LRO parsing error messages
miraleung Oct 27, 2020
642c606
feat: support deeply-nested types in AST and proto message parsing
miraleung Oct 28, 2020
3e26d87
fix: prevent resname tokens from matching subcomponents
miraleung Oct 28, 2020
837da38
fix: use TypeParser for proto message parsing
miraleung Oct 28, 2020
a5fc332
fix: use generic types in field instantiation in ServiceClientTest
miraleung Oct 28, 2020
b71b786
fix: prevent descension into map types in nested message parsing
miraleung Oct 29, 2020
602e1df
fix: merge master
miraleung Oct 29, 2020
07dddb8
fix: use both map generics in ServiceClientTest codegen
miraleung Oct 29, 2020
5e95e8f
fix: dir structure of generated files
miraleung Oct 29, 2020
c37c2d0
test: add asset API gradle pkg rules
miraleung Oct 29, 2020
8a7196f
fix: remove unused dep
miraleung Oct 29, 2020
f7f8099
test: add logging integration target and goldens, consolidate rules
miraleung Oct 29, 2020
9e0ad39
fix: merge master
miraleung Oct 29, 2020
9df3a5b
fix: fix asset_java_gapic build
miraleung Oct 30, 2020
96f8676
fix: fix test src packaging, update integration goldens
miraleung Oct 30, 2020
a91a085
fix: pass all tokens to instansiate in resname 1-pattern case
miraleung Oct 30, 2020
19e0a98
fix: update goldens
miraleung Oct 30, 2020
2dfd4b1
fix: update goldens
miraleung Oct 30, 2020
5dae221
build: add all integration tests to pre-commit hook
miraleung Oct 30, 2020
6917a2b
build: run pre-commit when goldens have changed
miraleung Oct 30, 2020
1aaf0a5
build: add integration golden tests to CircleCI
miraleung Oct 30, 2020
0ba9f53
fix: preserve newlines and parse itemized lists in protobuf comments
miraleung Oct 30, 2020
2b1b8d1
fix: remove extraneous escaper
miraleung Oct 30, 2020
c279667
Merge branch 'master' into alpha/g19
miraleung Oct 30, 2020
ceadd4e
Merge branch 'alpha/g19' of github.com:googleapis/gapic-generator-jav…
miraleung Oct 30, 2020
17893de
fix: update integration goldens for ServiceClient comment names
miraleung Oct 30, 2020
e75e828
fix: use serviceClient varname in ServiceClient codegen comments
miraleung Oct 30, 2020
3bf2ec4
fix: use imperative method names in Escapers
miraleung Oct 30, 2020
90cb64a
feat: parse/print paragraphs and itemized lists in @param Javadocs
miraleung Oct 30, 2020
4bee96c
Merge branch 'master' into alpha/g23
miraleung Oct 31, 2020
c2b221a
fix: merge master
miraleung Oct 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ then
fi
fi

# Check integration tests.
if [ $NUM_JAVA_FILES_CHANGED -gt 0 ] \
|| [ $NUM_INTEGRATION_GOLDEN_FILES_CHANGED -gt 0 ] \
|| [ $NUM_INTEGRATION_BAZEL_FILES_CHANGED -gt 0 ]
then
echo_status "Checking integration tests..."
bazel --batch test --disk_cache="$BAZEL_CACHE_DIR" //test/integration/...
TEST_STATUS=$?
if [ $TEST_STATUS != 0 ]
then
echo_error "Tests failed." "Please fix them and try again."
exit 1
fi
fi

# Check and fix Bazel format.
if [ $NUM_BAZEL_FILES_CHANGED -gt 0 ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@AutoValue
public abstract class JavaDocComment implements Comment {
Expand All @@ -44,6 +45,8 @@ public void accept(AstNodeVisitor visitor) {

@AutoValue.Builder
public abstract static class Builder {
static final String PARAM_INDENT = " ";

// The lack of a getter for these local variables in the external class is WAI.
String throwsType = null;
String throwsDescription = null;
Expand All @@ -67,7 +70,7 @@ public Builder setDeprecated(String deprecatedText) {
}

public Builder addParam(String name, String description) {
paramsList.add(String.format("@param %s %s", name, description));
paramsList.add(String.format("@param %s %s", name, processParamComment(description)));
return this;
}

Expand Down Expand Up @@ -135,5 +138,42 @@ public JavaDocComment build() {
setComment(String.join("\n", componentsList));
return autoBuild();
}

// TODO(miraleung): Refactor param paragraph parsing to be more robust.
private static String processParamComment(String rawComment) {
StringBuilder processedCommentBuilder = new StringBuilder();
String[] descriptionParagraphs = rawComment.split("\\n\\n");
for (int i = 0; i < descriptionParagraphs.length; i++) {
boolean startsWithItemizedList = descriptionParagraphs[i].startsWith(" * ");
// Split by listed items, then join newlines.
List<String> listItems =
Stream.of(descriptionParagraphs[i].split("\\n \\*"))
.map(s -> s.replace("\n", ""))
.collect(Collectors.toList());
if (startsWithItemizedList) {
// Remove the first asterisk.
listItems.set(0, listItems.get(0).substring(2));
}
if (!startsWithItemizedList) {
if (i == 0) {
processedCommentBuilder.append(String.format("%s", listItems.get(0)));
} else {
processedCommentBuilder.append(
String.format("%s<p> %s", PARAM_INDENT, listItems.get(0)));
}
}
if (listItems.size() > 1 || startsWithItemizedList) {
processedCommentBuilder.append(
String.format(
"%s<ul>\n%s\n%s</ul>",
PARAM_INDENT,
listItems.subList(startsWithItemizedList ? 0 : 1, listItems.size()).stream()
.map(li -> String.format("%s <li>%s", PARAM_INDENT, li))
.reduce("", String::concat),
PARAM_INDENT));
}
}
return processedCommentBuilder.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class MetacharEscaper extends Escaper {
.addEscape('\b', "\\b")
.addEscape('\r', "\\r")
.addEscape('\f', "\\f")
.addEscape('\n', "\\n")
.addEscape('\\', "\\\\")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ static List<CommentStatement> createRpcMethodHeaderComment(
for (MethodArgument argument : methodArguments) {
// TODO(miraleung): Remove the newline replacement when we support CommonMark.
String description =
argument.field().hasDescription()
? argument.field().description().replace("\n", "")
: EMPTY_STRING;
argument.field().hasDescription() ? argument.field().description() : EMPTY_STRING;
methodJavadocBuilder.addParam(argument.name(), description);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ public void createJavaDocComment_specialCharacter() {
.addComment("Service comment may include special characters: \\ \t\b\r&\"\f\n`'@*/")
.addParagraph("title: GetBigBook: <War and Peace>")
.addSampleCode(
"ApiFuture<Shelf> future = libraryClient.createShelfCallable().futureCall(request);")
"ApiFuture<Shelf> future ="
+ " libraryClient.createShelfCallable().futureCall(request);")
.setThrows("Exception", "This is an exception.")
.build();
String expected =
"Service comment may include special characters: \\\\ \\t\\b\\r&amp;\"\\f\\n`'{@literal @}&#42;/\n"
"Service comment may include special characters: \\\\ \\t\\b\\r"
+ "&amp;\"\\f\n"
+ "`'{@literal @}&#42;/\n"
+ "<p> title: GetBigBook: <War and Peace>\n"
+ "<pre><code>\n"
+ "ApiFuture&lt;Shelf&gt; future = libraryClient.createShelfCallable().futureCall(request);\n"
+ "ApiFuture&lt;Shelf&gt; future ="
+ " libraryClient.createShelfCallable().futureCall(request);\n"
+ "</code></pre>\n"
+ "@throws Exception This is an exception.";
assertEquals(javaDocComment.comment(), expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ public void writeLineComment_specialChar() {
String expected =
"// usage: gradle run -PmainClass=com.google.example.examples.library.v1.Hopper"
+ " [--args='[--shelf\n"
+ "// \"Novel\\\\\"`\\b\\t\\n"
+ "\\r"
+ "// \"Novel\\\\\"`\\b\\t\n"
+ "// \\r"
+ "\"]']\n";
lineComment.accept(writerVisitor);
assertEquals(writerVisitor.write(), expected);
Expand Down
98 changes: 63 additions & 35 deletions test/integration/goldens/asset/AssetServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,31 +473,47 @@ public final UnaryCallable<DeleteFeedRequest, Empty> deleteFeedCallable() {
* @param scope Required. A scope can be a project, a folder, or an organization. The search is
* limited to the resources within the `scope`. The caller must be granted the
* [`cloudasset.assets.searchAllResources`](http://cloud.google.com/asset-inventory/docs/access-control#required_permissions)
* permission on the desired scope. The allowed values are: * projects/{PROJECT_ID} (e.g.,
* "projects/foo-bar") * projects/{PROJECT_NUMBER} (e.g., "projects/12345678") *
* folders/{FOLDER_NUMBER} (e.g., "folders/1234567") * organizations/{ORGANIZATION_NUMBER}
* (e.g., "organizations/123456")
* permission on the desired scope.
* <p>The allowed values are:
* <ul>
* <li>projects/{PROJECT_ID} (e.g., "projects/foo-bar")
* <li>projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
* <li>folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
* <li>organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
* </ul>
*
* @param query Optional. The query statement. See [how to construct a
* query](http://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query)
* for more information. If not specified or empty, it will search all the resources within
* the specified `scope`. Note that the query string is compared against each Cloud IAM policy
* binding, including its members, roles, and Cloud IAM conditions. The returned Cloud IAM
* policies will only contain the bindings that match your query. To learn more about the IAM
* policy structure, see [IAM policy
* doc](https://cloud.google.com/iam/docs/policies#structure). Examples: * `name:Important` to
* find Cloud resources whose name contains "Important" as a word. * `displayName:Impor*` to
* find Cloud resources whose display name contains "Impor" as a prefix. * `description:*por*`
* to find Cloud resources whose description contains "por" as a substring. *
* `location:us-west*` to find Cloud resources whose location is prefixed with "us-west". *
* `labels:prod` to find Cloud resources whose labels contain "prod" as a key or value. *
* `labels.env:prod` to find Cloud resources that have a label "env" and its value is "prod".
* * `labels.env:*` to find Cloud resources that have a label "env". * `Important` to find
* Cloud resources that contain "Important" as a word in any of the searchable fields. *
* `Impor*` to find Cloud resources that contain "Impor" as a prefix in any of the searchable
* fields. * `*por*` to find Cloud resources that contain "por" as a substring in any of the
* searchable fields. * `Important location:(us-west1 OR global)` to find Cloud resources that
* contain "Important" as a word in any of the searchable fields and are also located in the
* "us-west1" region or the "global" location.
* doc](https://cloud.google.com/iam/docs/policies#structure).
* <p>Examples:
* <ul>
* <li>`name:Important` to find Cloud resources whose name contains "Important" as a word.
* <li>`displayName:Impor*` to find Cloud resources whose display name contains "Impor" as a
* prefix.
* <li>`description:*por*` to find Cloud resources whose description contains "por" as a
* substring.
* <li>`location:us-west*` to find Cloud resources whose location is prefixed with
* "us-west".
* <li>`labels:prod` to find Cloud resources whose labels contain "prod" as a key or value.
* <li>`labels.env:prod` to find Cloud resources that have a label "env" and its value is
* "prod".
* <li>`labels.env:*` to find Cloud resources that have a label "env".
* <li>`Important` to find Cloud resources that contain "Important" as a word in any of the
* searchable fields.
* <li>`Impor*` to find Cloud resources that contain "Impor" as a prefix in any of the
* searchable fields.
* <li>`*por*` to find Cloud resources that contain "por" as a substring in any of the
* searchable fields.
* <li>`Important location:(us-west1 OR global)` to find Cloud resources that contain
* "Important" as a word in any of the searchable fields and are also located in the
* "us-west1" region or the "global" location.
* </ul>
*
* @param asset_types Optional. A list of asset types that this request searches for. If empty, it
* will search all the [searchable asset
* types](https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types).
Expand Down Expand Up @@ -567,26 +583,38 @@ public final SearchAllResourcesPagedResponse searchAllResources(
* @param scope Required. A scope can be a project, a folder, or an organization. The search is
* limited to the IAM policies within the `scope`. The caller must be granted the
* [`cloudasset.assets.searchAllIamPolicies`](http://cloud.google.com/asset-inventory/docs/access-control#required_permissions)
* permission on the desired scope. The allowed values are: * projects/{PROJECT_ID} (e.g.,
* "projects/foo-bar") * projects/{PROJECT_NUMBER} (e.g., "projects/12345678") *
* folders/{FOLDER_NUMBER} (e.g., "folders/1234567") * organizations/{ORGANIZATION_NUMBER}
* (e.g., "organizations/123456")
* permission on the desired scope.
* <p>The allowed values are:
* <ul>
* <li>projects/{PROJECT_ID} (e.g., "projects/foo-bar")
* <li>projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
* <li>folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
* <li>organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
* </ul>
*
* @param query Optional. The query statement. See [how to construct a
* query](https://cloud.google.com/asset-inventory/docs/searching-iam-policies#how_to_construct_a_query)
* for more information. If not specified or empty, it will search all the IAM policies within
* the specified `scope`. Examples: * `policy:[email protected]` to find IAM policy bindings that
* specify user "[email protected]". * `policy:roles/compute.admin` to find IAM policy bindings
* that specify the Compute Admin role. * `policy.role.permissions:storage.buckets.update` to
* find IAM policy bindings that specify a role containing "storage.buckets.update"
* permission. Note that if callers don't have `iam.roles.get` access to a role's included
* permissions, policy bindings that specify this role will be dropped from the search
* results. * `resource:organizations/123456` to find IAM policy bindings that are set on
* "organizations/123456". * `Important` to find IAM policy bindings that contain "Important"
* as a word in any of the searchable fields (except for the included permissions). * `*por*`
* to find IAM policy bindings that contain "por" as a substring in any of the searchable
* fields (except for the included permissions). * `resource:(instance1 OR instance2)
* policy:amy` to find IAM policy bindings that are set on resources "instance1" or
* "instance2" and also specify user "amy".
* the specified `scope`.
* <p>Examples:
* <ul>
* <li>`policy:[email protected]` to find IAM policy bindings that specify user "[email protected]".
* <li>`policy:roles/compute.admin` to find IAM policy bindings that specify the Compute
* Admin role.
* <li>`policy.role.permissions:storage.buckets.update` to find IAM policy bindings that
* specify a role containing "storage.buckets.update" permission. Note that if callers
* don't have `iam.roles.get` access to a role's included permissions, policy bindings
* that specify this role will be dropped from the search results.
* <li>`resource:organizations/123456` to find IAM policy bindings that are set on
* "organizations/123456".
* <li>`Important` to find IAM policy bindings that contain "Important" as a word in any of
* the searchable fields (except for the included permissions).
* <li>`*por*` to find IAM policy bindings that contain "por" as a substring in any of the
* searchable fields (except for the included permissions).
* <li>`resource:(instance1 OR instance2) policy:amy` to find IAM policy bindings that are
* set on resources "instance1" or "instance2" and also specify user "amy".
* </ul>
*
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final SearchAllIamPoliciesPagedResponse searchAllIamPolicies(String scope, String query) {
Expand Down
Loading