1
1
package processing .app .packages ;
2
2
3
- import static processing .app .helpers .StringUtils .wildcardMatch ;
4
-
5
3
import java .io .File ;
6
4
import java .io .IOException ;
7
5
import java .util .ArrayList ;
@@ -17,24 +15,30 @@ public class Library {
17
15
private String name ;
18
16
private String version ;
19
17
private String author ;
20
- private String email ;
21
- private String url ;
18
+ private String maintainer ;
22
19
private String sentence ;
23
20
private String paragraph ;
24
- private List < String > coreDependencies ;
25
- private List < String > dependencies ;
26
- private File folder , srcFolder , archFolder ;
21
+ private String url ;
22
+ private String category ;
23
+ private String license ;
27
24
private List <String > architectures ;
28
- private boolean pre15Lib ;
25
+ private File folder ;
26
+ private File srcFolder ;
27
+ private boolean useRecursion ;
28
+ private boolean isLegacy ;
29
29
30
30
private static final List <String > MANDATORY_PROPERTIES = Arrays
31
- .asList (new String [] { "architectures" , "author" , "core-dependencies" ,
32
- "dependencies" , "email" , "name" , "paragraph" , "sentence" , "url" ,
33
- "version" });
31
+ .asList (new String [] { "name" , "version" , "author" , "maintainer" ,
32
+ "sentence" , "paragraph" , "url" });
33
+
34
+ private static final List <String > CATEGORIES = Arrays .asList (new String [] {
35
+ "Display" , "Communication" , "Signal Input/Output" , "Sensors" ,
36
+ "Device Control" , "Timing" , "Data Storage" , "Data Processing" , "Other" ,
37
+ "Uncategorized" });
34
38
35
39
/**
36
40
* Scans inside a folder and create a Library object out of it. Automatically
37
- * detects pre-1.5 libraries. Automatically fills metadata from
41
+ * detects legacy libraries. Automatically fills metadata from
38
42
* library.properties file if found.
39
43
*
40
44
* @param libFolder
@@ -45,7 +49,7 @@ static public Library create(File libFolder) throws IOException {
45
49
// "library.properties"
46
50
File check = new File (libFolder , "library.properties" );
47
51
if (!check .exists () || !check .isFile ())
48
- return createPre15Library (libFolder );
52
+ return createLegacyLibrary (libFolder );
49
53
else
50
54
return createLibrary (libFolder );
51
55
}
@@ -59,17 +63,43 @@ private static Library createLibrary(File libFolder) throws IOException {
59
63
// Library sanity checks
60
64
// ---------------------
61
65
62
- // 1. Check mandatory properties
66
+ // Compatibility with 1.5 rev.1 libraries:
67
+ // "email" field changed to "maintainer"
68
+ if (!properties .containsKey ("maintainer" ))
69
+ properties .put ("maintainer" , properties .get ("email" ));
70
+
71
+ // Compatibility with 1.5 rev.1 libraries:
72
+ // "arch" folder no longer supported
73
+ File archFolder = new File (libFolder , "arch" );
74
+ if (archFolder .isDirectory ())
75
+ throw new IOException ("'arch' folder is no longer supported! See "
76
+ + "http://goo.gl/gfFJzU for more information" );
77
+
78
+ // Check mandatory properties
63
79
for (String p : MANDATORY_PROPERTIES )
64
80
if (!properties .containsKey (p ))
65
81
throw new IOException ("Missing '" + p + "' from library" );
66
82
67
- // 2. Check mandatory folders
83
+ // Check layout
84
+ boolean useRecursion ;
68
85
File srcFolder = new File (libFolder , "src" );
69
- if (!srcFolder .exists () || !srcFolder .isDirectory ())
70
- throw new IOException ("Missing 'src' folder" );
71
86
72
- // 3. Warn if root folder contains development leftovers
87
+ if (srcFolder .exists () && srcFolder .isDirectory ()) {
88
+ // Layout with a single "src" folder and recursive compilation
89
+ useRecursion = true ;
90
+
91
+ File utilFolder = new File (libFolder , "utility" );
92
+ if (utilFolder .exists () && utilFolder .isDirectory ()) {
93
+ throw new IOException (
94
+ "Library can't use both 'src' and 'utility' folders." );
95
+ }
96
+ } else {
97
+ // Layout with source code on library's root and "utility" folders
98
+ srcFolder = libFolder ;
99
+ useRecursion = false ;
100
+ }
101
+
102
+ // Warn if root folder contains development leftovers
73
103
for (File file : libFolder .listFiles ()) {
74
104
if (file .isDirectory ()) {
75
105
if (FileUtils .isSCCSOrHiddenFile (file )) {
@@ -81,71 +111,77 @@ private static Library createLibrary(File libFolder) throws IOException {
81
111
}
82
112
83
113
// Extract metadata info
114
+ String architectures = properties .get ("architectures" );
115
+ if (architectures == null )
116
+ architectures = "*" ; // defaults to "any"
84
117
List <String > archs = new ArrayList <String >();
85
- for (String arch : properties . get ( " architectures" ) .split ("," ))
118
+ for (String arch : architectures .split ("," ))
86
119
archs .add (arch .trim ());
87
120
88
- List <String > coreDeps = new ArrayList <String >();
89
- for (String dep : properties .get ("core-dependencies" ).split ("," ))
90
- coreDeps .add (dep .trim ());
121
+ String category = properties .get ("category" );
122
+ if (category == null )
123
+ category = "Uncategorized" ;
124
+ if (!CATEGORIES .contains (category ))
125
+ category = "Uncategorized" ;
91
126
92
- List <String > dependencies = new ArrayList <String >();
93
- for (String dependency : properties .get ("dependencies" ).split ("," )) {
94
- dependency = dependency .trim ();
95
- if (!dependency .equals ("" )) {
96
- dependencies .add (dependency );
97
- }
98
- }
127
+ String license = properties .get ("license" );
128
+ if (license == null )
129
+ license = "Unspecified" ;
99
130
100
131
Library res = new Library ();
101
132
res .folder = libFolder ;
102
133
res .srcFolder = srcFolder ;
103
- res .archFolder = new File (libFolder , "arch" );
104
134
res .name = properties .get ("name" ).trim ();
135
+ res .version = properties .get ("version" ).trim ();
105
136
res .author = properties .get ("author" ).trim ();
106
- res .email = properties .get ("email " ).trim ();
137
+ res .maintainer = properties .get ("maintainer " ).trim ();
107
138
res .sentence = properties .get ("sentence" ).trim ();
108
139
res .paragraph = properties .get ("paragraph" ).trim ();
109
140
res .url = properties .get ("url" ).trim ();
141
+ res .category = category .trim ();
142
+ res .license = license .trim ();
110
143
res .architectures = archs ;
111
- res .coreDependencies = coreDeps ;
112
- res .dependencies = dependencies ;
113
- res .version = properties .get ("version" ).trim ();
114
- res .pre15Lib = false ;
144
+ res .useRecursion = useRecursion ;
145
+ res .isLegacy = false ;
115
146
return res ;
116
147
}
117
148
118
- private static Library createPre15Library (File libFolder ) {
149
+ private static Library createLegacyLibrary (File libFolder ) {
119
150
// construct an old style library
120
151
Library res = new Library ();
121
152
res .folder = libFolder ;
122
153
res .srcFolder = libFolder ;
154
+ res .useRecursion = false ;
123
155
res .name = libFolder .getName ();
124
156
res .architectures = Arrays .asList ("*" );
125
- res .pre15Lib = true ;
157
+ res .isLegacy = true ;
126
158
return res ;
127
159
}
128
160
129
- public List <File > getSrcFolders (String reqArch ) {
130
- if (!supportsArchitecture (reqArch ))
131
- return null ;
132
- List <File > res = new ArrayList <File >();
133
- res .add (srcFolder );
134
- File archSpecificFolder = new File (archFolder , reqArch );
135
- if (archSpecificFolder .exists () && archSpecificFolder .isDirectory ()) {
136
- res .add (archSpecificFolder );
137
- } else {
138
- // If specific architecture folder is not found try with "default"
139
- archSpecificFolder = new File (archFolder , "default" );
140
- if (archSpecificFolder .exists () && archSpecificFolder .isDirectory ())
141
- res .add (archSpecificFolder );
142
- }
143
- return res ;
161
+ /**
162
+ * Returns <b>true</b> if the library declares to support the specified
163
+ * architecture (through the "architectures" property field).
164
+ *
165
+ * @param reqArch
166
+ * @return
167
+ */
168
+ public boolean supportsArchitecture (String reqArch ) {
169
+ return architectures .contains (reqArch ) || architectures .contains ("*" );
144
170
}
145
171
146
- public boolean supportsArchitecture (String reqArch ) {
147
- for (String arch : architectures )
148
- if (wildcardMatch (reqArch , arch ))
172
+ /**
173
+ * Returns <b>true</b> if the library declares to support at least one of the
174
+ * specified architectures.
175
+ *
176
+ * @param reqArchs
177
+ * A List of architectures to check
178
+ * @return
179
+ */
180
+ public boolean supportsArchitecture (List <String > reqArchs ) {
181
+ if (reqArchs .contains ("*" ))
182
+ return true ;
183
+ for (String reqArch : reqArchs )
184
+ if (supportsArchitecture (reqArch ))
149
185
return true ;
150
186
return false ;
151
187
}
@@ -157,18 +193,10 @@ public int compare(Library o1, Library o2) {
157
193
}
158
194
};
159
195
160
- public File getSrcFolder () {
161
- return srcFolder ;
162
- }
163
-
164
196
public String getName () {
165
197
return name ;
166
198
}
167
199
168
- public boolean isPre15Lib () {
169
- return pre15Lib ;
170
- }
171
-
172
200
public File getFolder () {
173
201
return folder ;
174
202
}
@@ -181,18 +209,6 @@ public String getAuthor() {
181
209
return author ;
182
210
}
183
211
184
- public List <String > getCoreDependencies () {
185
- return coreDependencies ;
186
- }
187
-
188
- public List <String > getDependencies () {
189
- return dependencies ;
190
- }
191
-
192
- public String getEmail () {
193
- return email ;
194
- }
195
-
196
212
public String getParagraph () {
197
213
return paragraph ;
198
214
}
@@ -205,23 +221,49 @@ public String getUrl() {
205
221
return url ;
206
222
}
207
223
224
+ public String getCategory () {
225
+ return category ;
226
+ }
227
+
228
+ public String getLicense () {
229
+ return license ;
230
+ }
231
+
232
+ public static List <String > getCategories () {
233
+ return CATEGORIES ;
234
+ }
235
+
208
236
public String getVersion () {
209
237
return version ;
210
238
}
211
239
240
+ public String getMaintainer () {
241
+ return maintainer ;
242
+ }
243
+
244
+ public boolean useRecursion () {
245
+ return useRecursion ;
246
+ }
247
+
248
+ public File getSrcFolder () {
249
+ return srcFolder ;
250
+ }
251
+
252
+ public boolean isLegacy () {
253
+ return isLegacy ;
254
+ }
255
+
212
256
@ Override
213
257
public String toString () {
214
258
String res = "Library:" ;
215
259
res += " (name=" + name + ")" ;
216
- res += " (architectures =" + architectures + ")" ;
260
+ res += " (version =" + version + ")" ;
217
261
res += " (author=" + author + ")" ;
218
- res += " (core-dependencies=" + coreDependencies + ")" ;
219
- res += " (dependencies=" + dependencies + ")" ;
220
- res += " (email=" + email + ")" ;
221
- res += " (paragraph=" + paragraph + ")" ;
262
+ res += " (maintainer=" + maintainer + ")" ;
222
263
res += " (sentence=" + sentence + ")" ;
264
+ res += " (paragraph=" + paragraph + ")" ;
223
265
res += " (url=" + url + ")" ;
224
- res += " (version =" + version + ")" ;
266
+ res += " (architectures =" + architectures + ")" ;
225
267
return res ;
226
268
}
227
269
}
0 commit comments