Skip to content

Commit 4fbef6e

Browse files
committed
devonfw#103: versionRange with open interval
1 parent 5518138 commit 4fbef6e

File tree

7 files changed

+140
-225
lines changed

7 files changed

+140
-225
lines changed

cli/src/main/java/com/devonfw/tools/ide/tool/helm/HelmUrlUpdater.java

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public String mapUrlVersionToCpeVersion(String version) {
4747
return version.substring(getVersionPrefixToRemove().length());
4848
}
4949

50+
public String mapCpeVersionToUrlVersion(String version) {
51+
52+
return getVersionPrefixToRemove() + version;
53+
}
54+
5055
@Override
5156
protected void addVersion(UrlVersion urlVersion) {
5257

cli/src/main/java/com/devonfw/tools/ide/url/updater/AbstractUrlUpdater.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public String getCpeVendor() {
105105

106106
return null;
107107
}
108+
108109
/***
109110
* @return the product name of the tool as specified in the CPE (Common Platform Enumeration)
110111
*/
@@ -121,15 +122,23 @@ public String getCpeEdition() {
121122
return null;
122123
}
123124

124-
/***
125+
/**
125126
* @return maps the version as specified by the directory name in the url repository to the version as specified in
126-
* the CPE (Common Platform Enumeration).
127+
* the CPE (Common Platform Enumeration).
127128
*/
128129
public String mapUrlVersionToCpeVersion(String version) {
129130

130131
return version;
131132
}
132133

134+
/**
135+
* @return maps the cpe version to the version as specified in the CPE (Common Platform Enumeration).
136+
*/
137+
public String mapCpeVersionToUrlVersion(String version) {
138+
139+
return version;
140+
}
141+
133142
/**
134143
* Retrieves the response body from a given URL.
135144
*
@@ -294,9 +303,9 @@ private boolean isValidDownload(String url, String tool, String version, HttpRes
294303
if (isSuccess(response)) {
295304
String contentType = response.headers().firstValue("content-type").orElse("undefined");
296305
boolean isValidContentType = isValidContentType(contentType);
297-
if (!isValidContentType){
306+
if (!isValidContentType) {
298307
logger.error("For tool {} and version {} the download has an invalid content type {} for URL {}", tool, version,
299-
contentType, url);
308+
contentType, url);
300309
return false;
301310
}
302311
return true;
@@ -306,7 +315,8 @@ private boolean isValidDownload(String url, String tool, String version, HttpRes
306315
}
307316

308317
/**
309-
* Checks if the content type was not of type text (this method is required because {@link com.devonfw.tools.ide.tool.pip.PipUrlUpdater} returns text and needs to be overridden)
318+
* Checks if the content type was not of type text (this method is required because
319+
* {@link com.devonfw.tools.ide.tool.pip.PipUrlUpdater} returns text and needs to be overridden)
310320
* <p>
311321
* See: <a href="https://github.com/devonfw/ide/issues/1343">#1343</a> for reference.
312322
*
@@ -351,7 +361,7 @@ private boolean checkDownloadUrl(String url, UrlVersion urlVersion, OperatingSys
351361
if (success) {
352362
if (checksum == null || checksum.isEmpty()) {
353363
String contentType = response.headers().firstValue("content-type").orElse("undefined");
354-
checksum = doGenerateChecksum(doGetResponseAsStream( url), url, version, contentType);
364+
checksum = doGenerateChecksum(doGetResponseAsStream(url), url, version, contentType);
355365
}
356366

357367
success = isChecksumStillValid(url, urlVersion, os, architecture, checksum, tool, version);
@@ -472,8 +482,8 @@ private void doUpdateStatusJson(boolean success, int statusCode, UrlVersion urlV
472482
modified = true;
473483
}
474484

475-
logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.", tool,
476-
version, code, url);
485+
logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.",
486+
tool, version, code, url);
477487
} else {
478488
if (status != null) {
479489
if (errorStatus == null) {

cli/src/main/java/com/devonfw/tools/ide/version/VersionIdentifier.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.devonfw.tools.ide.version;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
36
import java.util.Objects;
47

58
/**
@@ -191,6 +194,7 @@ public boolean equals(Object obj) {
191194
}
192195

193196
@Override
197+
@JsonSerialize
194198
public String toString() {
195199

196200
StringBuilder sb = new StringBuilder();
@@ -206,6 +210,7 @@ public String toString() {
206210
* @param version the {@link #toString() string representation} of the {@link VersionIdentifier} to parse.
207211
* @return the parsed {@link VersionIdentifier}.
208212
*/
213+
@JsonCreator
209214
public static VersionIdentifier of(String version) {
210215

211216
if (version.equals("latest")) {

cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java

+48-16
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,47 @@ public final class VersionRange implements Comparable<VersionRange> {
1818

1919
private final boolean rightIsExclusive;
2020

21+
private static final String VERSION_SEPARATOR = ">";
22+
23+
private static final String START_EXCLUDING_PREFIX = "(";
24+
25+
private static final String START_INCLUDING_PREFIX = "[";
26+
27+
private static final String END_EXCLUDING_SUFFIX = ")";
28+
29+
private static final String END_INCLUDING_SUFFIX = "]";
30+
31+
public static String getVersionSeparator() {
32+
33+
return VERSION_SEPARATOR;
34+
}
35+
36+
public static String getStartExcludingPrefix() {
37+
38+
return START_EXCLUDING_PREFIX;
39+
}
40+
41+
public static String getStartIncludingPrefix() {
42+
43+
return START_INCLUDING_PREFIX;
44+
}
45+
46+
public static String getEndExcludingSuffix() {
47+
48+
return END_EXCLUDING_SUFFIX;
49+
}
50+
51+
public static String getEndIncludingSuffix() {
52+
53+
return END_INCLUDING_SUFFIX;
54+
}
55+
2156
/**
2257
* The constructor.
2358
*
2459
* @param min the {@link #getMin() minimum}.
25-
* @param max the {@link #getMax() maximum} (including).
60+
* @param max the {@link #getMax() maximum}.
2661
*/
27-
2862
public VersionRange(VersionIdentifier min, VersionIdentifier max) {
2963

3064
super();
@@ -71,7 +105,6 @@ public VersionRange(VersionIdentifier min, VersionIdentifier max, boolean leftIs
71105
/**
72106
* @return the minimum {@link VersionIdentifier} or {@code null} for no lower bound.
73107
*/
74-
// @JsonBackReference
75108
public VersionIdentifier getMin() {
76109

77110
return this.min;
@@ -80,7 +113,6 @@ public VersionIdentifier getMin() {
80113
/**
81114
* @return the maximum {@link VersionIdentifier} or {@code null} for no upper bound.
82115
*/
83-
// @JsonBackReference
84116
public VersionIdentifier getMax() {
85117

86118
return this.max;
@@ -193,15 +225,15 @@ public boolean equals(Object obj) {
193225
public String toString() {
194226

195227
StringBuilder sb = new StringBuilder();
196-
sb.append(this.leftIsExclusive ? '(' : '[');
228+
sb.append(this.leftIsExclusive ? START_EXCLUDING_PREFIX : START_INCLUDING_PREFIX);
197229
if (this.min != null) {
198230
sb.append(this.min);
199231
}
200-
sb.append('>');
232+
sb.append(VERSION_SEPARATOR);
201233
if (this.max != null) {
202234
sb.append(this.max);
203235
}
204-
sb.append(this.rightIsExclusive ? ')' : ']');
236+
sb.append(this.rightIsExclusive ? END_EXCLUDING_SUFFIX : END_INCLUDING_SUFFIX);
205237
return sb.toString();
206238
}
207239

@@ -215,22 +247,22 @@ public static VersionRange of(String value) {
215247
boolean leftIsExclusive = false;
216248
boolean rightIsExclusive = false;
217249

218-
if (value.startsWith("(")) {
250+
if (value.startsWith(START_EXCLUDING_PREFIX)) {
219251
leftIsExclusive = true;
220-
value = value.substring(1);
252+
value = value.substring(START_EXCLUDING_PREFIX.length());
221253
}
222-
if (value.startsWith("[")) {
223-
value = value.substring(1);
254+
if (value.startsWith(START_INCLUDING_PREFIX)) {
255+
value = value.substring(START_INCLUDING_PREFIX.length());
224256
}
225-
if (value.endsWith(")")) {
257+
if (value.endsWith(END_EXCLUDING_SUFFIX)) {
226258
rightIsExclusive = true;
227-
value = value.substring(0, value.length() - 1);
259+
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
228260
}
229-
if (value.endsWith("]")) {
230-
value = value.substring(0, value.length() - 1);
261+
if (value.endsWith(END_INCLUDING_SUFFIX)) {
262+
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
231263
}
232264

233-
int index = value.indexOf('>');
265+
int index = value.indexOf(VERSION_SEPARATOR);
234266
if (index == -1) {
235267
return null; // log warning?
236268
}

security/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,17 @@
3131
<scope>compile</scope>
3232
</dependency>
3333
</dependencies>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-compiler-plugin</artifactId>
39+
<configuration>
40+
<source>9</source>
41+
<target>9</target>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
3446

3547
</project>

0 commit comments

Comments
 (0)