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
@@ -18,16 +18,17 @@ public class Library {
18
18
private File folder , srcFolder ;
19
19
private List <String > architectures ;
20
20
private boolean pre15Lib ;
21
+ private List <String > dependencies ;
21
22
22
23
/**
23
24
* Scans inside a folder and create a Library object out of it. Automatically
24
25
* detects pre-1.5 libraries. Automatically fills metadata from
25
26
* library.properties file if found.
26
- *
27
+ *
27
28
* @param libFolder
28
29
* @return
29
30
*/
30
- static public Library create (File libFolder ) {
31
+ static public Library create (File libFolder ) throws IOException {
31
32
// A library is considered "new" if it contains a file called
32
33
// "library.properties"
33
34
File check = new File (libFolder , "library.properties" );
@@ -37,46 +38,50 @@ static public Library create(File libFolder) {
37
38
return createLibrary (libFolder );
38
39
}
39
40
40
- private static Library createLibrary (File libFolder ) {
41
+ private static Library createLibrary (File libFolder ) throws IOException {
41
42
// Parse metadata
42
43
File propertiesFile = new File (libFolder , "library.properties" );
43
44
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 );
50
46
51
47
// Library sanity checks
52
48
// ---------------------
53
49
54
50
// 1. Check mandatory properties
55
51
if (!properties .containsKey ("name" ))
56
- return null ;
52
+ throw new IOException ( "Missing 'name' from library" ) ;
57
53
if (!properties .containsKey ("version" ))
58
- return null ;
54
+ throw new IOException ( "Missing 'version' from library" ) ;
59
55
if (!properties .containsKey ("architectures" ))
60
- return null ;
56
+ throw new IOException ( "Missing 'architectures' from library" ) ;
61
57
62
58
// 2. Check mandatory folders
63
59
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
+
67
63
// TODO: 3. check if root folder contains prohibited stuff
68
-
64
+
69
65
// Extract metadata info
70
66
// TODO: do for all metadata
71
67
List <String > archs = new ArrayList <String >();
72
68
for (String arch : properties .get ("architectures" ).split ("," ))
73
69
archs .add (arch .trim ());
74
70
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
+
75
79
Library res = new Library ();
76
80
res .folder = libFolder ;
77
81
res .srcFolder = srcFolder ;
78
82
res .name = properties .get ("name" ).trim ();
79
83
res .architectures = archs ;
84
+ res .dependencies = dependencies ;
80
85
res .version = properties .get ("version" ).trim ();
81
86
res .pre15Lib = false ;
82
87
return res ;
@@ -88,7 +93,7 @@ private static Library createPre15Library(File libFolder) {
88
93
res .folder = libFolder ;
89
94
res .srcFolder = libFolder ;
90
95
res .name = libFolder .getName ();
91
- res .architectures = Arrays .asList (new String [] { "*" });
96
+ res .architectures = Arrays .asList (new String []{ "*" });
92
97
res .pre15Lib = true ;
93
98
return res ;
94
99
}
@@ -133,4 +138,8 @@ public boolean isPre15Lib() {
133
138
public File getFolder () {
134
139
return folder ;
135
140
}
141
+
142
+ public List <String > getDependencies () {
143
+ return dependencies ;
144
+ }
136
145
}
0 commit comments