@@ -44,6 +44,12 @@ public class ExtensionProcessor implements AutoCloseable {
44
44
private static final String [] README = { "extension/README.md" , "extension/README" , "extension/README.txt" };
45
45
private static final String [] CHANGELOG = { "extension/CHANGELOG.md" , "extension/CHANGELOG" , "extension/CHANGELOG.txt" };
46
46
47
+ private static final String MANIFEST_METADATA = "Metadata" ;
48
+ private static final String MANIFEST_IDENTITY = "Identity" ;
49
+ private static final String MANIFEST_PROPERTIES = "Properties" ;
50
+ private static final String MANIFEST_PROPERTY = "Property" ;
51
+ private static final String MANIFEST_VALUE = "Value" ;
52
+
47
53
protected final Logger logger = LoggerFactory .getLogger (ExtensionProcessor .class );
48
54
49
55
private final TempFile extensionFile ;
@@ -91,7 +97,7 @@ private void loadPackageJson() {
91
97
// Read package.json
92
98
try (var entryFile = ArchiveUtil .readEntry (zipFile , PACKAGE_JSON )) {
93
99
if (entryFile == null ) {
94
- throw new ErrorResultException ("Entry not found: " + PACKAGE_JSON );
100
+ throw new ErrorResultException (entryNotFoundMessage ( PACKAGE_JSON ) );
95
101
}
96
102
97
103
var mapper = new ObjectMapper ();
@@ -114,7 +120,7 @@ private void loadVsixManifest() {
114
120
// Read extension.vsixmanifest
115
121
try (var entryFile = ArchiveUtil .readEntry (zipFile , VSIX_MANIFEST )) {
116
122
if (entryFile == null ) {
117
- throw new ErrorResultException ("Entry not found: " + VSIX_MANIFEST );
123
+ throw new ErrorResultException (entryNotFoundMessage ( VSIX_MANIFEST ) );
118
124
}
119
125
120
126
var mapper = new XmlMapper ();
@@ -127,6 +133,10 @@ private void loadVsixManifest() {
127
133
}
128
134
}
129
135
136
+ private String entryNotFoundMessage (String file ) {
137
+ return "Entry not found: " + file ;
138
+ }
139
+
130
140
private JsonNode findByIdInArray (Iterable <JsonNode > iter , String id ) {
131
141
for (JsonNode node : iter ){
132
142
var idNode = node .get ("Id" );
@@ -139,84 +149,84 @@ private JsonNode findByIdInArray(Iterable<JsonNode> iter, String id) {
139
149
140
150
public String getExtensionName () {
141
151
loadVsixManifest ();
142
- return vsixManifest .path ("Metadata" ).path ("Identity" ).path ("Id" ).asText ();
152
+ return vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_IDENTITY ).path ("Id" ).asText ();
143
153
}
144
154
145
155
public String getNamespace () {
146
156
loadVsixManifest ();
147
- return vsixManifest .path ("Metadata" ).path ("Identity" ).path ("Publisher" ).asText ();
157
+ return vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_IDENTITY ).path ("Publisher" ).asText ();
148
158
}
149
159
150
160
public List <String > getExtensionDependencies () {
151
161
loadVsixManifest ();
152
- var extDepenNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.ExtensionDependencies" );
153
- return asStringList (extDepenNode .path ("Value" ).asText (), "," );
162
+ var extDepenNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.ExtensionDependencies" );
163
+ return asStringList (extDepenNode .path (MANIFEST_VALUE ).asText (), "," );
154
164
}
155
165
156
166
public List <String > getBundledExtensions () {
157
167
loadVsixManifest ();
158
- var extPackNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.ExtensionPack" );
159
- return asStringList (extPackNode .path ("Value" ).asText (), "," );
168
+ var extPackNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.ExtensionPack" );
169
+ return asStringList (extPackNode .path (MANIFEST_VALUE ).asText (), "," );
160
170
}
161
171
162
172
public List <String > getExtensionKinds () {
163
173
loadVsixManifest ();
164
- var extKindNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.ExtensionKind" );
165
- return asStringList (extKindNode .path ("Value" ).asText (), "," );
174
+ var extKindNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.ExtensionKind" );
175
+ return asStringList (extKindNode .path (MANIFEST_VALUE ).asText (), "," );
166
176
}
167
177
168
178
public String getHomepage () {
169
179
loadVsixManifest ();
170
- var extKindNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Services.Links.Learn" );
171
- return extKindNode .path ("Value" ).asText ();
180
+ var extKindNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Services.Links.Learn" );
181
+ return extKindNode .path (MANIFEST_VALUE ).asText ();
172
182
}
173
183
174
184
public String getRepository () {
175
185
loadVsixManifest ();
176
- var sourceNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Services.Links.Source" );
177
- return sourceNode .path ("Value" ).asText ();
186
+ var sourceNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Services.Links.Source" );
187
+ return sourceNode .path (MANIFEST_VALUE ).asText ();
178
188
}
179
189
180
190
public String getBugs () {
181
191
loadVsixManifest ();
182
- var supportNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Services.Links.Support" );
183
- return supportNode .path ("Value" ).asText ();
192
+ var supportNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Services.Links.Support" );
193
+ return supportNode .path (MANIFEST_VALUE ).asText ();
184
194
}
185
195
186
196
public String getGalleryColor () {
187
197
loadVsixManifest ();
188
- var colorNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Services.Branding.Color" );
189
- return colorNode .path ("Value" ).asText ();
198
+ var colorNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Services.Branding.Color" );
199
+ return colorNode .path (MANIFEST_VALUE ).asText ();
190
200
}
191
201
192
202
public String getGalleryTheme () {
193
203
loadVsixManifest ();
194
- var themeNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Services.Branding.Theme" );
195
- return themeNode .path ("Value" ).asText ();
204
+ var themeNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Services.Branding.Theme" );
205
+ return themeNode .path (MANIFEST_VALUE ).asText ();
196
206
}
197
207
198
208
public List <String > getLocalizedLanguages () {
199
209
loadVsixManifest ();
200
- var languagesNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.LocalizedLanguages" );
201
- return asStringList (languagesNode .path ("Value" ).asText (), "," );
210
+ var languagesNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.LocalizedLanguages" );
211
+ return asStringList (languagesNode .path (MANIFEST_VALUE ).asText (), "," );
202
212
}
203
213
204
214
public boolean isPreview () {
205
215
loadVsixManifest ();
206
- var galleryFlags = vsixManifest .path ("Metadata" ).path ("GalleryFlags" );
216
+ var galleryFlags = vsixManifest .path (MANIFEST_METADATA ).path ("GalleryFlags" );
207
217
return asStringList (galleryFlags .asText (), " " ).contains ("Preview" );
208
218
}
209
219
210
220
public boolean isPreRelease () {
211
221
loadVsixManifest ();
212
- var preReleaseNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.PreRelease" );
213
- return preReleaseNode .path ("Value" ).asBoolean (false );
222
+ var preReleaseNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.PreRelease" );
223
+ return preReleaseNode .path (MANIFEST_VALUE ).asBoolean (false );
214
224
}
215
225
216
226
public String getSponsorLink () {
217
227
loadVsixManifest ();
218
- var sponsorLinkNode = findByIdInArray (vsixManifest .path ("Metadata" ).path ("Properties" ).path ("Property" ), "Microsoft.VisualStudio.Code.SponsorLink" );
219
- return sponsorLinkNode .path ("Value" ).asText ();
228
+ var sponsorLinkNode = findByIdInArray (vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_PROPERTIES ).path (MANIFEST_PROPERTY ), "Microsoft.VisualStudio.Code.SponsorLink" );
229
+ return sponsorLinkNode .path (MANIFEST_VALUE ).asText ();
220
230
}
221
231
222
232
public ExtensionVersion getMetadata () {
@@ -227,10 +237,10 @@ public ExtensionVersion getMetadata() {
227
237
extVersion .setTargetPlatform (getTargetPlatform ());
228
238
extVersion .setPreview (isPreview ());
229
239
extVersion .setPreRelease (isPreRelease ());
230
- extVersion .setDisplayName (vsixManifest .path ("Metadata" ).path ("DisplayName" ).asText ());
231
- extVersion .setDescription (vsixManifest .path ("Metadata" ).path ("Description" ).path ("" ).asText ());
240
+ extVersion .setDisplayName (vsixManifest .path (MANIFEST_METADATA ).path ("DisplayName" ).asText ());
241
+ extVersion .setDescription (vsixManifest .path (MANIFEST_METADATA ).path ("Description" ).path ("" ).asText ());
232
242
extVersion .setEngines (getEngines (packageJson .path ("engines" )));
233
- extVersion .setCategories (asStringList (vsixManifest .path ("Metadata" ).path ("Categories" ).asText (), "," ));
243
+ extVersion .setCategories (asStringList (vsixManifest .path (MANIFEST_METADATA ).path ("Categories" ).asText (), "," ));
234
244
extVersion .setExtensionKind (getExtensionKinds ());
235
245
extVersion .setTags (getTags ());
236
246
extVersion .setLicense (packageJson .path ("license" ).textValue ());
@@ -248,11 +258,11 @@ public ExtensionVersion getMetadata() {
248
258
}
249
259
250
260
public String getVersion () {
251
- return vsixManifest .path ("Metadata" ).path ("Identity" ).path ("Version" ).asText ();
261
+ return vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_IDENTITY ).path ("Version" ).asText ();
252
262
}
253
263
254
264
private String getTargetPlatform () {
255
- var targetPlatform = vsixManifest .path ("Metadata" ).path ("Identity" ).path ("TargetPlatform" ).asText ();
265
+ var targetPlatform = vsixManifest .path (MANIFEST_METADATA ).path (MANIFEST_IDENTITY ).path ("TargetPlatform" ).asText ();
256
266
if (targetPlatform .isEmpty ()) {
257
267
targetPlatform = TargetPlatform .NAME_UNIVERSAL ;
258
268
}
@@ -261,7 +271,7 @@ private String getTargetPlatform() {
261
271
}
262
272
263
273
private List <String > getTags () {
264
- var tags = vsixManifest .path ("Metadata" ).path ("Tags" ).asText ();
274
+ var tags = vsixManifest .path (MANIFEST_METADATA ).path ("Tags" ).asText ();
265
275
return asStringList (tags , "," ).stream ()
266
276
.collect (Collectors .groupingBy (String ::toLowerCase ))
267
277
.entrySet ().stream ()
@@ -356,7 +366,7 @@ protected TempFile getManifest(ExtensionVersion extVersion) throws IOException {
356
366
readInputStream ();
357
367
var entryFile = ArchiveUtil .readEntry (zipFile , PACKAGE_JSON );
358
368
if (entryFile == null ) {
359
- throw new ErrorResultException ("Entry not found: " + PACKAGE_JSON );
369
+ throw new ErrorResultException (entryNotFoundMessage ( PACKAGE_JSON ) );
360
370
}
361
371
var manifest = new FileResource ();
362
372
manifest .setExtension (extVersion );
@@ -403,7 +413,7 @@ public TempFile getLicense(ExtensionVersion extVersion) throws IOException {
403
413
404
414
var entryFile = ArchiveUtil .readEntry (zipFile , assetPath );
405
415
if (entryFile == null ) {
406
- throw new ErrorResultException ("Entry not found: " + assetPath );
416
+ throw new ErrorResultException (entryNotFoundMessage ( assetPath ) );
407
417
}
408
418
409
419
var lastSegmentIndex = assetPath .lastIndexOf ('/' );
@@ -418,7 +428,7 @@ private TempFile readFromVsixPackage(String assetType, String[] alternateNames)
418
428
if (StringUtils .isNotEmpty (assetPath )) {
419
429
var entryFile = ArchiveUtil .readEntry (zipFile , assetPath );
420
430
if (entryFile == null ) {
421
- throw new ErrorResultException ("Entry not found: " + assetPath );
431
+ throw new ErrorResultException (entryNotFoundMessage ( assetPath ) );
422
432
}
423
433
424
434
var lastSegmentIndex = assetPath .lastIndexOf ('/' );
@@ -451,7 +461,7 @@ private TempFile readFromAlternateNames(String[] names) throws IOException {
451
461
452
462
private String tryGetLicensePath () {
453
463
loadVsixManifest ();
454
- var licensePath = vsixManifest .path ("Metadata" ).path ("License" ).asText ();
464
+ var licensePath = vsixManifest .path (MANIFEST_METADATA ).path ("License" ).asText ();
455
465
return licensePath .isEmpty ()
456
466
? tryGetAssetPath (ExtensionQueryResult .ExtensionFile .FILE_LICENSE )
457
467
: licensePath ;
@@ -486,7 +496,7 @@ protected TempFile getIcon(ExtensionVersion extVersion) throws IOException {
486
496
487
497
var entryFile = ArchiveUtil .readEntry (zipFile , iconPath );
488
498
if (entryFile == null ) {
489
- throw new ErrorResultException ("Entry not found: " + iconPath );
499
+ throw new ErrorResultException (entryNotFoundMessage ( iconPath ) );
490
500
}
491
501
492
502
var icon = new FileResource ();
@@ -511,7 +521,7 @@ public TempFile getVsixManifest(ExtensionVersion extVersion) throws IOException
511
521
512
522
var entryFile = ArchiveUtil .readEntry (zipFile , VSIX_MANIFEST );
513
523
if (entryFile == null ) {
514
- throw new ErrorResultException ("Entry not found: " + VSIX_MANIFEST );
524
+ throw new ErrorResultException (entryNotFoundMessage ( VSIX_MANIFEST ) );
515
525
}
516
526
517
527
entryFile .setResource (vsixManifest );
0 commit comments