mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Library: converted nulls to checked exceptions, removed printStackTrace, added "dependencies" member
Conflicts: app/src/processing/app/packages/Library.java
This commit is contained in:
parent
bddb47ed26
commit
2a051a76a7
@ -1,6 +1,6 @@
|
|||||||
package processing.app.packages;
|
package processing.app.packages;
|
||||||
|
|
||||||
import static processing.app.helpers.StringMatchers.wildcardMatch;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -9,7 +9,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import processing.app.helpers.PreferencesMap;
|
import static processing.app.helpers.StringMatchers.wildcardMatch;
|
||||||
|
|
||||||
public class Library {
|
public class Library {
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class Library {
|
|||||||
* @param libFolder
|
* @param libFolder
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static public Library create(File libFolder) {
|
static public Library create(File libFolder) throws IOException {
|
||||||
// A library is considered "new" if it contains a file called
|
// A library is considered "new" if it contains a file called
|
||||||
// "library.properties"
|
// "library.properties"
|
||||||
File check = new File(libFolder, "library.properties");
|
File check = new File(libFolder, "library.properties");
|
||||||
@ -53,16 +53,11 @@ public class Library {
|
|||||||
return createLibrary(libFolder);
|
return createLibrary(libFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Library createLibrary(File libFolder) {
|
private static Library createLibrary(File libFolder) throws IOException {
|
||||||
// Parse metadata
|
// Parse metadata
|
||||||
File propertiesFile = new File(libFolder, "library.properties");
|
File propertiesFile = new File(libFolder, "library.properties");
|
||||||
PreferencesMap properties = new PreferencesMap();
|
PreferencesMap properties = new PreferencesMap();
|
||||||
try {
|
properties.load(propertiesFile);
|
||||||
properties.load(propertiesFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Library sanity checks
|
// Library sanity checks
|
||||||
// ---------------------
|
// ---------------------
|
||||||
@ -70,25 +65,41 @@ public class Library {
|
|||||||
// 1. Check mandatory properties
|
// 1. Check mandatory properties
|
||||||
for (String p : MANDATORY_PROPERTIES)
|
for (String p : MANDATORY_PROPERTIES)
|
||||||
if (!properties.containsKey(p))
|
if (!properties.containsKey(p))
|
||||||
return null;
|
throw new IOException("Missing '" + p + "' from library");
|
||||||
|
|
||||||
// 2. Check mandatory folders
|
// 2. Check mandatory folders
|
||||||
File srcFolder = new File(libFolder, "src");
|
File srcFolder = new File(libFolder, "src");
|
||||||
if (!srcFolder.exists() && !srcFolder.isDirectory())
|
if (!srcFolder.exists() || !srcFolder.isDirectory())
|
||||||
return null;
|
throw new IOException("Missing 'src' folder");
|
||||||
|
|
||||||
// 3. check if root folder contains prohibited stuff
|
// 3. check if root folder contains prohibited stuff
|
||||||
for (File file : libFolder.listFiles()) {
|
for (File file : libFolder.listFiles()) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
if (!OPTIONAL_FOLDERS.contains(file.getName()))
|
if (!OPTIONAL_FOLDERS.contains(file.getName()))
|
||||||
return null;
|
throw new IOException("Invalid folder '" + file.getName() + "'.");
|
||||||
} else {
|
} else {
|
||||||
if (!OPTIONAL_FILES.contains(file.getName()))
|
if (!OPTIONAL_FILES.contains(file.getName()))
|
||||||
return null;
|
throw new IOException("Invalid file '" + file.getName() + "'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract metadata info
|
// Extract metadata info
|
||||||
|
List<String> archs = new ArrayList<String>();
|
||||||
|
for (String arch : properties.get("architectures").split(","))
|
||||||
|
archs.add(arch.trim());
|
||||||
|
|
||||||
|
List<String> coreDeps = new ArrayList<String>();
|
||||||
|
for (String dep : properties.get("core-dependencies").split(","))
|
||||||
|
coreDeps.add(dep.trim());
|
||||||
|
|
||||||
|
List<String> dependencies = new ArrayList<String>();
|
||||||
|
for (String dependency : properties.get("dependencies").split(",")) {
|
||||||
|
dependency = dependency.trim();
|
||||||
|
if (!dependency.equals("")) {
|
||||||
|
dependencies.add(dependency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Library res = new Library();
|
Library res = new Library();
|
||||||
res.folder = libFolder;
|
res.folder = libFolder;
|
||||||
res.srcFolder = srcFolder;
|
res.srcFolder = srcFolder;
|
||||||
@ -99,18 +110,9 @@ public class Library {
|
|||||||
res.sentence = properties.get("sentence").trim();
|
res.sentence = properties.get("sentence").trim();
|
||||||
res.paragraph = properties.get("paragraph").trim();
|
res.paragraph = properties.get("paragraph").trim();
|
||||||
res.url = properties.get("url").trim();
|
res.url = properties.get("url").trim();
|
||||||
List<String> archs = new ArrayList<String>();
|
|
||||||
for (String arch : properties.get("architectures").split(","))
|
|
||||||
archs.add(arch.trim());
|
|
||||||
res.architectures = archs;
|
res.architectures = archs;
|
||||||
List<String> deps = new ArrayList<String>();
|
|
||||||
for (String dep : properties.get("dependencies").split(","))
|
|
||||||
deps.add(dep.trim());
|
|
||||||
res.dependencies = deps;
|
|
||||||
List<String> coreDeps = new ArrayList<String>();
|
|
||||||
for (String dep : properties.get("core-dependencies").split(","))
|
|
||||||
coreDeps.add(dep.trim());
|
|
||||||
res.coreDependencies = coreDeps;
|
res.coreDependencies = coreDeps;
|
||||||
|
res.dependencies = dependencies;
|
||||||
res.version = properties.get("version").trim();
|
res.version = properties.get("version").trim();
|
||||||
res.pre15Lib = false;
|
res.pre15Lib = false;
|
||||||
return res;
|
return res;
|
||||||
@ -122,7 +124,7 @@ public class Library {
|
|||||||
res.folder = libFolder;
|
res.folder = libFolder;
|
||||||
res.srcFolder = libFolder;
|
res.srcFolder = libFolder;
|
||||||
res.name = libFolder.getName();
|
res.name = libFolder.getName();
|
||||||
res.architectures = Arrays.asList(new String[] { "*" });
|
res.architectures = Arrays.asList(new String[]{"*"});
|
||||||
res.pre15Lib = true;
|
res.pre15Lib = true;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user