11package source
22
3- import (
4- "os"
5- "path/filepath"
6- )
3+ import "path/filepath"
74
85// Info is detected platform information from a source directory
96type Info struct {
@@ -13,7 +10,7 @@ type Info struct {
1310
1411// DetectorFunc is a function that returns source Info from a given directory.
1512// It returns true if it was able to detect the code in the given directory.
16- type DetectorFunc func (dir string ) ( * Info , bool )
13+ type DetectorFunc func (dir string ) * Info
1714
1815// Detectors is a set of DetectorFunc that is used to detect the
1916// language/platform for a given source directory
@@ -33,66 +30,56 @@ var DefaultDetectors = Detectors{
3330}
3431
3532// DetectRuby detects Ruby source
36- func DetectRuby (dir string ) ( * Info , bool ) {
33+ func DetectRuby (dir string ) * Info {
3734 return detect ("ruby" , dir , "Gemfile" , "Rakefile" , "config.ru" )
3835}
3936
4037// DetectJava detects Java source
41- func DetectJava (dir string ) ( * Info , bool ) {
38+ func DetectJava (dir string ) * Info {
4239 return detect ("jee" , dir , "pom.xml" )
4340}
4441
4542// DetectNodeJS detects NodeJS source
46- func DetectNodeJS (dir string ) ( * Info , bool ) {
43+ func DetectNodeJS (dir string ) * Info {
4744 return detect ("nodejs" , dir , "app.json" , "package.json" )
4845}
4946
5047// DetectPHP detects PHP source
51- func DetectPHP (dir string ) ( * Info , bool ) {
48+ func DetectPHP (dir string ) * Info {
5249 return detect ("php" , dir , "index.php" , "composer.json" )
5350}
5451
5552// DetectPython detects Python source
56- func DetectPython (dir string ) ( * Info , bool ) {
53+ func DetectPython (dir string ) * Info {
5754 return detect ("python" , dir , "requirements.txt" , "setup.py" )
5855}
5956
6057// DetectPerl detects Perl source
61- func DetectPerl (dir string ) ( * Info , bool ) {
58+ func DetectPerl (dir string ) * Info {
6259 return detect ("perl" , dir , "index.pl" , "cpanfile" )
6360}
6461
6562// DetectScala detects Scala source
66- func DetectScala (dir string ) ( * Info , bool ) {
63+ func DetectScala (dir string ) * Info {
6764 return detect ("scala" , dir , "build.sbt" )
6865}
6966
70- // 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" )
67+ // DetectDotNet detects .NET source and matches it to a dotnet supported annotation or dotnet imagestream name
68+ func DetectDotNet (dir string ) * Info {
69+ return detect ("dotnet" , dir , "project.json" , "*.csproj" )
7370}
7471
7572// 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" )
73+ func DetectLiteralDotNet (dir string ) * Info {
74+ return detect (".net" , dir , "project.json" , "*.csproj" )
7875}
7976
8077// 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
86- }
87- return nil , false
88- }
89-
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
78+ func detect (platform string , dir string , globs ... string ) * Info {
79+ for _ , g := range globs {
80+ if matches , _ := filepath .Glob (filepath .Join (dir , g )); len (matches ) > 0 {
81+ return & Info {Platform : platform }
9582 }
9683 }
97- return false
84+ return nil
9885}
0 commit comments