You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@twill.apache.org by rob-morgan <gi...@git.apache.org> on 2015/03/25 01:22:30 UTC

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

GitHub user rob-morgan opened a pull request:

    https://github.com/apache/incubator-twill/pull/28

    (TWILL-125) Eliminate mainObject instance in BundedJarRunner

    Instantiating the object containing the main method in order to invoke
    the main method is unnecessary since main is always static. There is
    also a potential problem with calling newInstance() on the main object's
    class; it will throw an exception if the main object does not have
    a 0-args constructor.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/rob-morgan/incubator-twill master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-twill/pull/28.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #28
    
----
commit ca5877995e92da081c16e3f273f3e22e346e3c38
Author: Rob Morgan <rm...@tracelink.com>
Date:   2015-03-23T16:08:57Z

    (TWILL-125) Eliminate mainObject instance in BundedJarRunner
    
    Instantiating the object containing the main method in order to invoke
    the main method is unnecessary since main is always static. There is
    also a potential problem with calling newInstance() on the main object's
    class; it will throw an exception if the main object does not have
    a 0-args constructor.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

Posted by rob-morgan <gi...@git.apache.org>.
Github user rob-morgan commented on the pull request:

    https://github.com/apache/incubator-twill/pull/28#issuecomment-86048425
  
    Updated to use @ClassRule TemporaryFolder. I agree - much cleaner. Thanks for the pointer.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

Posted by chtyim <gi...@git.apache.org>.
Github user chtyim commented on the pull request:

    https://github.com/apache/incubator-twill/pull/28#issuecomment-86126795
  
    Changes LGTM :+1: and merged into master. Please close the PR, thanks.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

Posted by chtyim <gi...@git.apache.org>.
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.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

Posted by rob-morgan <gi...@git.apache.org>.
Github user rob-morgan closed the pull request at:

    https://github.com/apache/incubator-twill/pull/28


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-twill pull request: (TWILL-125) Eliminate mainObject ins...

Posted by chtyim <gi...@git.apache.org>.
Github user chtyim commented on the pull request:

    https://github.com/apache/incubator-twill/pull/28#issuecomment-85843423
  
    Thanks for the fix. Just one comment about creation of tmp file.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---