Skip to content

Commit 0f37609

Browse files
Added support for user-provided service instances in Maven plugin.
1 parent 5baa1b7 commit 0f37609

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed

cloudfoundry-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
<dependency>
103103
<groupId>org.cloudfoundry</groupId>
104104
<artifactId>cloudfoundry-client-lib</artifactId>
105-
<version>1.0.1</version>
105+
<version>1.0.2.BUILD-SNAPSHOT</version>
106106
</dependency>
107107

108108
<dependency>

cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/AbstractApplicationAwareCloudFoundryMojo.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ abstract class AbstractApplicationAwareCloudFoundryMojo extends AbstractCloudFou
133133
*
134134
* @parameter expression="${services}"
135135
*/
136-
private List<CloudService> services;
136+
private List<CloudServiceWithUserProvided> services;
137137

138138
/**
139139
* list of domains to use by the application.
@@ -466,9 +466,9 @@ public Integer getInstances() {
466466
*
467467
* @return Never null
468468
*/
469-
public List<CloudService> getServices() {
469+
public List<CloudServiceWithUserProvided> getServices() {
470470
if (this.services == null) {
471-
return new ArrayList<CloudService>(0);
471+
return new ArrayList<CloudServiceWithUserProvided>(0);
472472
} else {
473473
return this.services;
474474
}
@@ -528,7 +528,7 @@ public void createServices() throws MojoExecutionException {
528528
currentServicesNames.add(currentService.getName());
529529
}
530530

531-
for (CloudService service: getServices()) {
531+
for (CloudServiceWithUserProvided service: getServices()) {
532532
if (currentServicesNames.contains(service.getName())) {
533533
getLog().debug(String.format("Service '%s' already exists", service.getName()));
534534
}
@@ -537,7 +537,12 @@ public void createServices() throws MojoExecutionException {
537537
Assert.configurationServiceNotNull(service, null);
538538

539539
try {
540-
client.createService(service);
540+
if (service.getLabel().equals("user-provided")) {
541+
service.setLabel(null);
542+
client.createUserProvidedService(service, service.getUserProvidedCredentials());
543+
} else {
544+
client.createService(service);
545+
}
541546
} catch (CloudFoundryException e) {
542547
throw new MojoExecutionException(String.format("Not able to create service '%s'.", service.getName()));
543548
}

cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/AbstractPush.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.cloudfoundry.client.lib.domain.CloudService;
3232
import org.cloudfoundry.client.lib.domain.Staging;
3333

34-
import org.cloudfoundry.maven.common.Assert;
3534
import org.cloudfoundry.maven.common.CommonUtils;
3635

3736
import org.springframework.http.HttpStatus;
@@ -160,7 +159,7 @@ private void createApplication(String appname, String command, String buildpack,
160159
}
161160

162161
private List<String> getServiceNames() {
163-
final List<CloudService> services = getServices();
162+
final List<? extends CloudService> services = getServices();
164163
List<String> serviceNames = new ArrayList<String>();
165164

166165
for (CloudService service : services) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.cloudfoundry.maven;
2+
3+
import org.cloudfoundry.client.lib.domain.CloudService;
4+
5+
import java.util.Map;
6+
7+
public class CloudServiceWithUserProvided extends CloudService {
8+
private Map<String, Object> userProvidedCredentials;
9+
10+
public CloudServiceWithUserProvided() {
11+
super();
12+
}
13+
14+
public Map<String, Object> getUserProvidedCredentials() {
15+
return userProvidedCredentials;
16+
}
17+
18+
public void setUserProvidedCredentials(Map<String, Object> userProvidedCredentials) {
19+
this.userProvidedCredentials = userProvidedCredentials;
20+
}
21+
}

cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/common/CommonUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static String collectionToCommaDelimitedString(Collection<String> list, S
106106
* @return Returns the List as a comma delimited String. Returns an empty
107107
* String for a Null or empty list.
108108
*/
109-
public static String collectionServicesToCommaDelimitedString(Collection<CloudService> list) {
109+
public static String collectionServicesToCommaDelimitedString(Collection<? extends CloudService> list) {
110110
if (list == null || list.isEmpty()) {
111111
return "";
112112
}

cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/common/UiUtils.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,32 +251,43 @@ public int compare(CloudService a, CloudService b) {
251251
table.getHeaders().put(COLUMN_1, new TableHeader("name"));
252252
table.getHeaders().put(COLUMN_2, new TableHeader("service"));
253253
table.getHeaders().put(COLUMN_3, new TableHeader("provider"));
254-
table.getHeaders().put(COLUMN_4, new TableHeader("version"));
255-
table.getHeaders().put(COLUMN_5, new TableHeader("plan"));
256-
table.getHeaders().put(COLUMN_6, new TableHeader("bound apps"));
254+
table.getHeaders().put(COLUMN_4, new TableHeader("plan"));
255+
table.getHeaders().put(COLUMN_5, new TableHeader("bound apps"));
257256

258257
for (CloudService service : services) {
259258
TableRow tableRow = new TableRow();
260259

261-
table.getHeaders().get(COLUMN_1).updateWidth(service.getName().length());
262-
tableRow.addValue(COLUMN_1, service.getName());
260+
String name = service.getName();
263261

264-
table.getHeaders().get(COLUMN_2).updateWidth(service.getLabel().length());
265-
tableRow.addValue(COLUMN_2, service.getLabel());
262+
String label;
263+
String provider;
264+
String plan;
265+
if (service.isUserProvided()) {
266+
label = "user-provided";
267+
provider = "";
268+
plan = "";
269+
} else {
270+
label = service.getLabel();
271+
provider = service.getProvider();
272+
plan = service.getPlan();
273+
}
274+
275+
table.getHeaders().get(COLUMN_1).updateWidth(name.length());
276+
tableRow.addValue(COLUMN_1, name);
266277

267-
table.getHeaders().get(COLUMN_3).updateWidth(service.getProvider().length());
268-
tableRow.addValue(COLUMN_3, service.getProvider());
278+
table.getHeaders().get(COLUMN_2).updateWidth(label.length());
279+
tableRow.addValue(COLUMN_2, label);
269280

270-
table.getHeaders().get(COLUMN_4).updateWidth(service.getVersion().length());
271-
tableRow.addValue(COLUMN_4, service.getVersion());
281+
table.getHeaders().get(COLUMN_3).updateWidth(provider.length());
282+
tableRow.addValue(COLUMN_3, provider);
272283

273-
table.getHeaders().get(COLUMN_5).updateWidth(service.getPlan().length());
274-
tableRow.addValue(COLUMN_5, service.getPlan());
284+
table.getHeaders().get(COLUMN_4).updateWidth(plan.length());
285+
tableRow.addValue(COLUMN_4, plan);
275286

276-
final List<String> appNames = servicesToApps.get(service.getName());
287+
final List<String> appNames = servicesToApps.get(name);
277288
final String appNamesString = CommonUtils.collectionToCommaDelimitedString(appNames);
278-
table.getHeaders().get(COLUMN_6).updateWidth(appNamesString.length());
279-
tableRow.addValue(COLUMN_6, appNamesString);
289+
table.getHeaders().get(COLUMN_5).updateWidth(appNamesString.length());
290+
tableRow.addValue(COLUMN_5, appNamesString);
280291

281292
table.getRows().add(tableRow);
282293
}

0 commit comments

Comments
 (0)