Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching for the .mvn dir recursively by other modules that use this module #279

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion build/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type MavenModule struct {
outputWriter io.Writer
// Path to the build info temp file that will be generated by the maven extractor.
buildInfoPath string
// Path to the root project directory in maven multi-module project. May contain .mvn directory.
rootProjectDir string
galusben marked this conversation as resolved.
Show resolved Hide resolved
}

// Maven extractor is the engine for calculating the project dependencies.
Expand Down Expand Up @@ -161,6 +163,7 @@ func (mm *MavenModule) createMvnRunConfig() (*mvnRunConfig, error) {
buildInfoProperties: extractorProps,
mavenOpts: mm.extractorDetails.mavenOpts,
logger: mm.containingBuild.logger,
rootProjectDir: mm.rootProjectDir,
}, nil
}

Expand Down Expand Up @@ -288,6 +291,10 @@ func (mm *MavenModule) extractMavenPath(mavenVersionOutput bytes.Buffer) (mavenH
return
}

func (mm *MavenModule) SetrootProjectDir(rootDir string) {
galusben marked this conversation as resolved.
Show resolved Hide resolved
mm.rootProjectDir = rootDir
}

func downloadMavenExtractor(downloadTo string, downloadExtractorFunc func(downloadTo, downloadPath string) error, logger utils.Log) error {
filename := fmt.Sprintf(MavenExtractorFileName, MavenExtractorDependencyVersion)
filePath := fmt.Sprintf(MavenExtractorRemotePath, MavenExtractorDependencyVersion)
Expand All @@ -313,7 +320,7 @@ func (config *mvnRunConfig) GetCmd() *exec.Cmd {
cmd = append(cmd, "-DbuildInfoConfig.propertiesFile="+config.buildInfoProperties)
cmd = append(cmd, "-Dm3plugin.lib="+config.pluginDependencies)
cmd = append(cmd, "-Dclassworlds.conf="+config.cleassworldsConfig)
cmd = append(cmd, "-Dmaven.multiModuleProjectDirectory="+config.workspace)
cmd = append(cmd, "-Dmaven.multiModuleProjectDirectory="+config.rootProjectDir)
if config.mavenOpts != nil {
cmd = append(cmd, config.mavenOpts...)
}
Expand All @@ -334,6 +341,7 @@ type mvnRunConfig struct {
mavenOpts []string
logger utils.Log
outputWriter io.Writer
rootProjectDir string
}

func (config *mvnRunConfig) SetOutputWriter(outputWriter io.Writer) *mvnRunConfig {
Expand Down
32 changes: 32 additions & 0 deletions build/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,35 @@ func TestAddColorToCmdOutput(t *testing.T) {
})
}
}

func TestCommandWithRootProjectDir(t *testing.T) {
mvnc := &mvnRunConfig{
java: "myJava",
plexusClassworlds: "myPlexus",
cleassworldsConfig: "myCleassworldsConfig",
mavenHome: "myMavenHome",
pluginDependencies: "myPluginDependencies",
workspace: "myWorkspace",
goals: []string{"myGoal1", "myGoal2"},
buildInfoProperties: "myBuildInfoProperties",
mavenOpts: []string{"myMavenOpt1", "myMavenOpt2"},
logger: nil,
outputWriter: nil,
rootProjectDir: "myRootProjectDir",
}
cmd := mvnc.GetCmd()
assert.Equal(t, "myJava", cmd.Args[0])
assert.Equal(t, "-classpath", cmd.Args[1])
assert.Equal(t, "myPlexus", cmd.Args[2])
assert.Contains(t, cmd.Args, "-DbuildInfoConfig.propertiesFile=myBuildInfoProperties")
assert.Contains(t, cmd.Args, "-Dclassworlds.conf=myCleassworldsConfig")
assert.Contains(t, cmd.Args, "-Dclassworlds.conf=myCleassworldsConfig")
assert.Contains(t, cmd.Args, "-Dmaven.home=myMavenHome")
assert.Contains(t, cmd.Args, "-Dm3plugin.lib=myPluginDependencies")
assert.Contains(t, cmd.Args, "myGoal1")
assert.Contains(t, cmd.Args, "myGoal2")
assert.Contains(t, cmd.Args, "-DbuildInfoConfig.propertiesFile=myBuildInfoProperties")
assert.Contains(t, cmd.Args, "myMavenOpt1")
assert.Contains(t, cmd.Args, "myMavenOpt2")
assert.Contains(t, cmd.Args, "-Dmaven.multiModuleProjectDirectory=myRootProjectDir")
}
Loading