Skip to content

Commit

Permalink
discovery: Handle .war on Java command line (#31372)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitkyrka authored Nov 22, 2024
1 parent b67a6e6 commit 188e19d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/servicediscovery/usm/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (jd javaDetector) detect(args []string) (metadata ServiceMetadata, success
if arg = trimColonRight(arg); isRuneLetterAt(arg, 0) {
// do JEE detection to see if we can extract additional service names from context roots.
additionalNames = jeeExtractor(jd).extractServiceNamesForJEEServer()
if strings.HasSuffix(arg, javaJarExtension) {
if strings.HasSuffix(arg, javaJarExtension) || strings.HasSuffix(arg, javaWarExtension) {
// try to see if the application is a spring boot archive and extract its application name
if len(additionalNames) == 0 {
if springAppName, ok := newSpringBootParser(jd.ctx).GetSpringBootAppName(a); ok {
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/corechecks/servicediscovery/usm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
const (
javaJarFlag = "-jar"
javaJarExtension = ".jar"
javaWarExtension = ".war"
dllExtension = ".dll"
javaApachePrefix = "org.apache."
maxParseFileSize = 1024 * 1024
Expand Down
8 changes: 8 additions & 0 deletions pkg/collector/corechecks/servicediscovery/usm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func TestExtractServiceMetadata(t *testing.T) {
lang: language.Java,
expectedGeneratedName: "myservice",
},
{
name: "java using the -jar flag to point to a .war",
cmdline: []string{
"java", "-Duser.home=/var/jenkins_home", "-Dhudson.lifecycle=hudson.lifecycle.ExitLifecycle", "-jar", "/usr/share/jenkins/jenkins.war", "--httpPort=8000",
},
lang: language.Java,
expectedGeneratedName: "jenkins",
},
{
name: "java class name as service",
cmdline: []string{
Expand Down

0 comments on commit 188e19d

Please sign in to comment.