16
16
import com .devonfw .tools .ide .environment .EnvironmentVariablesType ;
17
17
import com .devonfw .tools .ide .io .FileAccess ;
18
18
import com .devonfw .tools .ide .io .TarCompression ;
19
+ import com .devonfw .tools .ide .json .mapping .JsonMapping ;
19
20
import com .devonfw .tools .ide .os .MacOsHelper ;
20
21
import com .devonfw .tools .ide .process .ProcessContext ;
21
22
import com .devonfw .tools .ide .process .ProcessErrorHandling ;
22
23
import com .devonfw .tools .ide .property .StringListProperty ;
23
24
import com .devonfw .tools .ide .url .model .file .UrlSecurityFile ;
24
25
import com .devonfw .tools .ide .util .FilenameUtil ;
25
26
import com .devonfw .tools .ide .version .VersionIdentifier ;
27
+ import com .fasterxml .jackson .databind .ObjectMapper ;
26
28
27
29
/**
28
30
* {@link Commandlet} for a tool integrated into the IDE.
@@ -172,24 +174,28 @@ public boolean install(boolean silent) {
172
174
return doInstall (silent );
173
175
}
174
176
175
- protected String question (String question , String ... options ) {
177
+ protected String question (String question , String ... options ) {
178
+
176
179
question += " Do you want to" ;
177
180
for (int i = 0 ; i < options .length - 1 ; i ++) {
178
181
options [i ] += " or" ;
179
182
}
180
183
options [options .length - 1 ] += "?" ;
181
184
return this .context .question (question , options );
182
185
}
186
+
183
187
protected VersionIdentifier securityRiskInteraction (VersionIdentifier configuredVersion ) {
184
188
185
189
// TODO vielleicht security file auch neu als json file wenn 1.2 > 2.9 nicht ausreicht
186
- // TODO vielleicht auch zusätzlich das tool scannen sobald es installiert ist,
187
-
188
190
// TODO webpage:\nhttps://github.com/devonfw/ide/blob/master/documentation/vulnerabilities.asciidoc\n\n";
189
191
192
+ // TODO if no version is save, find a version that has lowest security risk, or suggest multiple ones, such that the
193
+ // user can choose
194
+
190
195
UrlSecurityFile securityFile = this .context .getUrls ().getEdition (this .tool , this .getEdition ()).getSecurityFile ();
191
- VersionIdentifier current = this .context .getUrls ().getVersion (this .tool , this .getEdition (),
192
- configuredVersion );
196
+ ObjectMapper mapper = JsonMapping .create ();
197
+
198
+ VersionIdentifier current = this .context .getUrls ().getVersion (this .tool , this .getEdition (), configuredVersion );
193
199
if (!securityFile .contains (current )) {
194
200
return configuredVersion ;
195
201
}
@@ -201,7 +207,8 @@ protected VersionIdentifier securityRiskInteraction(VersionIdentifier configured
201
207
202
208
int currentVersionIndex = allVersions .indexOf (current );
203
209
204
- // VersionIdentifier nextVersion = currentVersionIndex == 0 ? null : allVersions.get(allVersions.indexOf(currentVersion) - 1);
210
+ // VersionIdentifier nextVersion = currentVersionIndex == 0 ? null :
211
+ // allVersions.get(allVersions.indexOf(currentVersion) - 1);
205
212
VersionIdentifier nextSafe = null ;
206
213
for (int i = currentVersionIndex - 1 ; i >= 0 ; i --) {
207
214
if (!securityFile .contains (allVersions .get (i ))) {
@@ -225,46 +232,45 @@ protected VersionIdentifier securityRiskInteraction(VersionIdentifier configured
225
232
}
226
233
227
234
String currentIsUnsafe = "Currently, version " + current + " of " + this .getName () + " is installed, "
228
- + "which is has a vulnerability." ;
235
+ + "which is has a vulnerability:\n " + " TODOODODO" + "\n \n " ;
236
+
229
237
String stay = "stay with the current unsafe version (" + current + ")" ;
230
238
String installLatestSafe = "install the latest safe version (" + latestSafe + ")" ;
231
239
String installSafeLatest = "install the (safe) latest version (" + latestSafe + ")" ;
232
- String installNextSafe = "install the next safe version (" + nextSafe + ")" ;
240
+ String installNextSafe = "install the next safe version (" + nextSafe + ")" ;
233
241
234
242
if (current .equals (latest )) {
235
243
String answer = question (currentIsUnsafe , stay , installLatestSafe );
236
244
return answer .startsWith (stay ) ? current : latestSafe ;
237
245
238
246
} else if (nextSafe == null ) {
239
247
// TODO also allow selection of next or previous version, even if they are unsafe?
240
- String answer = question (currentIsUnsafe + " All newer versions are also not safe." ,
241
- stay , installLatestSafe );
248
+ String answer = question (currentIsUnsafe + " All newer versions are also not safe." , stay , installLatestSafe );
242
249
return answer .startsWith (stay ) ? current : latestSafe ;
243
250
244
251
} else if (nextSafe .equals (latest )) {
245
- String answer = question ( currentIsUnsafe + " Of the newer versions, only the latest is safe." ,
246
- stay , installSafeLatest );
252
+ String answer = question (currentIsUnsafe + " Of the newer versions, only the latest is safe." , stay ,
253
+ installSafeLatest );
247
254
return answer .startsWith (stay ) ? current : latestSafe ;
248
255
249
256
} else if (nextSafe .equals (latestSafe )) {
250
- String answer = question (currentIsUnsafe +" Of the newer versions, only the version "
251
- + nextSafe + " is safe." , stay , "Install the safe version (" + nextSafe + ")" );
257
+ String answer = question (currentIsUnsafe + " Of the newer versions, only the version " + nextSafe + " is safe." ,
258
+ stay , "Install the safe version (" + nextSafe + ")" );
252
259
return answer .startsWith (stay ) ? current : nextSafe ;
253
260
254
261
} else {
255
262
if (latest .equals (latestSafe )) {
256
263
String answer = question (currentIsUnsafe , stay , installNextSafe , installSafeLatest );
257
- return answer .startsWith (stay ) ? current
258
- : answer .startsWith (installNextSafe ) ? nextSafe : latestSafe ;
264
+ return answer .startsWith (stay ) ? current : answer .startsWith (installNextSafe ) ? nextSafe : latestSafe ;
259
265
260
266
} else {
261
267
String answer = question (currentIsUnsafe , stay , installNextSafe , installLatestSafe );
262
268
return answer .startsWith (stay ) ? current : answer .startsWith (installNextSafe ) ? nextSafe : latestSafe ;
263
269
}
264
270
}
265
271
266
- // VersionIdentifier chosenVersion = securityRiskInteraction(configuredVersion);
267
- // setVersion(chosenVersion, silent);
272
+ // VersionIdentifier chosenVersion = securityRiskInteraction(configuredVersion);
273
+ // setVersion(chosenVersion, silent);
268
274
}
269
275
270
276
/**
0 commit comments