1
1
package processing .app .packages ;
2
2
3
- import static processing .app .helpers .StringMatchers . wildcardMatch ;
3
+ import processing .app .helpers .PreferencesMap ;
4
4
5
5
import java .io .File ;
6
6
import java .io .IOException ;
9
9
import java .util .Comparator ;
10
10
import java .util .List ;
11
11
12
- import processing .app .helpers .PreferencesMap ;
12
+ import static processing .app .helpers .StringMatchers . wildcardMatch ;
13
13
14
14
public class Library {
15
15
@@ -39,11 +39,11 @@ public class Library {
39
39
* Scans inside a folder and create a Library object out of it. Automatically
40
40
* detects pre-1.5 libraries. Automatically fills metadata from
41
41
* library.properties file if found.
42
- *
42
+ *
43
43
* @param libFolder
44
44
* @return
45
45
*/
46
- static public Library create (File libFolder ) {
46
+ static public Library create (File libFolder ) throws IOException {
47
47
// A library is considered "new" if it contains a file called
48
48
// "library.properties"
49
49
File check = new File (libFolder , "library.properties" );
@@ -53,42 +53,53 @@ static public Library create(File libFolder) {
53
53
return createLibrary (libFolder );
54
54
}
55
55
56
- private static Library createLibrary (File libFolder ) {
56
+ private static Library createLibrary (File libFolder ) throws IOException {
57
57
// Parse metadata
58
58
File propertiesFile = new File (libFolder , "library.properties" );
59
59
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 );
66
61
67
62
// Library sanity checks
68
63
// ---------------------
69
64
70
65
// 1. Check mandatory properties
71
66
for (String p : MANDATORY_PROPERTIES )
72
67
if (!properties .containsKey (p ))
73
- return null ;
68
+ throw new IOException ( "Missing '" + p + "' from library" ) ;
74
69
75
70
// 2. Check mandatory folders
76
71
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" ) ;
79
74
80
75
// 3. check if root folder contains prohibited stuff
81
76
for (File file : libFolder .listFiles ()) {
82
77
if (file .isDirectory ()) {
83
78
if (!OPTIONAL_FOLDERS .contains (file .getName ()))
84
- return null ;
79
+ throw new IOException ( "Invalid folder '" + file . getName () + "'." ) ;
85
80
} else {
86
81
if (!OPTIONAL_FILES .contains (file .getName ()))
87
- return null ;
82
+ throw new IOException ( "Invalid file '" + file . getName () + "'." ) ;
88
83
}
89
84
}
90
85
91
86
// 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
+
92
103
Library res = new Library ();
93
104
res .folder = libFolder ;
94
105
res .srcFolder = srcFolder ;
@@ -99,18 +110,9 @@ private static Library createLibrary(File libFolder) {
99
110
res .sentence = properties .get ("sentence" ).trim ();
100
111
res .paragraph = properties .get ("paragraph" ).trim ();
101
112
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 ());
105
113
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 ());
113
114
res .coreDependencies = coreDeps ;
115
+ res .dependencies = dependencies ;
114
116
res .version = properties .get ("version" ).trim ();
115
117
res .pre15Lib = false ;
116
118
return res ;
@@ -122,7 +124,7 @@ private static Library createPre15Library(File libFolder) {
122
124
res .folder = libFolder ;
123
125
res .srcFolder = libFolder ;
124
126
res .name = libFolder .getName ();
125
- res .architectures = Arrays .asList (new String [] { "*" });
127
+ res .architectures = Arrays .asList (new String []{ "*" });
126
128
res .pre15Lib = true ;
127
129
return res ;
128
130
}
0 commit comments