Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

skip excluded_folders when getting cached filepaths from root #210

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions go/pkg/utils/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"encoding/xml"
"errors"
"github.com/redhat-developer/alizer/go/pkg/utils/langfiles"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -211,9 +212,16 @@ func GetFilePathsFromRoot(root string) ([]string, error) {

var files []string
ignoreFile, errorIgnoreFile := getIgnoreFile(root)
excludedFolders := langfiles.Get().GetExcludedFolders()
errWalk := filepath.Walk(root,
func(path string, info os.FileInfo, err error) error {
relativePath := strings.Replace(path, root, "", 1)
// skip directories from excluded folders
for _, excludedFolder := range excludedFolders {
if strings.Contains(relativePath, excludedFolder) {
return filepath.SkipDir
}
}
if errorIgnoreFile == nil && ignoreFile.MatchesPath(relativePath) {
if info.IsDir() {
return filepath.SkipDir
Expand Down
32 changes: 32 additions & 0 deletions go/pkg/utils/langfiles/languages_file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Contributors:
* Red Hat, Inc.
******************************************************************************/

package langfiles

import (
Expand Down Expand Up @@ -171,3 +172,34 @@ func (l *LanguageFile) GetConfigurationPerLanguageMapping() map[string][]string
}
return configurationPerLanguage
}

func (l *LanguageFile) GetExcludedFolders() []string {
var excludedFolders []string
for _, langItem := range l.languages {
for _, exclude := range langItem.ExcludeFolders {
excludedFolders = append(excludedFolders, exclude)
}
}
excludedFolders = removeDuplicates(excludedFolders)
return excludedFolders
}

// RemoveDuplicates goes through a string slice and removes all duplicates.
// Reference: https://siongui.github.io/2018/04/14/go-remove-duplicates-from-slice-or-array/
func removeDuplicates(s []string) []string {

// Make a map and go through each value to see if it's a duplicate or not
m := make(map[string]bool)
for _, item := range s {
if _, ok := m[item]; !ok {
m[item] = true
}
}

// Append to the unique string
var result []string
for item := range m {
result = append(result, item)
}
return result
}
2 changes: 2 additions & 0 deletions go/pkg/utils/langfiles/resources/languages-customization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ F#:
GCC Machine Description:
disable_detection: true
Go:
exclude_folders:
- "vendor"
configuration_files:
- "go.mod"
component: true
Expand Down
Loading