Skip to content

Commit 76430a3

Browse files
committed
now depends on separate module 'ecs-java-client'
1 parent f29333c commit 76430a3

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

build.gradle

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@
77
*/
88

99
group 'de.eacg'
10-
version '1.0-SNAPSHOT'
10+
version '0.1.1-SNAPSHOT'
1111

1212
buildscript {
1313
dependencies {
14-
classpath group: 'de.eacg', name: 'ecs-gradle-plugin', version: '1.0-SNAPSHOT'
15-
classpath(group: 'de.eacg', name: 'ecs-mvn-plugin', version:'0.1.3') {
16-
exclude group: 'org.sonatype.sisu', module: 'sisu-guice'
17-
exclude group: 'org.codehaus.mojo', module: 'license-maven-plugin'
18-
exclude group: 'org.apache.maven'
19-
exclude group: 'org.apache.maven.shared'
20-
exclude group: 'org.apache.maven.plugin-tools'
21-
exclude group: 'org.twdata.maven'
22-
}
14+
classpath 'de.eacg:ecs-gradle-plugin:0.1.1-SNAPSHOT'
2315

2416
}
2517
repositories {
@@ -50,23 +42,14 @@ uploadArchives {
5042
dependencies {
5143
compile gradleApi()
5244
compile localGroovy()
53-
compile(group: 'de.eacg', name: 'ecs-mvn-plugin', version:'0.1.3') {
54-
exclude group: 'org.sonatype.sisu', module: 'sisu-guice'
55-
exclude group: 'org.codehaus.mojo', module: 'license-maven-plugin'
56-
exclude group: 'org.apache.maven'
57-
exclude group: 'org.apache.maven.shared'
58-
exclude group: 'org.apache.maven.plugin-tools'
59-
exclude group: 'org.twdata.maven'
60-
61-
}
45+
compile 'de.eacg:ecs-java-client:0.1.0-SNAPSHOT'
6246
testCompile 'junit:junit:4.12'
63-
testCompile 'de.eacg:ecs-mvn-plugin:0.1.3'
6447
}
6548

6649
ecsPlugin{
67-
configuration 'runtime', 'testCompile'
6850
configuration 'runtime'
6951
credentials = '~/.ecsrc.json'
7052

71-
skipTransfer = true
53+
skipTransfer = false
54+
baseUrl = "http://localhost:3000"
7255
}

src/main/groovy/de/eacg/ecs/gradle/plugin/ScanTask.groovy

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
package de.eacg.ecs.gradle.plugin
1010

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
1515
import org.gradle.api.DefaultTask
1616
import org.gradle.api.artifacts.Configuration
1717
import org.gradle.api.artifacts.ModuleVersionIdentifier
@@ -31,9 +31,11 @@ class ScanTask extends DefaultTask {
3131
def scan() {
3232
def scanExt = project.ecsPlugin
3333

34-
JsonCredentials credentials = readAndCheckCredentials(scanExt);
34+
def userAgent = "${project.name}/${project.version}"
35+
36+
JsonProperties apiClientConfig = readAndCheckCredentials(scanExt);
37+
3538

36-
def abc = scanExt.configurations
3739

3840
println "Scanning with ${scanExt.configurations.first()}"
3941
Configuration configuration = project.configurations.getByName(scanExt.configurations.first())
@@ -52,9 +54,7 @@ class ScanTask extends DefaultTask {
5254
if(scanExt.skipTransfer) {
5355
println 'Skipping transfer.'
5456
} 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);
5858

5959
Scan scan = new Scan(scanExt.projectName, scanExt.moduleName, scanExt.moduleId, ecsRootDependency);
6060
transferScan(restApi, scan)
@@ -113,7 +113,7 @@ class ScanTask extends DefaultTask {
113113
}
114114
}
115115

116-
return builder.getDependency();
116+
return builder.buildDependency();
117117
}
118118

119119
public printDependencies(Dependency d, int level) {
@@ -154,33 +154,36 @@ class ScanTask extends DefaultTask {
154154
}
155155
}
156156

157-
private JsonCredentials readAndCheckCredentials(def scanExt) {
157+
private JsonProperties readAndCheckCredentials(def scanExt) {
158+
JsonProperties properties
159+
158160
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);
163162
} catch (Exception e) {
164163
println "Evaluation of user credentials failed: ${e.toString()}"
165164
throw new RuntimeException("Exception while evaluating user credentials", e);
166165
}
167-
}
166+
properties.setUserName(scanExt.userName)
167+
properties.setApiKey(scanExt.apiKey)
168+
properties.setBaseUrl(scanExt.baseUrl)
169+
properties.setApiPath(scanExt.apiPath)
168170

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"
172174
print err
173175
throw new RuntimeException("Exception: " + err);
174176
}
177+
return properties;
175178
}
176179

177-
private void transferScan(RestApi api, Scan scan) {
180+
private void transferScan(RestClient client, Scan scan) {
178181
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}"
181184

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()}"
184187
}
185188
} catch (Exception e) {
186189
println e

0 commit comments

Comments
 (0)