Skip to content

Commit 838681d

Browse files
committed
Extended support for snapshot policy for resolver in Maven Projects
1 parent 5b6a23a commit 838681d

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

common/build/buildinfoproperties.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const Repo = "repo"
4545
const SnapshotRepo = "snapshotRepo"
4646
const ReleaseRepo = "releaseRepo"
4747

48+
const DisableSnapshots = "disableSnapshots"
49+
const SnapshotsUpdatePolicy = "snapshotsUpdatePolicy"
50+
4851
const ServerId = "serverId"
4952
const Url = "url"
5053
const Username = "username"
@@ -123,6 +126,8 @@ var mavenConfigMapping = map[string]string{
123126
"buildInfoConfig.artifactoryResolutionEnabled": "buildInfoConfig.artifactoryResolutionEnabled",
124127
"resolve.repoKey": ResolverPrefix + ReleaseRepo,
125128
"resolve.downSnapshotRepoKey": ResolverPrefix + SnapshotRepo,
129+
"resolve.snapshots.disabled": ResolverPrefix + DisableSnapshots,
130+
"resolve.snapshots.updatePolicy": ResolverPrefix + SnapshotsUpdatePolicy,
126131
"publish.repoKey": DeployerPrefix + ReleaseRepo,
127132
"publish.snapshot.repoKey": DeployerPrefix + SnapshotRepo,
128133
"publish.includePatterns": DeployerPrefix + IncludePatterns,

common/commands/configfile.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
deploymentSnapshotsRepo = "repo-deploy-snapshots"
4040
includePatterns = "include-patterns"
4141
excludePatterns = "exclude-patterns"
42+
disableSnapshots = "disable-snapshots"
43+
snapshotsUpdatePolicy = "snapshots-update-policy"
4244

4345
// Gradle flags
4446
usesPlugin = "uses-plugin"
@@ -251,14 +253,16 @@ func WithDeployerRepo(repoId string) ConfigOption {
251253
// Populate Maven related configuration from cli flags
252254
func (configFile *ConfigFile) populateMavenConfigFromFlags(c *cli.Context) {
253255
configFile.Resolver.SnapshotRepo = c.String(resolutionSnapshotsRepo)
256+
configFile.Resolver.DisableSnapshots = c.Bool(disableSnapshots)
257+
configFile.Resolver.SnapshotsUpdatePolicy = c.String(snapshotsUpdatePolicy)
254258
configFile.Resolver.ReleaseRepo = c.String(resolutionReleasesRepo)
255259
configFile.Deployer.SnapshotRepo = c.String(deploymentSnapshotsRepo)
256260
configFile.Deployer.ReleaseRepo = c.String(deploymentReleasesRepo)
257261
configFile.Deployer.IncludePatterns = c.String(includePatterns)
258262
configFile.Deployer.ExcludePatterns = c.String(excludePatterns)
259263
configFile.UseWrapper = c.Bool(useWrapper)
260264
configFile.Interactive = configFile.Interactive && !isAnyFlagSet(c, resolutionSnapshotsRepo, resolutionReleasesRepo,
261-
deploymentSnapshotsRepo, deploymentReleasesRepo, includePatterns, excludePatterns)
265+
disableSnapshots, snapshotsUpdatePolicy, deploymentSnapshotsRepo, deploymentReleasesRepo, includePatterns, excludePatterns)
262266
}
263267

264268
func WithResolverSnapshotRepo(repoId string) ConfigOption {

common/commands/flag_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package commands
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
7+
"github.com/urfave/cli"
8+
)
9+
10+
// This test demonstrates an existing bug in the urfave/cli library.
11+
// It highlights that both BoolT and Bool flags have their default values set to false.
12+
// Ideally, the BoolT flag should have a default value of true.
13+
func TestBoolVsBoolTFlag(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
args []string
17+
shouldUseBoolT bool
18+
expectValue bool
19+
}{
20+
{"Resolving flag value using Bool (default false)", []string{"cmd"}, false, false},
21+
{"Resolving flag value using Bool (default false)", []string{"cmd"}, true, false},
22+
}
23+
24+
for _, tt := range tests {
25+
t.Run(tt.name, func(t *testing.T) {
26+
app := &cli.App{
27+
Flags: []cli.Flag{
28+
&cli.BoolFlag{
29+
Name: "myflag",
30+
Usage: "Test boolean flag",
31+
},
32+
},
33+
Action: func(c *cli.Context) error {
34+
if tt.shouldUseBoolT {
35+
assert.Equal(t, tt.expectValue, c.BoolT("myflag"), "Expected %v, got %v", tt.expectValue, c.BoolT("myflag"))
36+
} else {
37+
assert.Equal(t, tt.expectValue, c.Bool("myflag"), "Expected %v, got %v", tt.expectValue, c.Bool("myflag"))
38+
}
39+
return nil
40+
},
41+
}
42+
43+
_ = app.Run(tt.args)
44+
})
45+
}
46+
}

common/project/projectconfig.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,19 @@ func (mre *MissingResolverErr) Error() string {
9696
}
9797

9898
type Repository struct {
99-
Repo string `yaml:"repo,omitempty"`
100-
ServerId string `yaml:"serverId,omitempty"`
101-
SnapshotRepo string `yaml:"snapshotRepo,omitempty"`
102-
ReleaseRepo string `yaml:"releaseRepo,omitempty"`
103-
DeployMavenDesc bool `yaml:"deployMavenDescriptors,omitempty"`
104-
DeployIvyDesc bool `yaml:"deployIvyDescriptors,omitempty"`
105-
IvyPattern string `yaml:"ivyPattern,omitempty"`
106-
ArtifactsPattern string `yaml:"artifactPattern,omitempty"`
107-
NugetV2 bool `yaml:"nugetV2,omitempty"`
108-
IncludePatterns string `yaml:"includePatterns,omitempty"`
109-
ExcludePatterns string `yaml:"excludePatterns,omitempty"`
99+
Repo string `yaml:"repo,omitempty"`
100+
ServerId string `yaml:"serverId,omitempty"`
101+
SnapshotRepo string `yaml:"snapshotRepo,omitempty"`
102+
DisableSnapshots bool `yaml:"disableSnapshots,omitempty"`
103+
SnapshotsUpdatePolicy string `yaml:"snapshotsUpdatePolicy,omitempty"`
104+
ReleaseRepo string `yaml:"releaseRepo,omitempty"`
105+
DeployMavenDesc bool `yaml:"deployMavenDescriptors,omitempty"`
106+
DeployIvyDesc bool `yaml:"deployIvyDescriptors,omitempty"`
107+
IvyPattern string `yaml:"ivyPattern,omitempty"`
108+
ArtifactsPattern string `yaml:"artifactPattern,omitempty"`
109+
NugetV2 bool `yaml:"nugetV2,omitempty"`
110+
IncludePatterns string `yaml:"includePatterns,omitempty"`
111+
ExcludePatterns string `yaml:"excludePatterns,omitempty"`
110112
}
111113

112114
type RepositoryConfig struct {

0 commit comments

Comments
 (0)