11package processing .app .packages ;
22
3- import static processing .app .helpers .StringUtils .wildcardMatch ;
4-
53import java .io .File ;
64import java .io .IOException ;
75import java .util .ArrayList ;
@@ -17,24 +15,30 @@ public class Library {
1715 private String name ;
1816 private String version ;
1917 private String author ;
20- private String email ;
21- private String url ;
18+ private String maintainer ;
2219 private String sentence ;
2320 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 ;
2724 private List <String > architectures ;
28- private boolean pre15Lib ;
25+ private File folder ;
26+ private File srcFolder ;
27+ private boolean useRecursion ;
28+ private boolean isLegacy ;
2929
3030 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" });
3438
3539 /**
3640 * 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
3842 * library.properties file if found.
3943 *
4044 * @param libFolder
@@ -45,7 +49,7 @@ static public Library create(File libFolder) throws IOException {
4549 // "library.properties"
4650 File check = new File (libFolder , "library.properties" );
4751 if (!check .exists () || !check .isFile ())
48- return createPre15Library (libFolder );
52+ return createLegacyLibrary (libFolder );
4953 else
5054 return createLibrary (libFolder );
5155 }
@@ -59,17 +63,43 @@ private static Library createLibrary(File libFolder) throws IOException {
5963 // Library sanity checks
6064 // ---------------------
6165
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
6379 for (String p : MANDATORY_PROPERTIES )
6480 if (!properties .containsKey (p ))
6581 throw new IOException ("Missing '" + p + "' from library" );
6682
67- // 2. Check mandatory folders
83+ // Check layout
84+ boolean useRecursion ;
6885 File srcFolder = new File (libFolder , "src" );
69- if (!srcFolder .exists () || !srcFolder .isDirectory ())
70- throw new IOException ("Missing 'src' folder" );
7186
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
73103 for (File file : libFolder .listFiles ()) {
74104 if (file .isDirectory ()) {
75105 if (FileUtils .isSCCSOrHiddenFile (file )) {
@@ -81,71 +111,77 @@ private static Library createLibrary(File libFolder) throws IOException {
81111 }
82112
83113 // Extract metadata info
114+ String architectures = properties .get ("architectures" );
115+ if (architectures == null )
116+ architectures = "*" ; // defaults to "any"
84117 List <String > archs = new ArrayList <String >();
85- for (String arch : properties . get ( " architectures" ) .split ("," ))
118+ for (String arch : architectures .split ("," ))
86119 archs .add (arch .trim ());
87120
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" ;
91126
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" ;
99130
100131 Library res = new Library ();
101132 res .folder = libFolder ;
102133 res .srcFolder = srcFolder ;
103- res .archFolder = new File (libFolder , "arch" );
104134 res .name = properties .get ("name" ).trim ();
135+ res .version = properties .get ("version" ).trim ();
105136 res .author = properties .get ("author" ).trim ();
106- res .email = properties .get ("email " ).trim ();
137+ res .maintainer = properties .get ("maintainer " ).trim ();
107138 res .sentence = properties .get ("sentence" ).trim ();
108139 res .paragraph = properties .get ("paragraph" ).trim ();
109140 res .url = properties .get ("url" ).trim ();
141+ res .category = category .trim ();
142+ res .license = license .trim ();
110143 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 ;
115146 return res ;
116147 }
117148
118- private static Library createPre15Library (File libFolder ) {
149+ private static Library createLegacyLibrary (File libFolder ) {
119150 // construct an old style library
120151 Library res = new Library ();
121152 res .folder = libFolder ;
122153 res .srcFolder = libFolder ;
154+ res .useRecursion = false ;
123155 res .name = libFolder .getName ();
124156 res .architectures = Arrays .asList ("*" );
125- res .pre15Lib = true ;
157+ res .isLegacy = true ;
126158 return res ;
127159 }
128160
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 ("*" );
144170 }
145171
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 ))
149185 return true ;
150186 return false ;
151187 }
@@ -157,18 +193,10 @@ public int compare(Library o1, Library o2) {
157193 }
158194 };
159195
160- public File getSrcFolder () {
161- return srcFolder ;
162- }
163-
164196 public String getName () {
165197 return name ;
166198 }
167199
168- public boolean isPre15Lib () {
169- return pre15Lib ;
170- }
171-
172200 public File getFolder () {
173201 return folder ;
174202 }
@@ -181,18 +209,6 @@ public String getAuthor() {
181209 return author ;
182210 }
183211
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-
196212 public String getParagraph () {
197213 return paragraph ;
198214 }
@@ -205,23 +221,49 @@ public String getUrl() {
205221 return url ;
206222 }
207223
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+
208236 public String getVersion () {
209237 return version ;
210238 }
211239
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+
212256 @ Override
213257 public String toString () {
214258 String res = "Library:" ;
215259 res += " (name=" + name + ")" ;
216- res += " (architectures =" + architectures + ")" ;
260+ res += " (version =" + version + ")" ;
217261 res += " (author=" + author + ")" ;
218- res += " (core-dependencies=" + coreDependencies + ")" ;
219- res += " (dependencies=" + dependencies + ")" ;
220- res += " (email=" + email + ")" ;
221- res += " (paragraph=" + paragraph + ")" ;
262+ res += " (maintainer=" + maintainer + ")" ;
222263 res += " (sentence=" + sentence + ")" ;
264+ res += " (paragraph=" + paragraph + ")" ;
223265 res += " (url=" + url + ")" ;
224- res += " (version =" + version + ")" ;
266+ res += " (architectures =" + architectures + ")" ;
225267 return res ;
226268 }
227269}
0 commit comments