Skip to content

Commit 83bea65

Browse files
author
Federico Fissore
committed
Library: converted nulls to checked exceptions, removed printStackTrace, added "dependencies" member
1 parent 8062e30 commit 83bea65

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

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

Lines changed: 28 additions & 19 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

@@ -18,16 +18,17 @@ public class Library {
1818
private File folder, srcFolder;
1919
private List<String> architectures;
2020
private boolean pre15Lib;
21+
private List<String> dependencies;
2122

2223
/**
2324
* Scans inside a folder and create a Library object out of it. Automatically
2425
* detects pre-1.5 libraries. Automatically fills metadata from
2526
* library.properties file if found.
26-
*
27+
*
2728
* @param libFolder
2829
* @return
2930
*/
30-
static public Library create(File libFolder) {
31+
static public Library create(File libFolder) throws IOException {
3132
// A library is considered "new" if it contains a file called
3233
// "library.properties"
3334
File check = new File(libFolder, "library.properties");
@@ -37,46 +38,50 @@ static public Library create(File libFolder) {
3738
return createLibrary(libFolder);
3839
}
3940

40-
private static Library createLibrary(File libFolder) {
41+
private static Library createLibrary(File libFolder) throws IOException {
4142
// Parse metadata
4243
File propertiesFile = new File(libFolder, "library.properties");
4344
PreferencesMap properties = new PreferencesMap();
44-
try {
45-
properties.load(propertiesFile);
46-
} catch (IOException e) {
47-
e.printStackTrace();
48-
return null;
49-
}
45+
properties.load(propertiesFile);
5046

5147
// Library sanity checks
5248
// ---------------------
5349

5450
// 1. Check mandatory properties
5551
if (!properties.containsKey("name"))
56-
return null;
52+
throw new IOException("Missing 'name' from library");
5753
if (!properties.containsKey("version"))
58-
return null;
54+
throw new IOException("Missing 'version' from library");
5955
if (!properties.containsKey("architectures"))
60-
return null;
56+
throw new IOException("Missing 'architectures' from library");
6157

6258
// 2. Check mandatory folders
6359
File srcFolder = new File(libFolder, "src");
64-
if (!srcFolder.exists() && !srcFolder.isDirectory())
65-
return null;
66-
60+
if (!srcFolder.exists() || !srcFolder.isDirectory())
61+
throw new IOException("Missing 'src' folder");
62+
6763
// TODO: 3. check if root folder contains prohibited stuff
68-
64+
6965
// Extract metadata info
7066
// TODO: do for all metadata
7167
List<String> archs = new ArrayList<String>();
7268
for (String arch : properties.get("architectures").split(","))
7369
archs.add(arch.trim());
7470

71+
List<String> dependencies = new ArrayList<String>();
72+
for (String dependency : properties.get("dependencies").split(",")) {
73+
dependency = dependency.trim();
74+
if (!dependency.equals("")) {
75+
dependencies.add(dependency);
76+
}
77+
}
78+
7579
Library res = new Library();
7680
res.folder = libFolder;
7781
res.srcFolder = srcFolder;
7882
res.name = properties.get("name").trim();
7983
res.architectures = archs;
84+
res.dependencies = dependencies;
8085
res.version = properties.get("version").trim();
8186
res.pre15Lib = false;
8287
return res;
@@ -88,7 +93,7 @@ private static Library createPre15Library(File libFolder) {
8893
res.folder = libFolder;
8994
res.srcFolder = libFolder;
9095
res.name = libFolder.getName();
91-
res.architectures = Arrays.asList(new String[] { "*" });
96+
res.architectures = Arrays.asList(new String[]{"*"});
9297
res.pre15Lib = true;
9398
return res;
9499
}
@@ -133,4 +138,8 @@ public boolean isPre15Lib() {
133138
public File getFolder() {
134139
return folder;
135140
}
141+
142+
public List<String> getDependencies() {
143+
return dependencies;
144+
}
136145
}

0 commit comments

Comments
 (0)