-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertx_detector.go
65 lines (56 loc) · 1.86 KB
/
vertx_detector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc.
******************************************************************************/
package enricher
import (
"context"
"encoding/json"
"github.com/mike-hoang/alizer-copy/go/pkg/apis/model"
"github.com/mike-hoang/alizer-copy/go/pkg/utils"
)
type VertxDetector struct{}
type VertxConf struct {
Port int `json:"http.port,omitempty"`
ServerConfig ServerConfig `json:"http.server,omitempty"`
}
type ServerConfig struct {
Port int `json:"http.server.port,omitempty"`
}
func (v VertxDetector) GetSupportedFrameworks() []string {
return []string{"Vertx"}
}
// DoFrameworkDetection uses the groupId to check for the framework name
func (v VertxDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "io.vertx", ""); hasFwk {
language.Frameworks = append(language.Frameworks, "Vertx")
}
}
// DoPortsDetection searches for the port in json files under src/main/conf/
func (v VertxDetector) DoPortsDetection(component *model.Component, ctx *context.Context) {
bytes, err := utils.ReadAnyApplicationFile(component.Path, []model.ApplicationFileInfo{
{
Dir: "src/main/conf",
File: ".*.json",
},
}, ctx)
if err != nil {
return
}
var data VertxConf
err = json.Unmarshal(bytes, &data)
if err != nil {
return
}
if utils.IsValidPort(data.Port) {
component.Ports = []int{data.Port}
} else if utils.IsValidPort(data.ServerConfig.Port) {
component.Ports = []int{data.ServerConfig.Port}
}
}