From b889d246c2a348537b3e392e79b428a94634900f Mon Sep 17 00:00:00 2001 From: Srikanth Date: Mon, 20 Apr 2020 12:17:40 +0530 Subject: [PATCH] launcher gets classpath from maven/gradle, #236 (#419) * launcher gets classpath from maven/gradle, #236 Signed-off-by: sriv * fix launcher.sh pom path Signed-off-by: sriv * fix launcher script Signed-off-by: sriv * Updated launcher.sh to use Gauge's maven and gradle plugin to get classpath. Signed-off-by: Dharmendra Singh * Updated launcher.ps1 to use Gauge's maven and gradle plugin to get classpath. Signed-off-by: Dharmendra Singh Co-authored-by: Dharmendra Singh --- bin/launcher.ps1 | 14 +++++++++++--- bin/launcher.sh | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/bin/launcher.ps1 b/bin/launcher.ps1 index 8b49dcb7..283bb6ad 100644 --- a/bin/launcher.ps1 +++ b/bin/launcher.ps1 @@ -14,8 +14,8 @@ elseif ("$env:JAVA_HOME" -ne "") { $javacCommand = "$env:JAVA_HOME\bin\$javacCommand" } -$verison = (Get-Command $javaCommand | Select-Object -ExpandProperty Version).Major | Out-String -if ( "$verison" -as [int] -lt 9 ) { +$version = (Get-Command $javaCommand | Select-Object -ExpandProperty Version).Major | Out-String +if ( "$version" -as [int] -lt 9 ) { Write-Output "This version of gauge-java plugin does not support Java versions < 1.9" Write-Output "Please upgrade your Java version or use a version of gauge-java <= v0.7.4" exit 1; @@ -24,9 +24,17 @@ if ( "$verison" -as [int] -lt 9 ) { $DefaultBuildDir = "gauge_bin" $PluginDir = Get-Location -$global:classpath = $env:gauge_custom_classpath Set-Location $env:GAUGE_PROJECT_ROOT +if (-not (Test-Path env:gauge_custom_classpath)) { + if (Test-Path "pom.xml" -PathType Leaf) { + $global:classpath = (mvn -q test-compile gauge:classpath) + } elseif (Test-Path "build.gradle" -PathType Leaf) { + $global:classpath = (./gradlew -q clean classpath) + } +} else { + $global:classpath = $env:gauge_custom_classpath +} function AddRunnerInClassPath { $global:classpath += "$PluginDir\libs\*" diff --git a/bin/launcher.sh b/bin/launcher.sh index fc9038b5..afbfc731 100755 --- a/bin/launcher.sh +++ b/bin/launcher.sh @@ -2,10 +2,9 @@ set -e +project_root="$GAUGE_PROJECT_ROOT" default_build_dir="gauge_bin" -class_path="$gauge_custom_classpath" plugin_dir=$(pwd) -project_root="$GAUGE_PROJECT_ROOT" compile_dir="$gauge_custom_compile_dir" TMP_DIR="$(dirname $(mktemp -u))/" @@ -35,6 +34,19 @@ fi cd "$project_root" +if [ -z "${gauge_custom_classpath}" ]; then + GAUGE_MAVEN_POM_FILE="${GAUGE_MAVEN_POM_FILE:-pom.xml}" + GAUGE_GRADLE_BUILD_FILE="${GAUGE_GRADLE_BUILD_FILE:-build.gradle}" + if test -f $GAUGE_MAVEN_POM_FILE; then + class_path=$(mvn -q test-compile gauge:classpath) + fi + if test -f $GAUGE_GRADLE_BUILD_FILE; then + class_path=$(./gradlew -q clean classpath) + fi +else + class_path="$gauge_custom_classpath"; +fi + function get_abs() { if [[ "$1" == /* ]]; then echo "$1" @@ -144,7 +156,7 @@ function init() { } tasks=(init start) -if [[ " ${tasks[@]} " =~ " $1 " ]]; then +if [[ " ${tasks[*]} " =~ $1 ]]; then $1 exit 0 fi