Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing directory entries in testng jar #1677

Open
dipak-pawar opened this issue Jan 30, 2018 · 40 comments
Open

Missing directory entries in testng jar #1677

dipak-pawar opened this issue Jan 30, 2018 · 40 comments

Comments

@dipak-pawar
Copy link
Contributor

TestNG Version

6.13.1

Description:

  • Run jar -tf testng-6.13.1.jar
  • All entries for directories are not packaged in the jar. This causes a problem while trying to get resources from classpath.
  • In particular this causes problem in Arquillian integration with testng. See issue#comment

Expected behavior

META-INF/
META-INF/MANIFEST.MF
com/
com/beust/
com/beust/testng/
com/beust/testng/TestNG.class
org/

Actual behavior

com/beust/testng/TestNG.class
META-INF/services/org.testng.xml.ISuiteParser
org/testng/annotations/AfterClass.class

Test case sample

https://github.com/bartoszmajsak/testng-classloading

@dipak-pawar
Copy link
Contributor Author

I can see one opened issue #1640 which is related to jar. Maybe while fixing this we should consider that as well

@krmahadevan
Copy link
Member

krmahadevan commented Jan 31, 2018

@dipak-pawar - There's a new version of TestNG that is scheduled for release. For now @cbeust has created a RC (Release candidate) for this and he will be publishing the actual version pretty soon.

Its currently available here : http://jcenter.bintray.com/org/testng/testng/6.14.0-RC1/

I quickly ran a few checks that are mentioned in this bug and I seem to get through just fine. I guess your issue will get addressed when @cbeust releases 6.14

Running the same project.

  1. I cloned the project from [email protected]:bartoszmajsak/testng-classloading.git
  2. Added the RC version into the pom file. The git diff looks like below
09:01 $ git diff pom.xml
diff --git a/pom.xml b/pom.xml
index 0a27422..dac6647 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,17 @@
   </dependencies>

   <profiles>
+    <profile>
+      <id>testng-fixed</id>
+      <dependencies>
+        <dependency>
+          <groupId>org.testng</groupId>
+          <artifactId>testng</artifactId>
+          <version>6.14.0-RC1</version>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
     <profile>
       <id>testng-patched</id>
       <dependencies>
  1. Ran mvn clean package -Ptestng-fixed . Here's the output
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testng-classloading 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ testng-classloading ---
[INFO] Deleting /Users/krmahadevan/temp/testng-classloading/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testng-classloading ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/krmahadevan/temp/testng-classloading/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testng-classloading ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ testng-classloading ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/krmahadevan/temp/testng-classloading/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ testng-classloading ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/krmahadevan/temp/testng-classloading/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ testng-classloading ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.bartoszmajsak.groovy.ClassLoadingTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.044 s - in com.bartoszmajsak.groovy.ClassLoadingTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ testng-classloading ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /Users/krmahadevan/temp/testng-classloading/target/testng-classloading-1.0.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.962 s
[INFO] Finished at: 2018-01-31T09:10:51+05:30
[INFO] Final Memory: 17M/216M
[INFO] ------------------------------------------------------------------------

Inspecting the jar contents.

Here's the partial output

09:12 $ jar -tf testng-6.14.0-RC1.jar | head
META-INF/
META-INF/MANIFEST.MF
com/
com/beust/
com/beust/testng/
com/beust/testng/TestNG.class
org/
org/testng/
org/testng/annotations/
org/testng/annotations/AfterClass.class

The complete output is here

@krmahadevan
Copy link
Member

krmahadevan commented Jan 31, 2018

I just now cross checked. TestNG 6.14 has been released and it fixes your problem. I am closing off this issue.

While the artifact gets synced to maven central, please do the following to consume TestNG from JCenter

  1. Add the following to your <repositories> section of your pom file
<repository>
    <id>jcenter</id>
    <name>jcenter</name>
    <url>http://jcenter.bintray.com</url>
