{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/22735351","id":22735351,"diff_hunk":"@@ -0,0 +1,170 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.apache.reef.javabridge;\n+\n+import org.apache.commons.compress.utils.IOUtils;\n+import org.apache.reef.runtime.common.files.REEFFileNames;\n+import org.apache.reef.util.logging.LoggingScope;\n+import org.apache.reef.util.logging.LoggingScopeFactory;\n+\n+import javax.inject.Inject;\n+import java.io.*;\n+import java.util.Date;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n+\n+/**\n+ * Loading CLR libraries\n+ */\n+public class LibLoader {\n+\n+  private static final Logger LOG = Logger.getLogger(LibLoader.class.getName());\n+\n+  private static final String LIB_BIN = \"/\";\n+  private static final String DLL_EXTENSION = \".dll\";\n+  private static final String USER_DIR = \"user.dir\";\n+  private static final String[] MANAGED_DLLS = {\n+      \"ClrHandler\",\n+      \"msvcr110\",\n+  };\n+\n+  private final LoggingScopeFactory loggingScopeFactory;\n+\n+  private final REEFFileNames reefFileNames;\n+\n+  @Inject\n+  private LibLoader(final LoggingScopeFactory loggingScopeFactory, final REEFFileNames reefFileNames) {\n+    this.loggingScopeFactory = loggingScopeFactory;\n+    this.reefFileNames = reefFileNames;\n+  }\n+\n+  /**\n+   * Load CLR libraries\n+   */\n+  public void loadLib() {\n+    LOG.log(Level.INFO, \"Loading DLLs for driver at time \" + new Date().toString());\n+    try (final LoggingScope lb = loggingScopeFactory.loadLib()) {\n+      final String tempLoadDir = System.getProperty(USER_DIR) + this.reefFileNames.getLoadDir();\n+      LOG.log(Level.INFO, \"load Folder: \" + tempLoadDir);\n+      new File(tempLoadDir).mkdir();\n+\n+      try {\n+        loadFromReefJar(this.reefFileNames.getCppBridge(), false);\n+\n+        LoadLibFromGlobal();\n+\n+        for (int i = 0; i < MANAGED_DLLS.length; i++) {\n+          loadFromReefJar(MANAGED_DLLS[i], true);\n+        }\n+      } catch (IOException e) {\n+        throw new RuntimeException(e);\n+      }\n+    }\n+    LOG.log(Level.INFO, \"Done loading DLLs for Driver at time \" + new Date().toString());\n+  }\n+\n+  /**\n+   * Load assemblies at global folder\n+   */\n+  private void LoadLibFromGlobal() {\n+    final String globalFilePath = System.getProperty(USER_DIR) + this.reefFileNames.getReefGlobal();\n+    final File[] files = new File(globalFilePath).listFiles(new FilenameFilter() {\n+      public boolean accept(File dir, String name) {\n+        return name.toLowerCase().endsWith(DLL_EXTENSION);\n+      }\n+    });\n+\n+    LOG.log(Level.INFO, \"Total dll files to load from {0} is {1}.\", new Object[] {globalFilePath, files.length} );\n+    for (int i = 0; i < files.length; i++) {\n+      try {\n+        LOG.log(Level.INFO, \"file to load : \" + files[i].toString());\n+        NativeInterop.loadClrAssembly(files[i].toString());\n+      } catch (final Exception e) {\n+        LOG.log(Level.SEVERE, \"exception in loading dll library: \", files[i].toString());\n+        throw e;\n+      }\n+    }\n+  }\n+\n+  /**\n+   * Get file from jar file and copy it to temp dir and loads the library to memory\n+  **/\n+  private void loadFromReefJar(String name, final boolean managed) throws IOException {","path":"reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java","position":109,"original_position":109,"commit_id":"8a52fe28120113f0214db1151efacd44d3d50bd4","original_commit_id":"8a52fe28120113f0214db1151efacd44d3d50bd4","user":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"body":"Yes. For the dlls supplied by clients in global folder, we don’t get them from jar anymore. For our native bridge files like ClrHandler.dll, msvcr110.dll and JavaClrBridge.dll, we still package them in the jar file. ","created_at":"2015-01-09T19:02:52Z","updated_at":"2015-01-09T19:02:52Z","html_url":"https://github.com/apache/incubator-reef/pull/48#discussion_r22735351","pull_request_url":"https://api.github.com/repos/apache/incubator-reef/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/22735351"},"html":{"href":"https://github.com/apache/incubator-reef/pull/48#discussion_r22735351"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-reef/pulls/48","id":27080512,"html_url":"https://github.com/apache/incubator-reef/pull/48","diff_url":"https://github.com/apache/incubator-reef/pull/48.diff","patch_url":"https://github.com/apache/incubator-reef/pull/48.patch","issue_url":"https://api.github.com/repos/apache/incubator-reef/issues/48","number":48,"state":"open","locked":false,"title":"[Reef-67] Refactor utility methods in NativeInterop","user":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"body":"\r\nNativeInterop currently load CLR assemblies for the files provided in global folder, but it gets files from the jar that is not necessarily and easy to cause out of sync. This change does the following:\r\n\r\n\t• Separate load lib in a new class LibLoader  and use injection to get the reference of the object through JobDriver constructor\r\n\t• Load global files directly instead of getting them from jar\r\n\t• Renamed and refactored the methods to use LoadLibFromGlobal() and loadFromReefJar()\r\n\t• Put file names, folder names in ReefFileName class and use injection to get the reference in LibLoader class\r\n\t• Replaced System.out into proper Log and updated logs\r\n\t• Add LogScope for LibLoader\r\n\t\r\nThis is to resolve issue REEF-67 \r\nhttps://issues.apache.org/jira/i#browse/REEF-67?filter=-1\r\n","created_at":"2015-01-09T05:09:13Z","updated_at":"2015-01-09T19:02:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b7f9651ab2e12449824c4463a6106cccb25e352d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-reef/pulls/48/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-reef/pulls/48/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/{number}","comments_url":"https://api.github.com/repos/apache/incubator-reef/issues/48/comments","statuses_url":"https://api.github.com/repos/apache/incubator-reef/statuses/8a52fe28120113f0214db1151efacd44d3d50bd4","head":{"label":"jwang98052:REEF-67","ref":"REEF-67","sha":"8a52fe28120113f0214db1151efacd44d3d50bd4","user":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"repo":{"id":25940156,"name":"incubator-reef","full_name":"jwang98052/incubator-reef","owner":{"login":"jwang98052","id":5666504,"avatar_url":"https://avatars.githubusercontent.com/u/5666504?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang98052","html_url":"https://github.com/jwang98052","followers_url":"https://api.github.com/users/jwang98052/followers","following_url":"https://api.github.com/users/jwang98052/following{/other_user}","gists_url":"https://api.github.com/users/jwang98052/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang98052/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang98052/subscriptions","organizations_url":"https://api.github.com/users/jwang98052/orgs","repos_url":"https://api.github.com/users/jwang98052/repos","events_url":"https://api.github.com/users/jwang98052/events{/privacy}","received_events_url":"https://api.github.com/users/jwang98052/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jwang98052/incubator-reef","description":"Mirror of Apache REEF (Incubating)","fork":true,"url":"https://api.github.com/repos/jwang98052/incubator-reef","forks_url":"https://api.github.com/repos/jwang98052/incubator-reef/forks","keys_url":"https://api.github.com/repos/jwang98052/incubator-reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jwang98052/incubator-reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jwang98052/incubator-reef/teams","hooks_url":"https://api.github.com/repos/jwang98052/incubator-reef/hooks","issue_events_url":"https://api.github.com/repos/jwang98052/incubator-reef/issues/events{/number}","events_url":"https://api.github.com/repos/jwang98052/incubator-reef/events","assignees_url":"https://api.github.com/repos/jwang98052/incubator-reef/assignees{/user}","branches_url":"https://api.github.com/repos/jwang98052/incubator-reef/branches{/branch}","tags_url":"https://api.github.com/repos/jwang98052/incubator-reef/tags","blobs_url":"https://api.github.com/repos/jwang98052/incubator-reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jwang98052/incubator-reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jwang98052/incubator-reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/jwang98052/incubator-reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jwang98052/incubator-reef/statuses/{sha}","languages_url":"https://api.github.com/repos/jwang98052/incubator-reef/languages","stargazers_url":"https://api.github.com/repos/jwang98052/incubator-reef/stargazers","contributors_url":"https://api.github.com/repos/jwang98052/incubator-reef/contributors","subscribers_url":"https://api.github.com/repos/jwang98052/incubator-reef/subscribers","subscription_url":"https://api.github.com/repos/jwang98052/incubator-reef/subscription","commits_url":"https://api.github.com/repos/jwang98052/incubator-reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/jwang98052/incubator-reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/jwang98052/incubator-reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/jwang98052/incubator-reef/issues/comments/{number}","contents_url":"https://api.github.com/repos/jwang98052/incubator-reef/contents/{+path}","compare_url":"https://api.github.com/repos/jwang98052/incubator-reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jwang98052/incubator-reef/merges","archive_url":"https://api.github.com/repos/jwang98052/incubator-reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jwang98052/incubator-reef/downloads","issues_url":"https://api.github.com/repos/jwang98052/incubator-reef/issues{/number}","pulls_url":"https://api.github.com/repos/jwang98052/incubator-reef/pulls{/number}","milestones_url":"https://api.github.com/repos/jwang98052/incubator-reef/milestones{/number}","notifications_url":"https://api.github.com/repos/jwang98052/incubator-reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jwang98052/incubator-reef/labels{/name}","releases_url":"https://api.github.com/repos/jwang98052/incubator-reef/releases{/id}","created_at":"2014-10-29T20:32:40Z","updated_at":"2015-01-08T01:23:24Z","pushed_at":"2015-01-09T00:54:54Z","git_url":"git://github.com/jwang98052/incubator-reef.git","ssh_url":"git@github.com:jwang98052/incubator-reef.git","clone_url":"https://github.com/jwang98052/incubator-reef.git","svn_url":"https://github.com/jwang98052/incubator-reef","homepage":null,"size":9996,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"fa45c5ca7b1e5cabcc4345c7e3472f31db86dbe6","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":25623941,"name":"incubator-reef","full_name":"apache/incubator-reef","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-reef","description":"Mirror of Apache REEF (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-reef","forks_url":"https://api.github.com/repos/apache/incubator-reef/forks","keys_url":"https://api.github.com/repos/apache/incubator-reef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-reef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-reef/teams","hooks_url":"https://api.github.com/repos/apache/incubator-reef/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-reef/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-reef/events","assignees_url":"https://api.github.com/repos/apache/incubator-reef/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-reef/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-reef/tags","blobs_url":"https://api.github.com/repos/apache/incubator-reef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-reef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-reef/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-reef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-reef/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-reef/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-reef/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-reef/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-reef/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-reef/subscription","commits_url":"https://api.github.com/repos/apache/incubator-reef/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-reef/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-reef/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-reef/issues/comments/{number}","contents_url":"https://api.github.com/repos/apache/incubator-reef/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-reef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-reef/merges","archive_url":"https://api.github.com/repos/apache/incubator-reef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-reef/downloads","issues_url":"https://api.github.com/repos/apache/incubator-reef/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-reef/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-reef/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-reef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-reef/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-reef/releases{/id}","created_at":"2014-10-23T07:00:10Z","updated_at":"2015-01-06T06:14:39Z","pushed_at":"2015-01-06T15:24:24Z","git_url":"git://github.com/apache/incubator-reef.git","ssh_url":"git@github.com:apache/incubator-reef.git","clone_url":"https://github.com/apache/incubator-reef.git","svn_url":"https://github.com/apache/incubator-reef","homepage":null,"size":10503,"stargazers_count":7,"watchers_count":7,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":"git://git.apache.org/incubator-reef.git","open_issues_count":5,"forks":11,"open_issues":5,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/48"},"html":{"href":"https://github.com/apache/incubator-reef/pull/48"},"issue":{"href":"https://api.github.com/repos/apache/incubator-reef/issues/48"},"comments":{"href":"https://api.github.com/repos/apache/incubator-reef/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-reef/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-reef/statuses/8a52fe28120113f0214db1151efacd44d3d50bd4"}}}}