github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/whitesource/scanMTA.go (about)

     1  package whitesource
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/SAP/jenkins-library/pkg/log"
     7  )
     8  
     9  // ExecuteMTAScan executes a scan for the Java part with maven, and performs a scan for each NPM module.
    10  func (s *Scan) ExecuteMTAScan(config *ScanOptions, utils Utils) error {
    11  	log.Entry().Infof("Executing Whitesource scan for MTA project")
    12  	pomExists, _ := utils.FileExists("pom.xml")
    13  	if pomExists {
    14  		if err := s.ExecuteMavenScanForPomFile(config, utils, "pom.xml"); err != nil {
    15  			return err
    16  		}
    17  	}
    18  
    19  	modules, err := utils.FindPackageJSONFiles(config)
    20  	if err != nil {
    21  		return err
    22  	}
    23  	if len(modules) > 0 {
    24  		if err := s.ExecuteNpmScan(config, utils); err != nil {
    25  			return err
    26  		}
    27  	}
    28  
    29  	if !pomExists && len(modules) == 0 {
    30  		return fmt.Errorf("neither Maven nor NPM modules found, no scan performed")
    31  	}
    32  	return nil
    33  }