Skip to content

Commit

Permalink
feat: retrieve project name when doing component detection (redhat-de…
Browse files Browse the repository at this point in the history
…veloper#96)

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi committed Jul 6, 2022
1 parent 4057f5a commit d712f28
Show file tree
Hide file tree
Showing 31 changed files with 184 additions and 125 deletions.
11 changes: 8 additions & 3 deletions go/pkg/apis/enricher/dotnet_enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package recognizer

import (
framework "github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/dotnet"
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
utils "github.com/redhat-developer/alizer/go/pkg/utils"
)

Expand All @@ -28,18 +28,23 @@ func getDotNetFrameworkDetectors() []FrameworkDetectorWithConfigFile {
}
}

func (j DotNetEnricher) DoEnrichLanguage(language *language.Language, files *[]string) {
func (j DotNetEnricher) DoEnrichLanguage(language *model.Language, files *[]string) {
configFiles := utils.GetFilesByRegex(files, ".*\\.\\w+proj")
for _, configFile := range configFiles {
getDotNetFrameworks(language, configFile)
}
}

func (j DotNetEnricher) DoEnrichComponent(component *model.Component) {
projectName := GetDefaultProjectName(component.Path)
component.Name = projectName
}

func (j DotNetEnricher) IsConfigValidForComponentDetection(language string, config string) bool {
return IsConfigurationValidForLanguage(language, config)
}

func getDotNetFrameworks(language *language.Language, configFile string) {
func getDotNetFrameworks(language *model.Language, configFile string) {
for _, detector := range getDotNetFrameworkDetectors() {
detector.DoFrameworkDetection(language, configFile)
}
Expand Down
13 changes: 9 additions & 4 deletions go/pkg/apis/enricher/enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ import (
"path/filepath"
"strings"

"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"github.com/redhat-developer/alizer/go/pkg/utils/langfiles"
)

type Enricher interface {
GetSupportedLanguages() []string
DoEnrichLanguage(language *language.Language, files *[]string)
DoEnrichLanguage(language *model.Language, files *[]string)
DoEnrichComponent(component *model.Component)
IsConfigValidForComponentDetection(language string, configFile string) bool
}

type FrameworkDetectorWithConfigFile interface {
DoFrameworkDetection(language *language.Language, config string)
DoFrameworkDetection(language *model.Language, config string)
}

type FrameworkDetectorWithoutConfigFile interface {
DoFrameworkDetection(language *language.Language, files *[]string)
DoFrameworkDetection(language *model.Language, files *[]string)
}

/*
Expand Down Expand Up @@ -107,3 +108,7 @@ func isLanguageSupportedByEnricher(nameLanguage string, enricher Enricher) bool
}
return false
}

func GetDefaultProjectName(path string) string {
return filepath.Base(path)
}
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/dotnet/dotnet_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (
"os"
"strings"

"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"github.com/redhat-developer/alizer/go/pkg/schema"
"github.com/redhat-developer/alizer/go/pkg/utils"
)

type DotNetDetector struct{}

func (m DotNetDetector) DoFrameworkDetection(language *language.Language, configFilePath string) {
func (m DotNetDetector) DoFrameworkDetection(language *model.Language, configFilePath string) {
framework := getFrameworks(configFilePath)
if framework == "" {
return
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/beego_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type BeegoDetector struct{}

func (e BeegoDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e BeegoDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/beego/beego") {
language.Frameworks = append(language.Frameworks, "Beego")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/echo_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type EchoDetector struct{}

func (e EchoDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e EchoDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/labstack/echo") {
language.Frameworks = append(language.Frameworks, "Echo")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/fasthttp_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type FastHttpDetector struct{}

func (e FastHttpDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e FastHttpDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/valyala/fasthttp") {
language.Frameworks = append(language.Frameworks, "FastHttp")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/gin_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type GinDetector struct{}

func (e GinDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e GinDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/gin-gonic/gin") {
language.Frameworks = append(language.Frameworks, "Gin")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/gofiber_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type GoFiberDetector struct{}

func (e GoFiberDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e GoFiberDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/gofiber/fiber") {
language.Frameworks = append(language.Frameworks, "GoFiber")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/go/mux_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"golang.org/x/mod/modfile"
)

type MuxDetector struct{}

func (e MuxDetector) DoFrameworkDetection(language *language.Language, goMod *modfile.File) {
func (e MuxDetector) DoFrameworkDetection(language *model.Language, goMod *modfile.File) {
if hasFramework(goMod.Require, "github.com/gorilla/mux") {
language.Frameworks = append(language.Frameworks, "Mux")
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/apis/enricher/framework/java/micronaut_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type MicronautDetector struct{}

func (m MicronautDetector) DoFrameworkDetection(language *language.Language, config string) {
func (m MicronautDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "io.micronaut"); hasFwk {
language.Frameworks = append(language.Frameworks, "Micronaut")
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/apis/enricher/framework/java/openliberty_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type OpenLibertyDetector struct{}

func (o OpenLibertyDetector) DoFrameworkDetection(language *language.Language, config string) {
func (o OpenLibertyDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "io.openliberty"); hasFwk {
language.Frameworks = append(language.Frameworks, "OpenLiberty")
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/apis/enricher/framework/java/quarkus_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type QuarkusDetector struct{}

func (q QuarkusDetector) DoFrameworkDetection(language *language.Language, config string) {
func (q QuarkusDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "io.quarkus"); hasFwk {
language.Frameworks = append(language.Frameworks, "Quarkus")
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/apis/enricher/framework/java/spring_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type SpringDetector struct{}

func (s SpringDetector) DoFrameworkDetection(language *language.Language, config string) {
func (s SpringDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "org.springframework"); hasFwk {
language.Frameworks = append(language.Frameworks, "Spring")
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/apis/enricher/framework/java/vertx_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type VertxDetector struct{}

func (v VertxDetector) DoFrameworkDetection(language *language.Language, config string) {
func (v VertxDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFwk, _ := hasFramework(config, "io.vertx"); hasFwk {
language.Frameworks = append(language.Frameworks, "Vertx")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type ExpressDetector struct{}

func (e ExpressDetector) DoFrameworkDetection(language *language.Language, config string) {
func (e ExpressDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFramework(config, "express") {
language.Frameworks = append(language.Frameworks, "Express")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
******************************************************************************/
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
)
import "github.com/redhat-developer/alizer/go/pkg/apis/model"

type ReactJsDetector struct{}

func (r ReactJsDetector) DoFrameworkDetection(language *language.Language, config string) {
func (r ReactJsDetector) DoFrameworkDetection(language *model.Language, config string) {
if hasFramework(config, "react") {
language.Frameworks = append(language.Frameworks, "React")
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/apis/enricher/framework/python/django_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package recognizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
"github.com/redhat-developer/alizer/go/pkg/utils"
)

type DjangoDetector struct{}

func (d DjangoDetector) DoFrameworkDetection(language *language.Language, files *[]string) {
func (d DjangoDetector) DoFrameworkDetection(language *model.Language, files *[]string) {
managePy := utils.GetFile(files, "manage.py")
urlsPy := utils.GetFile(files, "urls.py")
wsgiPy := utils.GetFile(files, "wsgi.py")
Expand Down
13 changes: 9 additions & 4 deletions go/pkg/apis/enricher/go_enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
"io/ioutil"

framework "github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/go"
"github.com/redhat-developer/alizer/go/pkg/apis/language"
"github.com/redhat-developer/alizer/go/pkg/apis/model"
utils "github.com/redhat-developer/alizer/go/pkg/utils"
"golang.org/x/mod/modfile"
)

type GoEnricher struct{}

type GoFrameworkDetector interface {
DoFrameworkDetection(language *language.Language, goMod *modfile.File)
DoFrameworkDetection(language *model.Language, goMod *modfile.File)
}

func getGoFrameworkDetectors() []GoFrameworkDetector {
Expand All @@ -41,7 +41,7 @@ func (j GoEnricher) GetSupportedLanguages() []string {
return []string{"go"}
}

func (j GoEnricher) DoEnrichLanguage(language *language.Language, files *[]string) {
func (j GoEnricher) DoEnrichLanguage(language *model.Language, files *[]string) {
goModPath := utils.GetFile(files, "go.mod")

if goModPath != "" {
Expand All @@ -56,6 +56,11 @@ func (j GoEnricher) DoEnrichLanguage(language *language.Language, files *[]strin
}
}

func (j GoEnricher) DoEnrichComponent(component *model.Component) {
projectName := GetDefaultProjectName(component.Path)
component.Name = projectName
}

func (j GoEnricher) IsConfigValidForComponentDetection(language string, config string) bool {
return IsConfigurationValidForLanguage(language, config)
}
Expand All @@ -68,7 +73,7 @@ func getGoModFile(filePath string) (*modfile.File, error) {
return modfile.Parse(filePath, b, nil)
}

func detectGoFrameworks(language *language.Language, configFile *modfile.File) {
func detectGoFrameworks(language *model.Language, configFile *modfile.File) {
for _, detector := range getGoFrameworkDetectors() {
detector.DoFrameworkDetection(language, configFile)
}
Expand Down
Loading

0 comments on commit d712f28

Please sign in to comment.