mirror of https://github.com/noisymime/Arduino.git
LibraryIndex: removed cateogories field, generating it every time
LibrariesIndexer: setting category to Uncategorized when missing
This commit is contained in:
parent
86f84c8a3e
commit
56b9fd7d93
|
@ -47,6 +47,8 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
|||
|
||||
public abstract String getCategory();
|
||||
|
||||
public abstract void setCategory(String category);
|
||||
|
||||
public abstract String getLicense();
|
||||
|
||||
public abstract String getParagraph();
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
*/
|
||||
package cc.arduino.libraries.contributions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class LibrariesIndex {
|
||||
|
||||
|
@ -46,24 +44,22 @@ public abstract class LibrariesIndex {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "";
|
||||
for (ContributedLibrary l : getLibraries())
|
||||
res += l.toString();
|
||||
return res;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (ContributedLibrary library : getLibraries()) {
|
||||
sb.append(library.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private List<String> categories = new ArrayList<String>();
|
||||
|
||||
public List<String> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void fillCategories() {
|
||||
categories.clear();
|
||||
List<String> categories = new LinkedList<String>();
|
||||
for (ContributedLibrary lib : getLibraries()) {
|
||||
if (!categories.contains(lib.getCategory()))
|
||||
if (lib.getCategory() != null && !categories.contains(lib.getCategory())) {
|
||||
categories.add(lib.getCategory());
|
||||
}
|
||||
}
|
||||
Collections.sort(categories);
|
||||
|
||||
return categories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,15 +64,12 @@ public class LibrariesIndexer {
|
|||
"libraries");
|
||||
}
|
||||
|
||||
public void parseIndex() throws JsonParseException, IOException {
|
||||
public void parseIndex() throws IOException {
|
||||
parseIndex(indexFile);
|
||||
|
||||
index.fillCategories();
|
||||
// TODO: resolve libraries inner references
|
||||
}
|
||||
|
||||
private void parseIndex(File indexFile) throws JsonParseException,
|
||||
IOException {
|
||||
private void parseIndex(File indexFile) throws IOException {
|
||||
InputStream indexIn = new FileInputStream(indexFile);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new MrBeanModule());
|
||||
|
@ -80,6 +77,12 @@ public class LibrariesIndexer {
|
|||
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
||||
index = mapper.readValue(indexIn, LibrariesIndex.class);
|
||||
|
||||
for (ContributedLibrary library : index.getLibraries()) {
|
||||
if (library.getCategory() == null || "".equals(library.getCategory())) {
|
||||
library.setCategory("Uncategorized");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLibrariesFolders(List<File> _librariesFolders)
|
||||
|
|
|
@ -80,7 +80,7 @@ public class LegacyUserLibrary extends UserLibrary {
|
|||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return null;
|
||||
return "Uncategorized";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -199,6 +199,11 @@ public class UserLibrary extends ContributedLibrary {
|
|||
return CATEGORIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
|
|
Loading…
Reference in New Issue