{"action":"created","comment":{"url":"https://api.github.com/repos/apollostack/apollo-android/pulls/comments/93240309","pull_request_review_id":13762268,"id":93240309,"diff_hunk":"@@ -36,48 +38,79 @@ public class ApolloIRGenTask extends NodeTask {\n     variant = variantName\n     config = extensionsConfig\n     group = ApolloPlugin.TASK_GROUP\n-    description = \"Generate IR files using apollo-codgen for ${variant.capitalize()} GraphQL queries\"\n+    description = \"Generate an IR file using apollo-codgen for ${variant.capitalize()} GraphQL queries\"\n     dependsOn(ApolloCodeGenInstallTask.NAME)\n-    outputDir = new File(\"${getSchemaPath()}/generatedIR\")\n+\n+    possibleGraphQLPaths = buildPossibleGraphQLPaths()\n+    outputDir = project.file(\"src/$variant/graphql/generatedIR\")\n   }\n \n   @Override\n   public void exec() {\n     File apolloScript = project.file(APOLLO_CODEGEN)\n+    File schemaFile = userProvidedSchemaFile() ?: searchForSchemaFile()\n \n     if (!apolloScript.isFile()) {\n       throw new GradleException(\"Apollo-codegen was not found in node_modules. Please run 'gradle \" +\n           \"${ApolloCodeGenInstallTask.NAME}\")\n     }\n-    if (!new File(\"$outputDir.parent/schema.json\").isFile()) {\n+\n+    if (!schemaFile.isFile()) {\n       throw new GradleException(\"Couldn't find a schema file. Please ensure a valid schema.json files exists in the \" +\n           \"sourceSet directory\")\n     }\n \n     setScript(apolloScript)\n     List<String> apolloArgs = [\"generate\"]\n+    println \"sending request with schema path ${schemaFile.absolutePath}\"\n     apolloArgs.addAll(getInputFiles().collect { project.file(it).absolutePath })\n-    apolloArgs.addAll([\"--schema\", \"$outputDir.parent/schema.json\",\n+    apolloArgs.addAll([\"--schema\", \"${schemaFile.absolutePath}\",\n                        \"--output\", \"$outputDir.absolutePath/${variant.capitalize()}API.json\",\n                        \"--target\", \"json\"]);\n     setArgs(apolloArgs)\n     super.exec()\n   }\n \n-  private String getSchemaPath() {\n-    String schemaPath = \"\"\n-    PatternSet patternSet = new PatternSet().include(\"**/schema.json\")\n-    for (String path : config.reverse().graphqlPath) {\n+  private File userProvidedSchemaFile() {\n+    List<String> schemaFiles = config.schemaFile?.findAll { it != null }\n+    File schemaFile\n+    if (schemaFiles) {\n+      if (schemaFiles.size() > 1) {\n+        throw new IllegalArgumentException(\"More than two schema files were specified for the build variant $variant.\" +\n+            \" Please ensure that only one schema field is specified for $variant's source sets\")\n+      }\n+      schemaFile = project.file(schemaFile.get(0))\n+    }\n+    return schemaFile\n+  }\n+\n+  private File searchForSchemaFile() {\n+    File schemaFile\n+    PatternSet patternSet = new PatternSet().include(DEFAULT_SCHEMA_FILE_PATTERN)\n+    for (String path : possibleGraphQLPaths) {\n       project.files(path).getAsFileTree().matching(patternSet).visit {\n         if (!it.directory) {\n-          schemaPath = it.file.parent\n+          schemaFile = it.file\n           return true\n         }\n       }\n-      if (!schemaPath.isEmpty()) {\n-        return schemaPath\n+      if (schemaFile?.isFile()) {\n+        return schemaFile\n+      }\n+    }\n+    return project.file(\"$DEFAULT_OUTPUT_DIR/schema.json\")\n+  }\n+\n+  private List<String> buildPossibleGraphQLPaths() {\n+    List<String> graphQLPaths = new ArrayList<>();\n+    config.each { ext ->\n+      graphQLPaths.add(\"src/${ext.getSourceSet()}/graphql\")","path":"apollo-gradle-plugin/src/main/groovy/com/apollostack/android/gradle/ApolloIRgenTask.groovy","position":107,"original_position":108,"commit_id":"92e21d1b1dd5d39ee53c372d6d983e4772a5cfe8","original_commit_id":"e0d938bada80945a7e8f2395a5ddf4bbc028eedb","user":{"login":"marwanad","id":7871596,"avatar_url":"https://avatars.githubusercontent.com/u/7871596?v=3","gravatar_id":"","url":"https://api.github.com/users/marwanad","html_url":"https://github.com/marwanad","followers_url":"https://api.github.com/users/marwanad/followers","following_url":"https://api.github.com/users/marwanad/following{/other_user}","gists_url":"https://api.github.com/users/marwanad/gists{/gist_id}","starred_url":"https://api.github.com/users/marwanad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marwanad/subscriptions","organizations_url":"https://api.github.com/users/marwanad/orgs","repos_url":"https://api.github.com/users/marwanad/repos","events_url":"https://api.github.com/users/marwanad/events{/privacy}","received_events_url":"https://api.github.com/users/marwanad/received_events","type":"User","site_admin":false},"body":"Those are the default sourceSets returned in the reverse lookup order.","created_at":"2016-12-20T13:52:36Z","updated_at":"2016-12-20T13:52:36Z","html_url":"https://github.com/apollostack/apollo-android/pull/52#discussion_r93240309","pull_request_url":"https://api.github.com/repos/apollostack/apollo-android/pulls/52","_links":{"self":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/comments/93240309"},"html":{"href":"https://github.com/apollostack/apollo-android/pull/52#discussion_r93240309"},"pull_request":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/52"}}},"pull_request":{"url":"https://api.github.com/repos/apollostack/apollo-android/pulls/52","id":98070684,"html_url":"https://github.com/apollostack/apollo-android/pull/52","diff_url":"https://github.com/apollostack/apollo-android/pull/52.diff","patch_url":"https://github.com/apollostack/apollo-android/pull/52.patch","issue_url":"https://api.github.com/repos/apollostack/apollo-android/issues/52","number":52,"state":"open","locked":false,"title":"add apollo-codgen gradle tasks","user":{"login":"marwanad","id":7871596,"avatar_url":"https://avatars.githubusercontent.com/u/7871596?v=3","gravatar_id":"","url":"https://api.github.com/users/marwanad","html_url":"https://github.com/marwanad","followers_url":"https://api.github.com/users/marwanad/followers","following_url":"https://api.github.com/users/marwanad/following{/other_user}","gists_url":"https://api.github.com/users/marwanad/gists{/gist_id}","starred_url":"https://api.github.com/users/marwanad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marwanad/subscriptions","organizations_url":"https://api.github.com/users/marwanad/orgs","repos_url":"https://api.github.com/users/marwanad/repos","events_url":"https://api.github.com/users/marwanad/events{/privacy}","received_events_url":"https://api.github.com/users/marwanad/received_events","type":"User","site_admin":false},"body":"@martijnwalraven @felipecsl @sav007 please take a look. \r\n\r\nIt's a lot of text but I just wanted to keep those points for the record. Also please check the comments on the diff.\r\n\r\nApolloPlugin now performs the following actions:\r\n- Adds a dependency on `gradle-node`. This handles installing node nicely under `.gradle` and npm dependencies.\r\n\r\n- The Apollo plugin starts off by adding the node plugin. This creates 5 gradle tasks (3 npm, 2 yarn) under the node group. Those won't have to be used.\r\n\r\n- The Apollo plugin then creates an `ApolloCodegenInstall` task. This task basically executes `npm install apollo-codgen` and depends on `nodeSetup` task.\r\n\r\n- Adds an `ApolloExtension` to every sourceSet in the project. This essentially allows to have configurable options through the Gradle DSL. For example, let the user decide whether they want to have an Rx Observable returned, etc. Here, it's used to allow the user to define custom sourceSet directories. \r\n\r\n- For every variant in the android project, register an ApolloIRGenTask. This would execute `apollo-codgen generate [...]`. Variants can have multiple sourceSets so that's the reason for having a List of ApolloExtensions in each ApolloIRGenTask. \r\n\r\nIt also creates a top-level apolloIRGenTask which depends on the variant ones. Thus, running this will basically run the ones on all registered variants. \r\n\r\nThus for `apollo-sample` project, you'll end up with the following tasks:\r\n\r\n```\r\nApollo tasks\r\n------------\r\ngenerateApolloClasses\r\ngenerateApolloIR\r\ngenerateDebugApolloClasses - Generate Android classes for Debug GraphQL queries\r\ngenerateDebugApolloIR - Generate IR files using apollo-codgen for Debug GraphQL queries\r\ngenerateReleaseApolloClasses - Generate Android classes for Release GraphQL queries\r\ngenerateReleaseApolloIR - Generate IR files using apollo-codgen for Release GraphQL queries\r\ninstallApolloCodegen - Runs npm install for apollo-codegen\r\n\r\nNode tasks\r\n----------\r\nnodeSetup - Download and install a local node/npm version.\r\nnpmInstall - Install node packages from package.json.\r\nnpmSetup - Setup a specific version of npm to be used by the build.\r\nyarn - Install node packages using Yarn.\r\nyarnSetup - Setup a specific version of Yarn to be used by the build.\r\n```\r\n\r\n### Running the snapshot jar.\r\n\r\nFor now, to run on the `apollo-sample` project:\r\n\r\n1. Add the following under the apollo-sample gradle build script:\r\n```\r\nbuildscript {\r\n    // needed for apollo-compiler dependencies\r\n    mavenCentral()\r\n    jcenter()\r\n    maven { url \"https://jitpack.io\" }\r\n  repositories { flatDir name: 'libs', dirs: \"../apollo-gradle-plugin/build/libs\" }\r\n}\r\n  dependencies {\r\n    classpath project(':apollo-compiler')\r\n    classpath 'test-plugin:apollo-gradle-plugin:0.0.1-SNAPSHOT'\r\n    classpath dep.gradleNodePlugin\r\n}\r\napply plugin: 'com.apollostack.android'\r\n```\r\n2. Create a `src/main/graphql/` folder with a schema.json and some .graphql query files. You can find some [here](https://github.com/apollostack/apollo-codegen/tree/master/test/starwars). (Ensure that no naming conflicts exist in the files you're using from apollo-codgen)\r\n\r\n3. Run `./gradlew apollo-sample:generateApolloIR`. This has a dependency on the node install task so it should install all dependencies if they don't exist.\r\n\r\nDiscussion Points:\r\n\r\n### ApolloClassgenTask\r\n\r\nI think we should add some sort of a Validator class that ships as part of the compiler that validates the JSON IR before attempting to generate the classes and handles exceptions nicely. This should be relatively simple since it would only validate JSON files. Open to discussions on that point.\r\n### Testing\r\nWe might need some integration tests once all the components are ready. \r\n\r\nCloses #43 ","created_at":"2016-12-15T01:27:37Z","updated_at":"2016-12-20T13:52:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"61d9c8124615af51c6f087698e508caa77dcc7f7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apollostack/apollo-android/pulls/52/commits","review_comments_url":"https://api.github.com/repos/apollostack/apollo-android/pulls/52/comments","review_comment_url":"https://api.github.com/repos/apollostack/apollo-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apollostack/apollo-android/issues/52/comments","statuses_url":"https://api.github.com/repos/apollostack/apollo-android/statuses/92e21d1b1dd5d39ee53c372d6d983e4772a5cfe8","head":{"label":"apollostack:apollo-gradle-plugin","ref":"apollo-gradle-plugin","sha":"92e21d1b1dd5d39ee53c372d6d983e4772a5cfe8","user":{"login":"apollostack","id":17189275,"avatar_url":"https://avatars.githubusercontent.com/u/17189275?v=3","gravatar_id":"","url":"https://api.github.com/users/apollostack","html_url":"https://github.com/apollostack","followers_url":"https://api.github.com/users/apollostack/followers","following_url":"https://api.github.com/users/apollostack/following{/other_user}","gists_url":"https://api.github.com/users/apollostack/gists{/gist_id}","starred_url":"https://api.github.com/users/apollostack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollostack/subscriptions","organizations_url":"https://api.github.com/users/apollostack/orgs","repos_url":"https://api.github.com/users/apollostack/repos","events_url":"https://api.github.com/users/apollostack/events{/privacy}","received_events_url":"https://api.github.com/users/apollostack/received_events","type":"Organization","site_admin":false},"repo":{"id":69469299,"name":"apollo-android","full_name":"apollostack/apollo-android","owner":{"login":"apollostack","id":17189275,"avatar_url":"https://avatars.githubusercontent.com/u/17189275?v=3","gravatar_id":"","url":"https://api.github.com/users/apollostack","html_url":"https://github.com/apollostack","followers_url":"https://api.github.com/users/apollostack/followers","following_url":"https://api.github.com/users/apollostack/following{/other_user}","gists_url":"https://api.github.com/users/apollostack/gists{/gist_id}","starred_url":"https://api.github.com/users/apollostack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollostack/subscriptions","organizations_url":"https://api.github.com/users/apollostack/orgs","repos_url":"https://api.github.com/users/apollostack/repos","events_url":"https://api.github.com/users/apollostack/events{/privacy}","received_events_url":"https://api.github.com/users/apollostack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apollostack/apollo-android","description":":pager: A GraphQL client for Android (WIP)","fork":false,"url":"https://api.github.com/repos/apollostack/apollo-android","forks_url":"https://api.github.com/repos/apollostack/apollo-android/forks","keys_url":"https://api.github.com/repos/apollostack/apollo-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apollostack/apollo-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apollostack/apollo-android/teams","hooks_url":"https://api.github.com/repos/apollostack/apollo-android/hooks","issue_events_url":"https://api.github.com/repos/apollostack/apollo-android/issues/events{/number}","events_url":"https://api.github.com/repos/apollostack/apollo-android/events","assignees_url":"https://api.github.com/repos/apollostack/apollo-android/assignees{/user}","branches_url":"https://api.github.com/repos/apollostack/apollo-android/branches{/branch}","tags_url":"https://api.github.com/repos/apollostack/apollo-android/tags","blobs_url":"https://api.github.com/repos/apollostack/apollo-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apollostack/apollo-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apollostack/apollo-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/apollostack/apollo-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apollostack/apollo-android/statuses/{sha}","languages_url":"https://api.github.com/repos/apollostack/apollo-android/languages","stargazers_url":"https://api.github.com/repos/apollostack/apollo-android/stargazers","contributors_url":"https://api.github.com/repos/apollostack/apollo-android/contributors","subscribers_url":"https://api.github.com/repos/apollostack/apollo-android/subscribers","subscription_url":"https://api.github.com/repos/apollostack/apollo-android/subscription","commits_url":"https://api.github.com/repos/apollostack/apollo-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/apollostack/apollo-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/apollostack/apollo-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/apollostack/apollo-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/apollostack/apollo-android/contents/{+path}","compare_url":"https://api.github.com/repos/apollostack/apollo-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apollostack/apollo-android/merges","archive_url":"https://api.github.com/repos/apollostack/apollo-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apollostack/apollo-android/downloads","issues_url":"https://api.github.com/repos/apollostack/apollo-android/issues{/number}","pulls_url":"https://api.github.com/repos/apollostack/apollo-android/pulls{/number}","milestones_url":"https://api.github.com/repos/apollostack/apollo-android/milestones{/number}","notifications_url":"https://api.github.com/repos/apollostack/apollo-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apollostack/apollo-android/labels{/name}","releases_url":"https://api.github.com/repos/apollostack/apollo-android/releases{/id}","deployments_url":"https://api.github.com/repos/apollostack/apollo-android/deployments","created_at":"2016-09-28T14:03:30Z","updated_at":"2016-12-17T07:34:19Z","pushed_at":"2016-12-20T13:35:23Z","git_url":"git://github.com/apollostack/apollo-android.git","ssh_url":"git@github.com:apollostack/apollo-android.git","clone_url":"https://github.com/apollostack/apollo-android.git","svn_url":"https://github.com/apollostack/apollo-android","homepage":"","size":205,"stargazers_count":44,"watchers_count":44,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":11,"forks":5,"open_issues":11,"watchers":44,"default_branch":"master"}},"base":{"label":"apollostack:master","ref":"master","sha":"30d67e1266c91032f17a4672f04843f3a438d54c","user":{"login":"apollostack","id":17189275,"avatar_url":"https://avatars.githubusercontent.com/u/17189275?v=3","gravatar_id":"","url":"https://api.github.com/users/apollostack","html_url":"https://github.com/apollostack","followers_url":"https://api.github.com/users/apollostack/followers","following_url":"https://api.github.com/users/apollostack/following{/other_user}","gists_url":"https://api.github.com/users/apollostack/gists{/gist_id}","starred_url":"https://api.github.com/users/apollostack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollostack/subscriptions","organizations_url":"https://api.github.com/users/apollostack/orgs","repos_url":"https://api.github.com/users/apollostack/repos","events_url":"https://api.github.com/users/apollostack/events{/privacy}","received_events_url":"https://api.github.com/users/apollostack/received_events","type":"Organization","site_admin":false},"repo":{"id":69469299,"name":"apollo-android","full_name":"apollostack/apollo-android","owner":{"login":"apollostack","id":17189275,"avatar_url":"https://avatars.githubusercontent.com/u/17189275?v=3","gravatar_id":"","url":"https://api.github.com/users/apollostack","html_url":"https://github.com/apollostack","followers_url":"https://api.github.com/users/apollostack/followers","following_url":"https://api.github.com/users/apollostack/following{/other_user}","gists_url":"https://api.github.com/users/apollostack/gists{/gist_id}","starred_url":"https://api.github.com/users/apollostack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollostack/subscriptions","organizations_url":"https://api.github.com/users/apollostack/orgs","repos_url":"https://api.github.com/users/apollostack/repos","events_url":"https://api.github.com/users/apollostack/events{/privacy}","received_events_url":"https://api.github.com/users/apollostack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apollostack/apollo-android","description":":pager: A GraphQL client for Android (WIP)","fork":false,"url":"https://api.github.com/repos/apollostack/apollo-android","forks_url":"https://api.github.com/repos/apollostack/apollo-android/forks","keys_url":"https://api.github.com/repos/apollostack/apollo-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apollostack/apollo-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apollostack/apollo-android/teams","hooks_url":"https://api.github.com/repos/apollostack/apollo-android/hooks","issue_events_url":"https://api.github.com/repos/apollostack/apollo-android/issues/events{/number}","events_url":"https://api.github.com/repos/apollostack/apollo-android/events","assignees_url":"https://api.github.com/repos/apollostack/apollo-android/assignees{/user}","branches_url":"https://api.github.com/repos/apollostack/apollo-android/branches{/branch}","tags_url":"https://api.github.com/repos/apollostack/apollo-android/tags","blobs_url":"https://api.github.com/repos/apollostack/apollo-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apollostack/apollo-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apollostack/apollo-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/apollostack/apollo-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apollostack/apollo-android/statuses/{sha}","languages_url":"https://api.github.com/repos/apollostack/apollo-android/languages","stargazers_url":"https://api.github.com/repos/apollostack/apollo-android/stargazers","contributors_url":"https://api.github.com/repos/apollostack/apollo-android/contributors","subscribers_url":"https://api.github.com/repos/apollostack/apollo-android/subscribers","subscription_url":"https://api.github.com/repos/apollostack/apollo-android/subscription","commits_url":"https://api.github.com/repos/apollostack/apollo-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/apollostack/apollo-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/apollostack/apollo-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/apollostack/apollo-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/apollostack/apollo-android/contents/{+path}","compare_url":"https://api.github.com/repos/apollostack/apollo-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apollostack/apollo-android/merges","archive_url":"https://api.github.com/repos/apollostack/apollo-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apollostack/apollo-android/downloads","issues_url":"https://api.github.com/repos/apollostack/apollo-android/issues{/number}","pulls_url":"https://api.github.com/repos/apollostack/apollo-android/pulls{/number}","milestones_url":"https://api.github.com/repos/apollostack/apollo-android/milestones{/number}","notifications_url":"https://api.github.com/repos/apollostack/apollo-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apollostack/apollo-android/labels{/name}","releases_url":"https://api.github.com/repos/apollostack/apollo-android/releases{/id}","deployments_url":"https://api.github.com/repos/apollostack/apollo-android/deployments","created_at":"2016-09-28T14:03:30Z","updated_at":"2016-12-17T07:34:19Z","pushed_at":"2016-12-20T13:35:23Z","git_url":"git://github.com/apollostack/apollo-android.git","ssh_url":"git@github.com:apollostack/apollo-android.git","clone_url":"https://github.com/apollostack/apollo-android.git","svn_url":"https://github.com/apollostack/apollo-android","homepage":"","size":205,"stargazers_count":44,"watchers_count":44,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":11,"forks":5,"open_issues":11,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/52"},"html":{"href":"https://github.com/apollostack/apollo-android/pull/52"},"issue":{"href":"https://api.github.com/repos/apollostack/apollo-android/issues/52"},"comments":{"href":"https://api.github.com/repos/apollostack/apollo-android/issues/52/comments"},"review_comments":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/52/comments"},"review_comment":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apollostack/apollo-android/pulls/52/commits"},"statuses":{"href":"https://api.github.com/repos/apollostack/apollo-android/statuses/92e21d1b1dd5d39ee53c372d6d983e4772a5cfe8"}}}}
{"actor":{"display_login":"marwanad"}}