From 73d96dd19f837ffcdff4d8074327985b7ce13419 Mon Sep 17 00:00:00 2001 From: "konveyor-ci-bot[bot]" <159171263+konveyor-ci-bot[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:00:42 -0500 Subject: [PATCH] :sparkles: discontinue using maven and analyzer-deps. (#97) (#120) closes #93 Requires: - https://github.com/konveyor/tackle2-hub/pull/668 - https://github.com/konveyor/analyzer-lsp/pull/671 - https://github.com/konveyor/analyzer-lsp/pull/686 --------- Signed-off-by: Jeff Ortel Signed-off-by: Cherry Picker Signed-off-by: Jeff Ortel Signed-off-by: Cherry Picker Co-authored-by: Jeff Ortel --- Dockerfile | 1 - builder/deps.go | 1 + cmd/analyzer.go | 74 +++++++++---------------------- cmd/main.go | 91 ++++++++++++++++++++++---------------- cmd/mode.go | 82 +--------------------------------- cmd/settings.go | 1 - hack/konveyor-analyzer | 23 ---------- hack/konveyor-analyzer-dep | 22 --------- hack/provider-java | 22 +++++++++ settings.yaml | 5 --- 10 files changed, 97 insertions(+), 225 deletions(-) delete mode 100755 hack/konveyor-analyzer delete mode 100755 hack/konveyor-analyzer-dep create mode 100755 hack/provider-java delete mode 100644 settings.yaml diff --git a/Dockerfile b/Dockerfile index b5ca68f..a6b9a45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,5 @@ ENV HOME=/addon ADDON=/addon WORKDIR /addon ARG GOPATH=/opt/app-root COPY --from=shim /usr/bin/windup-shim /usr/bin -COPY --from=addon $GOPATH/src/settings.yaml $ADDON/opt/settings.yaml COPY --from=addon $GOPATH/src/bin/addon /usr/bin ENTRYPOINT ["/usr/bin/addon"] diff --git a/builder/deps.go b/builder/deps.go index 8d84c08..64f86ac 100644 --- a/builder/deps.go +++ b/builder/deps.go @@ -63,6 +63,7 @@ func (b *Deps) read() (input []output.DepsFlatItem, err error) { f, err := os.Open(b.Path) if err != nil { if os.IsNotExist(err) { + addon.Activity(err.Error()) err = nil } return diff --git a/cmd/analyzer.go b/cmd/analyzer.go index 4c70ada..5fc0418 100644 --- a/cmd/analyzer.go +++ b/cmd/analyzer.go @@ -1,6 +1,7 @@ package main import ( + "os" "path" "github.com/konveyor/tackle2-addon-analyzer/builder" @@ -15,17 +16,19 @@ type Analyzer struct { } // Run analyzer. -func (r *Analyzer) Run() (b *builder.Issues, err error) { - output := path.Join(Dir, "report.yaml") +func (r *Analyzer) Run() (issueBuilder *builder.Issues, depBuilder *builder.Deps, err error) { + output := path.Join(Dir, "issues.yaml") + depOutput := path.Join(Dir, "deps.yaml") cmd := command.New("/usr/local/bin/konveyor-analyzer") - cmd.Options, err = r.options(output) + cmd.Options, err = r.options(output, depOutput) if err != nil { return } if Verbosity > 0 { cmd.Reporter.Verbosity = command.LiveOutput } - b = &builder.Issues{Path: output} + issueBuilder = &builder.Issues{Path: output} + depBuilder = &builder.Deps{Path: depOutput} err = cmd.Run() if err != nil { return @@ -37,14 +40,22 @@ func (r *Analyzer) Run() (b *builder.Issues, err error) { return } addon.Attach(f) + if _, stErr := os.Stat(depOutput); stErr == nil { + f, pErr = addon.File.Post(depOutput) + if pErr != nil { + err = pErr + return + } + addon.Attach(f) + } } return } // options builds Analyzer options. -func (r *Analyzer) options(output string) (options command.Options, err error) { +func (r *Analyzer) options(output, depOutput string) (options command.Options, err error) { settings := &Settings{} - err = settings.Read() + err = settings.AppendExtensions() if err != nil { return } @@ -54,6 +65,9 @@ func (r *Analyzer) options(output string) (options command.Options, err error) { "--output-file", output, } + if !r.Data.Mode.Discovery { + options.Add("--dep-output-file", depOutput) + } err = r.Tagger.AddOptions(&options) if err != nil { return @@ -85,51 +99,3 @@ func (r *Analyzer) options(output string) (options command.Options, err error) { addon.Attach(f) return } - -// DepAnalyzer application analyzer. -type DepAnalyzer struct { - *Data -} - -// Run analyzer. -func (r *DepAnalyzer) Run() (b *builder.Deps, err error) { - output := path.Join(Dir, "deps.yaml") - cmd := command.New("/usr/local/bin/konveyor-analyzer-dep") - cmd.Options, err = r.options(output) - if err != nil { - return - } - if Verbosity > 0 { - cmd.Reporter.Verbosity = command.LiveOutput - } - b = &builder.Deps{Path: output} - err = cmd.Run() - if err != nil { - return - } - return -} - -// options builds Analyzer options. -func (r *DepAnalyzer) options(output string) (options command.Options, err error) { - settings := &Settings{} - err = settings.Read() - if err != nil { - return - } - options = command.Options{ - "--provider-settings", - settings.path(), - "--output-file", - output, - } - err = r.Mode.AddDepOptions(&options, settings) - if err != nil { - return - } - err = settings.Write() - if err != nil { - return - } - return -} diff --git a/cmd/main.go b/cmd/main.go index 438d842..b607378 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ import ( "time" "github.com/gin-gonic/gin/binding" + "github.com/konveyor/tackle2-addon-analyzer/builder" "github.com/konveyor/tackle2-addon/ssh" hub "github.com/konveyor/tackle2-hub/addon" "github.com/konveyor/tackle2-hub/api" @@ -104,49 +105,22 @@ func main() { return } // - // Run analysis. + // Run the analyzer. analyzer := Analyzer{} analyzer.Data = d - issues, err := analyzer.Run() + issues, deps, err := analyzer.Run() if err != nil { return } - if !d.Mode.Discovery { - depAnalyzer := DepAnalyzer{} - depAnalyzer.Data = d - deps, dErr := depAnalyzer.Run() - if dErr != nil { - err = dErr - return - } - // - // Post report. - appAnalysis := addon.Application.Analysis(application.ID) - mark := time.Now() - analysis := &api.Analysis{} - err = appAnalysis.Create( - analysis, - binding.MIMEYAML, - issues.Reader(), - deps.Reader()) - if err != nil { - return - } - addon.Activity("Analysis reported. duration: %s", time.Since(mark)) - // - // RuleError - ruleErr := issues.RuleError() - ruleErr.Report() - // - // Facts - facts := addon.Application.Facts(application.ID) - facts.Source(Source) - err = facts.Replace(issues.Facts()) - if err == nil { - addon.Activity("Facts updated.") - } else { - return - } + // + // RuleError + ruleErr := issues.RuleError() + ruleErr.Report() + // + // Update application. + err = updateApplication(d, application.ID, issues, deps) + if err != nil { + return } // // Tags. @@ -165,3 +139,44 @@ func main() { return }) } + +// updateApplication creates analysis report and updates +// the application facts and tags. +func updateApplication(d *Data, appId uint, issues *builder.Issues, deps *builder.Deps) (err error) { + // + // Tags. + if d.Tagger.Enabled { + if d.Tagger.Source == "" { + d.Tagger.Source = Source + } + err = d.Tagger.Update(appId, issues.Tags()) + if err != nil { + return + } + } + if d.Mode.Discovery { + return + } + // + // Analysis. + appAnalysis := addon.Application.Analysis(appId) + mark := time.Now() + analysis := &api.Analysis{} + err = appAnalysis.Create( + analysis, + binding.MIMEYAML, + issues.Reader(), + deps.Reader()) + if err != nil { + return + } + addon.Activity("Analysis reported. duration: %s", time.Since(mark)) + // Facts. + facts := addon.Application.Facts(appId) + facts.Source(Source) + err = facts.Replace(issues.Facts()) + if err == nil { + addon.Activity("Facts updated.") + } + return +} diff --git a/cmd/mode.go b/cmd/mode.go index 6836b73..fb099e3 100644 --- a/cmd/mode.go +++ b/cmd/mode.go @@ -2,7 +2,6 @@ package main import ( "errors" - "os" "path" "strings" @@ -10,7 +9,6 @@ import ( "github.com/konveyor/tackle2-addon/command" "github.com/konveyor/tackle2-addon/repository" "github.com/konveyor/tackle2-hub/api" - "github.com/konveyor/tackle2-hub/nas" ) // Mode settings. @@ -29,27 +27,16 @@ type Mode struct { // Build assets. func (r *Mode) Build(application *api.Application) (err error) { - binDir := path.Join(BinDir, "maven") - maven := &repository.Maven{ - M2Dir: M2Dir, - BinDir: binDir, - Remote: repository.Remote{ - Identities: application.Identities, - }, - } if !r.Binary { err = r.fetchRepository(application) return } - if r.Artifact != "" { err = r.getArtifact() return } - if application.Binary != "" { - err = r.mavenArtifact(application, maven) - return + r.path.binary = application.Binary + "@" + BinDir } return } @@ -70,16 +57,6 @@ func (r *Mode) AddOptions(options *command.Options, settings *Settings) (err err return } -// AddDepOptions adds analyzer-dep options. -func (r *Mode) AddDepOptions(options *command.Options, settings *Settings) (err error) { - if r.Binary { - settings.Location(r.path.binary) - } else { - settings.Location(r.path.appDir) - } - return -} - // fetchRepository get SCM repository. func (r *Mode) fetchRepository(application *api.Application) (err error) { if application.Repository == nil { @@ -113,60 +90,3 @@ func (r *Mode) getArtifact() (err error) { r.path.binary = path.Join(BinDir, path.Base(r.Artifact)) return } - -// mavenArtifact get maven artifact. -func (r *Mode) mavenArtifact(application *api.Application, maven *repository.Maven) (err error) { - artifact := strings.TrimPrefix(application.Binary, "mvn://") - err = maven.FetchArtifact(artifact) - if err != nil { - return - } - dir, nErr := os.ReadDir(maven.BinDir) - if nErr != nil { - err = nErr - return - } - if len(dir) > 0 { - r.path.binary = path.Join(maven.BinDir, dir[0].Name()) - } - return -} - -// buildMavenSettings creates maven settings. -func (r *Mode) buildMavenSettings(application *api.Application) (err error) { - id, found, nErr := addon.Application.FindIdentity( - application.ID, - "maven") - if nErr != nil { - err = nErr - return - } - if found { - addon.Activity( - "[MVN] Using credentials (id=%d) %s.", - id.ID, - id.Name) - } else { - return - } - p := path.Join( - OptDir, - "maven", - "settings.xml") - err = nas.MkDir(path.Dir(p), 0755) - if err != nil { - return - } - f, err := os.Create(p) - if err != nil { - return - } - defer func() { - _ = f.Close() - }() - _, err = f.WriteString(id.Settings) - if err != nil { - return - } - return -} diff --git a/cmd/settings.go b/cmd/settings.go index fabcf9b..5fcd270 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -35,7 +35,6 @@ func (r *Settings) Read() (err error) { return } r.index = len(r.content) - err = r.AppendExtensions() return } diff --git a/hack/konveyor-analyzer b/hack/konveyor-analyzer deleted file mode 100755 index a30816d..0000000 --- a/hack/konveyor-analyzer +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -image=${IMAGE-quay.io/konveyor/analyzer-lsp} - -if [ -z "${image}" ] -then - exit -fi - -addon=/tmp/addon - -params=() -for p in "$@" -do - params+=("$p") -done - -docker run \ - --entrypoint /usr/local/bin/konveyor-analyzer \ - -v ${addon}:${addon} \ - ${image} \ - "${params[@]}" - diff --git a/hack/konveyor-analyzer-dep b/hack/konveyor-analyzer-dep deleted file mode 100755 index 043d319..0000000 --- a/hack/konveyor-analyzer-dep +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -image=${IMAGE-quay.io/konveyor/analyzer-lsp} - -if [ -z "${image}" ] -then - exit -fi - -addon=/tmp/addon - -params=() -for p in "$@" -do - params+=("$p") -done -docker run \ - --entrypoint /usr/local/bin/konveyor-analyzer-dep \ - -v ${addon}:${addon} \ - ${image} \ - "${params[@]}" - diff --git a/hack/provider-java b/hack/provider-java new file mode 100755 index 0000000..eff7e87 --- /dev/null +++ b/hack/provider-java @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +image=${IMAGE-quay.io/konveyor/java-external-provider} +port=${1-8000} + +if [ -z "${image}" ] +then + exit +fi + +shared=/shared + +params=() +for p in "$@" +do + params+=("$p") +done + +set -x + +docker run -v ${shared}:${shared} -p ${port}:${port} ${image} --port ${port} + diff --git a/settings.yaml b/settings.yaml deleted file mode 100644 index bfa6c6e..0000000 --- a/settings.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: builtin - initConfig: - - {} -