Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JFrog Pipelines Step committed May 17, 2023
2 parents ba63a12 + 152365c commit d5f085c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions build/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -40,6 +41,8 @@ type MavenModule struct {
srcPath string
// The Maven extractor (dependency) which calculates the build-info.
extractorDetails *extractorDetails
// A pipe to write the maven extractor output to.
outputWriter io.Writer
}

// Maven extractor is the engine for calculating the project dependencies.
Expand Down Expand Up @@ -96,6 +99,10 @@ func (mm *MavenModule) SetExtractorDetails(localExtractorPath, extractorPropsdir
return mm
}

func (mm *MavenModule) SetOutputWriter(outputWriter io.Writer) {
mm.outputWriter = outputWriter
}

func (mm *MavenModule) SetMavenGoals(goals ...string) {
mm.extractorDetails.goals = goals
}
Expand Down Expand Up @@ -172,7 +179,7 @@ func (mm *MavenModule) CalcDependencies() (err error) {
err = e
}
}()

mvnRunConfig.SetOutputWriter(mm.outputWriter)
mm.containingBuild.logger.Info("Running Mvn...")
return mvnRunConfig.runCmd()
}
Expand All @@ -185,7 +192,7 @@ func (mm *MavenModule) loadMavenHome() (mavenHome string, err error) {
// Since Maven installation can be located in different locations,
// depending on the installation type and the OS (for example: For Mac with brew install: /usr/local/Cellar/maven/{version}/libexec or Ubuntu with debian: /usr/share/maven),
// we need to grab the location using the mvn --version command.
// First we will try lo look for 'mvn' in PATH.
// First, we will try to look for 'mvn' in PATH.
maven, err := mm.getExecutableName()
if err != nil {
return maven, err
Expand Down Expand Up @@ -320,12 +327,22 @@ type mvnRunConfig struct {
buildInfoProperties string
mavenOpts []string
logger utils.Log
outputWriter io.Writer
}

func (config *mvnRunConfig) SetOutputWriter(outputWriter io.Writer) *mvnRunConfig {
config.outputWriter = outputWriter
return config
}

func (config *mvnRunConfig) runCmd() error {
command := config.GetCmd()
command.Stderr = os.Stderr
command.Stdout = os.Stderr
if config.outputWriter == nil {
command.Stdout = os.Stderr
} else {
command.Stdout = config.outputWriter
}
command.Dir = config.workspace
config.logger.Info("Running mvn command:", strings.Join(command.Args, " "))
return command.Run()
Expand Down

0 comments on commit d5f085c

Please sign in to comment.