Skip to content

Commit

Permalink
✨ Adding alizer to determine languages and components (konveyor#197)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Apr 17, 2024
1 parent 708078f commit 9e7363d
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 63 deletions.
38 changes: 33 additions & 5 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"sort"
"strings"

"github.com/devfile/alizer/pkg/apis/model"
"github.com/devfile/alizer/pkg/apis/recognizer"
"github.com/go-logr/logr"
"github.com/konveyor-ecosystem/kantra/cmd/internal/hiddenfile"
"github.com/konveyor-ecosystem/kantra/pkg/container"
Expand Down Expand Up @@ -123,7 +125,15 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
log.Error(err, "failed to convert xml rules")
return err
}
err = analyzeCmd.RunAnalysis(cmd.Context(), xmlOutputDir)
components, err := recognizer.DetectComponents(analyzeCmd.input)
if err != nil {
log.Error(err, "Failed to determine languages for input")
return err
}
for _, c := range components {
log.Info("Got component", "component language", c.Languages, "path", c.Path)
}
err = analyzeCmd.RunAnalysis(cmd.Context(), xmlOutputDir, components)
if err != nil {
log.Error(err, "failed to run analysis")
return err
Expand Down Expand Up @@ -401,7 +411,7 @@ func listOptionsFromLabels(sl []string, label string) {
}
}

func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
func (a *analyzeCommand) getConfigVolumes(components []model.Component) (map[string]string, error) {
tempDir, err := os.MkdirTemp("", "analyze-config-")
if err != nil {
a.log.V(1).Error(err, "failed creating temp dir", "dir", tempDir)
Expand All @@ -410,6 +420,19 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
a.log.V(1).Info("created directory for provider settings", "dir", tempDir)
a.tempDirs = append(a.tempDirs, tempDir)

var foundJava bool
var foundGolang bool
for _, c := range components {
for _, l := range c.Languages {
if l.Name == "Java" {
foundJava = true
}
if l.Name == "Go" {
foundGolang = true
}
}
}

otherProvsMountPath := SourceMountPath
// when input is a file, it means it's probably a binary
// only java provider can work with binaries, all others
Expand Down Expand Up @@ -463,7 +486,6 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
}

provConfig := []provider.Config{
javaConfig,
{
Name: "builtin",
InitConfig: []provider.InitConfig{
Expand All @@ -474,6 +496,12 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
},
},
}
if foundJava {
provConfig = append(provConfig, javaConfig)
}
if foundGolang {
provConfig = append(provConfig, goConfig)
}

// Set proxy to providers
if a.httpProxy != "" || a.httpsProxy != "" {
Expand Down Expand Up @@ -663,7 +691,7 @@ func (a analyzeCommand) createTempRuleSet(path string, name string) error {
return nil
}

func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) error {
func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string, components []model.Component) error {
volumes := map[string]string{
// application source code
a.input: SourceMountPath,
Expand All @@ -682,7 +710,7 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e
a.tempDirs = append(a.tempDirs, xmlOutputDir)
}

configVols, err := a.getConfigVolumes()
configVols, err := a.getConfigVolumes(components)
if err != nil {
a.log.V(1).Error(err, "failed to get config volumes for analysis")
return err
Expand Down
64 changes: 43 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
module github.com/konveyor-ecosystem/kantra

go 1.18
go 1.21

require (
github.com/go-logr/logr v1.2.3
github.com/spf13/cobra v1.7.0
github.com/getkin/kin-openapi v0.108.0
github.com/go-logr/logr v1.4.1
github.com/spf13/cobra v1.8.0
go.lsp.dev/uri v0.3.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/cbroglie/mustache v1.3.0 // indirect
github.com/getkin/kin-openapi v0.108.0 // indirect
github.com/containerd/typeurl/v2 v2.1.1 // indirect
github.com/devfile/alizer v1.4.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/invopop/yaml v0.1.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/moby/buildkit v0.13.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.2 // indirect
go.opentelemetry.io/otel/sdk v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/apimachinery v0.27.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/controller-runtime v0.14.7 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

require (
Expand Down
Loading

0 comments on commit 9e7363d

Please sign in to comment.