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

Support csproj files for identifying .NET Core projects #11896

Merged
merged 1 commit into from
Nov 21, 2016
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
2 changes: 1 addition & 1 deletion pkg/generate/app/sourcelookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (e SourceRepositoryEnumerator) Detect(dir string, noSourceDetection bool) (
// is docker or pipeline
if !noSourceDetection {
for _, d := range e.Detectors {
if detected, ok := d(dir); ok {
if detected := d(dir); detected != nil {
info.Types = append(info.Types, SourceLanguageType{
Platform: detected.Platform,
Version: detected.Version,
Expand Down
51 changes: 19 additions & 32 deletions pkg/generate/source/detector.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package source

import (
"os"
"path/filepath"
)
import "path/filepath"

// Info is detected platform information from a source directory
type Info struct {
Expand All @@ -13,7 +10,7 @@ type Info struct {

// DetectorFunc is a function that returns source Info from a given directory.
// It returns true if it was able to detect the code in the given directory.
type DetectorFunc func(dir string) (*Info, bool)
type DetectorFunc func(dir string) *Info

// Detectors is a set of DetectorFunc that is used to detect the
// language/platform for a given source directory
Expand All @@ -33,66 +30,56 @@ var DefaultDetectors = Detectors{
}

// DetectRuby detects Ruby source
func DetectRuby(dir string) (*Info, bool) {
func DetectRuby(dir string) *Info {
return detect("ruby", dir, "Gemfile", "Rakefile", "config.ru")
}

// DetectJava detects Java source
func DetectJava(dir string) (*Info, bool) {
func DetectJava(dir string) *Info {
return detect("jee", dir, "pom.xml")
}

// DetectNodeJS detects NodeJS source
func DetectNodeJS(dir string) (*Info, bool) {
func DetectNodeJS(dir string) *Info {
return detect("nodejs", dir, "app.json", "package.json")
}

// DetectPHP detects PHP source
func DetectPHP(dir string) (*Info, bool) {
func DetectPHP(dir string) *Info {
return detect("php", dir, "index.php", "composer.json")
}

// DetectPython detects Python source
func DetectPython(dir string) (*Info, bool) {
func DetectPython(dir string) *Info {
return detect("python", dir, "requirements.txt", "setup.py")
}

// DetectPerl detects Perl source
func DetectPerl(dir string) (*Info, bool) {
func DetectPerl(dir string) *Info {
return detect("perl", dir, "index.pl", "cpanfile")
}

// DetectScala detects Scala source
func DetectScala(dir string) (*Info, bool) {
func DetectScala(dir string) *Info {
return detect("scala", dir, "build.sbt")
}

// DetectDotNet detects .NET source and matches it to a dotnet supported annotatin or dotnet imagestream name
func DetectDotNet(dir string) (*Info, bool) {
return detect("dotnet", dir, "project.json")
// DetectDotNet detects .NET source and matches it to a dotnet supported annotation or dotnet imagestream name
func DetectDotNet(dir string) *Info {
return detect("dotnet", dir, "project.json", "*.csproj")
}

// DetectLiteralDotNet detects .NET source and matches it to a .net supported annotation
func DetectLiteralDotNet(dir string) (*Info, bool) {
return detect(".net", dir, "project.json")
func DetectLiteralDotNet(dir string) *Info {
return detect(".net", dir, "project.json", "*.csproj")
}

// detect returns an Info object with the given platform if the source at dir contains any of the argument files
Copy link
Contributor

Choose a reason for hiding this comment

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

this matches to imagestreams with a "supports" annotation with value of ".net"

func detect(platform string, dir string, files ...string) (*Info, bool) {
if filesPresent(dir, files) {
return &Info{
Platform: platform,
}, true
}
return nil, false
}

func filesPresent(dir string, files []string) bool {
for _, f := range files {
_, err := os.Stat(filepath.Join(dir, f))
if err == nil {
return true
func detect(platform string, dir string, globs ...string) *Info {
for _, g := range globs {
if matches, _ := filepath.Glob(filepath.Join(dir, g)); len(matches) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we not just do globbing in the existing detect function, regardless of whether the passed pattern contains a * ?

return &Info{Platform: platform}
}
}
return false
return nil
}