jfrog / jfrog-cli-core

Apache License 2.0
33 stars 58 forks source link

Maven version validation fails when ANSI control sequences are present in the version output #264

Open zsrv opened 2 years ago

zsrv commented 2 years ago

Describe the bug

jfrog-cli-core v2.5.1 introduced validation of the version of Maven that is in use, which is being done by parsing the output of mvn --version. This validation fails if the version line, which is found by searching for a line in the output that starts with "Apache Maven", contains extra characters at the beginning of the line.

The version of Maven that I am using prints the Maven version line in bold, with ANSI control characters at the beginning (and end) of the line.

There is also a related, but secondary, issue where "minSupportedMvnVersion" is not printed correctly (see below).

Example:

user@localhost:~> jfrog config add --interactive=false --url=http://example.com --access-token=x
user@localhost:~> jfrog mvn-config --repo-resolve-releases=x --repo-resolve-snapshots=x --repo-deploy-releases=x --repo-deploy-snapshots=x
[Info] maven build config successfully created.
user@localhost:~> jfrog mvn clean
[Info] Running Mvn...
[Info] Could not get maven version, by running 'mvn --version' command. JFrog CLI mvn commands requires Maven version "+minSupportedMvnVersion+" or higher.
[Error] JFrog CLI mvn commands requires Maven version "+minSupportedMvnVersion+" or higher. The Current version is: 
user@localhost:~> mvn --version
Apache Maven 3.6.3 (SUSE 3.6.3-4.2.1)
Maven home: /usr/share/maven
Java version: 11.0.13, vendor: Oracle Corporation, runtime: /usr/lib64/jvm/java-11-openjdk-11
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.18-59.34-default", arch: "amd64", family: "unix"

mvn --version output with control characters visible:

^[[1mApache Maven 3.6.3 (SUSE 3.6.3-4.2.1)^[[m
Maven home: /usr/share/maven
Java version: 11.0.13, vendor: Oracle Corporation, runtime: /usr/lib64/jvm/java-11-openjdk-11
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.18-59.34-default", arch: "amd64", family: "unix"

My workaround was to downgrade to JFrog CLI 2.6.1 (which uses jfrog-cli-core 2.5.0).

To Reproduce

Launch openSUSE Leap 15.3 using this image: https://download.opensuse.org/distribution/leap/15.3/appliances/openSUSE-Leap-15.3-JeOS.x86_64-15.3-OpenStack-Cloud-Build9.258.qcow2

# Install Maven
zypper install maven

# Add the JFrog CLI RPM repository
cat > jfrog-cli.repo <<EOF
[jfrog-cli]
name=jfrog-cli
baseurl=https://releases.jfrog.io/artifactory/jfrog-rpms
enabled=1
gpgcheck=0
EOF

zypper addrepo ./jfrog-cli.repo
zypper install jfrog-cli-v2

# Configure
jfrog config add --interactive=false --url=http://example.com --access-token=x
jfrog mvn-config --repo-resolve-releases=x --repo-resolve-snapshots=x --repo-deploy-releases=x --repo-deploy-snapshots=x

# Run the Maven command to observe the error
jfrog mvn clean

# (optional) Downgrade to JFrog CLI 2.6.1
zypper install --oldpackage jfrog-cli-v2=2.6.1-1

# Run the Maven command again, which will now progress
jfrog mvn clean

Expected behavior

JFrog CLI should recognize that I am using Maven version 3.1.0 or above.

Versions

sverdlov93 commented 2 years ago

Hi @zsrv, thanks for reporting this issue and also for the detailed logs. We managed to reproduce and hopefully fix this issue in #265 PR The fix may be included in the next release. We'll keep you updated.

eyalbe4 commented 2 years ago

@zsrv, Version 2.7.0 includes the fix. We're looking forward to your feedback for it.

zsrv commented 2 years ago

Version 2.7.0 is working for me, thank you!