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

launcher gets classpath from maven/gradle, #236 #419

Merged
merged 6 commits into from
Apr 20, 2020

Conversation

sriv
Copy link
Member

@sriv sriv commented Apr 13, 2020

No description provided.

Signed-off-by: sriv <srikanth.ddit@gmail.com>
@gaugebot gaugebot bot requested a review from BugDiver April 13, 2020 09:50
sriv added 2 commits April 13, 2020 18:14
Signed-off-by: sriv <srikanth.ddit@gmail.com>
Signed-off-by: sriv <srikanth.ddit@gmail.com>
sriv and others added 3 commits April 16, 2020 07:40
…sspath.

Signed-off-by: Dharmendra Singh <dharmenn@thoughtworks.com>
…asspath.

Signed-off-by: Dharmendra Singh <dharmenn@thoughtworks.com>
@negiDharmendra negiDharmendra requested review from NivedhaSenthil and removed request for BugDiver April 17, 2020 12:12
@taplar
Copy link

taplar commented Apr 21, 2020

I have a concern with this patch, related to addressing the usage of the gauge_additional_libs. I listed my issue in the #377 and BugDriver replied that this PR would address the issue. So I've been trying to get the project to build locally so I can test it.

I finally got JQ, Maven, and all that installed so it would finally allow me to ./build.ps1 forceinstall so I could test the latest master version out. It seems like there is still an issue with resolving the classpath.

Please excuse my debugging attempts as I'm not familiar with this language.

What I possibly have found is that launcher.ps1 does not currently seem to like the gauge_additional_libs being a wildcarded directory. I modified the start task to the following:

$tasks.Add('start', {
    if ("$global:classpath" -eq "") {
      AddRunnerInClassPath
      AddClassPathRequiredForExecution
    }
    if ("$env:GAUGE_DEBUG_OPTS" -ne "" ) {
      $debugArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$env:GAUGE_DEBUG_OPTS,timeout=25000"
      Write-Output "`nRunner Ready for Debugging"
    }
    EscapeSpaceInClasspath
    $random = (Get-Random)
    $targetFile = Join-Path "$env:TEMP" "$random.txt"
    Write-Output "The global classpath is $global:classpath"
    Write-Output "-cp $global:classpath `"-Dfile.encoding=UTF-8`" $debugArgs $env:gauge_jvm_args com.thoughtworks.gauge.GaugeRuntime --start" | Out-File $targetFile -Append -Encoding default
    & $javaCommand "@$targetFile"
    exit
  })

To try and see what the global:classpath is being set to, if it should be resolving a gauge_additional_libs of libs/* and it echoed out the following:

The global classpath is C:\Users\boydma\AppData\Roaming\gauge\plugins\java\0.7.6\libs\*;"D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\.gitkeep D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\db2jcc4.jar D:\\Users\\boydma\
\Repositories\\Item\\ItemWebFunctional\\libs\\db2jcc4_license_cisuz.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\db2jcc4_license_cu.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\j2ee.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\jersey-bundle-1.9.1.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\json-simple-1.1.1.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\junit.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\mongo-java-driver-3.10.2.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\selenium-server-standalone-3.12.0.jar";;D:\Users\boydma\Repositories\Item\ItemWebFunctional\gauge_bin;

As you can see, it does appear to have found the lib files, but it is putting them on the classpath all with in a "" string, separated by spaces. I'm assuming that syntax issue is why they are still not being found on the classpath.

I played around with trying to alter the GetAdditionalPath method to:

function GetAdditionalPath() {
  param(
    $DirNames
  )
  if ("$DirNames" -eq "") {
    return ""
  }
  $libs = ""
  foreach ($dir in $DirNames.Split(",")) {
    $lib = Resolve-Path -Path $dir
    foreach ($file in "$lib".Split(" ")) {
      $libs = "$file;$libs"
    }
  }
  return $libs
}

which resulted in the following:

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
The global classpath is C:\Users\boydma\AppData\Roaming\gauge\plugins\java\0.7.6\libs\*;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\selenium-server-standalone-3.12.0.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\mongo-java-drive
r-3.10.2.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\junit.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\json-simple-1.1.1.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\jersey-bundle-1.9.1.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\j2ee.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4_license_cu.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4_license_cisuz.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\.gitkeep;;D:\Users\boydma\Repositories\Item\ItemWebFunctional\gauge_bin;
Error: Could not find or load main class Files.Browser
Caused by: java.lang.ClassNotFoundException: Files.Browser

So that seems to have resolved the classpath issue, though there's still the weird Files.Browser issue I'm not sure if will also go away with a future patch.

So I'm not sure if I'm completely off base here, and I'm just doing something weird with trying to test this change out ahead of time, but I did want to bring it up just incase.

@sriv
Copy link
Member Author

sriv commented Apr 22, 2020

Thanks for the analysis @taplar - I believe you may be on to something here. We'll investigate this and see how best to fix this.

/cc @NivedhaSenthil

@taplar
Copy link

taplar commented Apr 22, 2020

Glad to hear I'm not completely off base! I do have a follow up with regards to the following error that was shown at the end of my last post.

Error: Could not find or load main class Files.Browser
Caused by: java.lang.ClassNotFoundException: Files.Browser

I believe this error is related to the gauge_jvm_args. Our project has the value set as the following:

# JVM arguments passed to java while launching. Enter multiple values separated by comma (,) eg. Xmx1024m, Xms128m
gauge_jvm_args = -Dwebdriver.chrome.driver=C:/Program Files/Browser Drivers/Chrome Driver/80/chromedriver.exe, -Xms2g, -Xmx2g

I modified the launcher.ps1 start task to write out what was being written to the $targetFile and I got the following:

-cp C:\Users\boydma\AppData\Roaming\gauge\plugins\java\0.7.6\libs\*;"D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\.gitkeep D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\db2jcc4.jar D:\\Users\\boydma\\Repositories\\Item\
\ItemWebFunctional\\libs\\db2jcc4_license_cisuz.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\db2jcc4_license_cu.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\j2ee.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\jersey-bundle-1.9.1.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\json-simple-1.1.1.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\junit.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\mongo-java-driver-3.10.2.jar D:\\Users\\boydma\\Repositories\\Item\\ItemWebFunctional\\libs\\selenium-server-standalone-3.12.0.jar";;D:\Users\boydma\Repositories\Item\ItemWebFunctional\gauge_bin; "-Dfile.encoding=UTF-8"  -Dwebdriver.chrome.driver=C:/Program Files/Browser Drivers/Chrome Driver/80/chromedriver.exe, -Xms2g, -Xmx2g com.thoughtworks.gauge.GaugeRuntime --start
Error: Could not find or load main class Files.Browser
Caused by: java.lang.ClassNotFoundException: Files.Browser

The thing I found interesting with that is that the file encoding option is ecapsulated in double quotes, while the value pulled from the gauge_jvm_args is just used as is.

To test if this was the issue I modified the logic to the following. I created a new method to split the gauge_jvm_args value and add them each encapsulated with double quotes.

function GetJvmArguments() {
    $jvmArgs = ""
  
    if ($env:gauge_jvm_args -ne "") {
      $prefix = ""
      foreach($arg in $env:gauge_jvm_args.Split(",")) {
        $argTrimmed = $arg.Trim()
        $jvmArgs += "$prefix`"$argTrimmed`""
        $prefix = " "
      }
    }
  
    return $jvmArgs
  }

