Skip to content

Commit 2a051a7

Browse files
Federico Fissorecmaglie
authored andcommitted
Library: converted nulls to checked exceptions, removed printStackTrace, added "dependencies" member
Conflicts: app/src/processing/app/packages/Library.java
1 parent bddb47e commit 2a051a7

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

app/src/processing/app/packages/Library.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package processing.app.packages;
22

3-
import static processing.app.helpers.StringMatchers.wildcardMatch;
3+
import processing.app.helpers.PreferencesMap;
44

55
import java.io.File;
66
import java.io.IOException;
@@ -9,7 +9,7 @@
99
import java.util.Comparator;
1010
import java.util.List;
1111

12-
import processing.app.helpers.PreferencesMap;
12+
import static processing.app.helpers.StringMatchers.wildcardMatch;
1313

1414
public class Library {
1515

@@ -39,11 +39,11 @@ public class Library {
3939
* Scans inside a folder and create a Library object out of it. Automatically
4040
* detects pre-1.5 libraries. Automatically fills metadata from
4141
* library.properties file if found.
42-
*
42+
*
4343
* @param libFolder
4444
* @return
4545
*/
46-
static public Library create(File libFolder) {
46+
static public Library create(File libFolder) throws IOException {
4747
// A library is considered "new" if it contains a file called
4848
// "library.properties"
4949
File check = new File(libFolder, "library.properties");
@@ -53,42 +53,53 @@ static public Library create(File libFolder) {
5353
return createLibrary(libFolder);
5454
}
5555

56-
private static Library createLibrary(File libFolder) {
56+
private static Library createLibrary(File libFolder) throws IOException {
5757
// Parse metadata
5858
File propertiesFile = new File(libFolder, "library.properties");
5959
PreferencesMap properties = new PreferencesMap();
60-
try {
61-
properties.load(propertiesFile);
62-
} catch (IOException e) {
63-
e.printStackTrace();
64-
return null;
65-
}
60+
properties.load(propertiesFile);
6661

6762
// Library sanity checks
6863
// ---------------------
6964

7065
// 1. Check mandatory properties
7166
for (String p : MANDATORY_PROPERTIES)
7267
if (!properties.containsKey(p))
73-
return null;
68+
throw new IOException("Missing '" + p + "' from library");
7469

7570
// 2. Check mandatory folders
7671
File srcFolder = new File(libFolder, "src");
77-
if (!srcFolder.exists() && !srcFolder.isDirectory())
78-
return null;
72+
if (!srcFolder.exists() || !srcFolder.isDirectory())
73+
throw new IOException("Missing 'src' folder");
7974

8075
// 3. check if root folder contains prohibited stuff
8176
for (File file : libFolder.listFiles()) {
8277
if (file.isDirectory()) {
8378
if (!OPTIONAL_FOLDERS.contains(file.getName()))
84-
return null;
79+
throw new IOException("Invalid folder '" + file.getName() + "'.");
8580
} else {
8681
if (!OPTIONAL_FILES.contains(file.getName()))
87-
return null;
82+
throw new IOException("Invalid file '" + file.getName() + "'.");
8883
}
8984
}
9085

9186
// Extract metadata info
87+
List<String> archs = new ArrayList<String>();
88+
for (String arch : properties.get("architectures").split(","))
89+
archs.add(arch.trim());
90+
91+
List<String> coreDeps = new ArrayList<String>();
92+
for (String dep : properties.get("core-dependencies").split(","))
93+
coreDeps.add(dep.trim());
94+
95+
List<String> dependencies = new ArrayList<String>();
96+
for (String dependency : properties.get("dependencies").split(",")) {
97+
dependency = dependency.trim();
98+
if (!dependency.equals("")) {
99+
dependencies.add(dependency);
100+
}
101+
}
102+
92103
Library res = new Library();
93104
res.folder = libFolder;
94105
res.srcFolder = srcFolder;
@@ -99,18 +110,9 @@ private static Library createLibrary(File libFolder) {
99110
res.sentence = properties.get("sentence").trim();
100111
res.paragraph = properties.get("paragraph").trim();
101112
res.url = properties.get("url").trim();
102-
List<String> archs = new ArrayList<String>();
103-
for (String arch : properties.get("architectures").split(","))
104-
archs.add(arch.trim());
105113
res.architectures = archs;
106-
List<String> deps = new ArrayList<String>();
107-
for (String dep : properties.get("dependencies").split(","))
108-
deps.add(dep.trim());
109-
res.dependencies = deps;
110-
List<String> coreDeps = new ArrayList<String>();
111-
for (String dep : properties.get("core-dependencies").split(","))
112-
coreDeps.add(dep.trim());
113114
res.coreDependencies = coreDeps;
115+
res.dependencies = dependencies;
114116
res.version = properties.get("version").trim();
115117
res.pre15Lib = false;
116118
return res;
@@ -122,7 +124,7 @@ private static Library createPre15Library(File libFolder) {
122124
res.folder = libFolder;
123125
res.srcFolder = libFolder;
124126
res.name = libFolder.getName();
125-
res.architectures = Arrays.asList(new String[] { "*" });
127+
res.architectures = Arrays.asList(new String[]{"*"});
126128
res.pre15Lib = true;
127129
return res;
128130
}

0 commit comments

Comments
 (0)