@@ -17,24 +17,23 @@ public class Library {
17
17
private String name ;
18
18
private String version ;
19
19
private String author ;
20
- private String email ;
21
- private String url ;
20
+ private String maintainer ;
22
21
private String sentence ;
23
22
private String paragraph ;
24
- private List <String > coreDependencies ;
25
- private List <String > dependencies ;
26
- private File folder , srcFolder , archFolder ;
23
+ private String url ;
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" });
34
33
35
34
/**
36
35
* Scans inside a folder and create a Library object out of it. Automatically
37
- * detects pre-1.5 libraries. Automatically fills metadata from
36
+ * detects legacy libraries. Automatically fills metadata from
38
37
* library.properties file if found.
39
38
*
40
39
* @param libFolder
@@ -45,7 +44,7 @@ static public Library create(File libFolder) throws IOException {
45
44
// "library.properties"
46
45
File check = new File (libFolder , "library.properties" );
47
46
if (!check .exists () || !check .isFile ())
48
- return createPre15Library (libFolder );
47
+ return createLegacyLibrary (libFolder );
49
48
else
50
49
return createLibrary (libFolder );
51
50
}
@@ -60,14 +59,34 @@ private static Library createLibrary(File libFolder) throws IOException {
60
59
// ---------------------
61
60
62
61
// 1. Check mandatory properties
62
+
63
+ // provide compatibility with 1.5 rev.1 libs
64
+ // ("email" field changed to "maintainer")
65
+ if (!properties .containsKey ("maintainer" ))
66
+ properties .put ("maintainer" , properties .get ("email" ));
67
+
63
68
for (String p : MANDATORY_PROPERTIES )
64
69
if (!properties .containsKey (p ))
65
70
throw new IOException ("Missing '" + p + "' from library" );
66
71
67
- // 2. Check mandatory folders
72
+ // 2. Check layout
73
+ boolean useRecursion ;
68
74
File srcFolder = new File (libFolder , "src" );
69
- if (!srcFolder .exists () || !srcFolder .isDirectory ())
70
- throw new IOException ("Missing 'src' folder" );
75
+
76
+ if (srcFolder .exists () && srcFolder .isDirectory ()) {
77
+ // Layout with a single "src" folder and recursive compilation
78
+ useRecursion = true ;
79
+
80
+ File utilFolder = new File (libFolder , "utility" );
81
+ if (utilFolder .exists () && utilFolder .isDirectory ()) {
82
+ throw new IOException (
83
+ "Library can't use both 'src' and 'utility' folders." );
84
+ }
85
+ } else {
86
+ // Layout with source code on library's root and "utility" folders
87
+ srcFolder = libFolder ;
88
+ useRecursion = false ;
89
+ }
71
90
72
91
// 3. Warn if root folder contains development leftovers
73
92
for (File file : libFolder .listFiles ()) {
@@ -81,65 +100,38 @@ private static Library createLibrary(File libFolder) throws IOException {
81
100
}
82
101
83
102
// Extract metadata info
103
+ String architectures = properties .get ("architectures" );
104
+ if (architectures == null )
105
+ architectures = "*" ; // defaults to "any"
84
106
List <String > archs = new ArrayList <String >();
85
- for (String arch : properties . get ( " architectures" ) .split ("," ))
107
+ for (String arch : architectures .split ("," ))
86
108
archs .add (arch .trim ());
87
109
88
- List <String > coreDeps = new ArrayList <String >();
89
- for (String dep : properties .get ("core-dependencies" ).split ("," ))
90
- coreDeps .add (dep .trim ());
91
-
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
- }
99
-
100
110
Library res = new Library ();
101
111
res .folder = libFolder ;
102
112
res .srcFolder = srcFolder ;
103
- res .archFolder = new File (libFolder , "arch" );
104
113
res .name = properties .get ("name" ).trim ();
114
+ res .version = properties .get ("version" ).trim ();
105
115
res .author = properties .get ("author" ).trim ();
106
- res .email = properties .get ("email " ).trim ();
116
+ res .maintainer = properties .get ("maintainer " ).trim ();
107
117
res .sentence = properties .get ("sentence" ).trim ();
108
118
res .paragraph = properties .get ("paragraph" ).trim ();
109
119
res .url = properties .get ("url" ).trim ();
110
120
res .architectures = archs ;
111
- res .coreDependencies = coreDeps ;
112
- res .dependencies = dependencies ;
113
- res .version = properties .get ("version" ).trim ();
114
- res .pre15Lib = false ;
121
+ res .useRecursion = useRecursion ;
122
+ res .isLegacy = false ;
115
123
return res ;
116
124
}
117
125
118
- private static Library createPre15Library (File libFolder ) {
126
+ private static Library createLegacyLibrary (File libFolder ) {
119
127
// construct an old style library
120
128
Library res = new Library ();
121
129
res .folder = libFolder ;
122
130
res .srcFolder = libFolder ;
131
+ res .useRecursion = false ;
123
132
res .name = libFolder .getName ();
124
133
res .architectures = Arrays .asList ("*" );
125
- res .pre15Lib = true ;
126
- return res ;
127
- }
128
-
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
- }
134
+ res .isLegacy = true ;
143
135
return res ;
144
136
}
145
137
@@ -157,18 +149,10 @@ public int compare(Library o1, Library o2) {
157
149
}
158
150
};
159
151
160
- public File getSrcFolder () {
161
- return srcFolder ;
162
- }
163
-
164
152
public String getName () {
165
153
return name ;
166
154
}
167
155
168
- public boolean isPre15Lib () {
169
- return pre15Lib ;
170
- }
171
-
172
156
public File getFolder () {
173
157
return folder ;
174
158
}
@@ -181,18 +165,6 @@ public String getAuthor() {
181
165
return author ;
182
166
}
183
167
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
168
public String getParagraph () {
197
169
return paragraph ;
198
170
}
@@ -209,19 +181,33 @@ public String getVersion() {
209
181
return version ;
210
182
}
211
183
184
+ public String getMaintainer () {
185
+ return maintainer ;
186
+ }
187
+
188
+ public boolean useRecursion () {
189
+ return useRecursion ;
190
+ }
191
+
192
+ public File getSrcFolder () {
193
+ return srcFolder ;
194
+ }
195
+
196
+ public boolean isLegacy () {
197
+ return isLegacy ;
198
+ }
199
+
212
200
@ Override
213
201
public String toString () {
214
202
String res = "Library:" ;
215
203
res += " (name=" + name + ")" ;
216
- res += " (architectures =" + architectures + ")" ;
204
+ res += " (version =" + version + ")" ;
217
205
res += " (author=" + author + ")" ;
218
- res += " (core-dependencies=" + coreDependencies + ")" ;
219
- res += " (dependencies=" + dependencies + ")" ;
220
- res += " (email=" + email + ")" ;
221
- res += " (paragraph=" + paragraph + ")" ;
206
+ res += " (maintainer=" + maintainer + ")" ;
222
207
res += " (sentence=" + sentence + ")" ;
208
+ res += " (paragraph=" + paragraph + ")" ;
223
209
res += " (url=" + url + ")" ;
224
- res += " (version =" + version + ")" ;
210
+ res += " (architectures =" + architectures + ")" ;
225
211
return res ;
226
212
}
227
213
}
0 commit comments