Skip to content

Commit

Permalink
devonfw#103: versionRange with open interval
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Dec 19, 2023
1 parent 5518138 commit 4fbef6e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public String mapUrlVersionToCpeVersion(String version) {
return version.substring(getVersionPrefixToRemove().length());
}

public String mapCpeVersionToUrlVersion(String version) {

return getVersionPrefixToRemove() + version;
}

@Override
protected void addVersion(UrlVersion urlVersion) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public String getCpeVendor() {

return null;
}

/***
* @return the product name of the tool as specified in the CPE (Common Platform Enumeration)
*/
Expand All @@ -121,15 +122,23 @@ public String getCpeEdition() {
return null;
}

/***
/**
* @return maps the version as specified by the directory name in the url repository to the version as specified in
* the CPE (Common Platform Enumeration).
* the CPE (Common Platform Enumeration).
*/
public String mapUrlVersionToCpeVersion(String version) {

return version;
}

/**
* @return maps the cpe version to the version as specified in the CPE (Common Platform Enumeration).
*/
public String mapCpeVersionToUrlVersion(String version) {

return version;
}

/**
* Retrieves the response body from a given URL.
*
Expand Down Expand Up @@ -294,9 +303,9 @@ private boolean isValidDownload(String url, String tool, String version, HttpRes
if (isSuccess(response)) {
String contentType = response.headers().firstValue("content-type").orElse("undefined");
boolean isValidContentType = isValidContentType(contentType);
if (!isValidContentType){
if (!isValidContentType) {
logger.error("For tool {} and version {} the download has an invalid content type {} for URL {}", tool, version,
contentType, url);
contentType, url);
return false;
}
return true;
Expand All @@ -306,7 +315,8 @@ private boolean isValidDownload(String url, String tool, String version, HttpRes
}

/**
* 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)
* 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)
* <p>
* See: <a href="https://github.com/devonfw/ide/issues/1343">#1343</a> for reference.
*
Expand Down Expand Up @@ -351,7 +361,7 @@ private boolean checkDownloadUrl(String url, UrlVersion urlVersion, OperatingSys
if (success) {
if (checksum == null || checksum.isEmpty()) {
String contentType = response.headers().firstValue("content-type").orElse("undefined");
checksum = doGenerateChecksum(doGetResponseAsStream( url), url, version, contentType);
checksum = doGenerateChecksum(doGetResponseAsStream(url), url, version, contentType);
}

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

logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.", tool,
version, code, url);
logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.",
tool, version, code, url);
} else {
if (status != null) {
if (errorStatus == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.devonfw.tools.ide.version;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.Objects;

/**
Expand Down Expand Up @@ -191,6 +194,7 @@ public boolean equals(Object obj) {
}

@Override
@JsonSerialize
public String toString() {

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

if (version.equals("latest")) {
Expand Down
64 changes: 48 additions & 16 deletions cli/src/main/java/com/devonfw/tools/ide/version/VersionRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,47 @@ public final class VersionRange implements Comparable<VersionRange> {

private final boolean rightIsExclusive;

private static final String VERSION_SEPARATOR = ">";

private static final String START_EXCLUDING_PREFIX = "(";

private static final String START_INCLUDING_PREFIX = "[";

private static final String END_EXCLUDING_SUFFIX = ")";

private static final String END_INCLUDING_SUFFIX = "]";

public static String getVersionSeparator() {

return VERSION_SEPARATOR;
}

public static String getStartExcludingPrefix() {

return START_EXCLUDING_PREFIX;
}

public static String getStartIncludingPrefix() {

return START_INCLUDING_PREFIX;
}

public static String getEndExcludingSuffix() {

return END_EXCLUDING_SUFFIX;
}

public static String getEndIncludingSuffix() {

return END_INCLUDING_SUFFIX;
}

/**
* The constructor.
*
* @param min the {@link #getMin() minimum}.
* @param max the {@link #getMax() maximum} (including).
* @param max the {@link #getMax() maximum}.
*/

public VersionRange(VersionIdentifier min, VersionIdentifier max) {

super();
Expand Down Expand Up @@ -71,7 +105,6 @@ public VersionRange(VersionIdentifier min, VersionIdentifier max, boolean leftIs
/**
* @return the minimum {@link VersionIdentifier} or {@code null} for no lower bound.
*/
// @JsonBackReference
public VersionIdentifier getMin() {

return this.min;
Expand All @@ -80,7 +113,6 @@ public VersionIdentifier getMin() {
/**
* @return the maximum {@link VersionIdentifier} or {@code null} for no upper bound.
*/
// @JsonBackReference
public VersionIdentifier getMax() {

return this.max;
Expand Down Expand Up @@ -193,15 +225,15 @@ public boolean equals(Object obj) {
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append(this.leftIsExclusive ? '(' : '[');
sb.append(this.leftIsExclusive ? START_EXCLUDING_PREFIX : START_INCLUDING_PREFIX);
if (this.min != null) {
sb.append(this.min);
}
sb.append('>');
sb.append(VERSION_SEPARATOR);
if (this.max != null) {
sb.append(this.max);
}
sb.append(this.rightIsExclusive ? ')' : ']');
sb.append(this.rightIsExclusive ? END_EXCLUDING_SUFFIX : END_INCLUDING_SUFFIX);
return sb.toString();
}

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

if (value.startsWith("(")) {
if (value.startsWith(START_EXCLUDING_PREFIX)) {
leftIsExclusive = true;
value = value.substring(1);
value = value.substring(START_EXCLUDING_PREFIX.length());
}
if (value.startsWith("[")) {
value = value.substring(1);
if (value.startsWith(START_INCLUDING_PREFIX)) {
value = value.substring(START_INCLUDING_PREFIX.length());
}
if (value.endsWith(")")) {
if (value.endsWith(END_EXCLUDING_SUFFIX)) {
rightIsExclusive = true;
value = value.substring(0, value.length() - 1);
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}
if (value.endsWith("]")) {
value = value.substring(0, value.length() - 1);
if (value.endsWith(END_INCLUDING_SUFFIX)) {
value = value.substring(0, value.length() - END_EXCLUDING_SUFFIX.length());
}

int index = value.indexOf('>');
int index = value.indexOf(VERSION_SEPARATOR);
if (index == -1) {
return null; // log warning?
}
Expand Down
12 changes: 12 additions & 0 deletions security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,17 @@
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 4fbef6e

Please sign in to comment.