Skip to content

Commit a1ecb5c

Browse files
committed
Added Maven native implementation using flexpack
1 parent 893219d commit a1ecb5c

File tree

4 files changed

+556
-26
lines changed

4 files changed

+556
-26
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ require (
242242
sigs.k8s.io/yaml v1.4.0 // indirect
243243
)
244244

245-
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250907205057-2bfe50c014b7
245+
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250911222232-c782a2a600e1
246246

247247
replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.7.2-0.20250907212025-fb4679f280a0
248248

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ github.com/jellydator/ttlcache/v3 v3.3.0 h1:BdoC9cE81qXfrxeb9eoJi9dWrdhSuwXMAnHT
349349
github.com/jellydator/ttlcache/v3 v3.3.0/go.mod h1:bj2/e0l4jRnQdrnSTaGTsh4GSXvMjQcy41i7th0GVGw=
350350
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
351351
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
352-
github.com/jfrog/build-info-go v1.8.9-0.20250907205057-2bfe50c014b7 h1:AH31gF//1Dv0ETrT2I4XLR4bCbG6anvw7tEEO8SkHzo=
353-
github.com/jfrog/build-info-go v1.8.9-0.20250907205057-2bfe50c014b7/go.mod h1:szdz9+WzB7+7PGnILLUgyY+OF5qD5geBT7UGNIxibyw=
352+
github.com/jfrog/build-info-go v1.8.9-0.20250911222232-c782a2a600e1 h1:785XxuIeWpTefTDFMcSEYywM+AIeLIUGc1Z526Bveu8=
353+
github.com/jfrog/build-info-go v1.8.9-0.20250911222232-c782a2a600e1/go.mod h1:szdz9+WzB7+7PGnILLUgyY+OF5qD5geBT7UGNIxibyw=
354354
github.com/jfrog/froggit-go v1.20.3 h1:U3HHT0+AEHUVSSyQBbagQR4fLRqGqzSptPujDZuuDTk=
355355
github.com/jfrog/froggit-go v1.20.3/go.mod h1:obSG1SlsWjktkuqmKtpq7MNTTL63e0ot+ucTnlOMV88=
356356
github.com/jfrog/go-mockhttp v0.3.1 h1:/wac8v4GMZx62viZmv4wazB5GNKs+GxawuS1u3maJH8=

maven_test.go

