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

Remove "MrBean" dependency

Sacrifice abstract classes and interfaces to reduce the amount of magic
performed by MrBean.

Refs https://github.com/HuayraLinux/pkg-arduino/issues/4
This commit is contained in:
Thomas L. Kjeldsen 2020-01-31 17:06:11 +01:00 committed by Cristian Maglie
parent 15133a0720
commit 488388050e
24 changed files with 143 additions and 153 deletions

View File

@ -23,7 +23,6 @@
<classpathentry kind="lib" path="app/lib/bcprov-jdk15on-152.jar"/>
<classpathentry kind="lib" path="app/lib/jackson-core-2.9.5.jar"/>
<classpathentry kind="lib" path="app/lib/jackson-databind-2.9.5.jar"/>
<classpathentry kind="lib" path="app/lib/jackson-module-mrbean-2.9.5.jar"/>
<classpathentry kind="lib" path="app/lib/jackson-annotations-2.9.5.jar"/>
<classpathentry kind="lib" path="app/lib/commons-compress-1.8.jar"/>
<classpathentry kind="lib" path="app/lib/commons-lang3-3.8.1.jar"/>

View File

@ -34,7 +34,6 @@
<classpathentry kind="lib" path="lib/jackson-annotations-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-databind-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-module-mrbean-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/java-semver-0.8.0.jar"/>
<classpathentry kind="lib" path="lib/jmdns-3.5.3.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/>

View File

