mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
Introducing UserLibraryFolder
This class allows to attach a Location property to a folder path, this way we directly know if a library is in the sketchbook, core, referenced-core or bundled in the IDE. This simplify a lot of logic in the IDE.
This commit is contained in:
parent
040caad124
commit
2374d9d1bd
@ -152,7 +152,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
|
|||||||
|
|
||||||
// Library name...
|
// Library name...
|
||||||
desc += format("<b>{0}</b>", name);
|
desc += format("<b>{0}</b>", name);
|
||||||
if (mayInstalled.isPresent() && mayInstalled.get().isReadOnly()) {
|
if (mayInstalled.isPresent() && mayInstalled.get().isIDEBuiltIn()) {
|
||||||
desc += " Built-In ";
|
desc += " Built-In ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
return new ContributedLibraryTableCellEditor() {
|
return new ContributedLibraryTableCellEditor() {
|
||||||
@Override
|
@Override
|
||||||
protected void onInstall(ContributedLibrary selectedLibrary, Optional<ContributedLibrary> mayInstalledLibrary) {
|
protected void onInstall(ContributedLibrary selectedLibrary, Optional<ContributedLibrary> mayInstalledLibrary) {
|
||||||
if (selectedLibrary.isReadOnly() && mayInstalledLibrary.isPresent()) {
|
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
|
||||||
onRemovePressed(mayInstalledLibrary.get());
|
onRemovePressed(mayInstalledLibrary.get());
|
||||||
} else {
|
} else {
|
||||||
onInstallPressed(selectedLibrary, mayInstalledLibrary);
|
onInstallPressed(selectedLibrary, mayInstalledLibrary);
|
||||||
|
@ -52,6 +52,7 @@ import processing.app.legacy.PApplet;
|
|||||||
import processing.app.macosx.ThinkDifferent;
|
import processing.app.macosx.ThinkDifferent;
|
||||||
import processing.app.packages.LibraryList;
|
import processing.app.packages.LibraryList;
|
||||||
import processing.app.packages.UserLibrary;
|
import processing.app.packages.UserLibrary;
|
||||||
|
import processing.app.packages.UserLibraryFolder.Location;
|
||||||
import processing.app.syntax.PdeKeywords;
|
import processing.app.syntax.PdeKeywords;
|
||||||
import processing.app.syntax.SketchTextAreaDefaultInputMap;
|
import processing.app.syntax.SketchTextAreaDefaultInputMap;
|
||||||
import processing.app.tools.MenuScroller;
|
import processing.app.tools.MenuScroller;
|
||||||
@ -337,8 +338,7 @@ public class Base {
|
|||||||
|
|
||||||
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
||||||
indexer.parseIndex();
|
indexer.parseIndex();
|
||||||
indexer.setSketchbookLibrariesFolder(BaseNoGui.getSketchbookLibrariesFolder());
|
indexer.setLibrariesFolders(BaseNoGui.getLibrariesFolders());
|
||||||
indexer.setLibrariesFolders(BaseNoGui.getLibrariesPath());
|
|
||||||
|
|
||||||
for (String library : parser.getLibraryToInstall().split(",")) {
|
for (String library : parser.getLibraryToInstall().split(",")) {
|
||||||
String[] libraryToInstallParts = library.split(":");
|
String[] libraryToInstallParts = library.split(":");
|
||||||
@ -359,7 +359,7 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Optional<ContributedLibrary> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
|
Optional<ContributedLibrary> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
|
||||||
if (selected.isReadOnly() && mayInstalled.isPresent()) {
|
if (mayInstalled.isPresent() && mayInstalled.get().isIDEBuiltIn()) {
|
||||||
libraryInstaller.remove(mayInstalled.get(), progressListener);
|
libraryInstaller.remove(mayInstalled.get(), progressListener);
|
||||||
} else {
|
} else {
|
||||||
libraryInstaller.install(selected, mayInstalled, progressListener);
|
libraryInstaller.install(selected, mayInstalled, progressListener);
|
||||||
@ -1148,10 +1148,6 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Libraries can come from 4 locations: collect info about all four
|
// Libraries can come from 4 locations: collect info about all four
|
||||||
File ideLibraryPath = BaseNoGui.getContentFile("libraries");
|
|
||||||
File sketchbookLibraryPath = BaseNoGui.getSketchbookLibrariesFolder();
|
|
||||||
File platformLibraryPath = null;
|
|
||||||
File referencedPlatformLibraryPath = null;
|
|
||||||
String boardId = null;
|
String boardId = null;
|
||||||
String referencedPlatformName = null;
|
String referencedPlatformName = null;
|
||||||
String myArch = null;
|
String myArch = null;
|
||||||
@ -1159,14 +1155,12 @@ public class Base {
|
|||||||
if (targetPlatform != null) {
|
if (targetPlatform != null) {
|
||||||
myArch = targetPlatform.getId();
|
myArch = targetPlatform.getId();
|
||||||
boardId = BaseNoGui.getTargetBoard().getName();
|
boardId = BaseNoGui.getTargetBoard().getName();
|
||||||
platformLibraryPath = new File(targetPlatform.getFolder(), "libraries");
|
|
||||||
String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
|
String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
|
||||||
if (core.contains(":")) {
|
if (core.contains(":")) {
|
||||||
String refcore = core.split(":")[0];
|
String refcore = core.split(":")[0];
|
||||||
TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
|
TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
|
||||||
if (referencedPlatform != null) {
|
if (referencedPlatform != null) {
|
||||||
referencedPlatformName = referencedPlatform.getPreferences().get("name");
|
referencedPlatformName = referencedPlatform.getPreferences().get("name");
|
||||||
referencedPlatformLibraryPath = new File(referencedPlatform.getFolder(), "libraries");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1186,7 +1180,7 @@ public class Base {
|
|||||||
LibraryList otherLibs = new LibraryList();
|
LibraryList otherLibs = new LibraryList();
|
||||||
for (UserLibrary lib : allLibraries) {
|
for (UserLibrary lib : allLibraries) {
|
||||||
// Get the library's location - used for sorting into categories
|
// Get the library's location - used for sorting into categories
|
||||||
File libraryLocation = lib.getInstalledFolder().getParentFile();
|
Location location = lib.getLocation();
|
||||||
// Is this library compatible?
|
// Is this library compatible?
|
||||||
List<String> arch = lib.getArchitectures();
|
List<String> arch = lib.getArchitectures();
|
||||||
boolean compatible;
|
boolean compatible;
|
||||||
@ -1196,7 +1190,7 @@ public class Base {
|
|||||||
compatible = arch.contains(myArch);
|
compatible = arch.contains(myArch);
|
||||||
}
|
}
|
||||||
// IDE Libaries (including retired)
|
// IDE Libaries (including retired)
|
||||||
if (libraryLocation.equals(ideLibraryPath)) {
|
if (location == Location.IDE_BUILTIN) {
|
||||||
if (compatible) {
|
if (compatible) {
|
||||||
// only compatible IDE libs are shown
|
// only compatible IDE libs are shown
|
||||||
boolean retired = false;
|
boolean retired = false;
|
||||||
@ -1209,15 +1203,15 @@ public class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Platform Libraries
|
// Platform Libraries
|
||||||
} else if (libraryLocation.equals(platformLibraryPath)) {
|
} else if (location == Location.CORE) {
|
||||||
// all platform libs are assumed to be compatible
|
// all platform libs are assumed to be compatible
|
||||||
platformLibs.add(lib);
|
platformLibs.add(lib);
|
||||||
// Referenced Platform Libraries
|
// Referenced Platform Libraries
|
||||||
} else if (libraryLocation.equals(referencedPlatformLibraryPath)) {
|
} else if (location == Location.REFERENCED_CORE) {
|
||||||
// all referenced platform libs are assumed to be compatible
|
// all referenced platform libs are assumed to be compatible
|
||||||
referencedPlatformLibs.add(lib);
|
referencedPlatformLibs.add(lib);
|
||||||
// Sketchbook Libraries (including incompatible)
|
// Sketchbook Libraries (including incompatible)
|
||||||
} else if (libraryLocation.equals(sketchbookLibraryPath)) {
|
} else if (location == Location.SKETCHBOOK) {
|
||||||
if (compatible) {
|
if (compatible) {
|
||||||
// libraries promoted from sketchbook (behave as builtin)
|
// libraries promoted from sketchbook (behave as builtin)
|
||||||
if (lib.getTypes() != null && lib.getTypes().contains("Arduino")
|
if (lib.getTypes() != null && lib.getTypes().contains("Arduino")
|
||||||
@ -2321,7 +2315,7 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy folder
|
// copy folder
|
||||||
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
|
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName());
|
||||||
if (!destinationFolder.mkdir()) {
|
if (!destinationFolder.mkdir()) {
|
||||||
activeEditor.statusError(I18n.format(tr("A library named {0} already exists"), sourceFile.getName()));
|
activeEditor.statusError(I18n.format(tr("A library named {0} already exists"), sourceFile.getName()));
|
||||||
return;
|
return;
|
||||||
|
@ -247,7 +247,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
|
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
|
||||||
|
|
||||||
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
|
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
|
||||||
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder());
|
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder().folder);
|
||||||
|
|
||||||
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
|
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
|
||||||
cmd.add("-fqbn=" + fqbn);
|
cmd.add("-fqbn=" + fqbn);
|
||||||
|
@ -85,6 +85,13 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
|||||||
installedLib = Optional.empty();
|
installedLib = Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIDEBuiltIn() {
|
||||||
|
if (!installedLib.isPresent()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return installedLib.get().isIDEBuiltIn();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <b>true</b> if the library declares to support the specified
|
* Returns <b>true</b> if the library declares to support the specified
|
||||||
* architecture (through the "architectures" property field).
|
* architecture (through the "architectures" property field).
|
||||||
|
@ -39,11 +39,12 @@ import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
|||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import processing.app.BaseNoGui;
|
import processing.app.BaseNoGui;
|
||||||
import processing.app.I18n;
|
import processing.app.I18n;
|
||||||
import processing.app.helpers.FileUtils;
|
|
||||||
import processing.app.helpers.filefilters.OnlyDirs;
|
import processing.app.helpers.filefilters.OnlyDirs;
|
||||||
import processing.app.packages.LegacyUserLibrary;
|
import processing.app.packages.LegacyUserLibrary;
|
||||||
import processing.app.packages.LibraryList;
|
import processing.app.packages.LibraryList;
|
||||||
import processing.app.packages.UserLibrary;
|
import processing.app.packages.UserLibrary;
|
||||||
|
import processing.app.packages.UserLibraryFolder;
|
||||||
|
import processing.app.packages.UserLibraryFolder.Location;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -59,10 +60,9 @@ public class LibrariesIndexer {
|
|||||||
|
|
||||||
private LibrariesIndex index;
|
private LibrariesIndex index;
|
||||||
private final LibraryList installedLibraries = new LibraryList();
|
private final LibraryList installedLibraries = new LibraryList();
|
||||||
private List<File> librariesFolders;
|
private List<UserLibraryFolder> librariesFolders;
|
||||||
private final File indexFile;
|
private final File indexFile;
|
||||||
private final File stagingFolder;
|
private final File stagingFolder;
|
||||||
private File sketchbookLibrariesFolder;
|
|
||||||
|
|
||||||
private final List<String> badLibNotified = new ArrayList<>();
|
private final List<String> badLibNotified = new ArrayList<>();
|
||||||
|
|
||||||
@ -104,12 +104,12 @@ public class LibrariesIndexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLibrariesFolders(List<File> _librariesFolders) {
|
public void setLibrariesFolders(List<UserLibraryFolder> folders) {
|
||||||
librariesFolders = _librariesFolders;
|
librariesFolders = folders;
|
||||||
rescanLibraries();
|
rescanLibraries();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> getLibrariesFolders() {
|
public List<UserLibraryFolder> getLibrariesFolders() {
|
||||||
return librariesFolders;
|
return librariesFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +126,8 @@ public class LibrariesIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rescan libraries
|
// Rescan libraries
|
||||||
for (File folder : librariesFolders) {
|
for (UserLibraryFolder folderDesc : librariesFolders) {
|
||||||
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
|
scanInstalledLibraries(folderDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
installedLibraries.stream().filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore()).forEach(userLibrary -> {
|
installedLibraries.stream().filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore()).forEach(userLibrary -> {
|
||||||
@ -136,46 +136,47 @@ public class LibrariesIndexer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanInstalledLibraries(File folder, boolean isSketchbook) {
|
private void scanInstalledLibraries(UserLibraryFolder folderDesc) {
|
||||||
File list[] = folder.listFiles(OnlyDirs.ONLY_DIRS);
|
File list[] = folderDesc.folder.listFiles(OnlyDirs.ONLY_DIRS);
|
||||||
// if a bad folder or something like that, this might come back null
|
// if a bad folder or something like that, this might come back null
|
||||||
if (list == null)
|
if (list == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (File subfolder : list) {
|
for (File subfolder : list) {
|
||||||
if (!BaseNoGui.isSanitaryName(subfolder.getName())) {
|
String subfolderName = subfolder.getName();
|
||||||
|
if (!BaseNoGui.isSanitaryName(subfolderName)) {
|
||||||
|
|
||||||
// Detect whether the current folder name has already had a notification.
|
// Detect whether the current folder name has already had a notification.
|
||||||
if (!badLibNotified.contains(subfolder.getName())) {
|
if (!badLibNotified.contains(subfolderName)) {
|
||||||
|
|
||||||
badLibNotified.add(subfolder.getName());
|
badLibNotified.add(subfolderName);
|
||||||
|
|
||||||
String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n"
|
String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n"
|
||||||
+ "Library names must contain only basic letters and numbers.\n"
|
+ "Library names must contain only basic letters and numbers.\n"
|
||||||
+ "(ASCII only and no spaces, and it cannot start with a number)"),
|
+ "(ASCII only and no spaces, and it cannot start with a number)"),
|
||||||
subfolder.getName());
|
subfolderName);
|
||||||
BaseNoGui.showMessage(tr("Ignoring bad library name"), mess);
|
BaseNoGui.showMessage(tr("Ignoring bad library name"), mess);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scanLibrary(subfolder, isSketchbook);
|
scanLibrary(new UserLibraryFolder(subfolder, folderDesc.location));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(I18n.format(tr("Invalid library found in {0}: {1}"), subfolder, e.getMessage()));
|
System.out.println(I18n.format(tr("Invalid library found in {0}: {1}"), subfolder, e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanLibrary(File folder, boolean isSketchbook) throws IOException {
|
private void scanLibrary(UserLibraryFolder folderDesc) throws IOException {
|
||||||
boolean readOnly = !FileUtils.isSubDirectory(sketchbookLibrariesFolder, folder);
|
boolean readOnly = (folderDesc.location == Location.SKETCHBOOK);
|
||||||
|
|
||||||
// A library is considered "legacy" if it doesn't contains
|
// A library is considered "legacy" if it doesn't contains
|
||||||
// a file called "library.properties"
|
// a file called "library.properties"
|
||||||
File check = new File(folder, "library.properties");
|
File check = new File(folderDesc.folder, "library.properties");
|
||||||
if (!check.exists() || !check.isFile()) {
|
if (!check.exists() || !check.isFile()) {
|
||||||
// Create a legacy library and exit
|
// Create a legacy library and exit
|
||||||
LegacyUserLibrary lib = LegacyUserLibrary.create(folder);
|
LegacyUserLibrary lib = LegacyUserLibrary.create(folderDesc);
|
||||||
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder());
|
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder());
|
||||||
if (headers.length == 0) {
|
if (headers.length == 0) {
|
||||||
throw new IOException(lib.getSrcFolder().getAbsolutePath());
|
throw new IOException(lib.getSrcFolder().getAbsolutePath());
|
||||||
@ -185,7 +186,7 @@ public class LibrariesIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a regular library
|
// Create a regular library
|
||||||
UserLibrary lib = UserLibrary.create(folder);
|
UserLibrary lib = UserLibrary.create(folderDesc);
|
||||||
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder());
|
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder());
|
||||||
if (headers.length == 0) {
|
if (headers.length == 0) {
|
||||||
throw new IOException(lib.getSrcFolder().getAbsolutePath());
|
throw new IOException(lib.getSrcFolder().getAbsolutePath());
|
||||||
@ -221,19 +222,6 @@ public class LibrariesIndexer {
|
|||||||
return stagingFolder;
|
return stagingFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the sketchbook library folder. <br />
|
|
||||||
* New libraries will be installed here. <br />
|
|
||||||
* Libraries not found on this folder will be marked as read-only.
|
|
||||||
*/
|
|
||||||
public void setSketchbookLibrariesFolder(File folder) {
|
|
||||||
this.sketchbookLibrariesFolder = folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getSketchbookLibrariesFolder() {
|
|
||||||
return sketchbookLibrariesFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getIndexFile() {
|
public File getIndexFile() {
|
||||||
return indexFile;
|
return indexFile;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class LibraryInstaller {
|
|||||||
// Step 2: Unpack library on the correct location
|
// Step 2: Unpack library on the correct location
|
||||||
progress.setStatus(I18n.format(tr("Installing library: {0}"), lib.getName()));
|
progress.setStatus(I18n.format(tr("Installing library: {0}"), lib.getName()));
|
||||||
progressListener.onProgress(progress);
|
progressListener.onProgress(progress);
|
||||||
File libsFolder = BaseNoGui.librariesIndexer.getSketchbookLibrariesFolder();
|
File libsFolder = BaseNoGui.getSketchbookLibrariesFolder().folder;
|
||||||
File tmpFolder = FileUtils.createTempFolder(libsFolder);
|
File tmpFolder = FileUtils.createTempFolder(libsFolder);
|
||||||
try {
|
try {
|
||||||
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||||
@ -132,7 +132,7 @@ public class LibraryInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {
|
public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {
|
||||||
if (lib.isReadOnly()) {
|
if (lib.isIDEBuiltIn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
|||||||
import processing.app.legacy.PApplet;
|
import processing.app.legacy.PApplet;
|
||||||
import processing.app.packages.LibraryList;
|
import processing.app.packages.LibraryList;
|
||||||
import processing.app.packages.UserLibrary;
|
import processing.app.packages.UserLibrary;
|
||||||
|
import processing.app.packages.UserLibraryFolder;
|
||||||
|
import processing.app.packages.UserLibraryFolder.Location;
|
||||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||||
import processing.app.helpers.FileUtils;
|
import processing.app.helpers.FileUtils;
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ public class BaseNoGui {
|
|||||||
public static Map<String, LibraryList> importToLibraryTable;
|
public static Map<String, LibraryList> importToLibraryTable;
|
||||||
|
|
||||||
// XXX: Remove this field
|
// XXX: Remove this field
|
||||||
static private List<File> librariesFolders;
|
static private List<UserLibraryFolder> librariesFolders;
|
||||||
|
|
||||||
static UserNotifier notifier = new BasicUserNotifier();
|
static UserNotifier notifier = new BasicUserNotifier();
|
||||||
|
|
||||||
@ -245,7 +246,7 @@ public class BaseNoGui {
|
|||||||
return getHardwareFolder().getAbsolutePath();
|
return getHardwareFolder().getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public List<File> getLibrariesPath() {
|
static public List<UserLibraryFolder> getLibrariesFolders() {
|
||||||
return librariesFolders;
|
return librariesFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +327,7 @@ public class BaseNoGui {
|
|||||||
return new File(getSketchbookFolder(), "hardware");
|
return new File(getSketchbookFolder(), "hardware");
|
||||||
}
|
}
|
||||||
|
|
||||||
static public File getSketchbookLibrariesFolder() {
|
static public UserLibraryFolder getSketchbookLibrariesFolder() {
|
||||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||||
if (!libdir.exists()) {
|
if (!libdir.exists()) {
|
||||||
FileWriter freadme = null;
|
FileWriter freadme = null;
|
||||||
@ -340,7 +341,7 @@ public class BaseNoGui {
|
|||||||
IOUtils.closeQuietly(freadme);
|
IOUtils.closeQuietly(freadme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return libdir;
|
return new UserLibraryFolder(libdir, Location.SKETCHBOOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String getSketchbookPath() {
|
static public String getSketchbookPath() {
|
||||||
@ -651,7 +652,7 @@ public class BaseNoGui {
|
|||||||
librariesFolders = new ArrayList<>();
|
librariesFolders = new ArrayList<>();
|
||||||
|
|
||||||
// Add IDE libraries folder
|
// Add IDE libraries folder
|
||||||
librariesFolders.add(getContentFile("libraries"));
|
librariesFolders.add(new UserLibraryFolder(getContentFile("libraries"), Location.IDE_BUILTIN));
|
||||||
|
|
||||||
TargetPlatform targetPlatform = getTargetPlatform();
|
TargetPlatform targetPlatform = getTargetPlatform();
|
||||||
if (targetPlatform != null) {
|
if (targetPlatform != null) {
|
||||||
@ -663,13 +664,13 @@ public class BaseNoGui {
|
|||||||
File referencedPlatformFolder = referencedPlatform.getFolder();
|
File referencedPlatformFolder = referencedPlatform.getFolder();
|
||||||
// Add libraries folder for the referenced platform
|
// Add libraries folder for the referenced platform
|
||||||
File folder = new File(referencedPlatformFolder, "libraries");
|
File folder = new File(referencedPlatformFolder, "libraries");
|
||||||
librariesFolders.add(folder);
|
librariesFolders.add(new UserLibraryFolder(folder, Location.REFERENCED_CORE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File platformFolder = targetPlatform.getFolder();
|
File platformFolder = targetPlatform.getFolder();
|
||||||
// Add libraries folder for the selected platform
|
// Add libraries folder for the selected platform
|
||||||
File folder = new File(platformFolder, "libraries");
|
File folder = new File(platformFolder, "libraries");
|
||||||
librariesFolders.add(folder);
|
librariesFolders.add(new UserLibraryFolder(folder, Location.CORE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add libraries folder for the sketchbook
|
// Add libraries folder for the sketchbook
|
||||||
@ -678,10 +679,7 @@ public class BaseNoGui {
|
|||||||
// Scan for libraries in each library folder.
|
// Scan for libraries in each library folder.
|
||||||
// Libraries located in the latest folders on the list can override
|
// Libraries located in the latest folders on the list can override
|
||||||
// other libraries with the same name.
|
// other libraries with the same name.
|
||||||
librariesIndexer.setSketchbookLibrariesFolder(getSketchbookLibrariesFolder());
|
librariesIndexer.setLibrariesFolders(librariesFolders);
|
||||||
if (librariesIndexer.getLibrariesFolders() == null || !librariesIndexer.getLibrariesFolders().equals(librariesFolders)) {
|
|
||||||
librariesIndexer.setLibrariesFolders(librariesFolders);
|
|
||||||
}
|
|
||||||
|
|
||||||
populateImportToLibraryTable();
|
populateImportToLibraryTable();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
*/
|
*/
|
||||||
package processing.app.packages;
|
package processing.app.packages;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -36,14 +35,15 @@ public class LegacyUserLibrary extends UserLibrary {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public static LegacyUserLibrary create(File libFolder) {
|
public static LegacyUserLibrary create(UserLibraryFolder folderDesc) {
|
||||||
// construct an old style library
|
// construct an old style library
|
||||||
LegacyUserLibrary res = new LegacyUserLibrary();
|
LegacyUserLibrary res = new LegacyUserLibrary();
|
||||||
res.installedFolder = libFolder;
|
res.installedFolder = folderDesc.folder;
|
||||||
res.layout = LibraryLayout.FLAT;
|
res.layout = LibraryLayout.FLAT;
|
||||||
res.name = libFolder.getName();
|
res.name = folderDesc.folder.getName();
|
||||||
res.setTypes(Arrays.asList("Contributed"));
|
res.setTypes(Arrays.asList("Contributed"));
|
||||||
res.setCategory("Uncategorized");
|
res.setCategory("Uncategorized");
|
||||||
|
res.location = folderDesc.location;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import cc.arduino.Constants;
|
|||||||
import cc.arduino.contributions.VersionHelper;
|
import cc.arduino.contributions.VersionHelper;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReference;
|
import cc.arduino.contributions.libraries.ContributedLibraryReference;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
import processing.app.packages.UserLibraryFolder.Location;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -60,8 +61,12 @@ public class UserLibrary {
|
|||||||
private boolean onGoingDevelopment;
|
private boolean onGoingDevelopment;
|
||||||
private List<String> includes;
|
private List<String> includes;
|
||||||
protected File installedFolder;
|
protected File installedFolder;
|
||||||
|
protected Location location;
|
||||||
|
|
||||||
|
public static UserLibrary create(UserLibraryFolder libFolderDesc) throws IOException {
|
||||||
|
File libFolder = libFolderDesc.folder;
|
||||||
|
Location location = libFolderDesc.location;
|
||||||
|
|
||||||
public static UserLibrary create(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();
|
||||||
@ -161,6 +166,7 @@ public class UserLibrary {
|
|||||||
res.declaredTypes = typesList;
|
res.declaredTypes = typesList;
|
||||||
res.onGoingDevelopment = Files.exists(Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
|
res.onGoingDevelopment = Files.exists(Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
|
||||||
res.includes = includes;
|
res.includes = includes;
|
||||||
|
res.location = location;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,9 +259,17 @@ public class UserLibrary {
|
|||||||
return (layout == LibraryLayout.RECURSIVE);
|
return (layout == LibraryLayout.RECURSIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIDEBuiltIn() {
|
||||||
|
return getLocation() == Location.IDE_BUILTIN;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name + ":" + version + " " + architectures + " " + installedFolder.getAbsolutePath();
|
return name + ":" + version + " " + architectures + " " + location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getInstalledFolder() {
|
public File getInstalledFolder() {
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2017 Arduino AG (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package processing.app.packages;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class UserLibraryFolder {
|
||||||
|
|
||||||
|
public enum Location {
|
||||||
|
SKETCHBOOK, CORE, REFERENCED_CORE, IDE_BUILTIN,
|
||||||
|
}
|
||||||
|
|
||||||
|
public File folder;
|
||||||
|
|
||||||
|
public Location location;
|
||||||
|
|
||||||
|
public UserLibraryFolder(File folder, Location location) {
|
||||||
|
this.folder = folder;
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user