Skip to content

Commit

Permalink
Fix Nuget requestedBy calculation (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Sep 1, 2022
1 parent e8821b4 commit b617a66
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 37 deletions.
19 changes: 10 additions & 9 deletions build/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ func TestGenerateBuildInfoForMavenProject(t *testing.T) {
mavenModule.SetMavenGoals("compile", "--no-transfer-progress")
// Calculate build-info.
err = mavenModule.CalcDependencies()
assert.NoError(t, err)
buildInfo, err := mavenBuild.ToBuildInfo()
assert.NoError(t, err)
// Check build-info results.
expectedModules := getExpectedMavenBuildInfo(t, filepath.Join(testdataDir, "maven", "expected_maven_buildinfo.json")).Modules
match, err := entities.IsEqualModuleSlices(buildInfo.Modules, expectedModules)
assert.NoError(t, err)
if !match {
testdatautils.PrintBuildInfoMismatch(t, expectedModules, buildInfo.Modules)
if assert.NoError(t, err) {
buildInfo, err := mavenBuild.ToBuildInfo()
assert.NoError(t, err)
// Check build-info results.
expectedModules := getExpectedMavenBuildInfo(t, filepath.Join(testdataDir, "maven", "expected_maven_buildinfo.json")).Modules
match, err := entities.IsEqualModuleSlices(buildInfo.Modules, expectedModules)
assert.NoError(t, err)
if !match {
testdatautils.PrintBuildInfoMismatch(t, expectedModules, buildInfo.Modules)
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions build/utils/dotnet/solution/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ func populateRequestedBy(parentDependency buildinfo.Dependency, dependenciesMap
if childDep.NodeHasLoop() || len(childDep.RequestedBy) >= buildinfo.RequestedByMaxLength {
continue
}
for _, parentRequestedBy := range parentDependency.RequestedBy {
childRequestedBy := append([]string{parentDependency.Id}, parentRequestedBy...)
childDep.RequestedBy = append(childDep.RequestedBy, childRequestedBy)
}
// Update RequestedBy field from parent's RequestedBy.
childDep.UpdateRequestedBy(parentDependency.Id, parentDependency.RequestedBy)

// Run recursive call on child dependencies
populateRequestedBy(*childDep, dependenciesMap, childrenMap)
}
Expand Down
12 changes: 2 additions & 10 deletions build/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/utils"
"github.com/jfrog/gofrog/version"
"golang.org/x/exp/slices"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (ym *YarnModule) appendDependencyRecursively(yarnDependency *buildutils.Yar
id := yarnDependency.Name() + ":" + yarnDependency.Details.Version

// To avoid infinite loops in case of circular dependencies, the dependency won't be added if it's already in pathToRoot
if stringsSliceContains(pathToRoot, id) {
if slices.Contains(pathToRoot, id) {
return nil
}

Expand Down Expand Up @@ -192,12 +193,3 @@ func runYarnCommand(executablePath, srcPath string, args ...string) error {
}
return err
}

func stringsSliceContains(slice []string, str string) bool {
for _, element := range slice {
if element == str {
return true
}
}
return false
}
7 changes: 3 additions & 4 deletions entities/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package entities

import (
"github.com/jfrog/build-info-go/utils/compareutils"
"golang.org/x/exp/slices"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -528,10 +529,8 @@ func (d *Dependency) UpdateRequestedBy(parentId string, parentRequestedBy [][]st

func (d *Dependency) NodeHasLoop() bool {
for _, requestedBy := range d.RequestedBy {
for _, depId := range requestedBy {
if depId == d.Id {
return true
}
if slices.Contains(requestedBy, d.Id) {
return true
}
}
return false
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.11.2
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 h1:tnebWN09GYg9OLPss1KXj8txwZc6X6uMr6VFdcGNbHw=
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 2 additions & 1 deletion utils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"golang.org/x/exp/slices"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -412,7 +413,7 @@ func CopyDir(fromPath, toPath string, includeDirs bool, excludeNames []string) e

for _, v := range files {
// Skip if excluded
if IsStringInSlice(filepath.Base(v), excludeNames) {
if slices.Contains(excludeNames, filepath.Base(v)) {
continue
}

Expand Down
9 changes: 0 additions & 9 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ func GetRegExp(regex string) (*regexp.Regexp, error) {
}
return regExp, nil
}

func IsStringInSlice(str string, strings []string) bool {
for _, v := range strings {
if v == str {
return true
}
}
return false
}

0 comments on commit b617a66

Please sign in to comment.