diff --git a/server/src/main/java/com/defold/extender/Extender.java b/server/src/main/java/com/defold/extender/Extender.java index 73f0f865..c8db80e0 100644 --- a/server/src/main/java/com/defold/extender/Extender.java +++ b/server/src/main/java/com/defold/extender/Extender.java @@ -645,7 +645,7 @@ private List buildJava(File rJar) throws ExtenderException { Map manifestContext = new HashMap<>(); if (manifestConfig.platforms != null) { - manifestContext = getManifestContext(manifestConfig); + manifestContext = getManifestContext(platform, config, manifestConfig); } this.manifestValidator.validate(manifestConfig.name, manifestContext); @@ -665,8 +665,8 @@ private List buildJava(File rJar) throws ExtenderException { return builtJars; } - private Map getManifestContext(ManifestConfiguration manifestConfig) throws ExtenderException { - ManifestPlatformConfig manifestPlatformConfig = manifestConfig.platforms.get(this.platform); + public static Map getManifestContext(String platform, Configuration config, ManifestConfiguration manifestConfig) throws ExtenderException { + ManifestPlatformConfig manifestPlatformConfig = manifestConfig.platforms.get(platform); // Check that the manifest only contains valid platforms Set allowedPlatforms = config.platforms.keySet(); @@ -676,7 +676,7 @@ private Map getManifestContext(ManifestConfiguration manifestCon throw new ExtenderException(String.format("Extension %s contains invalid platform(s): %s. Allowed platforms: %s", manifestConfig.name, manifestPlatforms.toString(), allowedPlatforms.toString())); } - if (manifestPlatformConfig != null) { + if (manifestPlatformConfig != null && manifestPlatformConfig.context != null) { return manifestPlatformConfig.context; } return new HashMap<>(); @@ -749,7 +749,7 @@ private File buildEngine() throws ExtenderException { Map manifestContext = new HashMap<>(); if (manifestConfig.platforms != null) { - manifestContext = getManifestContext(manifestConfig); + manifestContext = getManifestContext(platform, config, manifestConfig); } String relativePath = ExtenderUtil.getRelativePath(this.uploadDirectory, manifest); diff --git a/server/src/main/java/com/defold/extender/ExtenderUtil.java b/server/src/main/java/com/defold/extender/ExtenderUtil.java index 7a5ec037..a71f0943 100644 --- a/server/src/main/java/com/defold/extender/ExtenderUtil.java +++ b/server/src/main/java/com/defold/extender/ExtenderUtil.java @@ -132,7 +132,7 @@ public boolean accept(File file) { public static Map getAppManifestContext(AppManifestConfiguration manifest, String platform) throws ExtenderException { Map appManifestContext = new HashMap<>(); - if( manifest == null ) + if (manifest == null || manifest.platforms == null) return appManifestContext; if (manifest.platforms.containsKey("common")) { diff --git a/server/src/test/java/com/defold/extender/ExtenderTest.java b/server/src/test/java/com/defold/extender/ExtenderTest.java index cbdaf3d0..4c4c66a8 100644 --- a/server/src/test/java/com/defold/extender/ExtenderTest.java +++ b/server/src/test/java/com/defold/extender/ExtenderTest.java @@ -379,7 +379,7 @@ public void testCollectJsFiles() { public void testExcludeItems() throws IOException, InterruptedException, ExtenderException { File root = new File("test-data"); - File appManifestFile = new File("test-data/extendertest.app.manifest"); + File appManifestFile = new File("test-data/extendertest.appmanifest"); AppManifestConfiguration appManifest = Extender.loadYaml(root, appManifestFile, AppManifestConfiguration.class); @@ -450,10 +450,10 @@ public void testExcludeItems() throws IOException, InterruptedException, Extende } } @Test - public void testAppManifestContext() throws IOException, InterruptedException, ExtenderException { + public void testAppManifestContext() throws IOException, ExtenderException { File root = new File("test-data"); - File appManifestFile = new File("test-data/extendertest.app.manifest"); + File appManifestFile = new File("test-data/extendertest.appmanifest"); AppManifestConfiguration appManifest = Extender.loadYaml(root, appManifestFile, AppManifestConfiguration.class); @@ -468,4 +468,23 @@ public void testAppManifestContext() throws IOException, InterruptedException, E assertEquals( expectedItems, context.get("flags") ); } + @Test + public void testGetAppmanifest() throws IOException, ExtenderException { + File root = new File("test-data"); + + AppManifestConfiguration appManifest = Extender.loadYaml(root, new File("test-data/extendertest.platformnull.appmanifest"), AppManifestConfiguration.class); + // previous issue was that it threw a null pointer exception + ExtenderUtil.getAppManifestContext(appManifest, "x86_64-osx"); + } + + @Test + public void testGetManifestContext() throws IOException, ExtenderException { + File root = new File("test-data"); + Configuration config = Extender.loadYaml(root, new File("test-data/sdk/a/defoldsdk/extender/build.yml"), Configuration.class); + + ManifestConfiguration manifestConfig = Extender.loadYaml(root, new File("test-data/extendertest.emptycontext.manifest"), ManifestConfiguration.class); + // previous issue was that it returned a null pointer + Map manifestContext = Extender.getManifestContext("x86_64-osx", config, manifestConfig); + assertNotEquals(null, manifestContext); + } } diff --git a/server/test-data/extendertest.app.manifest b/server/test-data/extendertest.appmanifest similarity index 100% rename from server/test-data/extendertest.app.manifest rename to server/test-data/extendertest.appmanifest diff --git a/server/test-data/extendertest.emptycontext.manifest b/server/test-data/extendertest.emptycontext.manifest new file mode 100755 index 00000000..42d9f1ec --- /dev/null +++ b/server/test-data/extendertest.emptycontext.manifest @@ -0,0 +1,5 @@ +# Leaving the context empty will leave a null pointer +platforms: + x86_64-osx: + context: + diff --git a/server/test-data/extendertest.platformnull.appmanifest b/server/test-data/extendertest.platformnull.appmanifest new file mode 100755 index 00000000..fa7fa908 --- /dev/null +++ b/server/test-data/extendertest.platformnull.appmanifest @@ -0,0 +1,2 @@ +# By leaving the value empty, it will become null +platforms: \ No newline at end of file