1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-13 10:29:35 +01:00

Removed the now useless UserLibraryFolder

This commit is contained in:
Cristian Maglie 2019-12-05 18:02:24 +01:00
parent 3c46af8d2c
commit 0056cbc545
8 changed files with 49 additions and 93 deletions

View File

@ -57,7 +57,6 @@ 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;
@ -78,6 +77,10 @@ import java.util.stream.Stream;
import static processing.app.I18n.format; import static processing.app.I18n.format;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
import static processing.app.packages.UserLibrary.LOCATION_CORE;
import static processing.app.packages.UserLibrary.LOCATION_IDE;
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
/** /**
@ -1218,7 +1221,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
Location location = lib.getLocation(); String location = lib.getLocation();
// Is this library compatible? // Is this library compatible?
Collection<String> arch = lib.getArchitectures(); Collection<String> arch = lib.getArchitectures();
boolean compatible; boolean compatible;
@ -1228,7 +1231,7 @@ public class Base {
compatible = arch.contains(myArch); compatible = arch.contains(myArch);
} }
// IDE Libaries (including retired) // IDE Libaries (including retired)
if (location == Location.IDE_BUILTIN) { if (location.equals(LOCATION_IDE)) {
if (compatible) { if (compatible) {
// only compatible IDE libs are shown // only compatible IDE libs are shown
if (lib.getTypes().contains("Retired")) { if (lib.getTypes().contains("Retired")) {
@ -1238,15 +1241,15 @@ public class Base {
} }
} }
// Platform Libraries // Platform Libraries
} else if (location == Location.CORE) { } else if (location.equals(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 (location == Location.REFERENCED_CORE) { } else if (location.equals(LOCATION_REF_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 (location == Location.SKETCHBOOK) { } else if (location.equals(LOCATION_SKETCHBOOK)) {
if (compatible) { if (compatible) {
// libraries promoted from sketchbook (behave as builtin) // libraries promoted from sketchbook (behave as builtin)
if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino") if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
@ -2462,7 +2465,7 @@ public class Base {
} }
// copy folder // copy folder
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName()); File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
if (!destinationFolder.mkdir()) { if (!destinationFolder.mkdir()) {
activeEditor.statusError(format(tr("A library named {0} already exists"), sourceFile.getName())); activeEditor.statusError(format(tr("A library named {0} already exists"), sourceFile.getName()));
return; return;

View File

@ -249,7 +249,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().folder); addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder());
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);

View File

@ -35,7 +35,8 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.VersionComparator;
import processing.app.packages.UserLibraryFolder.Location;
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
public class ContributedLibrary { public class ContributedLibrary {
@ -77,12 +78,12 @@ public class ContributedLibrary {
return releases.values().stream() // return releases.values().stream() //
.filter(ContributedLibraryRelease::isLibraryInstalled) // .filter(ContributedLibraryRelease::isLibraryInstalled) //
.reduce((x, y) -> { .reduce((x, y) -> {
Location lx = x.getInstalledLibrary().get().getLocation(); String lx = x.getInstalledLibrary().get().getLocation();
Location ly = y.getInstalledLibrary().get().getLocation(); String ly = y.getInstalledLibrary().get().getLocation();
if (lx == ly) { if (lx.equals(ly)) {
return VersionComparator.max(x, y); return VersionComparator.max(x, y);
} }
return lx == Location.SKETCHBOOK ? x : y; return lx.equals(LOCATION_SKETCHBOOK) ? x : y;
}); });
} }

View File

@ -31,6 +31,9 @@ package cc.arduino.contributions.libraries;
import static processing.app.I18n.format; import static processing.app.I18n.format;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
import static processing.app.packages.UserLibrary.LOCATION_CORE;
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -49,7 +52,6 @@ import processing.app.debug.TargetPlatform;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
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.packages.UserLibraryPriorityComparator; import processing.app.packages.UserLibraryPriorityComparator;
public class LibrariesIndexer { public class LibrariesIndexer {
@ -206,8 +208,8 @@ public class LibrariesIndexer {
lib.getSrcFolder())); lib.getSrcFolder()));
} }
Location loc = lib.getLocation(); String loc = lib.getLocation();
if (loc != Location.CORE && loc != Location.REFERENCED_CORE) { if (!loc.equals(LOCATION_CORE) && !loc.equals(LOCATION_REF_CORE)) {
// Check if we can find the same library in the index // Check if we can find the same library in the index
// and mark it as installed // and mark it as installed
index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> { index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> {
@ -216,7 +218,7 @@ public class LibrariesIndexer {
}); });
} }
if (lib.getTypes().isEmpty() && loc == Location.SKETCHBOOK) { if (lib.getTypes().isEmpty() && loc.equals(LOCATION_SKETCHBOOK)) {
lib.setTypes(lib.getDeclaredTypes()); lib.setTypes(lib.getDeclaredTypes());
} }
@ -233,8 +235,8 @@ public class LibrariesIndexer {
// TODO: Should be done on the CLI? // TODO: Should be done on the CLI?
installedLibraries.stream() // installedLibraries.stream() //
.filter(l -> l.getTypes().contains("Contributed")) // .filter(l -> l.getTypes().contains("Contributed")) //
.filter(l -> l.getLocation() == Location.CORE .filter(l -> l.getLocation().equals(LOCATION_CORE)
|| l.getLocation() == Location.REFERENCED_CORE) // || l.getLocation().equals(LOCATION_REF_CORE)) //
.forEach(l -> { .forEach(l -> {
File libFolder = l.getInstalledFolder(); File libFolder = l.getInstalledFolder();
Optional<ContributedPlatform> platform = BaseNoGui.indexer Optional<ContributedPlatform> platform = BaseNoGui.indexer

View File

@ -21,8 +21,6 @@ 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;
@ -343,7 +341,7 @@ public class BaseNoGui {
return new File(getSketchbookFolder(), "hardware"); return new File(getSketchbookFolder(), "hardware");
} }
static public UserLibraryFolder getSketchbookLibrariesFolder() { static public File 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;
@ -357,7 +355,7 @@ public class BaseNoGui {
IOUtils.closeQuietly(freadme); IOUtils.closeQuietly(freadme);
} }
} }
return new UserLibraryFolder(libdir, Location.SKETCHBOOK); return libdir;
} }
static public String getSketchbookPath() { static public String getSketchbookPath() {

View File

@ -47,7 +47,6 @@ import cc.arduino.Constants;
import cc.arduino.contributions.VersionHelper; import cc.arduino.contributions.VersionHelper;
import cc.arduino.contributions.libraries.ContributedLibraryDependency; import cc.arduino.contributions.libraries.ContributedLibraryDependency;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
import processing.app.packages.UserLibraryFolder.Location;
public class UserLibrary { public class UserLibrary {
@ -66,12 +65,14 @@ public class UserLibrary {
private boolean onGoingDevelopment; private boolean onGoingDevelopment;
private Collection<String> includes; private Collection<String> includes;
protected File installedFolder; protected File installedFolder;
protected Location location;
public static UserLibrary create(UserLibraryFolder libFolderDesc) throws IOException { public static final String LOCATION_IDE = "ide";
File libFolder = libFolderDesc.folder; public static final String LOCATION_SKETCHBOOK = "sketchbook";
String location = libFolderDesc.location.toString(); public static final String LOCATION_CORE = "platform";
public static final String LOCATION_REF_CORE = "ref-platform";
protected String location;
public static UserLibrary create(File libFolder, String location) 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();
@ -211,15 +212,12 @@ public class UserLibrary {
this.declaredTypes = declaredTypes; this.declaredTypes = declaredTypes;
this.onGoingDevelopment = onGoingDevelopment; this.onGoingDevelopment = onGoingDevelopment;
this.includes = includes; this.includes = includes;
this.location = location;
switch (location) { switch (location) {
case "ide": case LOCATION_IDE:
this.location = Location.IDE_BUILTIN; case LOCATION_SKETCHBOOK:
break; case LOCATION_CORE:
case "sketchbook": case LOCATION_REF_CORE:
this.location = Location.SKETCHBOOK;
break;
case "platform":
this.location = Location.CORE;
break; break;
default: default:
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -316,12 +314,12 @@ public class UserLibrary {
return (layout == LibraryLayout.RECURSIVE); return (layout == LibraryLayout.RECURSIVE);
} }
public Location getLocation() { public String getLocation() {
return location; return location;
} }
public boolean isIDEBuiltIn() { public boolean isIDEBuiltIn() {
return getLocation() == Location.IDE_BUILTIN; return getLocation().equals(LOCATION_IDE);
} }
@Override @Override

View File

@ -1,49 +0,0 @@
/*
* 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;
}
}

View File

@ -32,16 +32,19 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import processing.app.packages.UserLibraryFolder.Location; import static processing.app.packages.UserLibrary.LOCATION_CORE;
import static processing.app.packages.UserLibrary.LOCATION_IDE;
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
public class UserLibraryPriorityComparator implements Comparator<UserLibrary> { public class UserLibraryPriorityComparator implements Comparator<UserLibrary> {
private final static Map<Location, Integer> priorities = new HashMap<>(); private final static Map<String, Integer> priorities = new HashMap<>();
static { static {
priorities.put(Location.SKETCHBOOK, 4); priorities.put(LOCATION_SKETCHBOOK, 4);
priorities.put(Location.CORE, 3); priorities.put(LOCATION_CORE, 3);
priorities.put(Location.REFERENCED_CORE, 2); priorities.put(LOCATION_REF_CORE, 2);
priorities.put(Location.IDE_BUILTIN, 1); priorities.put(LOCATION_IDE, 1);
} }
private String arch; private String arch;