@ -4,7 +4,6 @@ import cc.arduino.contributions.libraries.LibrariesIndex;
import cc.arduino.utils.MultiStepProgress;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -47,7 +46,6 @@ public class GzippedJsonDownloaderTest {
InputStream indexIn = new FileInputStream(tempFile);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -4,7 +4,6 @@ import cc.arduino.contributions.libraries.LibrariesIndex;
import cc.arduino.utils.MultiStepProgress;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -46,7 +45,6 @@ public class JsonDownloaderTest {
InputStream indexIn = new FileInputStream(tempFile);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -20,7 +20,6 @@
<classpathentry kind="lib" path="lib/jackson-annotations-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-databind-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/jackson-module-mrbean-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/java-semver-0.8.0.jar"/>
<classpathentry kind="lib" path="lib/jna-4.2.2.jar"/>
<classpathentry kind="lib" path="lib/jna-platform-4.2.2.jar"/>

View File

@ -35,38 +35,69 @@ import processing.app.packages.UserLibrary;
import static processing.app.I18n.tr;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import cc.arduino.contributions.VersionHelper;
public abstract class ContributedLibrary extends DownloadableContribution {
public class ContributedLibrary extends DownloadableContribution {
public abstract String getName();
private String url;
public String getUrl() { return url; }
public abstract String getMaintainer();
private String version;
public String getVersion() { return version; }
public abstract String getAuthor();
private String checksum;
public String getChecksum() { return checksum; }
public abstract String getWebsite();
private long size;
public long getSize() { return size; }
public abstract String getCategory();
private String archiveFileName;
public String getArchiveFileName() { return archiveFileName; }
public abstract void setCategory(String category);
public abstract String getLicense();
public abstract String getParagraph();
private String name;
public String getName() { return name; }
public abstract String getSentence();
private String maintainer;
public String getMaintainer() { return maintainer; }
public abstract List<String> getArchitectures();
private String author;
public String getAuthor() { return author; }
public abstract List<String> getTypes();
private String website;
public String getWebsite() { return website; }
private String category;
public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
private String licence;
public String getLicense() { return licence; }
private String paragraph;
public String getParagraph() { return paragraph; }
private String sentence;
public String getSentence() { return sentence; }
private ArrayList<String> architectures;
public List<String> getArchitectures() { return architectures; }
private ArrayList<String> types;
public List<String> getTypes() { return types; }
private ArrayList<ContributedLibraryDependency> dependencies;
public List<ContributedLibraryDependency> getDependencies() { return dependencies; }
private ArrayList<String> providesIncludes;
public List<String> getProvidesIncludes() { return providesIncludes; }
public abstract List<ContributedLibraryDependency> getDependencies();
public abstract List<String> getProvidesIncludes();
public static final Comparator<ContributedLibrary> CASE_INSENSITIVE_ORDER = (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());

View File

@ -29,11 +29,13 @@
package cc.arduino.contributions.libraries;
public abstract class ContributedLibraryDependency {
public class ContributedLibraryDependency {
public abstract String getName();
private String name;
public String getName() { return name; }
public abstract String getVersion();
private String version;
public String getVersion() { return version; }
@Override
public String toString() {

View File

@ -1,44 +0,0 @@
/*
* This file is part of Arduino.
*
* Copyright 2016 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.contributions.libraries;
import java.util.ArrayList;
import java.util.List;
public class EmptyLibrariesIndex extends LibrariesIndex {
private List<ContributedLibrary> list = new ArrayList<>();
@Override
public List<ContributedLibrary> getLibraries() {
return list;
}
}

View File

@ -40,9 +40,13 @@ import java.util.stream.Collectors;
import cc.arduino.contributions.VersionComparator;
public abstract class LibrariesIndex {
public class LibrariesIndex {
public abstract List<ContributedLibrary> getLibraries();
private ArrayList<ContributedLibrary> list = new ArrayList<>();
public List<ContributedLibrary> getLibraries() {
return list;
}
public List<ContributedLibrary> find(final String name) {
return getLibraries().stream() //

View File

@ -36,7 +36,6 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.BaseNoGui;
import processing.app.I18n;
@ -76,7 +75,7 @@ public class LibrariesIndexer {
}
public void parseIndex() throws IOException {
index = new EmptyLibrariesIndex(); // Fallback
index = new LibrariesIndex(); // Fallback
if (!indexFile.exists()) {
return;
@ -92,7 +91,6 @@ public class LibrariesIndexer {
try {
indexIn = new FileInputStream(file);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -29,8 +29,9 @@
package cc.arduino.contributions.packages;
public interface ContributedBoard {
public class ContributedBoard {
String getName();
private String name;
public String getName() { return name; }
}

View File

@ -29,8 +29,9 @@
package cc.arduino.contributions.packages;
public abstract class ContributedHelp {
public class ContributedHelp {
public abstract String getOnline();
private String online;
public String getOnline() { return online; }
}

View File

@ -29,23 +29,31 @@
package cc.arduino.contributions.packages;
import java.util.ArrayList;
import java.util.List;
public abstract class ContributedPackage {
public class ContributedPackage {
public abstract String getName();
private String name;
public String getName() { return name; }
public abstract String getMaintainer();
private String maintainer;
public String getMaintainer() { return maintainer; }
public abstract String getWebsiteURL();
private String websiteURL;
public String getWebsiteURL() { return websiteURL; }
public abstract String getEmail();
private String email;
public String getEmail() { return email; }
public abstract List<ContributedPlatform> getPlatforms();
private ArrayList<ContributedPlatform> platforms = new ArrayList<ContributedPlatform>();
public List<ContributedPlatform> getPlatforms() { return platforms; }
public abstract List<ContributedTool> getTools();
private ArrayList<ContributedTool> tools = new ArrayList<ContributedTool>();
public List<ContributedTool> getTools() { return tools; }
public abstract ContributedHelp getHelp();
private ContributedHelp help;
public ContributedHelp getHelp() { return help; }
private boolean trusted;

View File

@ -35,24 +35,42 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.File;
import java.util.*;
public abstract class ContributedPlatform extends DownloadableContribution {
public class ContributedPlatform extends DownloadableContribution {
public abstract String getName();
private String url;
public String getUrl() { return url; }
public abstract String getCategory();
private String version;
public String getVersion() { return version; }
public abstract void setCategory(String category);
private long size;
public long getSize() { return size; }
public abstract String getArchitecture();
private String archiveFileName;
public String getArchiveFileName() { return archiveFileName; }
private String name;
public String getName() { return name; }
private String category;
public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
private String architecture;
public String getArchitecture() { return architecture; }
private String checksum;
@Override
public abstract String getChecksum();
public String getChecksum() { return checksum; }
public abstract List<ContributedToolReference> getToolsDependencies();
private ArrayList<ContributedToolReference> toolsDependencies = new ArrayList<ContributedToolReference>();
public List<ContributedToolReference> getToolsDependencies() { return toolsDependencies; }
public abstract List<ContributedBoard> getBoards();
private ArrayList<ContributedBoard> boards = new ArrayList<ContributedBoard>();
public List<ContributedBoard> getBoards() { return boards; }
public abstract ContributedHelp getHelp();
private ContributedHelp help;
public ContributedHelp getHelp() { return help; }
private boolean installed;

View File

@ -33,15 +33,19 @@ import cc.arduino.contributions.DownloadableContribution;
import processing.app.Platform;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public abstract class ContributedTool {
public class ContributedTool {
public abstract String getName();
private String name;
public String getName() { return name; }
public abstract String getVersion();
private String version;
public String getVersion() { return version; }
public abstract List<HostDependentDownloadableContribution> getSystems();
private ArrayList<HostDependentDownloadableContribution> systems = new ArrayList<HostDependentDownloadableContribution>();
public List<HostDependentDownloadableContribution> getSystems() { return systems; }
private boolean installed;

View File

@ -31,13 +31,16 @@ package cc.arduino.contributions.packages;
import java.util.Collection;
public abstract class ContributedToolReference {
public class ContributedToolReference {
public abstract String getName();
private String name;
public String getName() { return name; }
public abstract String getVersion();
private String version;
public String getVersion() { return version; }
public abstract String getPackager();
private String packager;
public String getPackager() { return packager; }
public ContributedTool resolve(Collection<ContributedPackage> packages) {
for (ContributedPackage pack : packages) {

View File

@ -38,9 +38,10 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public abstract class ContributionsIndex {
public class ContributionsIndex {
public abstract List<ContributedPackage> getPackages();
private ArrayList<ContributedPackage> packages = new ArrayList<ContributedPackage>();
public List<ContributedPackage> getPackages() { return packages; }
public ContributedPackage findPackage(String packageName) {
for (ContributedPackage pack : getPackages()) {

View File

@ -35,7 +35,6 @@ import cc.arduino.contributions.SignatureVerifier;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.BaseNoGui;
@ -73,7 +72,7 @@ public class ContributionsIndexer {
this.builtInHardwareFolder = builtInHardwareFolder;
this.platform = platform;
this.signatureVerifier = signatureVerifier;
index = new EmptyContributionIndex();
index = new ContributionsIndex();
packagesFolder = new File(preferencesFolder, "packages");
stagingFolder = new File(preferencesFolder, "staging" + File.separator + "packages");
}
@ -208,7 +207,6 @@ public class ContributionsIndexer {
try {
inputStream = new FileInputStream(indexFile);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -1,42 +0,0 @@
/*
* This file is part of Arduino.
*
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.contributions.packages;
import java.util.ArrayList;
import java.util.List;
class EmptyContributionIndex extends ContributionsIndex {
List<ContributedPackage> packs = new ArrayList<>();
@Override
public List<ContributedPackage> getPackages() {
return packs;
}
}

View File

@ -32,9 +32,25 @@ package cc.arduino.contributions.packages;
import cc.arduino.contributions.DownloadableContribution;
import processing.app.Platform;
public abstract class HostDependentDownloadableContribution extends DownloadableContribution {
public class HostDependentDownloadableContribution extends DownloadableContribution {
public abstract String getHost();
private String url;
public String getUrl() { return url; }
private String version;
public String getVersion() { return version; }
private String checksum;
public String getChecksum() { return checksum; }
private long size;
public long getSize() { return size; }
private String archiveFileName;
public String getArchiveFileName() { return archiveFileName; }
private String host;
public String getHost() { return host; }
@Override
public String toString() {

View File

@ -40,7 +40,6 @@
<cp>%EXEDIR%/lib/jackson-annotations-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-core-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-databind-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-module-mrbean-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.5.3.jar</cp>
<cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp>

View File

@ -40,7 +40,6 @@
<cp>%EXEDIR%/lib/jackson-annotations-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-core-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-databind-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/jackson-module-mrbean-2.9.5.jar</cp>
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.5.3.jar</cp>
<cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp>