mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
4b2f61589d
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> Co-authored-by: Pavel Busko <pavel.busko@sap.com> Co-authored-by: Sumit Kulhadia <sumit.kulhadia@sap.com>
43 lines
952 B
Go
43 lines
952 B
Go
package project
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/cnbutils"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
)
|
|
|
|
// 1. If "path" is a directory, check for "${path}/${descriptor}"
|
|
// 2. If "path" is a file, check for "${PWD}/${descriptor}"
|
|
func ResolvePath(descriptor, path string, utils cnbutils.BuildUtils) (string, error) {
|
|
isDir, err := utils.DirExists(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if isDir {
|
|
return getFilename(path, descriptor, utils)
|
|
}
|
|
|
|
pwd, err := utils.Getwd()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return getFilename(pwd, descriptor, utils)
|
|
}
|
|
|
|
func getFilename(folder, filename string, utils cnbutils.BuildUtils) (string, error) {
|
|
descPath := filepath.Join(folder, filename)
|
|
exists, err := utils.FileExists(descPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if exists {
|
|
return descPath, nil
|
|
}
|
|
|
|
log.Entry().Infof("Project descriptor with the path '%s' was not found", descPath)
|
|
return "", nil
|
|
}
|