github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/piperutils/projectStructure.go (about) 1 package piperutils 2 3 import "path/filepath" 4 5 // ProjectStructure describes a directory containing source code 6 type ProjectStructure struct { 7 directory string 8 } 9 10 // UsesMta returns `true` if the project structure directory contains typical files for mta projects (mta.yaml, mta.yml), `false` otherwise 11 func (projectStructure *ProjectStructure) UsesMta() bool { 12 return projectStructure.anyFileExists("mta.yaml", "mta.yml") 13 } 14 15 // UsesMaven returns `true` if the project structure directory contains a pom.xml file, false otherwise 16 func (projectStructure *ProjectStructure) UsesMaven() bool { 17 return projectStructure.anyFileExists("pom.xml") 18 } 19 20 // UsesNpm returns `true` if the project structure directory contains a package.json file, false otherwise 21 func (projectStructure *ProjectStructure) UsesNpm() bool { 22 return projectStructure.anyFileExists("package.json") 23 } 24 25 func (projectStructure *ProjectStructure) anyFileExists(candidates ...string) bool { 26 for i := 0; i < len(candidates); i++ { 27 exists, err := FileExists(filepath.Join(projectStructure.directory, candidates[i])) 28 if err != nil { 29 continue 30 } 31 if exists { 32 return true 33 } 34 } 35 return false 36 }