mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge branch 'lib-1.5-newformat' into ide-1.5.x
This commit is contained in:
@ -37,7 +37,9 @@ import processing.app.helpers.Maps;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
||||
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;import processing.app.tools.MapWithSubkeys;
|
||||
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;import processing.app.packages.Library;
|
||||
import processing.app.packages.LibraryList;
|
||||
import processing.app.tools.MapWithSubkeys;
|
||||
import processing.app.tools.ZipDeflater;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
@ -89,10 +91,10 @@ public class Base {
|
||||
static private List<File> librariesFolders;
|
||||
|
||||
// maps library name to their library folder
|
||||
static private Map<String, File> libraries;
|
||||
static private LibraryList libraries;
|
||||
|
||||
// maps #included files to their library folder
|
||||
static Map<String, File> importToLibraryTable;
|
||||
static Map<String, Library> importToLibraryTable;
|
||||
|
||||
// classpath for all known libraries for p5
|
||||
// (both those in the p5/libs folder and those with lib subfolders
|
||||
@ -1041,26 +1043,18 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, File> getIDELibs() {
|
||||
public LibraryList getIDELibs() {
|
||||
if (libraries == null)
|
||||
return new HashMap<String, File>();
|
||||
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
|
||||
for (String lib : libraries.keySet()) {
|
||||
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||
ideLibs.remove(lib);
|
||||
}
|
||||
return ideLibs;
|
||||
return new LibraryList();
|
||||
LibraryList res = new LibraryList(libraries);
|
||||
res.removeAll(getUserLibs());
|
||||
return res;
|
||||
}
|
||||
|
||||
public Map<String, File> getUserLibs() {
|
||||
public LibraryList getUserLibs() {
|
||||
if (libraries == null)
|
||||
return new HashMap<String, File>();
|
||||
Map<String, File> userLibs = new HashMap<String, File>(libraries);
|
||||
for (String lib : libraries.keySet()) {
|
||||
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||
userLibs.remove(lib);
|
||||
}
|
||||
return userLibs;
|
||||
return new LibraryList();
|
||||
return libraries.filterLibrariesInSubfolder(getSketchbookFolder());
|
||||
}
|
||||
|
||||
public void rebuildImportMenu(JMenu importMenu, final Editor editor) {
|
||||
@ -1080,8 +1074,8 @@ public class Base {
|
||||
// Split between user supplied libraries and IDE libraries
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform != null) {
|
||||
Map<String, File> ideLibs = getIDELibs();
|
||||
Map<String, File> userLibs = getUserLibs();
|
||||
LibraryList ideLibs = getIDELibs();
|
||||
LibraryList userLibs = getUserLibs();
|
||||
try {
|
||||
// Find the current target. Get the platform, and then select the
|
||||
// correct name and core path.
|
||||
@ -1121,44 +1115,33 @@ public class Base {
|
||||
if (found) menu.addSeparator();
|
||||
|
||||
// Add examples from libraries
|
||||
Map<String, File> ideLibs = getIDELibs();
|
||||
List<String> names = new ArrayList<String>(ideLibs.keySet());
|
||||
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String name : names) {
|
||||
File folder = ideLibs.get(name);
|
||||
addSketchesSubmenu(menu, name, folder, false);
|
||||
// Allows "fat" libraries to have examples in the root folder
|
||||
if (folder.getName().equals(Base.getTargetPlatform().getName()))
|
||||
addSketchesSubmenu(menu, name, folder.getParentFile(), false);
|
||||
}
|
||||
LibraryList ideLibs = getIDELibs();
|
||||
ideLibs.sort();
|
||||
for (Library lib : ideLibs)
|
||||
addSketchesSubmenu(menu, lib, false);
|
||||
|
||||
Map<String, File> userLibs = getUserLibs();
|
||||
LibraryList userLibs = getUserLibs();
|
||||
if (userLibs.size()>0) {
|
||||
menu.addSeparator();
|
||||
names = new ArrayList<String>(userLibs.keySet());
|
||||
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String name : names) {
|
||||
File folder = userLibs.get(name);
|
||||
addSketchesSubmenu(menu, name, folder, false);
|
||||
// Allows "fat" libraries to have examples in the root folder
|
||||
if (folder.getName().equals(Base.getTargetPlatform().getName()))
|
||||
addSketchesSubmenu(menu, name, folder.getParentFile(), false);
|
||||
}
|
||||
userLibs.sort();
|
||||
for (Library lib : userLibs)
|
||||
addSketchesSubmenu(menu, lib, false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, File> scanLibraries(List<File> folders) {
|
||||
Map<String, File> res = new HashMap<String, File>();
|
||||
public LibraryList scanLibraries(List<File> folders) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
for (File folder : folders)
|
||||
res.putAll(scanLibraries(folder));
|
||||
res.addOrReplaceAll(scanLibraries(folder));
|
||||
return res;
|
||||
}
|
||||
|
||||
public Map<String, File> scanLibraries(File folder) {
|
||||
Map<String, File> res = new HashMap<String, File>();
|
||||
public LibraryList scanLibraries(File folder) throws IOException {
|
||||
LibraryList res = new LibraryList();
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null)
|
||||
@ -1175,41 +1158,14 @@ public class Base {
|
||||
continue;
|
||||
}
|
||||
|
||||
subfolder = scanFatLibrary(subfolder);
|
||||
|
||||
Library lib = Library.create(subfolder);
|
||||
// (also replace previously found libs with the same name)
|
||||
if (subfolder != null)
|
||||
res.put(libName, subfolder);
|
||||
if (lib != null)
|
||||
res.addOrReplace(lib);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans inside a "FAT" (multi-platform) library folder to see if it contains
|
||||
* a version suitable for the actual selected architecture. If a suitable
|
||||
* version is found the folder containing that version is returned, otherwise
|
||||
* <b>null</b> is returned.<br />
|
||||
* <br />
|
||||
* If a non-"FAT" library is detected, we assume that the library is suitable
|
||||
* for the current architecture and the libFolder parameter is returned.<br />
|
||||
*
|
||||
* @param libFolder
|
||||
* @return
|
||||
*/
|
||||
public File scanFatLibrary(File libFolder) {
|
||||
// A library is considered "fat" if it contains a file called
|
||||
// "library.properties"
|
||||
File libraryPropFile = new File(libFolder, "library.properties");
|
||||
if (!libraryPropFile.exists() || !libraryPropFile.isFile())
|
||||
return libFolder;
|
||||
|
||||
// Search for a subfolder for actual architecture, return null if not found
|
||||
File archSubfolder = new File(libFolder, Base.getTargetPlatform().getName());
|
||||
if (!archSubfolder.exists() || !archSubfolder.isDirectory())
|
||||
return null;
|
||||
return archSubfolder;
|
||||
}
|
||||
|
||||
public void onBoardOrPortChange() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
@ -1228,18 +1184,25 @@ public class Base {
|
||||
// Scan for libraries in each library folder.
|
||||
// Libraries located in the latest folders on the list can override
|
||||
// other libraries with the same name.
|
||||
libraries = scanLibraries(librariesFolders);
|
||||
|
||||
try {
|
||||
libraries = scanLibraries(librariesFolders);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), _("Error reading preferences"), e);
|
||||
}
|
||||
String currentArch = Base.getTargetPlatform().getName();
|
||||
libraries = libraries.filterByArchitecture(currentArch);
|
||||
|
||||
// Populate importToLibraryTable
|
||||
importToLibraryTable = new HashMap<String, File>();
|
||||
for (File subfolder : libraries.values()) {
|
||||
importToLibraryTable = new HashMap<String, Library>();
|
||||
for (Library lib : libraries) {
|
||||
try {
|
||||
String packages[] = headerListFromIncludePath(subfolder);
|
||||
for (String pkg : packages) {
|
||||
importToLibraryTable.put(pkg, subfolder);
|
||||
String headers[] = headerListFromIncludePath(lib.getSrcFolder());
|
||||
for (String header : headers) {
|
||||
importToLibraryTable.put(header, lib);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
|
||||
showWarning(_("Error"), I18n
|
||||
.format("Unable to list header files in {0}", lib.getSrcFolder()), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1517,6 +1480,13 @@ public class Base {
|
||||
return ifound; // actually ignored, but..
|
||||
}
|
||||
|
||||
private boolean addSketchesSubmenu(JMenu menu, Library lib,
|
||||
boolean replaceExisting)
|
||||
throws IOException {
|
||||
return addSketchesSubmenu(menu, lib.getName(), lib.getFolder(),
|
||||
replaceExisting);
|
||||
}
|
||||
|
||||
private boolean addSketchesSubmenu(JMenu menu, String name, File folder,
|
||||
final boolean replaceExisting) throws IOException {
|
||||
|
||||
@ -1583,29 +1553,28 @@ public class Base {
|
||||
return found;
|
||||
}
|
||||
|
||||
protected void addLibraries(JMenu menu, Map<String, File> libs) throws IOException {
|
||||
protected void addLibraries(JMenu menu, LibraryList libs) throws IOException {
|
||||
|
||||
List<String> list = new ArrayList<String>(libs.keySet());
|
||||
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
LibraryList list = new LibraryList(libs);
|
||||
list.sort();
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String jarPath = event.getActionCommand();
|
||||
try {
|
||||
activeEditor.getSketch().importLibrary(jarPath);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
|
||||
for (Library lib : list) {
|
||||
@SuppressWarnings("serial")
|
||||
AbstractAction action = new AbstractAction(lib.getName()) {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
Library l = (Library) getValue("library");
|
||||
try {
|
||||
activeEditor.getSketch().importLibrary(l);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (String name : list) {
|
||||
File folder = libs.get(name);
|
||||
|
||||
};
|
||||
action.putValue("library", lib);
|
||||
|
||||
// Add new element at the bottom
|
||||
JMenuItem item = new JMenuItem(name);
|
||||
item.addActionListener(listener);
|
||||
item.setActionCommand(folder.getAbsolutePath());
|
||||
JMenuItem item = new JMenuItem(action);
|
||||
item.putClientProperty("library", lib);
|
||||
menu.add(item);
|
||||
|
||||
// XXX: DAM: should recurse here so that library folders can be nested
|
||||
@ -1877,7 +1846,7 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
static public Map<String, File> getLibraries() {
|
||||
static public LibraryList getLibraries() {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ import processing.app.debug.RunnerException;
|
||||
import processing.app.debug.Sizer;
|
||||
import processing.app.debug.Uploader;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.packages.Library;
|
||||
import processing.app.packages.LibraryList;
|
||||
import processing.app.preproc.*;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
@ -87,16 +89,10 @@ public class Sketch {
|
||||
/** Class path determined during build. */
|
||||
private String classPath;
|
||||
|
||||
/**
|
||||
* This is *not* the "Processing" libraries path, this is the Java libraries
|
||||
* path, as in java.library.path=BlahBlah, which identifies search paths for
|
||||
* DLLs or JNILIBs.
|
||||
*/
|
||||
private String libraryPath;
|
||||
/**
|
||||
* List of library folders.
|
||||
*/
|
||||
private ArrayList<File> importedLibraries;
|
||||
private LibraryList importedLibraries;
|
||||
|
||||
/**
|
||||
* path is location of the main .pde file, because this is also
|
||||
@ -1120,15 +1116,19 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
public void importLibrary(Library lib) throws IOException {
|
||||
importLibrary(lib.getSrcFolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add import statements to the current tab for all of packages inside
|
||||
* the specified jar file.
|
||||
*/
|
||||
public void importLibrary(String jarPath) throws IOException {
|
||||
public void importLibrary(File jarPath) throws IOException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
String list[] = Base.headerListFromIncludePath(new File(jarPath));
|
||||
String list[] = Base.headerListFromIncludePath(jarPath);
|
||||
|
||||
// import statements into the main sketch file (code[0])
|
||||
// if the current code is a .java file, insert into current
|
||||
@ -1421,18 +1421,14 @@ public class Sketch {
|
||||
|
||||
// grab the imports from the code just preproc'd
|
||||
|
||||
importedLibraries = new ArrayList<File>();
|
||||
//Remember to clear library path before building it.
|
||||
libraryPath = "";
|
||||
importedLibraries = new LibraryList();
|
||||
for (String item : preprocessor.getExtraImports()) {
|
||||
|
||||
File libFolder = (File) Base.importToLibraryTable.get(item);
|
||||
//If needed can Debug libraryPath here
|
||||
Library lib = Base.importToLibraryTable.get(item);
|
||||
//If needed can Debug libraryPath here
|
||||
|
||||
if (libFolder != null && !importedLibraries.contains(libFolder)) {
|
||||
importedLibraries.add(libFolder);
|
||||
//classPath += Compiler.contentsToClassPath(libFolder);
|
||||
libraryPath += File.pathSeparator + libFolder.getAbsolutePath();
|
||||
if (lib != null && !importedLibraries.contains(lib)) {
|
||||
importedLibraries.add(lib);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1462,7 +1458,7 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<File> getImportedLibraries() {
|
||||
public LibraryList getImportedLibraries() {
|
||||
return importedLibraries;
|
||||
}
|
||||
|
||||
@ -1887,11 +1883,6 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
public String getLibraryPath() {
|
||||
return libraryPath;
|
||||
}
|
||||
|
||||
|
||||
public SketchCode[] getCode() {
|
||||
return code;
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ import processing.app.Sketch;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.packages.Library;
|
||||
import processing.core.PApplet;
|
||||
|
||||
public class Compiler implements MessageConsumer {
|
||||
@ -55,7 +57,8 @@ public class Compiler implements MessageConsumer {
|
||||
private PreferencesMap prefs;
|
||||
private boolean verbose;
|
||||
private boolean sketchIsCompiled;
|
||||
|
||||
private String targetArch;
|
||||
|
||||
private RunnerException exception;
|
||||
|
||||
/**
|
||||
@ -83,8 +86,9 @@ public class Compiler implements MessageConsumer {
|
||||
includePaths.add(prefs.get("build.core.path"));
|
||||
if (prefs.get("build.variant.path").length() != 0)
|
||||
includePaths.add(prefs.get("build.variant.path"));
|
||||
for (File file : sketch.getImportedLibraries())
|
||||
includePaths.add(file.getPath());
|
||||
for (Library lib : sketch.getImportedLibraries())
|
||||
for (File folder : lib.getSrcFolders(targetArch))
|
||||
includePaths.add(folder.getPath());
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
sketch.setCompilingProgress(30);
|
||||
@ -129,7 +133,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
|
||||
|
||||
// Merge all the global preference configuration in order of priority
|
||||
PreferencesMap p = new PreferencesMap();
|
||||
p.putAll(Preferences.getMap());
|
||||
@ -142,6 +146,8 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
p.put("build.path", _buildPath);
|
||||
p.put("build.project_name", _primaryClassName);
|
||||
targetArch = targetPlatform.getName();
|
||||
p.put("build.arch", targetArch.toUpperCase());
|
||||
|
||||
if (!p.containsKey("compiler.path"))
|
||||
p.put("compiler.path", Base.getAvrBasePath());
|
||||
@ -578,26 +584,49 @@ public class Compiler implements MessageConsumer {
|
||||
// 2. compile the libraries, outputting .o files to:
|
||||
// <buildPath>/<library>/
|
||||
void compileLibraries(List<String> includePaths) throws RunnerException {
|
||||
|
||||
for (File libraryFolder : sketch.getImportedLibraries()) {
|
||||
String outputPath = prefs.get("build.path");
|
||||
File outputFolder = new File(outputPath, libraryFolder.getName());
|
||||
File utilityFolder = new File(libraryFolder, "utility");
|
||||
createFolder(outputFolder);
|
||||
// this library can use includes in its utility/ folder
|
||||
includePaths.add(utilityFolder.getAbsolutePath());
|
||||
|
||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
||||
libraryFolder, false, includePaths));
|
||||
outputFolder = new File(outputFolder, "utility");
|
||||
createFolder(outputFolder);
|
||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
||||
utilityFolder, false, includePaths));
|
||||
// other libraries should not see this library's utility/ folder
|
||||
includePaths.remove(includePaths.size() - 1);
|
||||
File outputPath = new File(prefs.get("build.path"));
|
||||
for (Library lib : sketch.getImportedLibraries()) {
|
||||
for (File folder : lib.getSrcFolders(targetArch)) {
|
||||
if (lib.isPre15Lib()) {
|
||||
compileLibrary(outputPath, folder, includePaths);
|
||||
} else {
|
||||
recursiveCompileLibrary(outputPath, folder, includePaths);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void recursiveCompileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
||||
File newOutputPath = compileFilesInFolder(outputPath, libraryFolder, includePaths);
|
||||
for (File subFolder : libraryFolder.listFiles(new OnlyDirs())) {
|
||||
recursiveCompileLibrary(newOutputPath, subFolder, includePaths);
|
||||
}
|
||||
}
|
||||
|
||||
private File compileFilesInFolder(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
||||
File outputFolder = new File(outputPath, libraryFolder.getName());
|
||||
createFolder(outputFolder);
|
||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(), libraryFolder, false, includePaths));
|
||||
return outputFolder;
|
||||
}
|
||||
|
||||
private void compileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
||||
File outputFolder = new File(outputPath, libraryFolder.getName());
|
||||
File utilityFolder = new File(libraryFolder, "utility");
|
||||
createFolder(outputFolder);
|
||||
// this library can use includes in its utility/ folder
|
||||
includePaths.add(utilityFolder.getAbsolutePath());
|
||||
|
||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
||||
libraryFolder, false, includePaths));
|
||||
outputFolder = new File(outputFolder, "utility");
|
||||
createFolder(outputFolder);
|
||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
||||
utilityFolder, false, includePaths));
|
||||
// other libraries should not see this library's utility/ folder
|
||||
includePaths.remove(includePaths.size() - 1);
|
||||
}
|
||||
|
||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||
// collecting them into the core.a library file.
|
||||
void compileCore()
|
||||
|
21
app/src/processing/app/helpers/StringMatchers.java
Normal file
21
app/src/processing/app/helpers/StringMatchers.java
Normal file
@ -0,0 +1,21 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
public class StringMatchers {
|
||||
|
||||
/**
|
||||
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
|
||||
* "*" and "?" globs to match any-char-sequence and any-char respectively.
|
||||
*
|
||||
* @param input
|
||||
* The string to be checked
|
||||
* @param pattern
|
||||
* The pattern to match
|
||||
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
|
||||
* <b>false</b> otherwise.
|
||||
*/
|
||||
public static boolean wildcardMatch(String input, String pattern) {
|
||||
String regex = pattern.replace("?", ".?").replace("*", ".*?");
|
||||
return input.matches(regex);
|
||||
}
|
||||
|
||||
}
|
230
app/src/processing/app/packages/Library.java
Normal file
230
app/src/processing/app/packages/Library.java
Normal file
@ -0,0 +1,230 @@
|
||||
package processing.app.packages;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static processing.app.helpers.StringMatchers.wildcardMatch;
|
||||
|
||||
public class Library {
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
private String author;
|
||||
private String email;
|
||||
private String url;
|
||||
private String sentence;
|
||||
private String paragraph;
|
||||
private List<String> coreDependencies;
|
||||
private List<String> dependencies;
|
||||
private File folder, srcFolder, archFolder;
|
||||
private List<String> architectures;
|
||||
private boolean pre15Lib;
|
||||
|
||||
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||
.asList(new String[] { "architectures", "author", "core-dependencies",
|
||||
"dependencies", "email", "name", "paragraph", "sentence", "url",
|
||||
"version" });
|
||||
private static final List<String> OPTIONAL_FOLDERS = Arrays
|
||||
.asList(new String[] { "arch", "examples", "extras", "src" });
|
||||
private static final List<String> OPTIONAL_FILES = Arrays
|
||||
.asList(new String[] { "keywords.txt", "library.properties" });
|
||||
|
||||
/**
|
||||
* Scans inside a folder and create a Library object out of it. Automatically
|
||||
* detects pre-1.5 libraries. Automatically fills metadata from
|
||||
* library.properties file if found.
|
||||
*
|
||||
* @param libFolder
|
||||
* @return
|
||||
*/
|
||||
static public Library create(File libFolder) throws IOException {
|
||||
// A library is considered "new" if it contains a file called
|
||||
// "library.properties"
|
||||
File check = new File(libFolder, "library.properties");
|
||||
if (!check.exists() || !check.isFile())
|
||||
return createPre15Library(libFolder);
|
||||
else
|
||||
return createLibrary(libFolder);
|
||||
}
|
||||
|
||||
private static Library createLibrary(File libFolder) throws IOException {
|
||||
// Parse metadata
|
||||
File propertiesFile = new File(libFolder, "library.properties");
|
||||
PreferencesMap properties = new PreferencesMap();
|
||||
properties.load(propertiesFile);
|
||||
|
||||
// Library sanity checks
|
||||
// ---------------------
|
||||
|
||||
// 1. Check mandatory properties
|
||||
for (String p : MANDATORY_PROPERTIES)
|
||||
if (!properties.containsKey(p))
|
||||
throw new IOException("Missing '" + p + "' from library");
|
||||
|
||||
// 2. Check mandatory folders
|
||||
File srcFolder = new File(libFolder, "src");
|
||||
if (!srcFolder.exists() || !srcFolder.isDirectory())
|
||||
throw new IOException("Missing 'src' folder");
|
||||
|
||||
// 3. check if root folder contains prohibited stuff
|
||||
for (File file : libFolder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
if (!OPTIONAL_FOLDERS.contains(file.getName()))
|
||||
throw new IOException("Invalid folder '" + file.getName() + "'.");
|
||||
} else {
|
||||
if (!OPTIONAL_FILES.contains(file.getName()))
|
||||
throw new IOException("Invalid file '" + file.getName() + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
res.folder = libFolder;
|
||||
res.srcFolder = srcFolder;
|
||||
res.archFolder = new File(libFolder, "arch");
|
||||
res.name = properties.get("name").trim();
|
||||
res.author = properties.get("author").trim();
|
||||
res.email = properties.get("email").trim();
|
||||
res.sentence = properties.get("sentence").trim();
|
||||
res.paragraph = properties.get("paragraph").trim();
|
||||
res.url = properties.get("url").trim();
|
||||
res.architectures = archs;
|
||||
res.coreDependencies = coreDeps;
|
||||
res.dependencies = dependencies;
|
||||
res.version = properties.get("version").trim();
|
||||
res.pre15Lib = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
private static Library createPre15Library(File libFolder) {
|
||||
// construct an old style library
|
||||
Library res = new Library();
|
||||
res.folder = libFolder;
|
||||
res.srcFolder = libFolder;
|
||||
res.name = libFolder.getName();
|
||||
res.architectures = Arrays.asList(new String[]{"*"});
|
||||
res.pre15Lib = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<File> getSrcFolders(String reqArch) {
|
||||
if (!supportsArchitecture(reqArch))
|
||||
return null;
|
||||
List<File> res = new ArrayList<File>();
|
||||
res.add(srcFolder);
|
||||
File archSpecificFolder = new File(archFolder, reqArch);
|
||||
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) {
|
||||
res.add(archSpecificFolder);
|
||||
} else {
|
||||
// If specific architecture folder is not found try with "default"
|
||||
archSpecificFolder = new File(archFolder, "default");
|
||||
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
|
||||
res.add(archSpecificFolder);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean supportsArchitecture(String reqArch) {
|
||||
for (String arch : architectures)
|
||||
if (wildcardMatch(reqArch, arch))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final Comparator<Library> CASE_INSENSITIVE_ORDER = new Comparator<Library>() {
|
||||
@Override
|
||||
public int compare(Library o1, Library o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
};
|
||||
|
||||
public File getSrcFolder() {
|
||||
return srcFolder;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isPre15Lib() {
|
||||
return pre15Lib;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public List<String> getArchitectures() {
|
||||
return architectures;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public List<String> getCoreDependencies() {
|
||||
return coreDependencies;
|
||||
}
|
||||
|
||||
public List<String> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getParagraph() {
|
||||
return paragraph;
|
||||
}
|
||||
|
||||
public String getSentence() {
|
||||
return sentence;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "Library:";
|
||||
res += " (name=" + name + ")";
|
||||
res += " (architectures=" + architectures + ")";
|
||||
res += " (author=" + author + ")";
|
||||
res += " (core-dependencies=" + coreDependencies + ")";
|
||||
res += " (dependencies=" + dependencies + ")";
|
||||
res += " (email=" + email + ")";
|
||||
res += " (paragraph=" + paragraph + ")";
|
||||
res += " (sentence=" + sentence + ")";
|
||||
res += " (url=" + url + ")";
|
||||
res += " (version=" + version + ")";
|
||||
return res;
|
||||
}
|
||||
}
|
70
app/src/processing/app/packages/LibraryList.java
Normal file
70
app/src/processing/app/packages/LibraryList.java
Normal file
@ -0,0 +1,70 @@
|
||||
package processing.app.packages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LibraryList extends ArrayList<Library> {
|
||||
|
||||
public LibraryList(LibraryList libs) {
|
||||
super(libs);
|
||||
}
|
||||
|
||||
public LibraryList() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Library getByName(String name) {
|
||||
for (Library l : this)
|
||||
if (l.getName().equals(name))
|
||||
return l;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addOrReplace(Library lib) {
|
||||
Library l = getByName(lib.getName());
|
||||
if (l != null)
|
||||
remove(l);
|
||||
add(lib);
|
||||
}
|
||||
|
||||
public void addOrReplaceAll(Collection<? extends Library> c) {
|
||||
for (Library l : c)
|
||||
addOrReplace(l);
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(this, Library.CASE_INSENSITIVE_ORDER);
|
||||
}
|
||||
|
||||
public Library search(String name, String arch) {
|
||||
for (Library lib : this) {
|
||||
if (!lib.getName().equals(name))
|
||||
continue;
|
||||
if (!lib.supportsArchitecture(arch))
|
||||
continue;
|
||||
return lib;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LibraryList filterByArchitecture(String reqArch) {
|
||||
LibraryList res = new LibraryList();
|
||||
for (Library lib : this)
|
||||
if (lib.supportsArchitecture(reqArch))
|
||||
res.add(lib);
|
||||
return res;
|
||||
}
|
||||
|
||||
public LibraryList filterLibrariesInSubfolder(File subFolder) {
|
||||
LibraryList res = new LibraryList();
|
||||
for (Library lib : this)
|
||||
if (FileUtils.isSubDirectory(subFolder, lib.getFolder()))
|
||||
res.add(lib);
|
||||
return res;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.packages.Library;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@ -59,8 +60,8 @@ public class PdeKeywords extends CTokenMarker {
|
||||
keywordColoring = new KeywordMap(false);
|
||||
keywordToReference = new Hashtable();
|
||||
getKeywords(Base.getLibStream("keywords.txt"));
|
||||
for (File lib : Base.getLibraries().values()) {
|
||||
File keywords = new File(lib, "keywords.txt");
|
||||
for (Library lib : Base.getLibraries()) {
|
||||
File keywords = new File(lib.getFolder(), "keywords.txt");
|
||||
if (keywords.exists()) getKeywords(new FileInputStream(keywords));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
Reference in New Issue
Block a user