Skip to content

Commit

Permalink
Merge pull request #167 from alimgiray/master
Browse files Browse the repository at this point in the history
fix error handling
  • Loading branch information
peti2001 authored Mar 23, 2021
2 parents 6d635b4 + 8a03131 commit 7d65e94
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions librarydetection/languages/Java.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ type javaAnalyzer struct{}
func (a *javaAnalyzer) ExtractLibraries(contents string) ([]string, error) {
// regex to find imports like org.springframework (excluding standart java libraries)
regex1, err := regexp.Compile(`import ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*)`)
if err != nil {
return nil, err
}
// regex to find imports like org.springframework.boot
regex2, err := regexp.Compile(`import ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*)`)
if err != nil {
return nil, err
}
// regex to find static imports like org.springframework (excluding standart java libraries)
regex3, err := regexp.Compile(`import static ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*)`)
if err != nil {
return nil, err
}
// regex to find static imports like org.springframework.boot
regex4, err := regexp.Compile(`import static ([^java][a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*)`)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions librarydetection/languages/JavaScript.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ func NewJavaScriptAnalyzer() librarydetection.Analyzer {
type javaScriptAnalyzer struct{}

func (a *javaScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) {

require, err := regexp.Compile(`require\(["\'](.+)["\']\);?\s`)
if err != nil {
return nil, err
}

importRegex, err := regexp.Compile(`import\s*(?:.+ from)?\s?\(?[\'"](.+)[\'"]\)?;?\s`)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions librarydetection/languages/Python.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type pythonScriptAnalyzer struct{}

func (a *pythonScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) {
fromRegex, err := regexp.Compile(`from (.+) import`)
if err != nil {
return nil, err
}
importRegex, err := regexp.Compile(`import ([a-zA-Z0-9_-]+)(?:\s| as)`)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions librarydetection/languages/TypeScript.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type typeScriptAnalyzer struct{}

func (a *typeScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) {
require, err := regexp.Compile(`require\(["\'](.+)["\']\);?\s`)
if err != nil {
return nil, err
}
importRegex, err := regexp.Compile(`import\s*(?:.+ from)?\s?\(?[\'"](.+)[\'"]\)?;?\s`)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7d65e94

Please sign in to comment.