Skip to content

Commit 874729e

Browse files
committed
Allow empty bundle hardware folder
1 parent 4f29650 commit 874729e

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ public class ContributionsIndexer {
6969
private final File builtInHardwareFolder;
7070
private final Platform platform;
7171
private final SignatureVerifier signatureVerifier;
72-
private ContributionsIndex index;
72+
private final ContributionsIndex index;
7373

7474
public ContributionsIndexer(File preferencesFolder, File builtInHardwareFolder, Platform platform, SignatureVerifier signatureVerifier) {
7575
this.preferencesFolder = preferencesFolder;
7676
this.builtInHardwareFolder = builtInHardwareFolder;
7777
this.platform = platform;
7878
this.signatureVerifier = signatureVerifier;
79+
index = new EmptyContributionIndex();
7980
packagesFolder = new File(preferencesFolder, "packages");
8081
stagingFolder = new File(preferencesFolder, "staging" + File.separator + "packages");
8182
}
8283

8384
public void parseIndex() throws Exception {
8485
// Read bundled index...
8586
File bundledIndexFile = new File(builtInHardwareFolder, Constants.BUNDLED_INDEX_FILE_NAME);
86-
index = parseIndex(bundledIndexFile);
87+
mergeContributions(bundledIndexFile);
8788

8889
// ...and overlay the default index if present
8990
File defaultIndexFile = getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
@@ -93,7 +94,7 @@ public void parseIndex() throws Exception {
9394
throw new SignatureVerificationFailedException(Constants.DEFAULT_INDEX_FILE_NAME);
9495
}
9596

96-
mergeContributions(parseIndex(defaultIndexFile), defaultIndexFile);
97+
mergeContributions(defaultIndexFile);
9798
}
9899

99100
// Set main and bundled indexes as trusted
@@ -104,8 +105,7 @@ public void parseIndex() throws Exception {
104105

105106
for (File indexFile : indexFiles) {
106107
try {
107-
ContributionsIndex contributionsIndex = parseIndex(indexFile);
108-
mergeContributions(contributionsIndex, indexFile);
108+
mergeContributions(indexFile);
109109
} catch (JsonProcessingException e) {
110110
System.err.println(I18n.format(tr("Skipping contributed index file {0}, parsing error occured:"), indexFile));
111111
System.err.println(e);
@@ -136,7 +136,11 @@ public void parseIndex() throws Exception {
136136
index.fillCategories();
137137
}
138138

139-
private void mergeContributions(ContributionsIndex contributionsIndex, File indexFile) {
139+
private void mergeContributions(File indexFile) throws IOException {
140+
if (!indexFile.exists())
141+
return;
142+
143+
ContributionsIndex contributionsIndex = parseIndex(indexFile);
140144
boolean signed = signatureVerifier.isSigned(indexFile);
141145
boolean trustall = PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL);
142146

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions.packages;
31+
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
35+
class EmptyContributionIndex extends ContributionsIndex {
36+
List<ContributedPackage> packs = new ArrayList<>();
37+
38+
@Override
39+
public List<ContributedPackage> getPackages() {
40+
return packs;
41+
}
42+
}

0 commit comments

Comments
 (0)