I then used it in the start task as follows.

$tasks.Add('start', {
    if ("$global:classpath" -eq "") {
      AddRunnerInClassPath
      AddClassPathRequiredForExecution
    }
    if ("$env:GAUGE_DEBUG_OPTS" -ne "" ) {
      $debugArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$env:GAUGE_DEBUG_OPTS,timeout=25000"
      Write-Output "`nRunner Ready for Debugging"
    }
    EscapeSpaceInClasspath
    $random = (Get-Random)
    $targetFile = Join-Path "$env:TEMP" "$random.txt"
    $jvmArgs = GetJvmArguments
    Write-Output "-cp $global:classpath `"-Dfile.encoding=UTF-8`" $debugArgs $jvmArgs com.thoughtworks.gauge.GaugeRuntime --start"
    Write-Output "-cp $global:classpath `"-Dfile.encoding=UTF-8`" $debugArgs $jvmArgs com.thoughtworks.gauge.GaugeRuntime --start" | Out-File $targetFile -Append -Encoding default
    & $javaCommand "@$targetFile"
    exit
  })

Which, paired with my previous tinkering, resulted in the following.

$ gauge run --env st --tags P1
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
-cp C:\Users\boydma\AppData\Roaming\gauge\plugins\java\0.7.6\libs\*;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\selenium-server-standalone-3.12.0.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\mongo-java-driver-3.10.2.jar;D:\User
s\boydma\Repositories\Item\ItemWebFunctional\libs\junit.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\json-simple-1.1.1.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\jersey-bundle-1.9.1.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\j2ee.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4_license_cu.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4_license_cisuz.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\db2jcc4.jar;D:\Users\boydma\Repositories\Item\ItemWebFunctional\libs\.gitkeep;;D:\Users\boydma\Repositories\Item\ItemWebFunctional\gauge_bin; "-Dfile.encoding=UTF-8"  "-Dwebdriver.chrome.driver=C:/Program Files/Browser Drivers/Chrome Driver/80/chromedriver.exe" "-Xms2g" "-Xmx2g" com.thoughtworks.gauge.GaugeRuntime --start

$$$ SETUP SUITE

So making the changes related to the gauge_additional_libs and the gauge_jvm_args resulted in my tests running again.

@NivedhaSenthil
Copy link
Member

This is great ... would you like to create a PR with these changes ?

@taplar
Copy link

taplar commented Apr 23, 2020

I could try to do so, however I am hesitant to do so for a few reasons. I am not familiar with the process for creating a PR for a public git repository and I would need to familiarize myself with any practices your project has in place. I am also not sure what issue number I would associate the change with for the commit message(s); if it would be this same one or a new one.

Also, as I have previously stated, I am a novice when it comes to powershell scripts and from my point of view the changes I have tried were just to "get it working". I'm not confident enough with my proficiency of the language to know if there is a better way to do these changes, or to know if I am missing some edge case.

( cat $GAUGE_GRADLE_BUILD_FILE; echo "task printCP { println sourceSets.test.runtimeClasspath.asPath }" ) > build.gradle.temp
class_path=$(./gradlew -q -b build.gradle.temp printCP)
rm build.gradle.temp
class_path=$(./gradlew -q clean classpath)
Copy link
Member

@zabil zabil Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem in windows with limits to classpath and command line length.

https://support.thoughtworks.com/hc/en-us/articles/213248526-Getting-around-maximum-command-line-length-is-32767-characters-on-Windows

Although this on linux. I think there may be a limit in the output of $(./gradlew -q clean classpath) long list of items with path to the jar file?

@NivedhaSenthil
Copy link
Member

@taplar have created an issue separately for this #429 to track..

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

Successfully merging this pull request may close these issues.

5 participants