Github user chtyim commented on a diff in the pull request:

    https://github.com/apache/incubator-twill/pull/66#discussion_r41661046
  
    --- Diff: 
twill-yarn/src/main/java/org/apache/twill/yarn/YarnTwillRunnerService.java ---
    @@ -175,6 +187,36 @@ protected void shutDown() throws Exception {
         };
       }
     
    +  public Location createTwillJar() throws IOException {
    +    ApplicationBundler applicationBundler = new ApplicationBundler(new 
ClassAcceptor());
    +    List<Class<?>> classes = Lists.newArrayList();
    +    classes.add(ApplicationMasterMain.class);
    +    classes.add(TwillContainerMain.class);
    +    // Stuck in the yarnAppClient class to make bundler being able to 
pickup the right yarn-client version
    +    classes.add(yarnAppClient.getClass());
    +
    +    twillDependencyClasses = getTwillDependencyClasses(classes);
    +    File tempFile = File.createTempFile("twill", ".jar");
    +    Location twillJar = new 
LocalLocationFactory().create(tempFile.toURI());
    +    applicationBundler.createBundle(twillJar, classes);
    +    return twillJar;
    +  }
    +
    +  private Set<String> getTwillDependencyClasses(List<Class<?>> classes) 
throws IOException {
    +    Iterable<String> classNames = Iterables.transform(classes, new 
Function<Class<?>, String>() {
    +      @Override
    +      public String apply(Class<?> input) {
    +        return input.getName();
    +      }
    +    });
    +
    +    ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
    +    if (classLoader == null) {
    +      classLoader = getClass().getClassLoader();
    +    }
    +    return Dependencies.getClassDependencies(classLoader, new 
ClassAcceptor(), classNames);
    --- End diff --
    
    The `getClassDependencies` doesn't give you all twill classes. It only 
gives you all classes in the dependencies. I think the better way is using all 
classPathURL encountered during the creation of the twill jar to create a 
`URLClassLoader`. To check if a class is inside the twill.jar, you can use 
`ClassLoader.getResource()` on the `URLClassLoader`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to