LibraryIndex: removed cateogories field, generating it every time

LibrariesIndexer: setting category to Uncategorized when missing
This commit is contained in:
Federico Fissore 2015-02-24 12:32:52 +01:00
parent 86f84c8a3e
commit 56b9fd7d93
5 changed files with 30 additions and 24 deletions

View File

@ -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();
@ -79,7 +81,7 @@ public abstract class ContributedLibrary extends DownloadableContribution {
/**
* Returns <b>true</b> if the library declares to support the specified
* architecture (through the "architectures" property field).
*
*
* @param reqArch
* @return
*/
@ -91,7 +93,7 @@ public abstract class ContributedLibrary extends DownloadableContribution {
/**
* Returns <b>true</b> if the library declares to support at least one of the
* specified architectures.
*
*
* @param reqArchs
* A List of architectures to check
* @return

View File

@ -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;
}
}

View File

@ -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)
@ -172,7 +175,7 @@ public class LibrariesIndexer {
* Set the sketchbook library folder. <br />
* New libraries will be installed here. <br />
* Libraries not found on this folder will be marked as read-only.
*
*
* @param folder
*/
public void setSketchbookLibrariesFolder(File folder) {

View File

@ -80,7 +80,7 @@ public class LegacyUserLibrary extends UserLibrary {
@Override
public String getCategory() {
return null;
return "Uncategorized";
}
@Override

View File

@ -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;