Skip to content

Commit bb3c080

Browse files
Merge pull request cloudfoundry#173 from scottfrederick/gradle2
Made fields optional in build plugins.
2 parents a91872f + 2d0b43a commit bb3c080

File tree

11 files changed

+152
-203
lines changed

11 files changed

+152
-203
lines changed

cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryClient.java

+4
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ public List<CloudDomain> getDomains() {
429429
return cc.getDomains();
430430
}
431431

432+
public CloudDomain getDefaultDomain() {
433+
return cc.getDefaultDomain();
434+
}
435+
432436
public void addDomain(String domainName) {
433437
cc.addDomain(domainName);
434438
}

cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryOperations.java

+7
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ public void createApplication(String appName, Staging staging, Integer disk, Int
573573
*/
574574
List<CloudDomain> getDomains();
575575

576+
/**
577+
* Gets the default domain for the current org, which is the first shared domain.
578+
*
579+
* @return the default domain
580+
*/
581+
CloudDomain getDefaultDomain();
582+
576583
/**
577584
* Add a private domain in the current organization.
578585
*

cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/rest/CloudControllerClient.java

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ void createApplication(String appName, Staging staging, Integer disk, Integer me
179179

180180
List<CloudDomain> getSharedDomains();
181181

182+
CloudDomain getDefaultDomain();
183+
182184
void addDomain(String domainName);
183185

184186
void deleteDomain(String domainName);

cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/rest/CloudControllerClientImpl.java

+9
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,15 @@ public List<CloudDomain> getSharedDomains() {
13741374
return doGetDomains("/v2/shared_domains");
13751375
}
13761376

1377+
public CloudDomain getDefaultDomain() {
1378+
List<CloudDomain> sharedDomains = getSharedDomains();
1379+
if (sharedDomains.isEmpty()) {
1380+
return null;
1381+
} else {
1382+
return sharedDomains.get(0);
1383+
}
1384+
}
1385+
13771386
public void addDomain(String domainName) {
13781387
assertSpaceProvided("add domain");
13791388
UUID domainGuid = getDomainGuid(domainName, false);

cloudfoundry-client-lib/src/test/java/org/cloudfoundry/client/lib/CloudFoundryClientTest.java

+52-63
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void setUp() throws Exception {
207207
connectedClient = new CloudFoundryClient(new CloudCredentials(CCNG_USER_EMAIL, CCNG_USER_PASS),
208208
cloudControllerUrl, CCNG_USER_ORG, CCNG_USER_SPACE, httpProxyConfiguration, CCNG_API_SSL);
209209
connectedClient.login();
210-
defaultDomainName = getDefaultDomain(connectedClient.getDomains()).getName();
210+
defaultDomainName = connectedClient.getDefaultDomain().getName();
211211

212212
// Optimization to avoid redoing the work already done is tearDown()
213213
if (!tearDownComplete) {
@@ -279,7 +279,7 @@ public void checkByteManrulesAndInJvmProxyAssertMechanisms() {
279279
HttpHost proxy = new HttpHost("127.0.0.1", inJvmProxyPort);
280280
commonsFactory.getHttpClient().getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
281281
restTemplate.setRequestFactory(requestFactory);
282-
restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET,null, null);
282+
restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET, null, null);
283283

284284
//then executes fines, and the jetty proxy indeed received one request
285285
assertEquals("expected network calls to make it through the inJvmProxy.", 1, nbInJvmProxyRcvReqs.get());
@@ -999,40 +999,40 @@ public void getLogs() throws Exception {
999999

10001000
@Test
10011001
public void streamLogs() throws Exception {
1002-
String appName = namespacedAppName("simple_logs");
1003-
CloudApplication app = createAndUploadAndStartSimpleSpringApp(appName);
1004-
boolean pass = getInstanceInfosWithTimeout(appName, 1, true);
1005-
assertTrue("Couldn't get the right application state", pass);
1006-
1007-
AccumulatingApplicationLogListener testListener = new AccumulatingApplicationLogListener();
1008-
connectedClient.streamRecentLogs(appName, testListener);
1009-
1010-
int attempt = 0;
1011-
do {
1012-
if (testListener.logs.size() > 0) {
1013-
break;
1014-
}
1015-
Thread.sleep(1000);
1016-
} while (attempt < 20);
1017-
assertTrue("Failed to see recent logs", testListener.logs.size() > 0);
1018-
1019-
testListener.logs.clear();
1020-
connectedClient.streamLogs(appName, testListener);
1021-
String appUri = "http://" + app.getUris().get(0);
1022-
RestTemplate appTemplate = new RestTemplate();
1023-
attempt = 0;
1024-
do {
1025-
// no need to sleep, visiting the app uri should be sufficient
1026-
try {
1027-
appTemplate.getForObject(appUri, String.class);
1028-
} catch (HttpClientErrorException ex) {
1029-
// ignore
1030-
}
1031-
if (testListener.logs.size() > 0) {
1032-
break;
1033-
}
1034-
} while(attempt < 20);
1035-
assertTrue("Failed to stream normal log", testListener.logs.size() > 0);
1002+
String appName = namespacedAppName("simple_logs");
1003+
CloudApplication app = createAndUploadAndStartSimpleSpringApp(appName);
1004+
boolean pass = getInstanceInfosWithTimeout(appName, 1, true);
1005+
assertTrue("Couldn't get the right application state", pass);
1006+
1007+
AccumulatingApplicationLogListener testListener = new AccumulatingApplicationLogListener();
1008+
connectedClient.streamRecentLogs(appName, testListener);
1009+
1010+
int attempt = 0;
1011+
do {
1012+
if (testListener.logs.size() > 0) {
1013+
break;
1014+
}
1015+
Thread.sleep(1000);
1016+
} while (attempt < 20);
1017+
assertTrue("Failed to see recent logs", testListener.logs.size() > 0);
1018+
1019+
testListener.logs.clear();
1020+
connectedClient.streamLogs(appName, testListener);
1021+
String appUri = "http://" + app.getUris().get(0);
1022+
RestTemplate appTemplate = new RestTemplate();
1023+
attempt = 0;
1024+
do {
1025+
// no need to sleep, visiting the app uri should be sufficient
1026+
try {
1027+
appTemplate.getForObject(appUri, String.class);
1028+
} catch (HttpClientErrorException ex) {
1029+
// ignore
1030+
}
1031+
if (testListener.logs.size() > 0) {
1032+
break;
1033+
}
1034+
} while (attempt < 20);
1035+
assertTrue("Failed to stream normal log", testListener.logs.size() > 0);
10361036
}
10371037

10381038
@Test
@@ -1260,8 +1260,7 @@ public void bindAndUnbindService() throws IOException {
12601260

12611261
@Test
12621262
public void defaultDomainFound() throws Exception {
1263-
List<CloudDomain> domains = connectedClient.getSharedDomains();
1264-
assertNotNull(getDefaultDomain(domains));
1263+
assertNotNull(connectedClient.getDefaultDomain());
12651264
}
12661265

12671266
@Test
@@ -1270,7 +1269,7 @@ public void getDomains() {
12701269

12711270
List<CloudDomain> allDomains = connectedClient.getDomains();
12721271

1273-
assertNotNull(getDefaultDomain(allDomains));
1272+
assertNotNull(getDomainNamed(defaultDomainName, allDomains));
12741273
assertNotNull(getDomainNamed(TEST_DOMAIN, allDomains));
12751274
}
12761275

@@ -1295,7 +1294,6 @@ private void assertDomainInList(List<CloudDomain> domains) {
12951294
}
12961295

12971296
private void assertDomainNotInList(List<CloudDomain> domains) {
1298-
assertTrue(domains.size() >= 1);
12991297
assertNull(getDomainNamed(TEST_DOMAIN, domains));
13001298
}
13011299

@@ -1351,7 +1349,7 @@ public void appsWithRoutesAreCounted() throws IOException {
13511349

13521350
@Test
13531351
public void infoAvailableWithoutLoggingIn() throws Exception {
1354-
CloudFoundryClient infoClient = new CloudFoundryClient(new URL(CCNG_API_URL), httpProxyConfiguration);
1352+
CloudFoundryClient infoClient = new CloudFoundryClient(new URL(CCNG_API_URL), httpProxyConfiguration, CCNG_API_SSL);
13551353
CloudInfo info = infoClient.getCloudInfo();
13561354
assertNotNull(info.getName());
13571355
assertNotNull(info.getSupport());
@@ -1811,15 +1809,6 @@ private CloudDomain getDomainNamed(String domainName, List<CloudDomain> domains)
18111809
return null;
18121810
}
18131811

1814-
private CloudDomain getDefaultDomain(List<CloudDomain> domains) {
1815-
for (CloudDomain domain : domains) {
1816-
if (domain.getOwner().getName().equals("none")) {
1817-
return domain;
1818-
}
1819-
}
1820-
return null;
1821-
}
1822-
18231812
private String computeAppUrl(String appName) {
18241813
return appName + "." + defaultDomainName;
18251814
}
@@ -1865,18 +1854,18 @@ public boolean onProgress(String status) {
18651854
}
18661855

18671856
private class AccumulatingApplicationLogListener implements ApplicationLogListener {
1868-
private List<ApplicationLog> logs = new ArrayList<ApplicationLog>();
1869-
1870-
public void onMessage(ApplicationLog log) {
1871-
logs.add(log);
1872-
}
1873-
1874-
public void onError(Throwable exception) {
1875-
fail(exception.getMessage());
1876-
}
1877-
1878-
public void onComplete() {
1879-
}
1880-
1857+
private List<ApplicationLog> logs = new ArrayList<ApplicationLog>();
1858+
1859+
public void onMessage(ApplicationLog log) {
1860+
logs.add(log);
1861+
}
1862+
1863+
public void onError(Throwable exception) {
1864+
fail(exception.getMessage());
1865+
}
1866+
1867+
public void onComplete() {
1868+
}
1869+
18811870
}
18821871
}

cloudfoundry-gradle-plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repositories {
2727

2828
dependencies {
2929
compile gradleApi()
30-
compile 'org.cloudfoundry:cloudfoundry-client-lib:1.0.2'
30+
compile 'org.cloudfoundry:cloudfoundry-client-lib:1.0.3.BUILD-SNAPSHOT'
3131
compile 'org.codehaus.groovy:groovy:2.1.6'
3232
testCompile 'junit:junit:4.8.2'
3333
}

cloudfoundry-gradle-plugin/src/main/groovy/org/cloudfoundry/gradle/tasks/AbstractCloudFoundryTask.groovy

+18-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import org.cloudfoundry.client.lib.tokens.TokensFile
2626
import org.gradle.api.DefaultTask
2727
import org.cloudfoundry.gradle.GradlePluginRestLogCallback
2828
import org.gradle.api.Task
29+
import org.gradle.api.plugins.JavaPlugin
30+
import org.gradle.api.plugins.WarPlugin
2931
import org.springframework.http.HttpStatus
3032
import org.springframework.security.oauth2.common.OAuth2AccessToken
3133
import org.springframework.web.client.ResourceAccessException
@@ -289,6 +291,15 @@ abstract class AbstractCloudFoundryTask extends DefaultTask {
289291
String host = propertyOrExtension('host')
290292
List<String> hosts = project.cloudfoundry.hosts
291293

294+
if (!uri && !uris) {
295+
if (!domain) {
296+
domain = client.defaultDomain.name
297+
}
298+
if (!hosts && !host) {
299+
host = application
300+
}
301+
}
302+
292303
def allUris = []
293304

294305
if (!currentVariantSuffix) {
@@ -310,7 +321,13 @@ abstract class AbstractCloudFoundryTask extends DefaultTask {
310321
}
311322

312323
File getFile() {
313-
project.cloudfoundry.file
324+
((project.cloudfoundry.file ?:
325+
getDefaultArchiveForTask(WarPlugin.WAR_TASK_NAME)) ?:
326+
getDefaultArchiveForTask(JavaPlugin.JAR_TASK_NAME))
327+
}
328+
329+
File getDefaultArchiveForTask(String taskName) {
330+
project.tasks.findByName(taskName)?.archivePath
314331
}
315332

316333
Map<String, String> getEnv() {

cloudfoundry-maven-plugin/pom.xml

+1-1
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.2</version>
105+
<version>1.0.3.BUILD-SNAPSHOT</version>
106106
</dependency>
107107

108108
<dependency>

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

+8-36
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21-
import java.net.URI;
2221
import java.util.ArrayList;
22+
import java.util.Arrays;
2323
import java.util.HashMap;
2424
import java.util.List;
2525
import java.util.Map;
@@ -253,44 +253,18 @@ public Map<String,String> getEnv() {
253253
* If the application name was specified via the command line ({@link SystemProperties})
254254
* then that property is used. Otherwise return the appname.
255255
*
256-
* @return Returns the Cloud Foundry application url. Returns null in case
257-
* the target url cannot be used to determine a suitable default.
256+
* @return Returns the Cloud Foundry application url.
258257
*/
259258
public String getUrl() {
260259

261260
final String property = getCommandlineProperty(SystemProperties.URL);
262261

263262
if (property != null) {
264263
return property;
265-
}
266-
else if (this.url == null && this.urls == null) {
267-
if (getTarget() != null) {
268-
269-
final URI targetUri = getTarget();
270-
final String[] tokenizedTarget = targetUri.getSchemeSpecificPart().split("\\.");
271-
272-
if (tokenizedTarget.length >=2) {
273-
274-
String domain = tokenizedTarget[tokenizedTarget.length-2];
275-
276-
if (domain.startsWith("//")) {
277-
domain = domain.substring(2);
278-
}
279-
280-
return getAppname() + "." + domain
281-
+ "." + tokenizedTarget[tokenizedTarget.length-1];
282-
} else {
283-
getLog().warn(String.format("Unable to derive a suitable " +
284-
"Url from the provided Target Url '%s'", targetUri.toString()));
285-
return null;
286-
}
287-
288-
} else {
289-
return getAppname() + "." + "<undefined target>";
290-
}
291264
} else {
292265
return this.url;
293266
}
267+
294268
}
295269

296270
/**
@@ -754,18 +728,16 @@ private int getInstanceCount(List<InstanceInfo> instances, InstanceState state)
754728
}
755729

756730
protected List<String> getAllUris() throws MojoExecutionException {
757-
final List<String> uris = new ArrayList<String>(0);
758-
759731
Assert.configurationUrls(getUrl(), getUrls());
760732

761733
if (getUrl() != null) {
762-
uris.add(getUrl());
734+
return Arrays.asList(getUrl());
763735
} else if (!getUrls().isEmpty()) {
764-
for (String uri : getUrls()) {
765-
uris.add(uri);
766-
}
736+
return getUrls();
737+
} else {
738+
String defaultUri = getAppname() + "." + getClient().getDefaultDomain().getName();
739+
return Arrays.asList(defaultUri);
767740
}
768-
return uris;
769741
}
770742

771743
private long getAppStartupExpiry() {

0 commit comments

Comments
 (0)