Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Airline composition with @Inject #328

Merged
merged 1 commit into from Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -81,11 +81,13 @@ FeatureBuildItem feature() {
}

@BuildStep
public void beanConfig(BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotations,
public void beanConfig(CombinedIndexBuildItem index,
BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotations,
BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer) {
beanDefiningAnnotations.produce(new BeanDefiningAnnotationBuildItem(COMMAND, DEPENDENT));

annotationsTransformer.produce(new AnnotationsTransformerBuildItem(new HideAirlineInjectAnnotationsTransformer()));
annotationsTransformer
.produce(new AnnotationsTransformerBuildItem(new HideAirlineInjectAnnotationsTransformer(index.getIndex())));
}

@BuildStep
Expand Down
Expand Up @@ -6,14 +6,26 @@
import static io.quarkiverse.githubapp.command.airline.deployment.GitHubAppCommandAirlineDotNames.GLOBAL_METADATA;
import static io.quarkiverse.githubapp.command.airline.deployment.GitHubAppCommandAirlineDotNames.OPTION;

import java.util.Set;

import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Type;

import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.DotNames;

public class HideAirlineInjectAnnotationsTransformer implements AnnotationsTransformer {

private final IndexView index;

HideAirlineInjectAnnotationsTransformer(IndexView index) {
this.index = index;
}

@Override
public boolean appliesTo(Kind kind) {
return Kind.FIELD == kind;
Expand All @@ -31,10 +43,29 @@ public void transform(TransformationContext transformationContext) {
!fieldInfo.hasAnnotation(OPTION) &&
!GLOBAL_METADATA.equals(fieldInfo.type().name()) &&
!COMMAND_GROUP_METADATA.equals(fieldInfo.type().name()) &&
!COMMAND_METADATA.equals(fieldInfo.type().name())) {
!COMMAND_METADATA.equals(fieldInfo.type().name()) &&
!isComposition(fieldInfo)) {
return;
}

transformationContext.transform().remove(ai -> DotNames.INJECT.equals(ai.name())).done();
}

private boolean isComposition(FieldInfo fieldInfo) {
Type fieldType = fieldInfo.type();

if (fieldType.kind() != Type.Kind.CLASS) {
return false;
}

ClassInfo fieldClass = index.getClassByName(fieldType.asClassType().name());

if (fieldClass == null) {
return false;
}

Set<DotName> fieldClassAnnotations = fieldClass.annotations().keySet();

return fieldClassAnnotations.contains(ARGUMENTS) || fieldClassAnnotations.contains(OPTION);
}
}
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
@@ -1,4 +1,4 @@
:quarkus-version: 2.10.1.Final
:quarkus-version: 2.10.2.Final
:quarkus-github-app-version: 1.9.0

:github-api-javadoc-root-url: https://github-api.kohsuke.org/apidocs/org/kohsuke/github
Expand Down
@@ -0,0 +1,44 @@
package io.quarkiverse.githubapp.it.command.airline;

import java.io.IOException;

import javax.inject.Inject;

import org.kohsuke.github.GHEventPayload;

import com.github.rvesse.airline.annotations.Cli;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;

import io.quarkiverse.githubapp.it.command.airline.CompositionCli.TestCompositionCommand;

@Cli(name = "@composition", commands = { TestCompositionCommand.class })
public class CompositionCli {

@Command(name = "test")
static class TestCompositionCommand implements DefaultCommand {

@Inject
VerboseModule verboseModule = new VerboseModule();

@Override
public void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException {
if (verboseModule.verbose) {
issueCommentPayload.getIssue().comment("hello from @composition test - verbose");
} else {
issueCommentPayload.getIssue().comment("hello from @composition test");
}
}
}

public static class VerboseModule {

@Option(name = { "-v", "--verbose" }, description = "Enables verbose mode")
protected boolean verbose = false;
}

public interface DefaultCommand {

void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException;
}
}
@@ -0,0 +1,32 @@
package io.quarkiverse.githubapp.it.command.airline;

import static io.quarkiverse.githubapp.it.command.airline.util.CommandTestUtils.verifyCommandExecution;
import static io.quarkiverse.githubapp.testing.GitHubAppTesting.when;

import java.io.IOException;

import org.junit.jupiter.api.Test;
import org.kohsuke.github.GHEvent;

import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@GitHubAppTest
public class CompositionCliTest {

@Test
void test() throws IOException {
when().payloadFromClasspath("/issue-comment-composition.json")
.event(GHEvent.ISSUE_COMMENT)
.then().github(mocks -> {
verifyCommandExecution(mocks, "hello from @composition test");
});

when().payloadFromClasspath("/issue-comment-composition-verbose.json")
.event(GHEvent.ISSUE_COMMENT)
.then().github(mocks -> {
verifyCommandExecution(mocks, "hello from @composition test - verbose");
});
}
}
@@ -0,0 +1,236 @@
{
"action": "created",
"issue": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111",
"repository_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111/labels{/name}",
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111/comments",
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111/events",
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/pull/111",
"id": 1168785554,
"node_id": "PR_kwDOEq3cwc40asdO",
"number": 111,
"title": "test",
"user": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"labels": [],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [],
"milestone": null,
"comments": 14,
"created_at": "2022-03-14T19:01:38Z",
"updated_at": "2022-04-08T15:38:53Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
"draft": false,
"pull_request": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls/111",
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/pull/111",
"diff_url": "https://github.com/gsmet/quarkus-bot-java-playground/pull/111.diff",
"patch_url": "https://github.com/gsmet/quarkus-bot-java-playground/pull/111.patch",
"merged_at": null
},
"body": null,
"reactions": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111/timeline",
"performed_via_github_app": null
},
"comment": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments/1093016219",
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/pull/111#issuecomment-1093016219",
"issue_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/111",
"id": 1093016219,
"node_id": "IC_kwDOEq3cwc5BJhqb",
"user": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2022-04-08T15:38:53Z",
"updated_at": "2022-04-08T15:38:53Z",
"author_association": "OWNER",
"body": "@composition test --verbose",
"reactions": {
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments/1093016219/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"performed_via_github_app": null
},
"repository": {
"id": 313384129,
"node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=",
"name": "quarkus-bot-java-playground",
"full_name": "gsmet/quarkus-bot-java-playground",
"private": false,
"owner": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
"forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks",
"keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams",
"hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks",
"issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}",
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events",
"assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}",
"branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}",
"tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags",
"blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}",
"languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages",
"stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers",
"contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors",
"subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers",
"subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription",
"commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}",
"compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges",
"archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads",
"issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}",
"pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}",
"milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}",
"notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}",
"releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}",
"deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments",
"created_at": "2020-11-16T17:55:53Z",
"updated_at": "2021-12-22T17:20:52Z",
"pushed_at": "2022-03-21T19:50:31Z",
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
"ssh_url": "git@github.com:gsmet/quarkus-bot-java-playground.git",
"clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git",
"svn_url": "https://github.com/gsmet/quarkus-bot-java-playground",
"homepage": null,
"size": 113,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Java",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 2,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 34,
"license": null,
"allow_forking": true,
"is_template": false,
"topics": [],
"visibility": "public",
"forks": 2,
"open_issues": 34,
"watchers": 0,
"default_branch": "main"
},
"sender": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 13005535,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
}
}