9
9
********************************************************************************/
10
10
package org .eclipse .openvsx ;
11
11
12
+ import io .micrometer .observation .Observation ;
13
+ import io .micrometer .observation .ObservationRegistry ;
12
14
import org .apache .commons .lang3 .StringUtils ;
13
15
import org .apache .tika .Tika ;
14
16
import org .apache .tika .mime .MediaType ;
@@ -46,6 +48,11 @@ public class ExtensionValidator {
46
48
private final static int GALLERY_COLOR_SIZE = 16 ;
47
49
48
50
private final Pattern namePattern = Pattern .compile ("[\\ w\\ -\\ +\\ $~]+" );
51
+ private final ObservationRegistry observations ;
52
+
53
+ public ExtensionValidator (ObservationRegistry observations ) {
54
+ this .observations = observations ;
55
+ }
49
56
50
57
public Optional <Issue > validateNamespace (String namespace ) {
51
58
if (StringUtils .isEmpty (namespace ) || namespace .equals ("-" )) {
@@ -102,57 +109,63 @@ public List<Issue> validateNamespaceDetails(NamespaceDetailsJson json) {
102
109
}
103
110
104
111
public Optional <Issue > validateExtensionName (String name ) {
105
- if (StringUtils .isEmpty (name )) {
106
- return Optional .of (new Issue ("Name must not be empty." ));
107
- }
108
- if (!namePattern .matcher (name ).matches ()) {
109
- return Optional .of (new Issue ("Invalid extension name: " + name ));
110
- }
111
- if (name .length () > DEFAULT_STRING_SIZE ) {
112
- return Optional .of (new Issue ("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters." ));
113
- }
114
- return Optional .empty ();
112
+ return Observation .createNotStarted ("ExtensionValidator#validateExtensionName" , observations ).observe (() -> {
113
+ if (StringUtils .isEmpty (name )) {
114
+ return Optional .of (new Issue ("Name must not be empty." ));
115
+ }
116
+ if (!namePattern .matcher (name ).matches ()) {
117
+ return Optional .of (new Issue ("Invalid extension name: " + name ));
118
+ }
119
+ if (name .length () > DEFAULT_STRING_SIZE ) {
120
+ return Optional .of (new Issue ("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters." ));
121
+ }
122
+ return Optional .empty ();
123
+ });
115
124
}
116
125
117
126
public Optional <Issue > validateExtensionVersion (String version ) {
118
- var issues = new ArrayList <Issue >();
119
- checkVersion (version , issues );
120
- return issues .isEmpty ()
121
- ? Optional .empty ()
122
- : Optional .of (issues .get (0 ));
127
+ return Observation .createNotStarted ("ExtensionValidator#validateExtensionVersion" , observations ).observe (() -> {
128
+ var issues = new ArrayList <Issue >();
129
+ checkVersion (version , issues );
130
+ return issues .isEmpty ()
131
+ ? Optional .empty ()
132
+ : Optional .of (issues .get (0 ));
133
+ });
123
134
}
124
135
125
136
public List <Issue > validateMetadata (ExtensionVersion extVersion ) {
126
- var issues = new ArrayList <Issue >();
127
- checkVersion (extVersion .getVersion (), issues );
128
- checkTargetPlatform (extVersion .getTargetPlatform (), issues );
129
- checkCharacters (extVersion .getDisplayName (), "displayName" , issues );
130
- checkFieldSize (extVersion .getDisplayName (), DEFAULT_STRING_SIZE , "displayName" , issues );
131
- checkCharacters (extVersion .getDescription (), "description" , issues );
132
- checkFieldSize (extVersion .getDescription (), DESCRIPTION_SIZE , "description" , issues );
133
- checkCharacters (extVersion .getCategories (), "categories" , issues );
134
- checkFieldSize (extVersion .getCategories (), DEFAULT_STRING_SIZE , "categories" , issues );
135
- checkCharacters (extVersion .getTags (), "keywords" , issues );
136
- checkFieldSize (extVersion .getTags (), DEFAULT_STRING_SIZE , "keywords" , issues );
137
- checkCharacters (extVersion .getLicense (), "license" , issues );
138
- checkFieldSize (extVersion .getLicense (), DEFAULT_STRING_SIZE , "license" , issues );
139
- checkURL (extVersion .getHomepage (), "homepage" , issues );
140
- checkFieldSize (extVersion .getHomepage (), DEFAULT_STRING_SIZE , "homepage" , issues );
141
- checkURL (extVersion .getRepository (), "repository" , issues );
142
- checkFieldSize (extVersion .getRepository (), DEFAULT_STRING_SIZE , "repository" , issues );
143
- checkURL (extVersion .getBugs (), "bugs" , issues );
144
- checkFieldSize (extVersion .getBugs (), DEFAULT_STRING_SIZE , "bugs" , issues );
145
- checkInvalid (extVersion .getMarkdown (), s -> !MARKDOWN_VALUES .contains (s ), "markdown" , issues ,
146
- MARKDOWN_VALUES .toString ());
147
- checkCharacters (extVersion .getGalleryColor (), "galleryBanner.color" , issues );
148
- checkFieldSize (extVersion .getGalleryColor (), GALLERY_COLOR_SIZE , "galleryBanner.color" , issues );
149
- checkInvalid (extVersion .getGalleryTheme (), s -> !GALLERY_THEME_VALUES .contains (s ), "galleryBanner.theme" , issues ,
150
- GALLERY_THEME_VALUES .toString ());
151
- checkFieldSize (extVersion .getLocalizedLanguages (), DEFAULT_STRING_SIZE , "localizedLanguages" , issues );
152
- checkInvalid (extVersion .getQna (), s -> !QNA_VALUES .contains (s ) && isInvalidURL (s ), "qna" , issues ,
153
- QNA_VALUES .toString () + " or a URL" );
154
- checkFieldSize (extVersion .getQna (), DEFAULT_STRING_SIZE , "qna" , issues );
155
- return issues ;
137
+ return Observation .createNotStarted ("ExtensionValidator#validateMetadata" , observations ).observe (() -> {
138
+ var issues = new ArrayList <Issue >();
139
+ checkVersion (extVersion .getVersion (), issues );
140
+ checkTargetPlatform (extVersion .getTargetPlatform (), issues );
141
+ checkCharacters (extVersion .getDisplayName (), "displayName" , issues );
142
+ checkFieldSize (extVersion .getDisplayName (), DEFAULT_STRING_SIZE , "displayName" , issues );
143
+ checkCharacters (extVersion .getDescription (), "description" , issues );
144
+ checkFieldSize (extVersion .getDescription (), DESCRIPTION_SIZE , "description" , issues );
145
+ checkCharacters (extVersion .getCategories (), "categories" , issues );
146
+ checkFieldSize (extVersion .getCategories (), DEFAULT_STRING_SIZE , "categories" , issues );
147
+ checkCharacters (extVersion .getTags (), "keywords" , issues );
148
+ checkFieldSize (extVersion .getTags (), DEFAULT_STRING_SIZE , "keywords" , issues );
149
+ checkCharacters (extVersion .getLicense (), "license" , issues );
150
+ checkFieldSize (extVersion .getLicense (), DEFAULT_STRING_SIZE , "license" , issues );
151
+ checkURL (extVersion .getHomepage (), "homepage" , issues );
152
+ checkFieldSize (extVersion .getHomepage (), DEFAULT_STRING_SIZE , "homepage" , issues );
153
+ checkURL (extVersion .getRepository (), "repository" , issues );
154
+ checkFieldSize (extVersion .getRepository (), DEFAULT_STRING_SIZE , "repository" , issues );
155
+ checkURL (extVersion .getBugs (), "bugs" , issues );
156
+ checkFieldSize (extVersion .getBugs (), DEFAULT_STRING_SIZE , "bugs" , issues );
157
+ checkInvalid (extVersion .getMarkdown (), s -> !MARKDOWN_VALUES .contains (s ), "markdown" , issues ,
158
+ MARKDOWN_VALUES .toString ());
159
+ checkCharacters (extVersion .getGalleryColor (), "galleryBanner.color" , issues );
160
+ checkFieldSize (extVersion .getGalleryColor (), GALLERY_COLOR_SIZE , "galleryBanner.color" , issues );
161
+ checkInvalid (extVersion .getGalleryTheme (), s -> !GALLERY_THEME_VALUES .contains (s ), "galleryBanner.theme" , issues ,
162
+ GALLERY_THEME_VALUES .toString ());
163
+ checkFieldSize (extVersion .getLocalizedLanguages (), DEFAULT_STRING_SIZE , "localizedLanguages" , issues );
164
+ checkInvalid (extVersion .getQna (), s -> !QNA_VALUES .contains (s ) && isInvalidURL (s ), "qna" , issues ,
165
+ QNA_VALUES .toString () + " or a URL" );
166
+ checkFieldSize (extVersion .getQna (), DEFAULT_STRING_SIZE , "qna" , issues );
167
+ return issues ;
168
+ });
156
169
}
157
170
158
171
private void checkVersion (String version , List <Issue > issues ) {
@@ -163,11 +176,14 @@ private void checkVersion(String version, List<Issue> issues) {
163
176
if (version .equals (VersionAlias .LATEST ) || version .equals (VersionAlias .PRE_RELEASE ) || version .equals ("reviews" )) {
164
177
issues .add (new Issue ("The version string '" + version + "' is reserved." ));
165
178
}
166
- try {
167
- SemanticVersion .parse (version );
168
- } catch (RuntimeException e ) {
169
- issues .add (new Issue (e .getMessage ()));
170
- }
179
+
180
+ Observation .createNotStarted ("SemanticVersion#parse" , observations ).observe (() -> {
181
+ try {
182
+ SemanticVersion .parse (version );
183
+ } catch (RuntimeException e ) {
184
+ issues .add (new Issue (e .getMessage ()));
185
+ }
186
+ });
171
187
}
172
188
173
189
private void checkTargetPlatform (String targetPlatform , List <Issue > issues ) {
0 commit comments