From 3c46b3cbf51af9879f4ac33eb3182434815140ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20L=C3=B6thman?= Date: Mon, 19 Jun 2017 11:06:45 +0200 Subject: [PATCH] Make sure that build dir is removed. This makes sure that the build directory is removed even when a "Unsupported platform"-exception happens... --- .../java/com/defold/extender/Extender.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/com/defold/extender/Extender.java b/server/src/main/java/com/defold/extender/Extender.java index 7c090070..f753ad32 100644 --- a/server/src/main/java/com/defold/extender/Extender.java +++ b/server/src/main/java/com/defold/extender/Extender.java @@ -37,9 +37,9 @@ class Extender { private List extDirs = new ArrayList<>(); private List manifests = new ArrayList<>(); - public static final String FRAMEWORK_RE = "(.+)\\.framework"; - public static final String JAR_RE = "(.+\\.jar)"; - public static final String JS_RE = "(.+\\.js)"; + static final String FRAMEWORK_RE = "(.+)\\.framework"; + static final String JAR_RE = "(.+\\.jar)"; + static final String JS_RE = "(.+\\.js)"; private static final String ANDROID_NDK_PATH = System.getenv("ANDROID_NDK_PATH"); private static final String ANDROID_NDK_INCLUDE_PATH = System.getenv("ANDROID_NDK_INCLUDE"); @@ -71,16 +71,12 @@ class Extender { this.platform = platform; this.sdk = sdk; - this.platformConfig = config.platforms.get(platform); + this.platformConfig = getPlatformConfig(); Path buildPath = Paths.get(buildDirectory); Files.createDirectories(buildPath); this.build = Files.createTempDirectory(buildPath, "build").toFile(); - if (this.platformConfig == null) { - throw new ExtenderException(String.format("Unsupported platform %s", platform)); - } - this.manifestValidator = new ExtensionManifestValidator(new WhitelistConfig(), this.platformConfig.allowedFlags, this.platformConfig.allowedLibs); // Collect extension directories (used by both buildEngine and buildClassesDex) @@ -88,6 +84,16 @@ class Extender { this.extDirs = this.manifests.stream().map(File::getParentFile).collect(Collectors.toList()); } + private PlatformConfig getPlatformConfig() throws ExtenderException { + PlatformConfig platformConfig = config.platforms.get(platform); + + if (platformConfig == null) { + throw new ExtenderException(String.format("Unsupported platform %s", platform)); + } + + return platformConfig; + } + // Does a regexp match on the filename for each file found in a directory static List collectFilesByName(File dir, String re) { List libs = new ArrayList<>(); @@ -148,7 +154,7 @@ static T loadYaml(File root, File manifest, Class type) throws IOExceptio try { return new Yaml().loadAs(yaml, type); } catch(YAMLException e) { - throw new ExtenderException(String.format("Error in file '%s': %s", ExtenderUtil.getRelativePath(root, manifest).toString(), e.toString())); + throw new ExtenderException(String.format("Error in file '%s': %s", ExtenderUtil.getRelativePath(root, manifest), e.toString())); } } @@ -299,7 +305,7 @@ private File compileMain(File maincpp, Map manifestContext) thro return o; } - private File buildExtension(File manifest, Map manifestContext) throws IOException, InterruptedException, ExtenderException { + private void buildExtension(File manifest, Map manifestContext) throws IOException, InterruptedException, ExtenderException { File extDir = manifest.getParentFile(); File srcDir = new File(extDir, "src"); Collection srcFiles = new ArrayList<>(); @@ -329,7 +335,6 @@ private File buildExtension(File manifest, Map manifestContext) context.put("objs", objs); String command = templateExecutor.execute(platformConfig.libCmd, context); processExecutor.execute(command); - return lib; } static List getAppManifestItems(AppManifestConfiguration manifest, String platform, String name) throws ExtenderException { @@ -432,7 +437,7 @@ private File linkEngine(List symbols, Map manifestContex return exe; } - public File buildRJar() throws ExtenderException { + private File buildRJar() throws ExtenderException { try { File rJavaDir = new File(extensionSource, "_app/rjava/"); if (rJavaDir.exists() && rJavaDir.isDirectory()) { @@ -492,7 +497,7 @@ public File buildRJar() throws ExtenderException { return null; } - public File buildJavaExtension(File manifest, Map manifestContext, File rJar) throws ExtenderException { + private File buildJavaExtension(File manifest, Map manifestContext, File rJar) throws ExtenderException { if (platformConfig.javaSourceRe == null || platformConfig.javacCmd == null || platformConfig.jarCmd == null) { return null; @@ -571,7 +576,7 @@ public File buildJavaExtension(File manifest, Map manifestContex } } - public List buildJava(File rJar) throws ExtenderException { + private List buildJava(File rJar) throws ExtenderException { List builtJars = new ArrayList<>(); if (rJar != null) { builtJars.add(rJar); @@ -621,7 +626,7 @@ private Map getManifestContext(ManifestConfiguration manifestCon return new HashMap<>(); } - public File buildClassesDex(List extraJars) throws ExtenderException { + private File buildClassesDex(List extraJars) throws ExtenderException { LOGGER.info("Building classes.dex with extension source {}", extensionSource); // To support older versions of build.yml where dxCmd is not defined: @@ -655,7 +660,7 @@ public File buildClassesDex(List extraJars) throws ExtenderException { return classesDex; } - File buildEngine() throws ExtenderException { + private File buildEngine() throws ExtenderException { LOGGER.info("Building engine for platform {} with extension source {}", platform, extensionSource); try {