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 String getCategory();
|
||||||
|
|
||||||
|
public abstract void setCategory(String category);
|
||||||
|
|
||||||
public abstract String getLicense();
|
public abstract String getLicense();
|
||||||
|
|
||||||
public abstract String getParagraph();
|
public abstract String getParagraph();
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
*/
|
*/
|
||||||
package cc.arduino.libraries.contributions;
|
package cc.arduino.libraries.contributions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class LibrariesIndex {
|
public abstract class LibrariesIndex {
|
||||||
|
|
||||||
|
@ -46,24 +44,22 @@ public abstract class LibrariesIndex {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String res = "";
|
StringBuilder sb = new StringBuilder();
|
||||||
for (ContributedLibrary l : getLibraries())
|
for (ContributedLibrary library : getLibraries()) {
|
||||||
res += l.toString();
|
sb.append(library.toString());
|
||||||
return res;
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> categories = new ArrayList<String>();
|
|
||||||
|
|
||||||
public List<String> getCategories() {
|
public List<String> getCategories() {
|
||||||
return categories;
|
List<String> categories = new LinkedList<String>();
|
||||||
}
|
|
||||||
|
|
||||||
public void fillCategories() {
|
|
||||||
categories.clear();
|
|
||||||
for (ContributedLibrary lib : getLibraries()) {
|
for (ContributedLibrary lib : getLibraries()) {
|
||||||
if (!categories.contains(lib.getCategory()))
|
if (lib.getCategory() != null && !categories.contains(lib.getCategory())) {
|
||||||
categories.add(lib.getCategory());
|
categories.add(lib.getCategory());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(categories);
|
Collections.sort(categories);
|
||||||
|
|
||||||
|
return categories;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,15 +64,12 @@ public class LibrariesIndexer {
|
||||||
"libraries");
|
"libraries");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseIndex() throws JsonParseException, IOException {
|
public void parseIndex() throws IOException {
|
||||||
parseIndex(indexFile);
|
parseIndex(indexFile);
|
||||||
|
|
||||||
index.fillCategories();
|
|
||||||
// TODO: resolve libraries inner references
|
// TODO: resolve libraries inner references
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseIndex(File indexFile) throws JsonParseException,
|
private void parseIndex(File indexFile) throws IOException {
|
||||||
IOException {
|
|
||||||
InputStream indexIn = new FileInputStream(indexFile);
|
InputStream indexIn = new FileInputStream(indexFile);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.registerModule(new MrBeanModule());
|
mapper.registerModule(new MrBeanModule());
|
||||||
|
@ -80,6 +77,12 @@ public class LibrariesIndexer {
|
||||||
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
||||||
index = mapper.readValue(indexIn, LibrariesIndex.class);
|
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)
|
public void setLibrariesFolders(List<File> _librariesFolders)
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class LegacyUserLibrary extends UserLibrary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory() {
|
public String getCategory() {
|
||||||
return null;
|
return "Uncategorized";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -199,6 +199,11 @@ public class UserLibrary extends ContributedLibrary {
|
||||||
return CATEGORIES;
|
return CATEGORIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return version;
|
||||||
|
|
Loading…
Reference in New Issue