99 "path/filepath"
1010 "regexp"
1111 "runtime"
12+ "strconv"
1213 "strings"
1314 "sync"
1415 "time"
4748 ProjectURLRe = regexp .MustCompile (urlProjectRegexStr )
4849 // CommitURLRe Regex used to validate commit info /commit/someUUID
4950 CommitURLRe = regexp .MustCompile (urlCommitRegexStr )
51+ // deprecatedRegex covers the deprecated fields in the project file
52+ deprecatedRegex = regexp .MustCompile (`\s*(?:constraints|platforms|languages):` )
5053)
5154
5255type ErrorParseProject struct { * locale.LocalizedError }
@@ -443,12 +446,16 @@ func parse(configFilepath string) (*Project, error) {
443446 return nil , errs .Wrap (err , "ioutil.ReadFile %s failure" , configFilepath )
444447 }
445448
449+ if err := detectDeprecations (dat , configFilepath ); err != nil {
450+ return nil , errs .Wrap (err , "deprecations found" )
451+ }
452+
446453 project := Project {}
447- err = yaml .Unmarshal ([] byte ( dat ) , & project )
454+ err2 : = yaml .Unmarshal (dat , & project )
448455 project .path = configFilepath
449456
450- if err != nil {
451- return nil , & ErrorParseProject {locale .NewError (
457+ if err2 != nil {
458+ return nil , & ErrorParseProject {locale .NewInputError (
452459 "err_project_parsed" ,
453460 "Project file `{{.V1}}` could not be parsed, the parser produced the following error: {{.V0}}" , err .Error (), configFilepath ),
454461 }
@@ -457,6 +464,22 @@ func parse(configFilepath string) (*Project, error) {
457464 return & project , nil
458465}
459466
467+ func detectDeprecations (dat []byte , configFilepath string ) error {
468+ deprecations := deprecatedRegex .FindAllIndex (dat , - 1 )
469+ if len (deprecations ) == 0 {
470+ return nil
471+ }
472+ deplist := []string {}
473+ for _ , depIdxs := range deprecations {
474+ dep := strings .TrimSpace (strings .TrimSuffix (string (dat [depIdxs [0 ]:depIdxs [1 ]]), ":" ))
475+ deplist = append (deplist , locale .Tr ("pjfile_deprecation_entry" , dep , strconv .Itoa (depIdxs [0 ])))
476+ }
477+ return & ErrorParseProject {locale .NewInputError (
478+ "pjfile_deprecation_msg" ,
479+ "" , configFilepath , strings .Join (deplist , "\n " ), constants .DocumentationURL + "config/#deprecation" ),
480+ }
481+ }
482+
460483// Owner returns the project namespace's organization
461484func (p * Project ) Owner () string {
462485 return p .parsedURL .Owner
0 commit comments