@@ -13,7 +13,7 @@ type Info struct {
13
13
14
14
// DetectorFunc is a function that returns source Info from a given directory.
15
15
// 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
17
17
18
18
// Detectors is a set of DetectorFunc that is used to detect the
19
19
// language/platform for a given source directory
@@ -29,70 +29,67 @@ var DefaultDetectors = Detectors{
29
29
DetectPerl ,
30
30
DetectScala ,
31
31
DetectDotNet ,
32
- DetectLiteralDotNet ,
33
32
}
34
33
35
34
// DetectRuby detects Ruby source
36
- func DetectRuby (dir string ) ( * Info , bool ) {
35
+ func DetectRuby (dir string ) * Info {
37
36
return detect ("ruby" , dir , "Gemfile" , "Rakefile" , "config.ru" )
38
37
}
39
38
40
39
// DetectJava detects Java source
41
- func DetectJava (dir string ) ( * Info , bool ) {
40
+ func DetectJava (dir string ) * Info {
42
41
return detect ("jee" , dir , "pom.xml" )
43
42
}
44
43
45
44
// DetectNodeJS detects NodeJS source
46
- func DetectNodeJS (dir string ) ( * Info , bool ) {
45
+ func DetectNodeJS (dir string ) * Info {
47
46
return detect ("nodejs" , dir , "app.json" , "package.json" )
48
47
}
49
48
50
49
// DetectPHP detects PHP source
51
- func DetectPHP (dir string ) ( * Info , bool ) {
50
+ func DetectPHP (dir string ) * Info {
52
51
return detect ("php" , dir , "index.php" , "composer.json" )
53
52
}
54
53
55
54
// DetectPython detects Python source
56
- func DetectPython (dir string ) ( * Info , bool ) {
55
+ func DetectPython (dir string ) * Info {
57
56
return detect ("python" , dir , "requirements.txt" , "setup.py" )
58
57
}
59
58
60
59
// DetectPerl detects Perl source
61
- func DetectPerl (dir string ) ( * Info , bool ) {
60
+ func DetectPerl (dir string ) * Info {
62
61
return detect ("perl" , dir , "index.pl" , "cpanfile" )
63
62
}
64
63
65
64
// DetectScala detects Scala source
66
- func DetectScala (dir string ) ( * Info , bool ) {
65
+ func DetectScala (dir string ) * Info {
67
66
return detect ("scala" , dir , "build.sbt" )
68
67
}
69
68
70
69
// 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
78
76
}
79
77
80
78
// 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
+ }
86
84
}
87
- return nil , false
85
+ return nil
88
86
}
89
87
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 }
95
92
}
96
93
}
97
- return false
94
+ return nil
98
95
}
0 commit comments