8
8
9
9
package de.eacg.ecs.gradle.plugin
10
10
11
- import de.eacg.ecs.plugin.JsonCredentials
12
- import de.eacg.ecs.plugin.rest .Dependency
13
- import de.eacg.ecs.plugin.rest.RestApi
14
- import de.eacg.ecs.plugin.rest .Scan
11
+ import de.eacg.ecs.client.JsonProperties
12
+ import de.eacg.ecs.client .Dependency
13
+ import de.eacg.ecs.client.RestClient
14
+ import de.eacg.ecs.client .Scan
15
15
import org.gradle.api.DefaultTask
16
16
import org.gradle.api.artifacts.Configuration
17
17
import org.gradle.api.artifacts.ModuleVersionIdentifier
@@ -31,9 +31,11 @@ class ScanTask extends DefaultTask {
31
31
def scan () {
32
32
def scanExt = project. ecsPlugin
33
33
34
- JsonCredentials credentials = readAndCheckCredentials(scanExt);
34
+ def userAgent = " ${ project.name} /${ project.version} "
35
+
36
+ JsonProperties apiClientConfig = readAndCheckCredentials(scanExt);
37
+
35
38
36
- def abc = scanExt. configurations
37
39
38
40
println " Scanning with ${ scanExt.configurations.first()} "
39
41
Configuration configuration = project. configurations. getByName(scanExt. configurations. first())
@@ -52,9 +54,7 @@ class ScanTask extends DefaultTask {
52
54
if (scanExt. skipTransfer) {
53
55
println ' Skipping transfer.'
54
56
} else {
55
- RestApi restApi = new RestApi (scanExt. baseUrl, scanExt. apiPath,
56
- credentials. getApiKey(scanExt. apiKey),
57
- credentials. getUser(scanExt. userName))
57
+ RestClient restApi = new RestClient (apiClientConfig, userAgent);
58
58
59
59
Scan scan = new Scan (scanExt. projectName, scanExt. moduleName, scanExt. moduleId, ecsRootDependency);
60
60
transferScan(restApi, scan)
@@ -113,7 +113,7 @@ class ScanTask extends DefaultTask {
113
113
}
114
114
}
115
115
116
- return builder. getDependency ();
116
+ return builder. buildDependency ();
117
117
}
118
118
119
119
public printDependencies (Dependency d , int level ) {
@@ -154,33 +154,36 @@ class ScanTask extends DefaultTask {
154
154
}
155
155
}
156
156
157
- private JsonCredentials readAndCheckCredentials (def scanExt ) {
157
+ private JsonProperties readAndCheckCredentials (def scanExt ) {
158
+ JsonProperties properties
159
+
158
160
try {
159
- JsonCredentials credentials = new JsonCredentials ((String )scanExt. credentials);
160
- checkMandatoryParameter(" userName" , credentials. getUser(scanExt. userName));
161
- checkMandatoryParameter(" apiKey" , credentials. getApiKey(scanExt. apiKey));
162
- return credentials;
161
+ properties = new JsonProperties ((String )scanExt. credentials);
163
162
} catch (Exception e) {
164
163
println " Evaluation of user credentials failed: ${ e.toString()} "
165
164
throw new RuntimeException (" Exception while evaluating user credentials" , e);
166
165
}
167
- }
166
+ properties. setUserName(scanExt. userName)
167
+ properties. setApiKey(scanExt. apiKey)
168
+ properties. setBaseUrl(scanExt. baseUrl)
169
+ properties. setApiPath(scanExt. apiPath)
168
170
169
- private void checkMandatoryParameter ( String name , String p ) throws RuntimeException {
170
- if (p == null || p . isEmpty()) {
171
- String err = " The mandatory parameter '${ name } ' for plugin 'ecs-gradle-plugin' is missing or invalid"
171
+ def missingKeys = properties . validate()
172
+ if (missingKeys . isEmpty() == false ) {
173
+ String err = " The mandatory parameter(s) '${ missingKeys } ' for plugin 'ecs-gradle-plugin' is/are missing or invalid"
172
174
print err
173
175
throw new RuntimeException (" Exception: " + err);
174
176
}
177
+ return properties;
175
178
}
176
179
177
- private void transferScan (RestApi api , Scan scan ) {
180
+ private void transferScan (RestClient client , Scan scan ) {
178
181
try {
179
- String body = api . transferScan(scan);
180
- println " API Response: code: ${ api .getResponseStatus()} , body: ${ body} "
182
+ String body = client . transferScan(scan);
183
+ println " API Response: code: ${ client .getResponseStatus()} , body: ${ body} "
181
184
182
- if (api . getResponseStatus() != 201 ) {
183
- println " Failed : HTTP error code : ${ api .getResponseStatus()} "
185
+ if (client . getResponseStatus() != 201 ) {
186
+ println " Failed : HTTP error code : ${ client .getResponseStatus()} "
184
187
}
185
188
} catch (Exception e) {
186
189
println e
0 commit comments