</repository>
  1. Add a dependency on TestNG 6.14
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.0</version>
    <scope>test</scope>
</dependency>

@missedone
Copy link
Contributor

@cbeust , if 6.14 released, the git tag is missing.

@dipak-pawar
Copy link
Contributor Author

@krmahadevan Looks like TestNG 6.14 has runtime dependency on com.beust:jcommander:jar:1.66 which has similar issue which I opened already.

[INFO] +- org.testng:testng:jar:6.14.0:compile
[INFO] |  +- org.apache-extras.beanshell:bsh:jar:2.0b6:runtime
[INFO] |  +- com.beust:jcommander:jar:1.66:runtime
[INFO] |  \- org.apache.ant:ant:jar:1.9.7:runtime
[INFO] |     \- org.apache.ant:ant-launcher:jar:1.9.7:runtime

This causes again Arquillian integration to break with latest TestNG. Can you reopen this?

@krmahadevan
Copy link
Member

@cbeust @juherr any idea how the runtime dependency is getting added ?
I checked both our kobalt and gradle build files. In both places its available as compile time dependency.

@krmahadevan krmahadevan reopened this Jan 31, 2018
@cbeust
Copy link
Collaborator

cbeust commented Jan 31, 2018

Indeed :-(

There's something wrong in build.gradle in the part that publishes but not idea what. I think I'm going to go back with publishing to Kobalt, at least I understand that.

@krmahadevan
Copy link
Member

This is now fixed in TestNG 6.14.2

Here's the output

[INFO] org.framework:framework:jar:1.0-SNAPSHOT
[INFO] \- org.testng:testng:jar:6.14.2:compile
[INFO]    +- com.beust:jcommander:jar:1.72:compile
[INFO]    \- org.apache-extras.beanshell:bsh:jar:2.0b6:compile

@dipak-pawar
Copy link
Contributor Author

@krmahadevan Looks like issue is still there. You can see output of jar -tf testng-6.14.2.jar here.

I believe we have same issue with jcommander. We need to fix it and release new version. Then we have to package TestNG against this new released version of Jcommander.

Can you reopen this issue @krmahadevan?

@krmahadevan
Copy link
Member

@dipak-pawar - I dont understand what directory is missing ? Can you please help call out ?

The most important directories are available in your gist post

META-INF/MANIFEST.MF
com/beust/testng/TestNG.class
META-INF/services/org.testng.xml.ISuiteParser

For issues with JCommander, I would request you to please log an issue here

@rwalkerands
Copy link

It is the entries for the directories that are missing for the JAR file, as listed in the "Expected behaviour".

E.g., unzip -l testng-6.14.2.jar gives:

Archive:  testng-6.14.2.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
     1332  02-05-2018 00:53   META-INF/MANIFEST.MF
      288  02-05-2018 00:53   com/beust/testng/TestNG.class
       30  02-05-2018 00:53   META-INF/services/org.testng.xml.ISuiteParser
      781  02-05-2018 00:53   org/testng/annotations/AfterClass.class
      800  02-05-2018 00:53   org/testng/annotations/AfterGroups.class
      815  02-05-2018 00:53   org/testng/annotations/AfterMethod.class
      781  02-05-2018 00:53   org/testng/annotations/AfterSuite.class
... etc.

but it should give something like this instead:

Archive: testng-6.14.2-with-directories.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-23-2018 12:13   META-INF/
     1332  02-05-2018 00:53   META-INF/MANIFEST.MF
        0  02-23-2018 12:13   META-INF/services/
       30  02-04-2018 05:53   META-INF/services/org.testng.xml.ISuiteParser
        0  02-23-2018 12:13   com/
        0  02-23-2018 12:13   com/beust/
        0  02-23-2018 12:13   com/beust/testng/
      288  02-04-2018 05:53   com/beust/testng/TestNG.class
        0  02-23-2018 12:13   org/
        0  02-23-2018 12:13   org/testng/
        0  02-23-2018 12:13   org/testng/annotations/
      781  02-04-2018 05:53   org/testng/annotations/AfterClass.class
      800  02-04-2018 05:53   org/testng/annotations/AfterGroups.class
... etc.

I confirm that this causes a problem with Arquillian. If you merely unzip the testng-6.14.2.jar file to extract its contents, then use zip to create a new JAR file with the same contents, that JAR file does contain the directory entries, and it does then work with Arquillian.

@krmahadevan
Copy link
Member

@dipak-pawar @rwalkerands - I think this perhaps could be an issue with kobalt because that's the build tool that is involved here. So maybe we need to open up an additional issue there as well ?

ping @cbeust Please let me know your thoughts on this.

I am re-opening this issue, but there's nothing that needs to be done from the TestNG codebase itself. Its more of a fix that is needed in the build tool (kobalt in this case)

@krmahadevan krmahadevan reopened this Feb 23, 2018
@dipak-pawar
Copy link
Contributor Author

@krmahadevan

For issues with JCommander, I would request you to please log an issue here

I already reported it there for JCommander cbeust/jcommander#430

@cbeust
Copy link
Collaborator

cbeust commented Feb 23, 2018

This should be fixed in TestNG 6.14.3 (JCenter only right now).

$ jar tf kobaltBuild/libs/testng-6.14.3.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/beust/
com/beust/testng/

Please confirm.

@krmahadevan
Copy link
Member

@rwalkerands @dipak-pawar - Can you please confirm ?

Here's what I see

08:38 $ unzip -l testng-6.14.3.jar | head -n20
Archive:  testng-6.14.3.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-23-2018 08:34   META-INF/
     1333  02-23-2018 08:34   META-INF/MANIFEST.MF
        0  02-23-2018 08:34   kobaltBuild/
        0  02-23-2018 08:34   kobaltBuild/classes/
        0  02-23-2018 08:34   kobaltBuild/classes/com/
        0  02-23-2018 08:34   kobaltBuild/classes/com/beust/
        0  02-23-2018 08:34   kobaltBuild/classes/com/beust/testng/
        0  02-23-2018 08:34   com/
        0  02-23-2018 08:34   com/beust/
        0  02-23-2018 08:34   com/beust/testng/
      288  02-23-2018 08:34   com/beust/testng/TestNG.class
        0  02-23-2018 08:34   kobaltBuild/classes/META-INF/
        0  02-23-2018 08:34   kobaltBuild/classes/META-INF/services/
        0  02-23-2018 08:34   META-INF/services/
       30  02-23-2018 08:34   META-INF/services/org.testng.xml.ISuiteParser
        0  02-23-2018 08:34   kobaltBuild/classes/org/
        0  02-23-2018 08:34   kobaltBuild/classes/org/testng/

The full output is available below
fulloutput.txt

@dipak-pawar
Copy link
Contributor Author

dipak-pawar commented Feb 26, 2018

@krmahadevan , @cbeust This issue is not fixed. Looks like released version of TestNG 6.14.3 is bundled with jcommander - 1.72.

[INFO] \- org.testng:testng:jar:6.14.3:test
[INFO]    +- com.beust:jcommander:jar:1.72:test
[INFO]    \- org.apache-extras.beanshell:bsh:jar:2.0b6:test

But cbeust/jcommander#430 is fixed in jcommander 1.73. This causes problem to load resources from jcommander using this.getClass().getClassLoader().getResource("com/beust/jcommander")

Steps To Reproduce

  1. git clone https://github.com/dipak-pawar/testng-classloading
  2. mvn clean test
  3. mvn clean test -Ptestng-old

Result

  • Step 2 - testng 6.14.3 - Test should_load_jcommander should pass, but it's failing
  • Step 3 - testng 5.14.6 - All tests are passing.

@krmahadevan
Copy link
Member

@dipak-pawar - Can you not just update your pom file to add an exclusion of the older jcommander version from testng dependency and explicitly depend on the newer version to get past this ? Just trying to understand as to why do you expect TestNG to include the latest JCommander version ?

@dipak-pawar
Copy link
Contributor Author

@krmahadevan , I have updated code in https://github.com/dipak-pawar/testng-classloading.
Give a try with mvn clean test -Ptestng-latest-jcommander.

@krmahadevan
Copy link
Member

@dipak-pawar - It works for me. I dont see any failures. Here's the output

TestNG version 6.14.3
[INFO] Running com.bartoszmajsak.groovy.ClassLoadingTest
TestNG version 6.14.3
TestNG version 6.14.3
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 s - in com.bartoszmajsak.groovy.ClassLoadingTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

@dipak-pawar
Copy link
Contributor Author

dipak-pawar commented Feb 26, 2018

@krmahadevan ,
It works for me for mvn clean test -Ptestng-latest-jcommander. But it fails for mvn clean test where testng depends on jcommander 1.72.

Is it working for mvn clean test for you?

@krmahadevan
Copy link
Member

You need to fix your pom file to get this to work when you run mvn clean test by updating the profile with id testng-default so that it looks like testng-latest-jcommander. Your pom file defines testng-default to be the default profile (notice how it has <activeByDefault> tag set to true) which is what gets applied when you use mvn clean test.

@dipak-pawar
Copy link
Contributor Author

@krmahadevan Looks like there is some misunderstanding.

  • testng-default profile is activated by default which is using testng 6.14.3, this should pass ideally which is failing.
  • testng-latest-jcommander profile is using testng 6.14.3 by excluding jcommander from testng and adding latest jcommander 1.73,
      <dependencies>
        <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>6.14.3</version>
          <scope>test</scope>
          <exclusions>
            <exclusion>
              <groupId>com.beust</groupId>
              <artifactId>jcommander</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>com.beust</groupId>
          <artifactId>jcommander</artifactId>
          <version>1.73</version>
        </dependency>
      </dependencies>

So this should pass ideally. It's passing.

So Ideally if you release testng with jcommander 1.73. user don't have to exclude it from testng and add it as extra dependency.

@krmahadevan
Copy link
Member

krmahadevan commented Feb 26, 2018 via email

@juherr
Copy link
Member

juherr commented Feb 26, 2018

I think we should upgrade our dependencies when they fix known issues.
So, we can update jcommander (and maybe some others) in the next release.

@dipak-pawar
Copy link
Contributor Author

@krmahadevan, @cbeust We are using testng in provided scope in Arquillian to avoid tightly coupling with any testng version and let users use as per their need.

So as per above workaround, every user has to explicitly remove jcommander from his testng and use another version of jcommander(> 1.73 as 1.73 has cbeust/jcommander#434), which is not good user experience in my opinion.

      <dependencies>
        <dependency>
          <groupId>com.beust</groupId>
          <artifactId>jcommander</artifactId>
          <version>latest</version> <!-- greater than 1.73 -->
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>6.14.3</version>
          <scope>test</scope>
          <exclusions>
            <exclusion>
              <groupId>com.beust</groupId>
              <artifactId>jcommander</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>

It'll be really appreciated if you can release testng with new version of jcommander having cbeust/jcommander#434 fixed in coming days.

@rwalkerands
Copy link

I confirmed that testng-6.14.3.jar works (with Arquillian 1.1.15).

(I do my own, manual dependencies, which in this case means I'm using an older jcommander JAR that was not affected.)

Looking forward to an update to the Eclipse plugin so that I can switch over all together ...

@cbeust
Copy link
Collaborator

cbeust commented Feb 26, 2018

ping @missedone for the Eclipse plug-in.

@missedone
Copy link
Contributor

missedone commented Feb 26, 2018

@rwalkerands , you can go direct to "Help -> Check for Updates...", there will be a update for 'testng-p2' 6.14.3.
if you don't see the update, explicitly install from the update site: https://dl.bintray.com/testng-team/testng-p2-release

Note: testng-p2 is the osgified testng.

@SomberOfShadow
Copy link

How can i get TestNG jar absolute path when TestNG is used in test case ? Anyone can tell me ? Thanks a lot.

@krmahadevan
Copy link
Member

@SomberOfShadow - Check if this helps

        URL loc = TestNG.class.getProtectionDomain().getCodeSource().getLocation();
        File file = new File(loc.toURI());

@dipak-pawar
Copy link
Contributor Author

@SomberOfShadow You can easily get using
URL resource = this.getClass().getClassLoader().getResource("org/testng");

Look for sample example here
https://github.com/dipak-pawar/testng-classloading/blob/master/src/test/java/com/bartoszmajsak/groovy/ClassLoadingTest.java#L22

@SomberOfShadow
Copy link

@SomberOfShadow You can easily get using
URL resource = this.getClass().getClassLoader().getResource("org/testng");

Look for sample example here
https://github.com/dipak-pawar/testng-classloading/blob/master/src/test/java/com/bartoszmajsak/groovy/ClassLoadingTest.java#L22

I will have a try . Thanks a lot.

@SomberOfShadow
Copy link

@SomberOfShadow - Check if this helps

        URL loc = TestNG.class.getProtectionDomain().getCodeSource().getLocation();
        File file = new File(loc.toURI());

Ok , thanks , i will try. And maybe i need to state my question again. My question is that there are several testNG versions in project, but which version is really used in test case and how to get the really used testNG version. Am i clear ? I will appreciate it if you can give me help.

@krmahadevan
Copy link
Member

@SomberOfShadow - The code snippet I shared will automatically ensure that the version of TestNG that is being resolved to is what will be used to obtain the path.

@SomberOfShadow
Copy link

@SomberOfShadow - The code snippet I shared will automatically ensure that the version of TestNG that is being resolved to is what will be used to obtain the path.

I dont know why, i use the code snippet in transform (), but NullPointerException occured.

@SomberOfShadow
Copy link

@SomberOfShadow You can easily get using
URL resource = this.getClass().getClassLoader().getResource("org/testng");
Look for sample example here
https://github.com/dipak-pawar/testng-classloading/blob/master/src/test/java/com/bartoszmajsak/groovy/ClassLoadingTest.java#L22

I will have a try . Thanks a lot.

hi, I have had a try. but the result is not my expected. Anyway, thanks a lot.

@SomberOfShadow
Copy link

@SomberOfShadow - The code snippet I shared will automatically ensure that the version of TestNG that is being resolved to is what will be used to obtain the path.

I dont know why, i use the code snippet in transform (), but NullPointerException occured.

Maybe I made something wrong, and I will have another try. Thanks you very much.

@SomberOfShadow
Copy link

@SomberOfShadow - The code snippet I shared will automatically ensure that the version of TestNG that is being resolved to is what will be used to obtain the path.

hi, thank you very much . It works. But now i have another question. I will very appreciate it if you can give me help.

Case One: In TestNG.jar (such as testng-6.14.12.jar) , there is a MATA-INF/MANIFEST.MF file , we can get Bundle-Version from MANIFEST.MF to get TestNG version.

Case Two: Assume there are two Maven projects, named A and B. In A project , there is no TestNG dependency, but in B project, TestNG dependency is included. Now , B.jar is included in A project. We still want to get TestNG version in A, but we can not find MANIFEST.MF about TestNG.jar in B.jar, so we can we do to get TestNG version in this case ?

Looking forward to your reply.

Best Regards ///

@juherr
Copy link
Member

juherr commented Oct 12, 2019

Fyi, maybe you can use org.testng.internal.Version.getVersionString()

@SomberOfShadow
Copy link

Fyi, maybe you can use org.testng.internal.Version.getVersionString()

Thanks you a lot. It works . And the code snippet is different from Version.VERSION. If using Version.VERSION to get TestNG version, the result may be not the correct version used in test cases in run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants