Skip to content

Commit a4a7e3e

Browse files
author
Federico Fissore
committed
Libraries in unknown categories get set as Uncategorized. Fixes #3732
1 parent f84b58e commit a4a7e3e

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

arduino-core/src/cc/arduino/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class Constants {
6565
public static final String LIBRARY_INDEX_URL;
6666
public static final String LIBRARY_INDEX_URL_GZ;
6767

68+
public static final List<String> LIBRARY_CATEGORIES = Arrays.asList("Display", "Communication", "Signal Input/Output", "Sensors", "Device Control", "Timing", "Data Storage", "Data Processing", "Other", "Uncategorized");
69+
public static final List<String> LIBRARY_MANDATORY_PROPERTIES = Arrays.asList("name", "version", "author", "maintainer", "sentence", "paragraph", "url");
70+
6871
static {
6972
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
7073
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
package cc.arduino.contributions.libraries;
3131

32+
import cc.arduino.Constants;
3233
import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore;
3334
import cc.arduino.contributions.libraries.filters.TypePredicate;
3435
import cc.arduino.contributions.packages.ContributedPlatform;
@@ -92,7 +93,7 @@ private void parseIndex(File indexFile) throws IOException {
9293

9394
index.getLibraries()
9495
.stream()
95-
.filter(library -> library.getCategory() == null || "".equals(library.getCategory()))
96+
.filter(library -> library.getCategory() == null || "".equals(library.getCategory()) || !Constants.LIBRARY_CATEGORIES.contains(library.getCategory()))
9697
.forEach(library -> library.setCategory("Uncategorized"));
9798
} finally {
9899
IOUtils.closeQuietly(indexIn);

arduino-core/src/processing/app/packages/UserLibrary.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.nio.file.Files;
4040
import java.nio.file.Paths;
4141
import java.util.ArrayList;
42-
import java.util.Arrays;
4342
import java.util.LinkedList;
4443
import java.util.List;
4544

@@ -59,15 +58,6 @@ public class UserLibrary extends ContributedLibrary {
5958
private List<String> declaredTypes;
6059
private boolean onGoingDevelopment;
6160

62-
private static final List<String> MANDATORY_PROPERTIES = Arrays
63-
.asList("name", "version", "author", "maintainer",
64-
"sentence", "paragraph", "url");
65-
66-
private static final List<String> CATEGORIES = Arrays.asList(
67-
"Display", "Communication", "Signal Input/Output", "Sensors",
68-
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
69-
"Uncategorized");
70-
7161
public static UserLibrary create(File libFolder) throws IOException {
7262
// Parse metadata
7363
File propertiesFile = new File(libFolder, "library.properties");
@@ -90,7 +80,7 @@ public static UserLibrary create(File libFolder) throws IOException {
9080
throw new IOException("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");
9181

9282
// Check mandatory properties
93-
for (String p : MANDATORY_PROPERTIES)
83+
for (String p : Constants.LIBRARY_MANDATORY_PROPERTIES)
9484
if (!properties.containsKey(p))
9585
throw new IOException("Missing '" + p + "' from library");
9686

@@ -135,7 +125,7 @@ public static UserLibrary create(File libFolder) throws IOException {
135125
String category = properties.get("category");
136126
if (category == null)
137127
category = "Uncategorized";
138-
if (!CATEGORIES.contains(category)) {
128+
if (!Constants.LIBRARY_CATEGORIES.contains(category)) {
139129
System.out.println("WARNING: Category '" + category + "' in library " + properties.get("name") + " is not valid. Setting to 'Uncategorized'");
140130
category = "Uncategorized";
141131
}
@@ -222,10 +212,6 @@ public String getLicense() {
222212
return license;
223213
}
224214

225-
public static List<String> getCategories() {
226-
return CATEGORIES;
227-
}
228-
229215
@Override
230216
public void setCategory(String category) {
231217
this.category = category;

0 commit comments

Comments
 (0)