@@ -12,6 +12,8 @@ import (
12
12
"github.com/SAP/jenkins-library/pkg/log"
13
13
)
14
14
15
+ const defaultMavenProjectSettingsPath = ".pipeline/mavenProjectSettings.xml"
16
+
15
17
var getenv = os .Getenv
16
18
17
19
// SettingsDownloadUtils defines an interface for downloading and storing maven settings files.
@@ -40,7 +42,7 @@ func DownloadAndGetMavenParameters(globalSettingsFile string, projectSettingsFil
40
42
}
41
43
42
44
if len (projectSettingsFile ) > 0 {
43
- projectSettingsFileName , err := getSettingsFilePath (projectSettingsFile , ".pipeline/mavenProjectSettings.xml" , utils , false )
45
+ projectSettingsFileName , err := getSettingsFilePath (projectSettingsFile , defaultMavenProjectSettingsPath , utils , false )
44
46
if err != nil {
45
47
return nil , err
46
48
}
@@ -66,7 +68,6 @@ func DownloadAndCopySettingsFiles(globalSettingsFile string, projectSettingsFile
66
68
return err
67
69
}
68
70
} else {
69
-
70
71
log .Entry ().Debugf ("Project settings file not provided via configuration." )
71
72
}
72
73
@@ -79,7 +80,6 @@ func DownloadAndCopySettingsFiles(globalSettingsFile string, projectSettingsFile
79
80
return err
80
81
}
81
82
} else {
82
-
83
83
log .Entry ().Debugf ("Global settings file not provided via configuration." )
84
84
}
85
85
@@ -98,9 +98,7 @@ func UpdateActiveProfileInSettingsXML(newActiveProfiles []string, utils Settings
98
98
}
99
99
100
100
var projectSettings Settings
101
- err = xml .Unmarshal ([]byte (settingsXMLContent ), & projectSettings )
102
-
103
- if err != nil {
101
+ if err = xml .Unmarshal (settingsXMLContent , & projectSettings ); err != nil {
104
102
return fmt .Errorf ("failed to unmarshal settings xml file '%v': %w" , settingsFile , err )
105
103
}
106
104
@@ -123,9 +121,7 @@ func UpdateActiveProfileInSettingsXML(newActiveProfiles []string, utils Settings
123
121
settingsXmlString = Replacer .Replace (settingsXmlString )
124
122
xmlstring := []byte (xml .Header + settingsXmlString )
125
123
126
- err = utils .FileWrite (settingsFile , xmlstring , 0777 )
127
-
128
- if err != nil {
124
+ if err = utils .FileWrite (settingsFile , xmlstring , 0777 ); err != nil {
129
125
return fmt .Errorf ("failed to write maven Settings during <activeProfile> update xml: %w" , err )
130
126
}
131
127
log .Entry ().Infof ("Successfully updated <acitveProfile> details in maven settings file : '%s'" , settingsFile )
@@ -157,25 +153,26 @@ func CreateNewProjectSettingsXML(altDeploymentRepositoryID string, altDeployment
157
153
158
154
xmlstring = []byte (xml .Header + string (xmlstring ))
159
155
160
- err = utils .FileWrite (".pipeline/mavenProjectSettings.xml" , xmlstring , 0777 )
161
- if err != nil {
156
+ if err = utils .FileWrite (defaultMavenProjectSettingsPath , xmlstring , 0777 ); err != nil {
162
157
return "" , fmt .Errorf ("failed to write maven Project Settings xml: %w" , err )
163
158
}
164
159
165
- log .Entry ().Infof ("Successfully created maven project settings with <server> details at .pipeline/mavenProjectSettings.xml" )
160
+ log .Entry ().Infof ("Successfully created maven project settings with <server> details at %s" , defaultMavenProjectSettingsPath )
166
161
167
- return ".pipeline/mavenProjectSettings.xml" , nil
162
+ return defaultMavenProjectSettingsPath , nil
168
163
169
164
}
170
165
171
166
func UpdateProjectSettingsXML (projectSettingsFile string , altDeploymentRepositoryID string , altDeploymentRepositoryUser string , altDeploymentRepositoryPassword string , utils SettingsDownloadUtils ) (string , error ) {
172
- projectSettingsFileDestination := ".pipeline/mavenProjectSettings"
167
+ projectSettingsFileDestination := defaultMavenProjectSettingsPath
173
168
var err error
174
169
if exists , _ := utils .FileExists (projectSettingsFile ); exists {
170
+ log .Entry ().Debugf ("Project settings file provided via configuration: %s" , projectSettingsFile )
175
171
projectSettingsFileDestination = projectSettingsFile
176
172
err = addServerTagtoProjectSettingsXML (projectSettingsFile , altDeploymentRepositoryID , altDeploymentRepositoryUser , altDeploymentRepositoryPassword , utils )
177
173
} else {
178
- err = addServerTagtoProjectSettingsXML (".pipeline/mavenProjectSettings" , altDeploymentRepositoryID , altDeploymentRepositoryUser , altDeploymentRepositoryPassword , utils )
174
+ log .Entry ().Debugf ("Project settings file provided '%s' does not exist. Using default location: %s" , projectSettingsFile , defaultMavenProjectSettingsPath )
175
+ err = addServerTagtoProjectSettingsXML (defaultMavenProjectSettingsPath , altDeploymentRepositoryID , altDeploymentRepositoryUser , altDeploymentRepositoryPassword , utils )
179
176
}
180
177
181
178
if err != nil {
@@ -246,31 +243,28 @@ func downloadAndCopySettingsFile(src string, dest string, utils SettingsDownload
246
243
log .Entry ().Debugf ("Copying file \" %s\" to \" %s\" " , src , dest )
247
244
248
245
if strings .HasPrefix (src , "http:" ) || strings .HasPrefix (src , "https:" ) {
249
- err := downloadSettingsFromURL (src , dest , utils , true )
250
- if err != nil {
246
+ if err := downloadSettingsFromURL (src , dest , utils , true ); err != nil {
251
247
return err
252
248
}
253
- } else {
254
-
255
- // for sake os symmetry it would be better to use a file protocol prefix here (file:)
256
249
257
- parent := filepath .Dir (dest )
250
+ return nil
251
+ }
258
252
259
- parentFolderExists , err := utils .FileExists (parent )
253
+ // for sake os symmetry it would be better to use a file protocol prefix here (file:)
254
+ parent := filepath .Dir (dest )
255
+ parentFolderExists , err := utils .FileExists (parent )
256
+ if err != nil {
257
+ return err
258
+ }
260
259
261
- if err != nil {
260
+ if ! parentFolderExists {
261
+ if err = utils .MkdirAll (parent , 0775 ); err != nil {
262
262
return err
263
263
}
264
+ }
264
265
265
- if ! parentFolderExists {
266
- if err = utils .MkdirAll (parent , 0775 ); err != nil {
267
- return err
268
- }
269
- }
270
-
271
- if _ , err := utils .Copy (src , dest ); err != nil {
272
- return err
273
- }
266
+ if _ , err := utils .Copy (src , dest ); err != nil {
267
+ return err
274
268
}
275
269
276
270
return nil
0 commit comments