{"action":"created","comment":{"url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/comments/57624730","id":57624730,"diff_hunk":"@@ -0,0 +1,87 @@\n+/*\n+ * Copyright 2016 Palantir Technologies, Inc. All rights reserved.\n+ */\n+\n+package com.palantir.indexpage;\n+\n+import static com.google.common.base.Preconditions.checkNotNull;\n+\n+import com.github.mustachejava.DefaultMustacheFactory;\n+import com.github.mustachejava.Mustache;\n+import com.google.common.base.Charsets;\n+import com.google.common.base.Optional;\n+import com.google.common.collect.ImmutableMap;\n+import com.google.common.io.Files;\n+import java.io.BufferedReader;\n+import java.io.File;\n+import java.io.FileNotFoundException;\n+import java.io.StringWriter;\n+import java.util.Map;\n+\n+/**\n+ * Used to represent the index page loaded from the file system.\n+ */\n+public final class FileSystemIndexPage implements TemplatedAsset {\n+\n+    private final DefaultMustacheFactory factory;\n+    private final File file;\n+\n+    private Map<String, String> context;\n+    private long lastModified;\n+    private Mustache mustacheCompiler;\n+    private StringWriter writer;\n+\n+    public FileSystemIndexPage(File file) {\n+        checkNotNull(file);\n+\n+        this.factory = new DefaultMustacheFactory();\n+        this.file = file;\n+        writer = new StringWriter();\n+\n+        try {\n+            loadFile();\n+        } catch (FileNotFoundException e) {\n+            throw new RuntimeException(\"Index page cannot be found at \" + file.toString(), e);\n+        }\n+    }\n+\n+    @Override\n+    public Optional<String> getContent(Map<String, String> inputContext) {\n+        checkNotNull(inputContext);\n+\n+        try {\n+            checkAndReloadFile(inputContext);\n+        } catch (FileNotFoundException e) {\n+\n+            // the file could be deleted during run time, so return absent in order to handle the behavior gracefully\n+            return Optional.absent();\n+        }\n+\n+        return Optional.of(writer.toString());\n+    }\n+\n+    private synchronized void checkAndReloadFile(Map<String, String> inputContext) throws FileNotFoundException {\n+\n+        // If file has been changed, we need to load the file and resolve the template. Otherwise,\n+        // only resolve the template if the context has been changed.\n+        if (lastModified != file.lastModified()) {\n+            loadFile();\n+            executeTemplate(inputContext);\n+        } else if (!inputContext.equals(context)) {\n+            executeTemplate(inputContext);\n+        }\n+    }\n+\n+    private void loadFile() throws FileNotFoundException {","path":"dropwizard-index-page/src/main/java/com/palantir/indexpage/FileSystemIndexPage.java","position":75,"original_position":75,"commit_id":"efc567d3431e079744212c1d9526e264e7ec3c01","original_commit_id":"efc567d3431e079744212c1d9526e264e7ec3c01","user":{"login":"jmcampanini","id":316848,"avatar_url":"https://avatars.githubusercontent.com/u/316848?v=3","gravatar_id":"","url":"https://api.github.com/users/jmcampanini","html_url":"https://github.com/jmcampanini","followers_url":"https://api.github.com/users/jmcampanini/followers","following_url":"https://api.github.com/users/jmcampanini/following{/other_user}","gists_url":"https://api.github.com/users/jmcampanini/gists{/gist_id}","starred_url":"https://api.github.com/users/jmcampanini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmcampanini/subscriptions","organizations_url":"https://api.github.com/users/jmcampanini/orgs","repos_url":"https://api.github.com/users/jmcampanini/repos","events_url":"https://api.github.com/users/jmcampanini/events{/privacy}","received_events_url":"https://api.github.com/users/jmcampanini/received_events","type":"User","site_admin":false},"body":"syncronized","created_at":"2016-03-28T20:05:35Z","updated_at":"2016-03-28T20:05:35Z","html_url":"https://github.com/palantir/dropwizard-index-page/pull/29#discussion_r57624730","pull_request_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/comments/57624730"},"html":{"href":"https://github.com/palantir/dropwizard-index-page/pull/29#discussion_r57624730"},"pull_request":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29","id":64086751,"html_url":"https://github.com/palantir/dropwizard-index-page/pull/29","diff_url":"https://github.com/palantir/dropwizard-index-page/pull/29.diff","patch_url":"https://github.com/palantir/dropwizard-index-page/pull/29.patch","issue_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/29","number":29,"state":"open","locked":false,"title":"add cache and classpath support ","user":{"login":"qinfchen","id":8294715,"avatar_url":"https://avatars.githubusercontent.com/u/8294715?v=3","gravatar_id":"","url":"https://api.github.com/users/qinfchen","html_url":"https://github.com/qinfchen","followers_url":"https://api.github.com/users/qinfchen/followers","following_url":"https://api.github.com/users/qinfchen/following{/other_user}","gists_url":"https://api.github.com/users/qinfchen/gists{/gist_id}","starred_url":"https://api.github.com/users/qinfchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qinfchen/subscriptions","organizations_url":"https://api.github.com/users/qinfchen/orgs","repos_url":"https://api.github.com/users/qinfchen/repos","events_url":"https://api.github.com/users/qinfchen/events{/privacy}","received_events_url":"https://api.github.com/users/qinfchen/received_events","type":"User","site_admin":false},"body":"- [x] cache file that loads from file system if it is not being modified, fixes #24\r\n- [x] add support to serve file from the classpath, fixes #29 \r\n- [x] update readme","created_at":"2016-03-24T19:33:36Z","updated_at":"2016-03-28T20:05:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5cbc1e35c9fafe6e76084c9d959a815071bca8a7","assignee":{"login":"jmcampanini","id":316848,"avatar_url":"https://avatars.githubusercontent.com/u/316848?v=3","gravatar_id":"","url":"https://api.github.com/users/jmcampanini","html_url":"https://github.com/jmcampanini","followers_url":"https://api.github.com/users/jmcampanini/followers","following_url":"https://api.github.com/users/jmcampanini/following{/other_user}","gists_url":"https://api.github.com/users/jmcampanini/gists{/gist_id}","starred_url":"https://api.github.com/users/jmcampanini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmcampanini/subscriptions","organizations_url":"https://api.github.com/users/jmcampanini/orgs","repos_url":"https://api.github.com/users/jmcampanini/repos","events_url":"https://api.github.com/users/jmcampanini/events{/privacy}","received_events_url":"https://api.github.com/users/jmcampanini/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29/commits","review_comments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29/comments","review_comment_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/comments{/number}","comments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/29/comments","statuses_url":"https://api.github.com/repos/palantir/dropwizard-index-page/statuses/efc567d3431e079744212c1d9526e264e7ec3c01","head":{"label":"palantir:qchen/FileAssets","ref":"qchen/FileAssets","sha":"efc567d3431e079744212c1d9526e264e7ec3c01","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":52290713,"name":"dropwizard-index-page","full_name":"palantir/dropwizard-index-page","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/dropwizard-index-page","description":"A Dropwizard bundle that serves the index page for a single page application","fork":false,"url":"https://api.github.com/repos/palantir/dropwizard-index-page","forks_url":"https://api.github.com/repos/palantir/dropwizard-index-page/forks","keys_url":"https://api.github.com/repos/palantir/dropwizard-index-page/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/dropwizard-index-page/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/dropwizard-index-page/teams","hooks_url":"https://api.github.com/repos/palantir/dropwizard-index-page/hooks","issue_events_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/dropwizard-index-page/events","assignees_url":"https://api.github.com/repos/palantir/dropwizard-index-page/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/dropwizard-index-page/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/dropwizard-index-page/tags","blobs_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/dropwizard-index-page/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/dropwizard-index-page/languages","stargazers_url":"https://api.github.com/repos/palantir/dropwizard-index-page/stargazers","contributors_url":"https://api.github.com/repos/palantir/dropwizard-index-page/contributors","subscribers_url":"https://api.github.com/repos/palantir/dropwizard-index-page/subscribers","subscription_url":"https://api.github.com/repos/palantir/dropwizard-index-page/subscription","commits_url":"https://api.github.com/repos/palantir/dropwizard-index-page/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/comments{/number}","contents_url":"https://api.github.com/repos/palantir/dropwizard-index-page/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/dropwizard-index-page/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/dropwizard-index-page/merges","archive_url":"https://api.github.com/repos/palantir/dropwizard-index-page/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/dropwizard-index-page/downloads","issues_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/dropwizard-index-page/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/dropwizard-index-page/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/dropwizard-index-page/labels{/name}","releases_url":"https://api.github.com/repos/palantir/dropwizard-index-page/releases{/id}","deployments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/deployments","created_at":"2016-02-22T17:17:38Z","updated_at":"2016-03-18T20:52:38Z","pushed_at":"2016-03-28T17:55:59Z","git_url":"git://github.com/palantir/dropwizard-index-page.git","ssh_url":"git@github.com:palantir/dropwizard-index-page.git","clone_url":"https://github.com/palantir/dropwizard-index-page.git","svn_url":"https://github.com/palantir/dropwizard-index-page","homepage":"https://bintray.com/palantir/releases/dropwizard-index-page/view","size":223,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":2,"default_branch":"develop"}},"base":{"label":"palantir:develop","ref":"develop","sha":"88846d9ca3483f526deb17dd70469752d6b8c55d","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":52290713,"name":"dropwizard-index-page","full_name":"palantir/dropwizard-index-page","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/dropwizard-index-page","description":"A Dropwizard bundle that serves the index page for a single page application","fork":false,"url":"https://api.github.com/repos/palantir/dropwizard-index-page","forks_url":"https://api.github.com/repos/palantir/dropwizard-index-page/forks","keys_url":"https://api.github.com/repos/palantir/dropwizard-index-page/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/dropwizard-index-page/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/dropwizard-index-page/teams","hooks_url":"https://api.github.com/repos/palantir/dropwizard-index-page/hooks","issue_events_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/dropwizard-index-page/events","assignees_url":"https://api.github.com/repos/palantir/dropwizard-index-page/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/dropwizard-index-page/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/dropwizard-index-page/tags","blobs_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/dropwizard-index-page/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/dropwizard-index-page/languages","stargazers_url":"https://api.github.com/repos/palantir/dropwizard-index-page/stargazers","contributors_url":"https://api.github.com/repos/palantir/dropwizard-index-page/contributors","subscribers_url":"https://api.github.com/repos/palantir/dropwizard-index-page/subscribers","subscription_url":"https://api.github.com/repos/palantir/dropwizard-index-page/subscription","commits_url":"https://api.github.com/repos/palantir/dropwizard-index-page/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/dropwizard-index-page/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/comments{/number}","contents_url":"https://api.github.com/repos/palantir/dropwizard-index-page/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/dropwizard-index-page/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/dropwizard-index-page/merges","archive_url":"https://api.github.com/repos/palantir/dropwizard-index-page/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/dropwizard-index-page/downloads","issues_url":"https://api.github.com/repos/palantir/dropwizard-index-page/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/dropwizard-index-page/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/dropwizard-index-page/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/dropwizard-index-page/labels{/name}","releases_url":"https://api.github.com/repos/palantir/dropwizard-index-page/releases{/id}","deployments_url":"https://api.github.com/repos/palantir/dropwizard-index-page/deployments","created_at":"2016-02-22T17:17:38Z","updated_at":"2016-03-18T20:52:38Z","pushed_at":"2016-03-28T17:55:59Z","git_url":"git://github.com/palantir/dropwizard-index-page.git","ssh_url":"git@github.com:palantir/dropwizard-index-page.git","clone_url":"https://github.com/palantir/dropwizard-index-page.git","svn_url":"https://github.com/palantir/dropwizard-index-page","homepage":"https://bintray.com/palantir/releases/dropwizard-index-page/view","size":223,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29"},"html":{"href":"https://github.com/palantir/dropwizard-index-page/pull/29"},"issue":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/29"},"comments":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/palantir/dropwizard-index-page/statuses/efc567d3431e079744212c1d9526e264e7ec3c01"}}}}