Skip to content

Commit 5b85318

Browse files
committed
Merge branch 'dev'
2 parents a250408 + d68abab commit 5b85318

File tree

10 files changed

+83
-50
lines changed

10 files changed

+83
-50
lines changed

artifactory/commands/buildinfo/publish.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,21 @@ func extractBuildInfoData(partials buildinfo.Partials, includeFilter, excludeFil
148148
var vcs []buildinfo.Vcs
149149
var issues buildinfo.Issues
150150
env := make(map[string]string)
151-
partialModules := make(map[string]partialModule)
151+
partialModules := make(map[string]*partialModule)
152152
issuesMap := make(map[string]*buildinfo.AffectedIssue)
153153
for _, partial := range partials {
154+
moduleId := partial.ModuleId
155+
if partialModules[moduleId] == nil {
156+
partialModules[moduleId] = &partialModule{moduleType: partial.ModuleType}
157+
}
154158
switch {
155159
case partial.Artifacts != nil:
156160
for _, artifact := range partial.Artifacts {
157-
addArtifactToPartialModule(artifact, partial.ModuleId, partialModules)
161+
addArtifactToPartialModule(artifact, moduleId, partialModules)
158162
}
159163
case partial.Dependencies != nil:
160164
for _, dependency := range partial.Dependencies {
161-
addDependencyToPartialModule(dependency, partial.ModuleId, partialModules)
165+
addDependencyToPartialModule(dependency, moduleId, partialModules)
162166
}
163167
case partial.VcsList != nil:
164168
for _, partialVcs := range partial.VcsList {
@@ -190,16 +194,13 @@ func extractBuildInfoData(partials buildinfo.Partials, includeFilter, excludeFil
190194
env[k] = v
191195
}
192196
case partial.ModuleType == buildinfo.Build:
193-
partialModules[partial.ModuleId] = partialModule{
194-
moduleType: partial.ModuleType,
195-
checksum: partial.Checksum,
196-
}
197+
partialModules[moduleId].checksum = partial.Checksum
197198
}
198199
}
199200
return partialModulesToModules(partialModules), env, vcs, issuesMapToArray(issues, issuesMap), nil
200201
}
201202

202-
func partialModulesToModules(partialModules map[string]partialModule) []buildinfo.Module {
203+
func partialModulesToModules(partialModules map[string]*partialModule) []buildinfo.Module {
203204
var modules []buildinfo.Module
204205
for moduleId, singlePartialModule := range partialModules {
205206
moduleArtifacts := artifactsMapToList(singlePartialModule.artifacts)
@@ -216,23 +217,19 @@ func issuesMapToArray(issues buildinfo.Issues, issuesMap map[string]*buildinfo.A
216217
return issues
217218
}
218219

219-
func addDependencyToPartialModule(dependency buildinfo.Dependency, moduleId string, partialModules map[string]partialModule) {
220+
func addDependencyToPartialModule(dependency buildinfo.Dependency, moduleId string, partialModules map[string]*partialModule) {
220221
// init map if needed
221222
if partialModules[moduleId].dependencies == nil {
222-
partialModules[moduleId] =
223-
partialModule{artifacts: partialModules[moduleId].artifacts,
224-
dependencies: make(map[string]buildinfo.Dependency)}
223+
partialModules[moduleId].dependencies = make(map[string]buildinfo.Dependency)
225224
}
226225
key := fmt.Sprintf("%s-%s-%s-%s", dependency.Id, dependency.Sha1, dependency.Md5, dependency.Scopes)
227226
partialModules[moduleId].dependencies[key] = dependency
228227
}
229228

230-
func addArtifactToPartialModule(artifact buildinfo.Artifact, moduleId string, partialModules map[string]partialModule) {
229+
func addArtifactToPartialModule(artifact buildinfo.Artifact, moduleId string, partialModules map[string]*partialModule) {
231230
// init map if needed
232231
if partialModules[moduleId].artifacts == nil {
233-
partialModules[moduleId] =
234-
partialModule{artifacts: make(map[string]buildinfo.Artifact),
235-
dependencies: partialModules[moduleId].dependencies}
232+
partialModules[moduleId].artifacts = make(map[string]buildinfo.Artifact)
236233
}
237234
key := fmt.Sprintf("%s-%s-%s", artifact.Name, artifact.Sha1, artifact.Md5)
238235
partialModules[moduleId].artifacts[key] = artifact

artifactory/commands/npm/installorci.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ func (nic *NpmInstallOrCiCommand) Run() error {
112112
if err != nil {
113113
return err
114114
}
115-
threads, jsonOutput, filteredNpmArgs, buildConfiguration, err := npm.ExtractNpmOptionsFromArgs(nic.npmArgs)
116-
nic.SetRepoConfig(resolverParams).SetArgs(filteredNpmArgs).SetThreads(threads).SetJsonOutput(jsonOutput).SetBuildConfiguration(buildConfiguration)
115+
threads, filteredNpmArgs, buildConfiguration, err := npm.ExtractNpmOptionsFromArgs(nic.npmArgs)
116+
nic.SetRepoConfig(resolverParams).SetArgs(filteredNpmArgs).SetThreads(threads).SetBuildConfiguration(buildConfiguration)
117117
if err != nil {
118118
return err
119119
}
@@ -125,11 +125,6 @@ func (nca *NpmCommandArgs) SetThreads(threads int) *NpmCommandArgs {
125125
return nca
126126
}
127127

128-
func (nca *NpmCommandArgs) SetJsonOutput(jsonOutput bool) *NpmCommandArgs {
129-
nca.jsonOutput = jsonOutput
130-
return nca
131-
}
132-
133128
func NewNpmCommandArgs(npmCommand string) *NpmCommandArgs {
134129
return &NpmCommandArgs{command: npmCommand}
135130
}
@@ -186,6 +181,10 @@ func (nca *NpmCommandArgs) preparePrerequisites(repo string) error {
186181
return err
187182
}
188183

184+
if err := nca.setJsonOutput(); err != nil {
185+
return err
186+
}
187+
189188
if err := nca.setWorkingDirectory(); err != nil {
190189
return err
191190
}
@@ -249,6 +248,17 @@ func (nca *NpmCommandArgs) setWorkingDirectory() error {
249248
return nil
250249
}
251250

251+
func (nca *NpmCommandArgs) setJsonOutput() error {
252+
jsonOutput, err := npm.ConfigGet(nca.npmArgs, "json", nca.executablePath)
253+
if err != nil {
254+
return err
255+
}
256+
257+
// In case of --json=<not boolean>, the value of json is set to 'true', but the result from the command is not 'true'
258+
nca.jsonOutput = jsonOutput != "false"
259+
return nil
260+
}
261+
252262
// In order to make sure the install/ci downloads the dependencies from Artifactory, we are creating a.npmrc file in the project's root directory.
253263
// If such a file already exists, we are copying it aside.
254264
// This method restores the backed up file and deletes the one created by the command.

artifactory/commands/npm/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (npc *NpmPublishCommand) Run() error {
7676
if err != nil {
7777
return err
7878
}
79-
_, _, filteredNpmArgs, buildConfiguration, err := npm.ExtractNpmOptionsFromArgs(npc.NpmPublishCommandArgs.npmArgs)
79+
_, filteredNpmArgs, buildConfiguration, err := npm.ExtractNpmOptionsFromArgs(npc.NpmPublishCommandArgs.npmArgs)
8080
if err != nil {
8181
return err
8282
}

artifactory/utils/dotnet/dependencies/assetsjson.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"io/ioutil"
8+
"path/filepath"
9+
"strings"
10+
711
"github.com/jfrog/jfrog-client-go/artifactory/buildinfo"
812
"github.com/jfrog/jfrog-client-go/utils/errorutils"
913
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
1014
"github.com/jfrog/jfrog-client-go/utils/log"
11-
"io/ioutil"
12-
"path/filepath"
13-
"strings"
1415
)
1516

16-
var assetsFilePath = filepath.Join("obj", "project.assets.json")
17+
var assetsFilePath = filepath.Join(AssetDirName, AssetFileName)
1718

18-
const AssetFileName = "project.assets.json"
19+
const (
20+
AssetFileName = "project.assets.json"
21+
AssetDirName = "obj"
22+
)
1923

2024
// Register project.assets.json extractor
2125
func init() {

artifactory/utils/dotnet/solution/solution.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"io/ioutil"
8+
"os"
9+
"path/filepath"
10+
"regexp"
11+
"strings"
12+
713
"github.com/jfrog/jfrog-cli-core/artifactory/utils/dotnet/dependencies"
814
"github.com/jfrog/jfrog-cli-core/artifactory/utils/dotnet/solution/project"
915
"github.com/jfrog/jfrog-cli-core/utils/ioutils"
@@ -12,11 +18,6 @@ import (
1218
"github.com/jfrog/jfrog-client-go/utils/errorutils"
1319
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
1420
"github.com/jfrog/jfrog-client-go/utils/log"
15-
"io/ioutil"
16-
"os"
17-
"path/filepath"
18-
"regexp"
19-
"strings"
2021
)
2122

2223
type Solution interface {
@@ -133,13 +134,14 @@ func (solution *solution) loadSingleProjectFromDir() error {
133134

134135
func (solution *solution) loadSingleProject(projectName, projFilePath string) {
135136
// First we wil find the project's dependencies source.
136-
// It can be located in the project's root directory or in a directory with the project name under the solution root.
137+
// It can be located directly in the project's root directory or in a directory with the project name under the solution root
138+
// or under obj directory (in case of assets.json file)
137139
projectRootPath := filepath.Dir(projFilePath)
138-
projectPathPattern := projectRootPath + string(filepath.Separator)
140+
projectPathPattern := filepath.Join(projectRootPath, dependencies.AssetDirName) + string(filepath.Separator)
139141
projectNamePattern := string(filepath.Separator) + projectName + string(filepath.Separator)
140142
var dependenciesSource string
141143
for _, source := range solution.dependenciesSources {
142-
if strings.Contains(source, projectPathPattern) || strings.Contains(source, projectNamePattern) {
144+
if projectRootPath == filepath.Dir(source) || strings.Contains(source, projectPathPattern) || strings.Contains(source, projectNamePattern) {
143145
dependenciesSource = source
144146
break
145147
}

artifactory/utils/npm/args.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/jfrog/jfrog-client-go/utils/errorutils"
99
)
1010

11-
func ExtractNpmOptionsFromArgs(args []string) (threads int, jsonOutput bool, cleanArgs []string, buildConfig *utils.BuildConfiguration, err error) {
11+
func ExtractNpmOptionsFromArgs(args []string) (threads int, cleanArgs []string, buildConfig *utils.BuildConfiguration, err error) {
1212
threads = 3
1313
// Extract threads information from the args.
1414
flagIndex, valueIndex, numOfThreads, err := coreutils.FindFlag("--threads", args)
@@ -24,15 +24,6 @@ func ExtractNpmOptionsFromArgs(args []string) (threads int, jsonOutput bool, cle
2424
}
2525
}
2626

27-
// Since we use --json flag for retrieving the npm config for writing the temp .npmrc, json=true is written to the config list.
28-
// We don't want to force the json output for all users, so we check whether the json output was explicitly required.
29-
flagIndex, jsonOutput, err = coreutils.FindBooleanFlag("--json", args)
30-
if err != nil {
31-
return
32-
}
33-
// Since boolean flag might appear as --flag or --flag=value, the value index is the same as the flag index.
34-
coreutils.RemoveFlagFromCommand(&args, flagIndex, flagIndex)
35-
3627
cleanArgs, buildConfig, err = utils.ExtractBuildDetailsFromArgs(args)
3728
return
3829
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package npm
2+
3+
import (
4+
gofrogcmd "github.com/jfrog/gofrog/io"
5+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
6+
"strings"
7+
)
8+
9+
func ConfigGet(npmFlags []string, confName, executablePath string) (string, error) {
10+
configGetCmdConfig := createConfigGetCmdConfig(executablePath, confName, npmFlags)
11+
output, err := gofrogcmd.RunCmdOutput(configGetCmdConfig)
12+
if err != nil {
13+
return "", errorutils.CheckError(err)
14+
}
15+
confValue := strings.TrimSpace(output)
16+
17+
return confValue, nil
18+
}
19+
20+
func createConfigGetCmdConfig(executablePath, confName string, splitFlags []string) *NpmConfig {
21+
return &NpmConfig{
22+
Npm: executablePath,
23+
Command: []string{"config", "get", confName},
24+
CommandFlags: append(splitFlags),
25+
StrWriter: nil,
26+
ErrWriter: nil,
27+
}
28+
}

artifactory/utils/npm/config.go renamed to artifactory/utils/npm/config-list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func GetConfigList(npmFlags []string, executablePath string) ([]byte, error) {
1414
pipeReader, pipeWriter := io.Pipe()
1515
defer pipeReader.Close()
1616

17+
npmFlags = append(npmFlags, "--json=false")
1718
configListCmdConfig := createConfigListCmdConfig(executablePath, npmFlags, pipeWriter)
1819
var npmError error
1920
go func() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/codegangsta/cli v1.20.0
1010
github.com/jfrog/gocmd v0.2.0
1111
github.com/jfrog/gofrog v1.0.6
12-
github.com/jfrog/jfrog-client-go v0.22.2
12+
github.com/jfrog/jfrog-client-go v0.22.3
1313
github.com/magiconair/properties v1.8.1
1414
github.com/manifoldco/promptui v0.8.0
1515
github.com/mattn/go-shellwords v1.0.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ github.com/jfrog/gocmd v0.2.0/go.mod h1:TeZBKJw38D3aKpkIH6tCCztECdhNLIkwHbnCZG8u
135135
github.com/jfrog/gofrog v1.0.6 h1:yUDxSCw8gTK6vC4PvtG0HTnEOQJSZ+O4lWGCgkev1nU=
136136
github.com/jfrog/gofrog v1.0.6/go.mod h1:HkDzg+tMNw23UryoOv0+LB94BzYcl6MCIoz8Tmlb+s8=
137137
github.com/jfrog/jfrog-client-go v0.21.0/go.mod h1:0RYDrQKCIdJbx6pjopwtwXh4/PaEW9FqFc4b4ox8fl0=
138-
github.com/jfrog/jfrog-client-go v0.22.2 h1:dwIwKrgzwkYwZK+BBOma2+WlTEbwnFlzyNi6mEKMvBo=
139-
github.com/jfrog/jfrog-client-go v0.22.2/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
138+
github.com/jfrog/jfrog-client-go v0.22.3 h1:CqircVnWso+EbpYymsLq1CplHlQ8zxHdy/VOhaAX6Bs=
139+
github.com/jfrog/jfrog-client-go v0.22.3/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
140140
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
141141
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
142142
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=

0 commit comments

Comments
 (0)