Skip to content

Commit d7f669b

Browse files
authored
Merge pull request #192 from per1234/fallback-ids
Use JSON pointer as package component ID when standard ID component empty
2 parents f3c4d55 + 95584cc commit d7f669b

File tree

3 files changed

+273
-5
lines changed

3 files changed

+273
-5
lines changed

internal/project/projectdata/packageindex.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,31 @@ func getPackageIndexData(interfaceObject map[string]interface{}, pointerPrefix s
127127
}
128128

129129
objectID := func() string {
130+
// In the event missing data prevents creating a standard reference ID for the data, use the JSON pointer.
131+
fallbackID := interfaceElementData.JSONPointer
132+
130133
if iDPrefix != "" && strings.HasPrefix(iDPrefix, pointerPrefix) {
131134
// Parent object uses fallback ID, so this one must even if it was possible to generate a true suffix.
132-
return interfaceElementData.JSONPointer
135+
return fallbackID
133136
}
134137
iD := iDPrefix
135138

136139
iDSuffix, ok := object[iDKey].(string)
137140
if !ok {
138-
// Use fallback ID.
139-
return interfaceElementData.JSONPointer
141+
return fallbackID
142+
}
143+
if iDSuffix == "" {
144+
return fallbackID
140145
}
141146
iD += iDSuffix
142147

143148
if versionKey != "" {
144149
iDVersion, ok := object[versionKey].(string)
145150
if !ok {
146-
// Use fallback ID.
147-
return interfaceElementData.JSONPointer
151+
return fallbackID
152+
}
153+
if iDVersion == "" {
154+
return fallbackID
148155
}
149156
iD += "@" + iDVersion
150157
}

internal/project/projectdata/packageindex_test.go

+75
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,81 @@ func TestInitializeForPackageIndex(t *testing.T) {
192192
},
193193
},
194194
},
195+
{
196+
testName: "Empty IDs",
197+
path: packageIndexTestDataPath.Join("empty-ids", "package_foo_index.json"),
198+
packageIndexAssertion: assert.NotNil,
199+
packageIndexLoadErrorAssertion: assert.Nil,
200+
packageIndexCLILoadErrorAssertion: assert.Nil,
201+
packageIndexPackagesAssertion: assert.NotNil,
202+
packageIndexPackagesDataAssertion: []PackageIndexData{
203+
{
204+
ID: "/packages/0",
205+
JSONPointer: "/packages/0",
206+
},
207+
{
208+
ID: "foopackager2",
209+
JSONPointer: "/packages/1",
210+
},
211+
},
212+
packageIndexPlatformsAssertion: assert.NotNil,
213+
packageIndexPlatformsDataAssertion: []PackageIndexData{
214+
{
215+
ID: "/packages/0/platforms/0",
216+
JSONPointer: "/packages/0/platforms/0",
217+
},
218+
{
219+
ID: "/packages/0/platforms/1",
220+
JSONPointer: "/packages/0/platforms/1",
221+
},
222+
{
223+
ID: "/packages/1/platforms/0",
224+
JSONPointer: "/packages/1/platforms/0",
225+
},
226+
{
227+
ID: "/packages/1/platforms/1",
228+
JSONPointer: "/packages/1/platforms/1",
229+
},
230+
},
231+
packageIndexToolsAssertion: assert.NotNil,
232+
packageIndexToolsDataAssertion: []PackageIndexData{
233+
{
234+
ID: "/packages/1/tools/0",
235+
JSONPointer: "/packages/1/tools/0",
236+
},
237+
{
238+
ID: "/packages/1/tools/1",
239+
JSONPointer: "/packages/1/tools/1",
240+
},
241+
{
242+
ID: "foopackager2:[email protected]",
243+
JSONPointer: "/packages/1/tools/2",
244+
},
245+
},
246+
packageIndexSystemsAssertion: assert.NotNil,
247+
packageIndexSystemsDataAssertion: []PackageIndexData{
248+
{
249+
ID: "/packages/1/tools/0/systems/0",
250+
JSONPointer: "/packages/1/tools/0/systems/0",
251+
},
252+
{
253+
ID: "/packages/1/tools/0/systems/1",
254+
JSONPointer: "/packages/1/tools/0/systems/1",
255+
},
256+
{
257+
ID: "/packages/1/tools/1/systems/0",
258+
JSONPointer: "/packages/1/tools/1/systems/0",
259+
},
260+
{
261+
ID: "/packages/1/tools/1/systems/1",
262+
JSONPointer: "/packages/1/tools/1/systems/1",
263+
},
264+
{
265+
ID: "/packages/1/tools/2/systems/0",
266+
JSONPointer: "/packages/1/tools/2/systems/0",
267+
},
268+
},
269+
},
195270
{
196271
testName: "Invalid package index",
197272
path: packageIndexTestDataPath.Join("invalid-package-index", "package_foo_index.json"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "",
5+
"maintainer": "Jane Developer",
6+
"websiteURL": "https://github.com/janedeveloper/myboard",
7+
"email": "[email protected]",
8+
"help": {
9+
"online": "http://example.com/forum/myboard"
10+
},
11+
"platforms": [
12+
{
13+
"name": "My Board",
14+
"architecture": "avr",
15+
"version": "1.0.0",
16+
"category": "Contributed",
17+
"help": {
18+
"online": "http://example.com/forum/myboard"
19+
},
20+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.0.zip",
21+
"archiveFileName": "myboard-1.0.0.zip",
22+
"checksum": "SHA-256:ec3ff8a1dc96d3ba6f432b9b837a35fd4174a34b3d2927de1d51010e8b94f9f1",
23+
"size": "15005",
24+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
25+
"toolsDependencies": [
26+
{
27+
"packager": "arduino",
28+
"name": "avr-gcc",
29+
"version": "4.8.1-arduino5"
30+
},
31+
{
32+
"packager": "arduino",
33+
"name": "avrdude",
34+
"version": "6.0.1-arduino5"
35+
}
36+
]
37+
},
38+
{
39+
"name": "My Board",
40+
"architecture": "avr",
41+
"version": "1.0.1",
42+
"category": "Contributed",
43+
"help": {
44+
"online": "http://example.com/forum/myboard"
45+
},
46+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.1.zip",
47+
"archiveFileName": "myboard-1.0.1.zip",
48+
"checksum": "SHA-256:9c86ee28a7ce9fe33e8b07ec643316131e0031b0d22e63bb398902a5fdadbca9",
49+
"size": "15125",
50+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
51+
"toolsDependencies": [
52+
{
53+
"packager": "arduino",
54+
"name": "avr-gcc",
55+
"version": "4.8.1-arduino5"
56+
},
57+
{
58+
"packager": "arduino",
59+
"name": "avrdude",
60+
"version": "6.0.1-arduino5"
61+
}
62+
]
63+
}
64+
],
65+
"tools": []
66+
},
67+
{
68+
"name": "foopackager2",
69+
"maintainer": "Jane Developer",
70+
"websiteURL": "https://github.com/janedeveloper/myboard",
71+
"email": "[email protected]",
72+
"help": {
73+
"online": "http://example.com/forum/myboard"
74+
},
75+
"platforms": [
76+
{
77+
"name": "My Board",
78+
"architecture": "",
79+
"version": "2.0.0",
80+
"category": "Contributed",
81+
"help": {
82+
"online": "http://example.com/forum/myboard"
83+
},
84+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.0.zip",
85+
"archiveFileName": "myboard-1.0.0.zip",
86+
"checksum": "SHA-256:ec3ff8a1dc96d3ba6f432b9b837a35fd4174a34b3d2927de1d51010e8b94f9f1",
87+
"size": "15005",
88+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
89+
"toolsDependencies": [
90+
{
91+
"packager": "arduino",
92+
"name": "avr-gcc",
93+
"version": "4.8.1-arduino5"
94+
},
95+
{
96+
"packager": "arduino",
97+
"name": "avrdude",
98+
"version": "6.0.1-arduino5"
99+
}
100+
]
101+
},
102+
{
103+
"name": "My Board",
104+
"architecture": "mbed",
105+
"version": "",
106+
"category": "Contributed",
107+
"help": {
108+
"online": "http://example.com/forum/myboard"
109+
},
110+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.1.zip",
111+
"archiveFileName": "myboard-1.0.1.zip",
112+
"checksum": "SHA-256:9c86ee28a7ce9fe33e8b07ec643316131e0031b0d22e63bb398902a5fdadbca9",
113+
"size": "15125",
114+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
115+
"toolsDependencies": [
116+
{
117+
"packager": "arduino",
118+
"name": "avr-gcc",
119+
"version": "4.8.1-arduino5"
120+
},
121+
{
122+
"packager": "arduino",
123+
"name": "avrdude",
124+
"version": "6.0.1-arduino5"
125+
}
126+
]
127+
}
128+
],
129+
"tools": [
130+
{
131+
"name": "",
132+
"version": "0.10.0-arduino1-static",
133+
"systems": [
134+
{
135+
"host": "i386-apple-darwin11",
136+
"url": "http://downloads.arduino.cc/arduino.org/OpenOCD-0.10.0-nrf52-osx-static.tar.gz",
137+
"archiveFileName": "OpenOCD-0.10.0-nrf52-osx-static.tar.gz",
138+
"size": "1529841",
139+
"checksum": "SHA-256:46bd02c1d42c5d94c4936e4d4a0ff29697b621840be9a6f882e316203122049d"
140+
},
141+
{
142+
"host": "x86_64-linux-gnu",
143+
"url": "http://downloads.arduino.cc/arduino.org/OpenOCD-0.10.0-nrf52-linux64-static.tar.gz",
144+
"archiveFileName": "OpenOCD-0.10.0-nrf52-linux64-static.tar.gz",
145+
"size": "1777984",
146+
"checksum": "SHA-256:1c9ae77930dd7377d8c13f84abe7307b67fdcd6da74cc1ce269a79e138e7a00a"
147+
}
148+
]
149+
},
150+
{
151+
"name": "CMSIS",
152+
"version": "",
153+
"systems": [
154+
{
155+
"host": "arm-linux-gnueabihf",
156+
"url": "http://example.com",
157+
"archiveFileName": "CMSIS-4.0.0.tar.bz2",
158+
"checksum": "SHA-256:7d637d2d7a0c6bacc22065848a201db2fff124268e4a56868260d0f472b4bbb7",
159+
"size": "17642623"
160+
},
161+
{
162+
"host": "i686-mingw32",
163+
"url": "http://example.com",
164+
"archiveFileName": "CMSIS-4.0.0.tar.bz2",
165+
"checksum": "SHA-256:7d637d2d7a0c6bacc22065848a201db2fff124268e4a56868260d0f472b4bbb7",
166+
"size": "17642623"
167+
}
168+
]
169+
},
170+
{
171+
"name": "bossac",
172+
"version": "1.9.1-arduino2",
173+
"systems": [
174+
{
175+
"host": "",
176+
"url": "http://downloads.arduino.cc/tools/bossac-1.9.1-arduino2-linuxaarch64.tar.gz",
177+
"archiveFileName": "bossac-1.9.1-arduino2-linuxaarch64.tar.gz",
178+
"checksum": "SHA-256:c167fa0ea223966f4d21f5592da3888bcbfbae385be6c5c4e41f8abff35f5cb1",
179+
"size": "442853"
180+
}
181+
]
182+
}
183+
]
184+
}
185+
]
186+
}

0 commit comments

Comments
 (0)