Skip to content

Commit

Permalink
✨ discontinue using maven and analyzer-deps. (#97) (#120)
Browse files Browse the repository at this point in the history
closes #93

Requires:
- konveyor/tackle2-hub#668
- konveyor/analyzer-lsp#671
- konveyor/analyzer-lsp#686

---------

Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>

Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
Co-authored-by: Jeff Ortel <[email protected]>
  • Loading branch information
konveyor-ci-bot[bot] and jortel authored Aug 1, 2024
1 parent ebfd878 commit 73d96dd
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 225 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions builder/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 20 additions & 54 deletions cmd/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"os"
"path"

"github.com/konveyor/tackle2-addon-analyzer/builder"
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
91 changes: 53 additions & 38 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
82 changes: 1 addition & 81 deletions cmd/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package main

import (
"errors"
"os"
"path"
"strings"

"github.com/konveyor/analyzer-lsp/provider"
"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.
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (r *Settings) Read() (err error) {
return
}
r.index = len(r.content)
err = r.AppendExtensions()
return
}

Expand Down
Loading

0 comments on commit 73d96dd

Please sign in to comment.