Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion buildscripts/download-jars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://github.com/jfrog/maven-dep-tree

# 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.
GRADLE_DEP_TREE_VERSION="3.2.0"
GRADLE_DEP_TREE_VERSION="3.2.1"
# Changing this version also requires a change in mavenDepTreeVersion within utils/java/mvn.go.
MAVEN_DEP_TREE_VERSION="1.1.5"

Expand Down
11 changes: 9 additions & 2 deletions sca/bom/buildinfo/technologies/java/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -37,6 +38,8 @@ const (
}
}

apply plugin: com.jfrog.GradleDepTreeSettings

allprojects {
repositories { %s
}
Expand Down Expand Up @@ -102,8 +105,9 @@ func (gdt *gradleDepTreeManager) createDepTreeScriptAndGetDir() (tmpDir string,
if err != nil {
return
}

var releasesRepo string
releasesRepo, gdt.depsRepo, err = getRemoteRepos(gdt.depsRepo, gdt.server)
releasesRepo, gdt.depsRepo, err = getRemoteRepos(gdt.depsRepo, gdt.server, gdt.isCurationCmd)
if err != nil {
return
}
Expand All @@ -121,11 +125,14 @@ func (gdt *gradleDepTreeManager) createDepTreeScriptAndGetDir() (tmpDir string,
// depsRemoteRepo - name of the remote repository that proxies the relevant registry, e.g. maven central.
// server - the Artifactory server details on which the repositories reside in.
// Returns the constructed sections.
func getRemoteRepos(depsRepo string, server *config.ServerDetails) (string, string, error) {
func getRemoteRepos(depsRepo string, server *config.ServerDetails, isCurationCmd bool) (string, string, error) {
constructedReleasesRepo, err := constructReleasesRemoteRepo()
if err != nil {
return "", "", err
}
if isCurationCmd && depsRepo != "" {
depsRepo = path.Join("api/curation/audit", depsRepo)
}
constructedDepsRepo, err := getDepTreeArtifactoryRepository(depsRepo, server)
if err != nil {
return "", "", err
Expand Down
85 changes: 66 additions & 19 deletions sca/bom/buildinfo/technologies/java/gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const expectedInitScriptWithRepos = `initscript {
}
}

apply plugin: com.jfrog.GradleDepTreeSettings

allprojects {
repositories {
maven {
Expand All @@ -44,6 +46,30 @@ allprojects {
apply plugin: com.jfrog.GradleDepTree
}`

const expectedInitScriptWithCuration = `initscript {
repositories {
mavenCentral()
}
dependencies {
classpath files('%s')
}
}

apply plugin: com.jfrog.GradleDepTreeSettings

allprojects {
repositories {
maven {
url "https://myartifactory.com/artifactory/api/curation/audit/deps-repo"
credentials {
username = 'admin'
password = '%s'
}
}
}
apply plugin: com.jfrog.GradleDepTree
}`

func TestGradleTreesWithoutConfig(t *testing.T) {
// Create and change directory to test workspace
tempDirPath, cleanUp := technologies.CreateTestWorkspace(t, filepath.Join("projects", "package-managers", "gradle", "gradle"))
Expand Down Expand Up @@ -255,30 +281,51 @@ func TestConstructReleasesRemoteRepo(t *testing.T) {
}
}

func TestGradleCurationAuditMode(t *testing.T) {
// Test that curation audit mode flag is added when IsCurationCmd is true
params := &DepTreeParams{
IsCurationCmd: true,
}

func TestCreateDepTreeScriptWithCuration(t *testing.T) {
manager := &gradleDepTreeManager{
DepTreeManager: NewDepTreeManager(params),
isCurationCmd: params.IsCurationCmd,
DepTreeManager: DepTreeManager{
depsRepo: "deps-repo",
server: &config.ServerDetails{
Url: "https://myartifactory.com/",
ArtifactoryUrl: "https://myartifactory.com/artifactory",
AccessToken: dummyToken,
},
},
isCurationCmd: true,
}
assert.True(t, manager.isCurationCmd)

// Verify that the manager has the curation flag set
assert.True(t, manager.isCurationCmd, "isCurationCmd should be true for curation commands")
tmpDir, err := manager.createDepTreeScriptAndGetDir()
assert.NoError(t, err)
defer func() {
assert.NoError(t, os.Remove(filepath.Join(tmpDir, gradleDepTreeInitFile)))
}()

// Test with non-curation command
paramsNonCuration := &DepTreeParams{
IsCurationCmd: false,
}
content, err := os.ReadFile(filepath.Join(tmpDir, gradleDepTreeInitFile))
assert.NoError(t, err)
gradleDepTreeJarPath := ioutils.DoubleWinPathSeparator(filepath.Join(tmpDir, gradleDepTreeJarFile))

assert.Equal(t, fmt.Sprintf(expectedInitScriptWithCuration, gradleDepTreeJarPath, dummyToken), string(content))
assert.Contains(t, string(content), "api/curation/audit/deps-repo")
}

managerNonCuration := &gradleDepTreeManager{
DepTreeManager: NewDepTreeManager(paramsNonCuration),
isCurationCmd: paramsNonCuration.IsCurationCmd,
func TestCreateDepTreeScriptWithCurationEmptyRepo(t *testing.T) {
manager := &gradleDepTreeManager{
DepTreeManager: DepTreeManager{},
isCurationCmd: true,
}
assert.True(t, manager.isCurationCmd)

tmpDir, err := manager.createDepTreeScriptAndGetDir()
assert.NoError(t, err)
defer func() {
assert.NoError(t, os.Remove(filepath.Join(tmpDir, gradleDepTreeInitFile)))
}()

content, err := os.ReadFile(filepath.Join(tmpDir, gradleDepTreeInitFile))
assert.NoError(t, err)
gradleDepTreeJarPath := ioutils.DoubleWinPathSeparator(filepath.Join(tmpDir, gradleDepTreeJarFile))

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