1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Libraries in unknown categories get set as Uncategorized. Fixes #3732

This commit is contained in:
Federico Fissore 2015-09-08 15:30:34 +02:00
parent f84b58e96d
commit a4a7e3ec96
3 changed files with 7 additions and 17 deletions

View File

@ -65,6 +65,9 @@ public class Constants {
public static final String LIBRARY_INDEX_URL; public static final String LIBRARY_INDEX_URL;
public static final String LIBRARY_INDEX_URL_GZ; public static final String LIBRARY_INDEX_URL_GZ;
public static final List<String> LIBRARY_CATEGORIES = Arrays.asList("Display", "Communication", "Signal Input/Output", "Sensors", "Device Control", "Timing", "Data Storage", "Data Processing", "Other", "Uncategorized");
public static final List<String> LIBRARY_MANDATORY_PROPERTIES = Arrays.asList("name", "version", "author", "maintainer", "sentence", "paragraph", "url");
static { static {
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL"); String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) { if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {

View File

@ -29,6 +29,7 @@
package cc.arduino.contributions.libraries; package cc.arduino.contributions.libraries;
import cc.arduino.Constants;
import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore; import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore;
import cc.arduino.contributions.libraries.filters.TypePredicate; import cc.arduino.contributions.libraries.filters.TypePredicate;
import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedPlatform;
@ -92,7 +93,7 @@ public class LibrariesIndexer {
index.getLibraries() index.getLibraries()
.stream() .stream()
.filter(library -> library.getCategory() == null || "".equals(library.getCategory())) .filter(library -> library.getCategory() == null || "".equals(library.getCategory()) || !Constants.LIBRARY_CATEGORIES.contains(library.getCategory()))
.forEach(library -> library.setCategory("Uncategorized")); .forEach(library -> library.setCategory("Uncategorized"));
} finally { } finally {
IOUtils.closeQuietly(indexIn); IOUtils.closeQuietly(indexIn);

View File

@ -39,7 +39,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -59,15 +58,6 @@ public class UserLibrary extends ContributedLibrary {
private List<String> declaredTypes; private List<String> declaredTypes;
private boolean onGoingDevelopment; private boolean onGoingDevelopment;
private static final List<String> MANDATORY_PROPERTIES = Arrays
.asList("name", "version", "author", "maintainer",
"sentence", "paragraph", "url");
private static final List<String> CATEGORIES = Arrays.asList(
"Display", "Communication", "Signal Input/Output", "Sensors",
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
"Uncategorized");
public static UserLibrary create(File libFolder) throws IOException { 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");
@ -90,7 +80,7 @@ public class UserLibrary extends ContributedLibrary {
throw new IOException("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information"); throw new IOException("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");
// Check mandatory properties // Check mandatory properties
for (String p : MANDATORY_PROPERTIES) for (String p : Constants.LIBRARY_MANDATORY_PROPERTIES)
if (!properties.containsKey(p)) if (!properties.containsKey(p))
throw new IOException("Missing '" + p + "' from library"); throw new IOException("Missing '" + p + "' from library");
@ -135,7 +125,7 @@ public class UserLibrary extends ContributedLibrary {
String category = properties.get("category"); String category = properties.get("category");
if (category == null) if (category == null)
category = "Uncategorized"; category = "Uncategorized";
if (!CATEGORIES.contains(category)) { if (!Constants.LIBRARY_CATEGORIES.contains(category)) {
System.out.println("WARNING: Category '" + category + "' in library " + properties.get("name") + " is not valid. Setting to 'Uncategorized'"); System.out.println("WARNING: Category '" + category + "' in library " + properties.get("name") + " is not valid. Setting to 'Uncategorized'");
category = "Uncategorized"; category = "Uncategorized";
} }
@ -222,10 +212,6 @@ public class UserLibrary extends ContributedLibrary {
return license; return license;
} }
public static List<String> getCategories() {
return CATEGORIES;
}
@Override @Override
public void setCategory(String category) { public void setCategory(String category) {
this.category = category; this.category = category;