Skip to content

Commit b8731b7

Browse files
author
Jim Minter
committed
Support csproj files for identifying .NET Core projects
1 parent 9c4f9ee commit b8731b7

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

pkg/generate/app/sourcelookup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (e SourceRepositoryEnumerator) Detect(dir string, dockerStrategy bool) (*So
500500
// is docker
501501
if !dockerStrategy {
502502
for _, d := range e.Detectors {
503-
if detected, ok := d(dir); ok {
503+
if detected := d(dir); detected != nil {
504504
info.Types = append(info.Types, SourceLanguageType{
505505
Platform: detected.Platform,
506506
Version: detected.Version,

pkg/generate/source/detector.go

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Info struct {
1313

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

1818
// Detectors is a set of DetectorFunc that is used to detect the
1919
// language/platform for a given source directory
@@ -29,70 +29,67 @@ var DefaultDetectors = Detectors{
2929
DetectPerl,
3030
DetectScala,
3131
DetectDotNet,
32-
DetectLiteralDotNet,
3332
}
3433

3534
// DetectRuby detects Ruby source
36-
func DetectRuby(dir string) (*Info, bool) {
35+
func DetectRuby(dir string) *Info {
3736
return detect("ruby", dir, "Gemfile", "Rakefile", "config.ru")
3837
}
3938

4039
// DetectJava detects Java source
41-
func DetectJava(dir string) (*Info, bool) {
40+
func DetectJava(dir string) *Info {
4241
return detect("jee", dir, "pom.xml")
4342
}
4443

4544
// DetectNodeJS detects NodeJS source
46-
func DetectNodeJS(dir string) (*Info, bool) {
45+
func DetectNodeJS(dir string) *Info {
4746
return detect("nodejs", dir, "app.json", "package.json")
4847
}
4948

5049
// DetectPHP detects PHP source
51-
func DetectPHP(dir string) (*Info, bool) {
50+
func DetectPHP(dir string) *Info {
5251
return detect("php", dir, "index.php", "composer.json")
5352
}
5453

5554
// DetectPython detects Python source
56-
func DetectPython(dir string) (*Info, bool) {
55+
func DetectPython(dir string) *Info {
5756
return detect("python", dir, "requirements.txt", "setup.py")
5857
}
5958

6059
// DetectPerl detects Perl source
61-
func DetectPerl(dir string) (*Info, bool) {
60+
func DetectPerl(dir string) *Info {
6261
return detect("perl", dir, "index.pl", "cpanfile")
6362
}
6463

6564
// DetectScala detects Scala source
66-
func DetectScala(dir string) (*Info, bool) {
65+
func DetectScala(dir string) *Info {
6766
return detect("scala", dir, "build.sbt")
6867
}
6968

7069
// DetectDotNet detects .NET source and matches it to a dotnet supported annotatin or dotnet imagestream name
71-
func DetectDotNet(dir string) (*Info, bool) {
72-
return detect("dotnet", dir, "project.json")
73-
}
74-
75-
// DetectLiteralDotNet detects .NET source and matches it to a .net supported annotation
76-
func DetectLiteralDotNet(dir string) (*Info, bool) {
77-
return detect(".net", dir, "project.json")
70+
func DetectDotNet(dir string) *Info {
71+
info := detect("dotnet", dir, "project.json")
72+
if info == nil {
73+
info = detectGlob("dotnet", dir, "*.csproj")
74+
}
75+
return info
7876
}
7977

8078
// detect returns an Info object with the given platform if the source at dir contains any of the argument files
81-
func detect(platform string, dir string, files ...string) (*Info, bool) {
82-
if filesPresent(dir, files) {
83-
return &Info{
84-
Platform: platform,
85-
}, true
79+
func detect(platform string, dir string, files ...string) *Info {
80+
for _, f := range files {
81+
if _, err := os.Stat(filepath.Join(dir, f)); err == nil {
82+
return &Info{Platform: platform}
83+
}
8684
}
87-
return nil, false
85+
return nil
8886
}
8987

90-
func filesPresent(dir string, files []string) bool {
91-
for _, f := range files {
92-
_, err := os.Stat(filepath.Join(dir, f))
93-
if err == nil {
94-
return true
88+
func detectGlob(platform string, dir string, globs ...string) *Info {
89+
for _, g := range globs {
90+
if matches, _ := filepath.Glob(filepath.Join(dir, g)); len(matches) > 0 {
91+
return &Info{Platform: platform}
9592
}
9693
}
97-
return false
94+
return nil
9895
}

0 commit comments

Comments
 (0)