Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude pattern for dotnet #233

Merged
merged 9 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (dm *DotnetModule) CalcDependencies() error {
if err != nil {
return err
}
sol, err := solution.Load(dm.solutionPath, slnFile, dm.containingBuild.logger)
sol, err := solution.Load(dm.solutionPath, slnFile, "", dm.containingBuild.logger)
if err != nil {
return err
}
Expand Down
23 changes: 18 additions & 5 deletions build/utils/dotnet/solution/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type Solution interface {

var projectRegExp *regexp.Regexp

func Load(path, slnFile string, log utils.Log) (Solution, error) {
func Load(path, slnFile, excludePattern string, log utils.Log) (Solution, error) {
solution := &solution{path: path, slnFile: slnFile}
// Reads all projects from '.sln' files.
slnProjects, err := solution.getProjectsListFromSlns(log)
slnProjects, err := solution.getProjectsListFromSlns(excludePattern, log)
if err != nil {
return solution, err
}
Expand Down Expand Up @@ -148,13 +148,13 @@ func (solution *solution) DependenciesSourcesAndProjectsPathExist() bool {
return len(solution.dependenciesSources) > 0 && len(solution.projects) > 0
}

func (solution *solution) getProjectsListFromSlns(log utils.Log) ([]project.Project, error) {
func (solution *solution) getProjectsListFromSlns(excludePattern string, log utils.Log) ([]project.Project, error) {
slnProjects, err := solution.getProjectsFromSlns()
if err != nil {
return nil, err
}
if slnProjects != nil {
return solution.parseProjectsFromSolutionFile(slnProjects, log)
return solution.parseProjectsFromSolutionFile(slnProjects, excludePattern, log)
}
return nil, nil
}
Expand All @@ -174,14 +174,27 @@ func (solution *solution) loadProjects(slnProjects []project.Project, log utils.
return nil
}

func (solution *solution) parseProjectsFromSolutionFile(slnProjects []string, log utils.Log) ([]project.Project, error) {
func (solution *solution) parseProjectsFromSolutionFile(slnProjects []string, excludePattern string, log utils.Log) ([]project.Project, error) {
var projects []project.Project
for _, projectLine := range slnProjects {
projectName, projFilePath, err := parseProjectLine(projectLine, solution.path)
if err != nil {
log.Error(err)
continue
}
// Exclude projects by pattern.
if len(excludePattern) > 0 {
attiasas marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of errors can be thrown here that we can accept and not killing the process?
if these "errors" are such we can accept it might be better to use log.Warn so it will not look like an Error to the customer that we didn't take care of or ignored

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an error is OK in this case, we log it just like we log when we can't parse at the above line.
There could be an error from the pattern or a lot of other reasons...
We got an error for this project so we report it and skip to the next, we don't want to fail all the build but still an error occur and it is not the full one, the customer may be at fault since we rely on input given to us.

}
if exclude {
log.Debug(fmt.Sprintf("The path '%s' is excluded", projFilePath))
continue
}
}
// Looking for .*proj files.
if !strings.HasSuffix(filepath.Ext(projFilePath), "proj") {
log.Debug(fmt.Sprintf("Skipping a project \"%s\", since it doesn't have a '.*proj' file path.", projectName))
Expand Down
4 changes: 2 additions & 2 deletions build/utils/dotnet/solution/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var logger = utils.NewDefaultLogger(utils.INFO)

func TestEmptySolution(t *testing.T) {
solution, err := Load(".", "", logger)
solution, err := Load(".", "", "", logger)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestLoad(t *testing.T) {
// 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)
solutions, err := Load(solution.path, solution.slnFile, "", log)
attiasas marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
t.Error(err)
}
Expand Down
Loading