Skip to content

Commit 18e9f5e

Browse files
authored
fixed-curation-block-for-plugins (#681)
1 parent d7514fb commit 18e9f5e

4 files changed

Lines changed: 76 additions & 22 deletions

File tree

buildscripts/download-jars.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# https://github.com/jfrog/maven-dep-tree
88

99
# Once you have updated the versions mentioned below, please execute this script from the root directory of the jfrog-cli-core to ensure the JAR files are updated.
10-
GRADLE_DEP_TREE_VERSION="3.2.0"
10+
GRADLE_DEP_TREE_VERSION="3.2.1"
1111
# Changing this version also requires a change in mavenDepTreeVersion within utils/java/mvn.go.
1212
MAVEN_DEP_TREE_VERSION="1.1.5"
1313

sca/bom/buildinfo/technologies/java/gradle.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"os/exec"
9+
"path"
910
"path/filepath"
1011
"strings"
1112

@@ -37,6 +38,8 @@ const (
3738
}
3839
}
3940
41+
apply plugin: com.jfrog.GradleDepTreeSettings
42+
4043
allprojects {
4144
repositories { %s
4245
}
@@ -102,8 +105,9 @@ func (gdt *gradleDepTreeManager) createDepTreeScriptAndGetDir() (tmpDir string,
102105
if err != nil {
103106
return
104107
}
108+
105109
var releasesRepo string
106-
releasesRepo, gdt.depsRepo, err = getRemoteRepos(gdt.depsRepo, gdt.server)
110+
releasesRepo, gdt.depsRepo, err = getRemoteRepos(gdt.depsRepo, gdt.server, gdt.isCurationCmd)
107111
if err != nil {
108112
return
109113
}
@@ -121,11 +125,14 @@ func (gdt *gradleDepTreeManager) createDepTreeScriptAndGetDir() (tmpDir string,
121125
// depsRemoteRepo - name of the remote repository that proxies the relevant registry, e.g. maven central.
122126
// server - the Artifactory server details on which the repositories reside in.
123127
// Returns the constructed sections.
124-
func getRemoteRepos(depsRepo string, server *config.ServerDetails) (string, string, error) {
128+
func getRemoteRepos(depsRepo string, server *config.ServerDetails, isCurationCmd bool) (string, string, error) {
125129
constructedReleasesRepo, err := constructReleasesRemoteRepo()
126130
if err != nil {
127131
return "", "", err
128132
}
133+
if isCurationCmd && depsRepo != "" {
134+
depsRepo = path.Join("api/curation/audit", depsRepo)
135+
}
129136
constructedDepsRepo, err := getDepTreeArtifactoryRepository(depsRepo, server)
130137
if err != nil {
131138
return "", "", err

sca/bom/buildinfo/technologies/java/gradle_test.go

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const expectedInitScriptWithRepos = `initscript {
3131
}
3232
}
3333
34+
apply plugin: com.jfrog.GradleDepTreeSettings
35+
3436
allprojects {
3537
repositories {
3638
maven {
@@ -44,6 +46,30 @@ allprojects {
4446
apply plugin: com.jfrog.GradleDepTree
4547
}`
4648

49+
const expectedInitScriptWithCuration = `initscript {
50+
repositories {
51+
mavenCentral()
52+
}
53+
dependencies {
54+
classpath files('%s')
55+
}
56+
}
57+
58+
apply plugin: com.jfrog.GradleDepTreeSettings
59+
60+
allprojects {
61+
repositories {
62+
maven {
63+
url "https://myartifactory.com/artifactory/api/curation/audit/deps-repo"
64+
credentials {
65+
username = 'admin'
66+
password = '%s'
67+
}
68+
}
69+
}
70+
apply plugin: com.jfrog.GradleDepTree
71+
}`
72+
4773
func TestGradleTreesWithoutConfig(t *testing.T) {
4874
// Create and change directory to test workspace
4975
tempDirPath, cleanUp := technologies.CreateTestWorkspace(t, filepath.Join("projects", "package-managers", "gradle", "gradle"))
@@ -255,30 +281,51 @@ func TestConstructReleasesRemoteRepo(t *testing.T) {
255281
}
256282
}
257283

258-
func TestGradleCurationAuditMode(t *testing.T) {
259-
// Test that curation audit mode flag is added when IsCurationCmd is true
260-
params := &DepTreeParams{
261-
IsCurationCmd: true,
262-
}
263-
284+
func TestCreateDepTreeScriptWithCuration(t *testing.T) {
264285
manager := &gradleDepTreeManager{
265-
DepTreeManager: NewDepTreeManager(params),
266-
isCurationCmd: params.IsCurationCmd,
286+
DepTreeManager: DepTreeManager{
287+
depsRepo: "deps-repo",
288+
server: &config.ServerDetails{
289+
Url: "https://myartifactory.com/",
290+
ArtifactoryUrl: "https://myartifactory.com/artifactory",
291+
AccessToken: dummyToken,
292+
},
293+
},
294+
isCurationCmd: true,
267295
}
296+
assert.True(t, manager.isCurationCmd)
268297

269-
// Verify that the manager has the curation flag set
270-
assert.True(t, manager.isCurationCmd, "isCurationCmd should be true for curation commands")
298+
tmpDir, err := manager.createDepTreeScriptAndGetDir()
299+
assert.NoError(t, err)
300+
defer func() {
301+
assert.NoError(t, os.Remove(filepath.Join(tmpDir, gradleDepTreeInitFile)))
302+
}()
271303

272-
// Test with non-curation command
273-
paramsNonCuration := &DepTreeParams{
274-
IsCurationCmd: false,
275-
}
304+
content, err := os.ReadFile(filepath.Join(tmpDir, gradleDepTreeInitFile))
305+
assert.NoError(t, err)
306+
gradleDepTreeJarPath := ioutils.DoubleWinPathSeparator(filepath.Join(tmpDir, gradleDepTreeJarFile))
307+
308+
assert.Equal(t, fmt.Sprintf(expectedInitScriptWithCuration, gradleDepTreeJarPath, dummyToken), string(content))
309+
assert.Contains(t, string(content), "api/curation/audit/deps-repo")
310+
}
276311

277-
managerNonCuration := &gradleDepTreeManager{
278-
DepTreeManager: NewDepTreeManager(paramsNonCuration),
279-
isCurationCmd: paramsNonCuration.IsCurationCmd,
312+
func TestCreateDepTreeScriptWithCurationEmptyRepo(t *testing.T) {
313+
manager := &gradleDepTreeManager{
314+
DepTreeManager: DepTreeManager{},
315+
isCurationCmd: true,
280316
}
317+
assert.True(t, manager.isCurationCmd)
318+
319+
tmpDir, err := manager.createDepTreeScriptAndGetDir()
320+
assert.NoError(t, err)
321+
defer func() {
322+
assert.NoError(t, os.Remove(filepath.Join(tmpDir, gradleDepTreeInitFile)))
323+
}()
324+
325+
content, err := os.ReadFile(filepath.Join(tmpDir, gradleDepTreeInitFile))
326+
assert.NoError(t, err)
327+
gradleDepTreeJarPath := ioutils.DoubleWinPathSeparator(filepath.Join(tmpDir, gradleDepTreeJarFile))
281328

282-
// Verify that the manager does not have the curation flag set
283-
assert.False(t, managerNonCuration.isCurationCmd, "isCurationCmd should be false for non-curation commands")
329+
assert.Equal(t, fmt.Sprintf(gradleDepTreeInitScript, "", gradleDepTreeJarPath, ""), string(content))
330+
assert.NotContains(t, string(content), "api/curation/audit")
284331
}
Binary file not shown.

0 commit comments

Comments
 (0)