-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
@@ -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 | ||
|
@@ -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 | ||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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"