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