Lines changed: 142 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
7+
"net/http"
8+
"os"
9+
"os/exec"
10+
"path/filepath"
11+
"strings"
12+
"testing"
13+
614
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
715
outputFormat "github.com/jfrog/jfrog-cli-core/v2/common/format"
816
"github.com/jfrog/jfrog-cli-core/v2/common/project"
@@ -12,12 +20,6 @@ import (
1220
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
1321
"github.com/stretchr/testify/require"
1422
"gopkg.in/yaml.v2"
15-
"net/http"
16-
"os"
17-
"os/exec"
18-
"path/filepath"
19-
"strings"
20-
"testing"
2123

2224
"github.com/jfrog/build-info-go/build"
2325
buildinfo "github.com/jfrog/build-info-go/entities"
@@ -59,6 +61,124 @@ func TestMavenBuildWithServerID(t *testing.T) {
5961
cleanMavenTest(t)
6062
}
6163

64+
func TestMavenBuildWithFlexPack(t *testing.T) {
65+
initMavenTest(t, false)
66+
// Set environment for native FlexPack implementation
67+
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "true")
68+
defer setEnvCallBack()
69+
70+
assert.NoError(t, runMaven(t, createSimpleMavenProject, tests.MavenConfig, "install"))
71+
// Validate artifacts are deployed
72+
searchSpec, err := tests.CreateSpec(tests.SearchAllMaven)
73+
assert.NoError(t, err)
74+
inttestutils.VerifyExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, serverDetails, t)
75+
cleanMavenTest(t)
76+
}
77+
78+
func TestMavenBuildWithFlexPackBuildInfo(t *testing.T) {
79+
initMavenTest(t, false)
80+
buildName := tests.MvnBuildName + "-flexpack"
81+
buildNumber := "1"
82+
83+
// Set environment for native FlexPack implementation
84+
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "true")
85+
defer setEnvCallBack()
86+
87+
// Run Maven with build info
88+
args := []string{"install", "--build-name=" + buildName, "--build-number=" + buildNumber}
89+
assert.NoError(t, runMaven(t, createSimpleMavenProject, tests.MavenConfig, args...))
90+
91+
// Validate artifacts are deployed
92+
searchSpec, err := tests.CreateSpec(tests.SearchAllMaven)
93+
assert.NoError(t, err)
94+
inttestutils.VerifyExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, serverDetails, t)
95+
96+
// Publish build info
97+
assert.NoError(t, runJfrogCliWithoutAssertion("rt", "bp", buildName, buildNumber))
98+
99+
// Validate build info was created with FlexPack dependencies
100+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
101+
if !assert.NoError(t, err, "Failed to get build info") {
102+
return
103+
}
104+
if !assert.True(t, found, "build info was expected to be found") {
105+
return
106+
}
107+
108+
// Validate build info structure
109+
assert.NotEmpty(t, publishedBuildInfo.Modules, "Build info should have modules")
110+
if len(publishedBuildInfo.Modules) > 0 {
111+
module := publishedBuildInfo.Modules[0]
112+
assert.Equal(t, "maven", string(module.Type), "Module type should be maven")
113+
assert.NotEmpty(t, module.Id, "Module should have ID")
114+
115+
// FlexPack should collect dependencies
116+
assert.Greater(t, len(module.Dependencies), 0, "FlexPack should collect dependencies")
117+
118+
// Validate dependency structure
119+
for _, dep := range module.Dependencies {
120+
assert.NotEmpty(t, dep.Id, "Dependency should have ID")
121+
assert.NotEmpty(t, dep.Type, "Dependency should have type")
122+
assert.NotEmpty(t, dep.Scopes, "Dependency should have scopes")
123+
// FlexPack should provide checksums
124+
hasChecksum := dep.Checksum.Sha1 != "" || dep.Checksum.Sha256 != "" || dep.Checksum.Md5 != ""
125+
assert.True(t, hasChecksum, "Dependency %s should have at least one checksum", dep.Id)
126+
}
127+
128+
// Should have artifacts from native Maven deployment
129+
assert.Greater(t, len(module.Artifacts), 0, "Should have artifacts from Maven deployment")
130+
}
131+
132+
cleanMavenTest(t)
133+
}
134+
135+
func TestMavenFlexPackBuildProperties(t *testing.T) {
136+
initMavenTest(t, false)
137+
buildName := tests.MvnBuildName + "-props"
138+
buildNumber := "42"
139+
140+
// Set environment for native FlexPack implementation
141+
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "true")
142+
defer setEnvCallBack()
143+
144+
// Run Maven deploy with build info (this should set build properties on artifacts)
145+
args := []string{"deploy", "--build-name=" + buildName, "--build-number=" + buildNumber}
146+
assert.NoError(t, runMaven(t, createSimpleMavenProject, tests.MavenConfig, args...))
147+
148+
// Validate artifacts are deployed
149+
searchSpec, err := tests.CreateSpec(tests.SearchAllMaven)
150+
assert.NoError(t, err)
151+
inttestutils.VerifyExistInArtifactory(tests.GetMavenDeployedArtifacts(), searchSpec, serverDetails, t)
152+
153+
// Publish build info
154+
assert.NoError(t, runJfrogCliWithoutAssertion("rt", "bp", buildName, buildNumber))
155+
156+
// Search for artifacts with build properties
157+
// This validates that FlexPack correctly set build.name and build.number properties
158+
propsSearchSpec := fmt.Sprintf(`{
159+
"files": [{
160+
"aql": {
161+
"items.find": {
162+
"repo": "%s",
163+
"@build.name": "%s",
164+
"@build.number": "%s"
165+
}
166+
}
167+
}]
168+
}`, tests.MvnRepo1, buildName, buildNumber)
169+
170+
propsSpec := new(spec.SpecFiles)
171+
err = json.Unmarshal([]byte(propsSearchSpec), propsSpec)
172+
assert.NoError(t, err)
173+
174+
// Verify artifacts have build properties set by FlexPack
175+
propsResults, err := inttestutils.SearchInArtifactory(propsSpec, serverDetails)
176+
assert.NoError(t, err)
177+
assert.Greater(t, len(propsResults), 0, "Should find artifacts with build properties set by FlexPack")
178+
179+
cleanMavenTest(t)
180+
}
181+
62182
func TestMavenBuildWithNoProxy(t *testing.T) {
63183
initMavenTest(t, false)
64184
// jfrog-ignore - not a real password
@@ -107,17 +227,17 @@ func TestMavenBuildWithConditionalUpload(t *testing.T) {
107227
cleanMavenTest(t)
108228
}
109229

110-
func runMvnConditionalUploadTest(buildName, buildNumber string) (err error) {
230+
func runMvnConditionalUploadTest(buildName, buildNumber string) error {
111231
configFilePath, exists, err := project.GetProjectConfFilePath(project.Maven)
112232
if err != nil {
113-
return
233+
return err
114234
}
115235
if !exists {
116236
return errors.New("no config file was found!")
117237
}
118238
buildConfig := buildUtils.NewBuildConfiguration(buildName, buildNumber, "", "")
119239
if err = buildConfig.ValidateBuildAndModuleParams(); err != nil {
120-
return
240+
return err
121241
}
122242
printDeploymentView := log.IsStdErrTerminal()
123243
mvnCmd := mvn.NewMvnCommand().
@@ -215,8 +335,7 @@ func createSimpleMavenProject(t *testing.T) string {
215335
func createMultiMavenProject(t *testing.T) string {
216336
projectDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "maven", "multiproject")
217337
destPath, err := os.Getwd()
218-
if err != nil {
219-
assert.NoError(t, err)
338+
if !assert.NoError(t, err, "Failed to get current working directory") {
220339
return ""
221340
}
222341
destPath = filepath.Join(destPath, tests.Temp)
@@ -266,17 +385,14 @@ func TestMavenBuildIncludePatterns(t *testing.T) {
266385
// Validate build info.
267386
assert.NoError(t, artifactoryCli.Exec("build-publish", tests.MvnBuildName, buildNumber))
268387
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.MvnBuildName, buildNumber)
269-
if err != nil {
270-
assert.NoError(t, err)
388+
if !assert.NoError(t, err, "Failed to get build info") {
271389
return
272390
}
273-
if !found {
274-
assert.True(t, found, "build info was expected to be found")
391+
if !assert.True(t, found, "build info was expected to be found") {
275392
return
276393
}
277394
buildInfo := publishedBuildInfo.BuildInfo
278-
if len(buildInfo.Modules) != 4 {
279-
assert.Len(t, buildInfo.Modules, 4)
395+
if !assert.Len(t, buildInfo.Modules, 4, "Expected 4 modules in build info") {
280396
return
281397
}
282398
validateSpecificModule(buildInfo, t, 13, 2, 1, "org.jfrog.test:multi1:3.7-SNAPSHOT", buildinfo.Maven)
@@ -302,8 +418,9 @@ func runMavenAndValidateDeployedArtifacts(t *testing.T, shouldDeployArtifact boo
302418
if shouldDeployArtifact {
303419
inttestutils.VerifyExistInArtifactory(tests.GetMavenMultiIncludedDeployedArtifacts(), searchSpec, serverDetails, t)
304420
} else {
305-
results, _ := inttestutils.SearchInArtifactory(searchSpec, serverDetails, t)
306-
assert.Zero(t, results)
421+
results, err := inttestutils.SearchInArtifactory(searchSpec, serverDetails, t)
422+
assert.NoError(t, err)
423+
assert.Zero(t, len(results))
307424
}
308425
}
309426
func TestMavenWithSummary(t *testing.T) {
@@ -414,7 +531,9 @@ func prepareMavenSetupTest(t *testing.T, homeDir string) func() {
414531
restoreSettingsXml, err := ioutils.BackupFile(settingsXml, ".settings.xml.backup")
415532
require.NoError(t, err)
416533
defer func() {
417-
assert.NoError(t, restoreSettingsXml())
534+
if err := restoreSettingsXml(); err != nil {
535+
t.Errorf("Failed to restore settings.xml: %v", err)
536+
}
418537
}()
419538

420539
wd, err := os.Getwd()
@@ -433,7 +552,9 @@ func prepareMavenSetupTest(t *testing.T, homeDir string) func() {
433552
restoreDir := clientTestUtils.ChangeDirWithCallback(t, wd, filepath.Join(tempDir, "mock-project"))
434553

435554
return func() {
436-
assert.NoError(t, restoreSettingsXml())
555+
if err := restoreSettingsXml(); err != nil {
556+
t.Errorf("Failed to restore settings.xml: %v", err)
557+
}
437558
restoreDir()
438559
}
439560
}

0 commit comments

Comments
 (0)