Skip to content

Commit 7c85333

Browse files
committed
Relative Paths in Manifest
In a previous change relative paths in manifests were lost. This change reinstates them. Signed-off-by: Ben Hale <[email protected]>
1 parent 7d15d82 commit 7c85333

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtils.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.Writer;
2929
import java.nio.file.Files;
3030
import java.nio.file.Path;
31-
import java.nio.file.Paths;
3231
import java.nio.file.StandardOpenOption;
3332
import java.util.Arrays;
3433
import java.util.Collections;
@@ -227,14 +226,14 @@ private static Map<String, Object> deserialize(Path path) {
227226
private static List<ApplicationManifest> doRead(Path path) {
228227
Map<String, Object> root = deserialize(path);
229228

230-
ApplicationManifest template = getTemplate(root);
229+
ApplicationManifest template = getTemplate(path, root);
231230

232231
return Optional.ofNullable(root.get("applications"))
233232
.map(value -> ((List<Map<String, Object>>) value).stream())
234233
.orElseGet(Stream::empty)
235234
.map(application -> {
236235
String name = getName(application);
237-
return toApplicationManifest(application, ApplicationManifest.builder().from(template))
236+
return toApplicationManifest(application, ApplicationManifest.builder().from(template), path)
238237
.name(name)
239238
.build();
240239
})
@@ -266,8 +265,8 @@ private static Route getRoute(Map<String, Object> raw) {
266265
return Route.builder().route(route).build();
267266
}
268267

269-
private static ApplicationManifest getTemplate(Map<String, Object> root) {
270-
return toApplicationManifest(root, ApplicationManifest.builder())
268+
private static ApplicationManifest getTemplate(Path path, Map<String, Object> root) {
269+
return toApplicationManifest(root, ApplicationManifest.builder(), path)
271270
.name("template")
272271
.build();
273272
}
@@ -323,7 +322,7 @@ private static <T> void putIfPresent(Map<String, Object> yaml, String key, T val
323322
}
324323

325324
@SuppressWarnings("unchecked")
326-
private static ApplicationManifest.Builder toApplicationManifest(Map<String, Object> application, ApplicationManifest.Builder builder) {
325+
private static ApplicationManifest.Builder toApplicationManifest(Map<String, Object> application, ApplicationManifest.Builder builder, Path root) {
327326
asString(application, "buildpack", builder::buildpack);
328327
asString(application, "command", builder::command);
329328
asMemoryInteger(application, "disk_quota", builder::disk);
@@ -340,7 +339,7 @@ private static ApplicationManifest.Builder toApplicationManifest(Map<String, Obj
340339
asString(application, "name", builder::name);
341340
asBoolean(application, "no-hostname", builder::noHostname);
342341
asBoolean(application, "no-route", builder::noRoute);
343-
asString(application, "path", path -> builder.path(Paths.get(path)));
342+
asString(application, "path", path -> builder.path(root.getParent().resolve(path)));
344343
asBoolean(application, "random-route", builder::randomRoute);
345344
asList(application, "routes", raw -> getRoute((Map<String, Object>) raw), builder::route);
346345
asListOfString(application, "services", builder::service);

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,21 @@ public void readNoRoute() throws IOException {
458458
ApplicationManifestUtils.read(new ClassPathResource("fixtures/manifest-golf.yml").getFile().toPath());
459459
}
460460

461+
@Test
462+
public void relativePath() throws IOException {
463+
Path root = new ClassPathResource("fixtures/manifest-mike.yml").getFile().toPath();
464+
465+
List<ApplicationManifest> expected = Collections.singletonList(
466+
ApplicationManifest.builder()
467+
.name("alpha-application-1")
468+
.path(root.getParent().resolve("alpha-path"))
469+
.build());
470+
471+
List<ApplicationManifest> actual = ApplicationManifestUtils.read(root);
472+
473+
assertThat(actual).isEqualTo(expected);
474+
}
475+
461476
@Test
462477
public void testDiskQuotaAndMemoryParsing() throws Exception {
463478
List<ApplicationManifest> expected = Arrays.asList(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
applications:
3+
- name: alpha-application-1
4+
path: alpha-path

0 commit comments

Comments
 (0)