From 4eeea50b59c302618e2506ab57ba28c7fecadd5f Mon Sep 17 00:00:00 2001 From: galba Date: Sun, 29 Sep 2024 16:58:16 +0300 Subject: [PATCH 1/3] 2673 - Recursively search for .mvn dir --- build/maven.go | 11 +++++++++-- build/maven_test.go | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/build/maven.go b/build/maven.go index 970c1394..5cff00bd 100644 --- a/build/maven.go +++ b/build/maven.go @@ -45,7 +45,8 @@ type MavenModule struct { // A pipe to write the maven extractor output to. outputWriter io.Writer // Path to the build info temp file that will be generated by the maven extractor. - buildInfoPath string + buildInfoPath string + rootProjectDir string } // Maven extractor is the engine for calculating the project dependencies. @@ -161,6 +162,7 @@ func (mm *MavenModule) createMvnRunConfig() (*mvnRunConfig, error) { buildInfoProperties: extractorProps, mavenOpts: mm.extractorDetails.mavenOpts, logger: mm.containingBuild.logger, + rootProjectDir: mm.rootProjectDir, }, nil } @@ -288,6 +290,10 @@ func (mm *MavenModule) extractMavenPath(mavenVersionOutput bytes.Buffer) (mavenH return } +func (mm *MavenModule) SetMavenRootDir(rootDir string) { + 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) @@ -313,7 +319,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...) } @@ -334,6 +340,7 @@ type mvnRunConfig struct { mavenOpts []string logger utils.Log outputWriter io.Writer + rootProjectDir string } func (config *mvnRunConfig) SetOutputWriter(outputWriter io.Writer) *mvnRunConfig { diff --git a/build/maven_test.go b/build/maven_test.go index a6cb8f60..46b36f06 100644 --- a/build/maven_test.go +++ b/build/maven_test.go @@ -180,3 +180,22 @@ func TestAddColorToCmdOutput(t *testing.T) { }) } } + +func TestCommandWithRootProjectDir(t *testing.T) { + mvnc := &mvnRunConfig{ + java: "java", + plexusClassworlds: "plexus", + cleassworldsConfig: "", + mavenHome: "", + pluginDependencies: "", + workspace: "", + goals: nil, + buildInfoProperties: "", + mavenOpts: nil, + logger: nil, + outputWriter: nil, + rootProjectDir: "root", + } + cmd := mvnc.GetCmd() + assert.Equal(t, "-Dmaven.multiModuleProjectDirectory=root", cmd.Args[7]) +} From 0cd6b2493c45f9d9148e7a32300f1fff777bf659 Mon Sep 17 00:00:00 2001 From: galba Date: Mon, 30 Sep 2024 12:58:30 +0300 Subject: [PATCH 2/3] 2673 - Recursively search for .mvn dir --- build/maven.go | 5 +++-- build/maven_test.go | 35 ++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/build/maven.go b/build/maven.go index 5cff00bd..c4d6b37e 100644 --- a/build/maven.go +++ b/build/maven.go @@ -45,7 +45,8 @@ type MavenModule struct { // A pipe to write the maven extractor output to. outputWriter io.Writer // Path to the build info temp file that will be generated by the maven extractor. - buildInfoPath string + buildInfoPath string + // Path to the root project directory in maven multi-module project. May contain .mvn directory. rootProjectDir string } @@ -290,7 +291,7 @@ func (mm *MavenModule) extractMavenPath(mavenVersionOutput bytes.Buffer) (mavenH return } -func (mm *MavenModule) SetMavenRootDir(rootDir string) { +func (mm *MavenModule) SetrootProjectDir(rootDir string) { mm.rootProjectDir = rootDir } diff --git a/build/maven_test.go b/build/maven_test.go index 46b36f06..c52a047a 100644 --- a/build/maven_test.go +++ b/build/maven_test.go @@ -183,19 +183,32 @@ func TestAddColorToCmdOutput(t *testing.T) { func TestCommandWithRootProjectDir(t *testing.T) { mvnc := &mvnRunConfig{ - java: "java", - plexusClassworlds: "plexus", - cleassworldsConfig: "", - mavenHome: "", - pluginDependencies: "", - workspace: "", - goals: nil, - buildInfoProperties: "", - mavenOpts: nil, + 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: "root", + rootProjectDir: "myRootProjectDir", } cmd := mvnc.GetCmd() - assert.Equal(t, "-Dmaven.multiModuleProjectDirectory=root", cmd.Args[7]) + 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") } From ac3b31030284363e3b5ca20ce5bd2dd890c36244 Mon Sep 17 00:00:00 2001 From: galba Date: Mon, 30 Sep 2024 14:32:38 +0300 Subject: [PATCH 3/3] 2673 - Recursively search for .mvn dir --- build/maven.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/maven.go b/build/maven.go index c4d6b37e..584eda13 100644 --- a/build/maven.go +++ b/build/maven.go @@ -291,7 +291,7 @@ func (mm *MavenModule) extractMavenPath(mavenVersionOutput bytes.Buffer) (mavenH return } -func (mm *MavenModule) SetrootProjectDir(rootDir string) { +func (mm *MavenModule) SetRootProjectDir(rootDir string) { mm.rootProjectDir = rootDir }