From a6013720e5d2222a08956a09be6b60668862687f Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Jul 2014 15:22:49 +0200 Subject: [PATCH] Explicitely store a layout type for a library Previously, the useRecursion and srcFolders were filled on library creation, based on the existence of the src folder. Now, a layout variable is set, and the useRecursion() and getSrcFolder() methods change their return value based on the layout in use. --- app/src/processing/app/packages/Library.java | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/processing/app/packages/Library.java b/app/src/processing/app/packages/Library.java index 9c505fe4e..bf69c4edd 100644 --- a/app/src/processing/app/packages/Library.java +++ b/app/src/processing/app/packages/Library.java @@ -23,10 +23,11 @@ public class Library { private String license; private List architectures; private File folder; - private File srcFolder; - private boolean useRecursion; private boolean isLegacy; + private enum LibraryLayout { FLAT, RECURSIVE }; + private LibraryLayout layout; + private static final List MANDATORY_PROPERTIES = Arrays .asList(new String[] { "name", "version", "author", "maintainer", "sentence", "paragraph", "url" }); @@ -82,12 +83,12 @@ public class Library { throw new IOException("Missing '" + p + "' from library"); // Check layout - boolean useRecursion; + LibraryLayout layout; File srcFolder = new File(libFolder, "src"); if (srcFolder.exists() && srcFolder.isDirectory()) { // Layout with a single "src" folder and recursive compilation - useRecursion = true; + layout = LibraryLayout.RECURSIVE; File utilFolder = new File(libFolder, "utility"); if (utilFolder.exists() && utilFolder.isDirectory()) { @@ -96,8 +97,7 @@ public class Library { } } else { // Layout with source code on library's root and "utility" folders - srcFolder = libFolder; - useRecursion = false; + layout = LibraryLayout.FLAT; } // Warn if root folder contains development leftovers @@ -134,7 +134,6 @@ public class Library { Library res = new Library(); res.folder = libFolder; - res.srcFolder = srcFolder; res.name = properties.get("name").trim(); res.version = properties.get("version").trim(); res.author = properties.get("author").trim(); @@ -145,8 +144,8 @@ public class Library { res.category = category.trim(); res.license = license.trim(); res.architectures = archs; - res.useRecursion = useRecursion; res.isLegacy = false; + res.layout = layout; return res; } @@ -154,8 +153,7 @@ public class Library { // construct an old style library Library res = new Library(); res.folder = libFolder; - res.srcFolder = libFolder; - res.useRecursion = false; + res.layout = LibraryLayout.FLAT; res.name = libFolder.getName(); res.architectures = Arrays.asList("*"); res.isLegacy = true; @@ -246,11 +244,18 @@ public class Library { } public boolean useRecursion() { - return useRecursion; + return (layout == LibraryLayout.RECURSIVE); } public File getSrcFolder() { - return srcFolder; + switch (layout) { + case FLAT: + return folder; + case RECURSIVE: + return new File(folder, "src"); + default: + return null; // Keep compiler happy :-( + } } public boolean isLegacy() {