[ 
https://issues.apache.org/jira/browse/TWILL-125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14379314#comment-14379314
 ] 

ASF GitHub Bot commented on TWILL-125:
--------------------------------------

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

    https://github.com/apache/incubator-twill/pull/28#discussion_r27095484
  
    --- Diff: 
twill-ext/src/test/java/org/apache/twill/ext/BundledJarRunnerTest.java ---
    @@ -0,0 +1,125 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.twill.ext;
    +
    +import com.google.common.io.ByteStreams;
    +import com.google.common.io.Files;
    +
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.io.File;
    +import java.io.FileOutputStream;
    +import java.io.InputStream;
    +import java.io.IOException;
    +import java.util.jar.JarOutputStream;
    +import java.util.zip.ZipEntry;
    +
    +/**
    + * Tests for {@link BundledJarRunner}.
    + */
    +public class BundledJarRunnerTest {
    +
    +  private static String jarOutput;
    +
    +  static class Simple {
    +    public static void main(String[] args) {
    +      jarOutput = args[0];
    +    }
    +  }
    +
    +  static class NoZeroArgsConstructor {
    +    public static void main(String[] args) {
    +      NoZeroArgsConstructor obj = new NoZeroArgsConstructor(args[0]);
    +    }
    +    public NoZeroArgsConstructor(String arg) {
    +      jarOutput = arg;
    +    }
    +  }
    +
    +  @Test
    +  public void runSimpleJar() throws Throwable {
    +    String output = "Simple";
    +    String jarFileName = "simple.jar";
    +    String className = "org.apache.twill.ext.BundledJarRunnerTest$Simple";
    +    runJarFile(jarFileName, className, new String[]{output});
    +    Assert.assertEquals(jarOutput, output);
    +  }
    +
    +  @Test
    +  public void runNoZeroArgsConstructorJar() throws Throwable {
    +    String output = "NoZeroArgsConstructor";
    +    String jarFileName = "nozeroargs.jar";
    +    String className = 
"org.apache.twill.ext.BundledJarRunnerTest$NoZeroArgsConstructor";
    +    runJarFile(jarFileName, className, new String[]{output});
    +    Assert.assertEquals(jarOutput, output);
    +  }
    +
    +  private void runJarFile(String jarFileName, String className, String[] 
mainArgs) throws Throwable {
    +    File outdir = Files.createTempDir();
    --- End diff --
    
    Can you use junit `@ClassRule TemporaryFolder` instead? That will make the 
code cleaner and no need to worry about cleaning up.


> BundledJarRunner doesn't work for classes with no zero-args constructor
> -----------------------------------------------------------------------
>
>                 Key: TWILL-125
>                 URL: https://issues.apache.org/jira/browse/TWILL-125
>             Project: Apache Twill
>          Issue Type: Bug
>          Components: ext
>    Affects Versions: 0.5.0-incubating
>            Reporter: Rob Morgan
>
> BundledJarRunner attempts to load the main class using Class#newInstance. The 
> call to newInstance will then attempt to find and invoke the class's 
> zero-args constructor. This will throw an InstantiationException if there is 
> no zero-args constructor to be found.
> Loading the main class is unnecessary. Since main is always static it can be 
> invoked with a null target object.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to