Skip to content

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Feb 25, 2024
1 parent 3255cf9 commit 7a4b604
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
27 changes: 16 additions & 11 deletions build/utils/dotnet/solution/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (solution *solution) getProjectsListFromSlns(excludePattern string, log uti
return nil, err
}
if slnProjects != nil {
if len(excludePattern) > 0 {
log.Debug(fmt.Sprintf("Testing to exclude projects by pattern: %s", excludePattern))
}
return solution.parseProjectsFromSolutionFile(slnProjects, excludePattern, log)
}
return nil, nil
Expand Down Expand Up @@ -183,17 +186,12 @@ func (solution *solution) parseProjectsFromSolutionFile(slnProjects []string, ex
continue
}
// Exclude projects by pattern.
if len(excludePattern) > 0 {
log.Debug(fmt.Sprintf("Testing to exclude projects by pattern: %s", excludePattern))
exclude, err := regexp.MatchString(excludePattern, projFilePath)
if err != nil {
log.Error(err)
continue
}
if exclude {
log.Debug(fmt.Sprintf("The path '%s' is excluded", projFilePath))
continue
}
if exclude, err := isProjectExcluded(projFilePath, excludePattern, log); err != nil {
log.Error(err)
continue
} else if exclude {
log.Debug(fmt.Sprintf("Skipping a project \"%s\", since the path '%s' is excluded", projectName, projFilePath))
continue
}
// Looking for .*proj files.
if !strings.HasSuffix(filepath.Ext(projFilePath), "proj") {
Expand All @@ -205,6 +203,13 @@ func (solution *solution) parseProjectsFromSolutionFile(slnProjects []string, ex
return projects, nil
}

func isProjectExcluded(projFilePath, excludePattern string, log utils.Log) (exclude bool, err error) {

Check failure on line 206 in build/utils/dotnet/solution/solution.go

View workflow job for this annotation

GitHub Actions / Static-Check

`isProjectExcluded` - `log` is unused (unparam)
if len(excludePattern) == 0 {
return
}
return regexp.MatchString(excludePattern, projFilePath)
}

func (solution *solution) loadSingleProjectFromDir(log utils.Log) error {
// List files with .*proj extension.
projFiles, err := utils.ListFilesByFilterFunc(solution.path, func(filePath string) (bool, error) {
Expand Down
30 changes: 22 additions & 8 deletions build/utils/dotnet/solution/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func replaceCarriageSign(results []string) {
}

func TestLoad(t *testing.T) {
// Prepare
log := utils.NewDefaultLogger(utils.INFO)
wd, err := os.Getwd()
if err != nil {
Expand All @@ -156,13 +157,26 @@ func TestLoad(t *testing.T) {
nugetCmd := exec.Command("nuget", "restore", filepath.Join(wd, "tmp", "nugetproj", "solutions", "nugetproj.sln"))
assert.NoError(t, nugetCmd.Run())

// 'nugetproj' contains 2 'packages.config' files for 2 projects -
// 1. located in the project's root directory.
// 2. located in solutions directory.
solution := solution{path: filepath.Join(wd, "testdata", "nugetproj", "solutions"), slnFile: "nugetproj.sln"}
solutions, err := Load(solution.path, solution.slnFile, "", log)
if err != nil {
t.Error(err)
testCases := []struct {
name string
excludePattern string
expectedProjectCount int
}{
{"noExcludePattern", "", 2},
{"excludePattern", `(^.*.*/proj1.*/.*.*$)`, 1},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
// 'nugetproj' contains 2 'packages.config' files for 2 projects -
// 1. located in the project's root directory.
// 2. located in solutions directory.
solution := solution{path: filepath.Join(wd, "testdata", "nugetproj", "solutions"), slnFile: "nugetproj.sln"}
solutions, err := Load(solution.path, solution.slnFile, testCase.excludePattern, log)
if err != nil {
t.Error(err)
}
assert.Equal(t, testCase.expectedProjectCount, len(solutions.GetProjects()))
})
}
assert.Equal(t, 2, len(solutions.GetProjects()))
}

0 comments on commit 7a4b604

Please sign in to comment.