Skip to content

Commit

Permalink
Merge branch 'master' into devonfw#1112-Version-prefix-not-working-as…
Browse files Browse the repository at this point in the history
…-expected
  • Loading branch information
hohwille authored May 5, 2023
2 parents b261466 + fa4de78 commit 646f11a
Show file tree
Hide file tree
Showing 11 changed files with 1,020 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/update-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
run: |
cd url-updater
mvn -B -ntp -Dstyle.color=always install
mvn exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls"
mvn -B -ntp -Dstyle.color=always exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls"
- name: Commit and push to ide-urls
run: |
cd ide-urls
git add .
git config --global user.name ${{ secrets.BUILD_USER }}
git config --global user.email ${{ secrets.BUILD_USER_EMAIL }}
git commit -m "Update urls"
git commit -m "Update urls" || echo "No changes, nothing to do." && exit 0
git push
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,42 @@ protected String getTool() {
}

@Override
protected void addVersion(UrlVersion urlVersion) {
protected String getGithubOrganization() {

return "aws";
}

@Override
protected String getGithubRepository() {

if (!urlVersion.getName().startsWith("2")) {
return; // There are no valid download links for aws-cli below version 2
return "aws-cli";
}

@Override
protected String mapVersion(String version) {

int majorEnd = 0;
int len = version.length();
while (majorEnd < len) {
char c = version.charAt(majorEnd);
if ((c >= '0') && (c <= '9')) {
majorEnd++;
} else {
break;
}
}
if (majorEnd > 0) {
int major = Integer.parseInt(version.substring(0, majorEnd));
if (major < 2) {
return null; // There are no valid download links for aws-cli below version 2
}
}
return super.mapVersion(version);
}

@Override
protected void addVersion(UrlVersion urlVersion) {

String baseUrl = "https://awscli.amazonaws.com/";
boolean ok = doAddVersion(urlVersion, baseUrl + "AWSCLIV2-${version}.msi", OperatingSystem.WINDOWS);
if (!ok) {
Expand All @@ -30,15 +61,4 @@ protected void addVersion(UrlVersion urlVersion) {
doAddVersion(urlVersion, baseUrl + "AWSCLIV2-${version}.pkg", OperatingSystem.MAC);
}

@Override
protected String getGithubOrganization() {

return "aws";
}

@Override
protected String getGithubRepository() {

return "aws-cli";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.devonfw.tools.ide.version;

/**
* Enum with the available categories of a {@link Character} for a {@link VersionSegment}.
*/
enum CharCategory {

/** Category for {@link VersionSegment#getSeparator() separator} characters. */
SEPARATOR,

/** Category for {@link VersionSegment#getLetters() letter} characters. */
LETTER,

/** Category for {@link VersionSegment#getDigits() digit} characters. */
DIGIT;

public static CharCategory of(char c) {

if (isLetter(c)) {
return LETTER;
} else if (isDigit(c)) {
return DIGIT;
} else {
return SEPARATOR;
}
}

static boolean isDigit(char c) {

return (c >= '0') && (c <= '9');
}

static boolean isLetter(char c) {

return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}

static boolean isValidSeparator(char c) {

return (c == '.') || (c == '-') || (c == '_');
}

static boolean isLetterSeparator(char c) {

return (c == '-') || (c == '_');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.devonfw.tools.ide.version;

/**
* Stateful object to read a {@link String} as stream of characters.
*/
final class CharReader {

private final String string;

private final int len;

private int i;

/**
* The constructor.
*
* @param string the {@link String} to read.
*/
public CharReader(String string) {

super();
this.string = string;
this.len = string.length();
this.i = 0;
}

public boolean hasNext() {

return (this.i < this.len);
}

public char peek() {

if (this.i < this.len) {
return this.string.charAt(this.i);
}
return '\0';
}

public char next() {

if (this.i < this.len) {
return this.string.charAt(this.i++);
}
return '\0';
}

public String readSeparator() {

int start = this.i;
while (this.i < this.len) {
char c = this.string.charAt(this.i);
if (!CharCategory.isDigit(c) && !CharCategory.isLetter(c)) {
this.i++;
} else {
break;
}
}
return this.string.substring(start, this.i);
}

public String readDigits() {

int start = this.i;
while (this.i < this.len) {
char c = this.string.charAt(this.i);
if (CharCategory.isDigit(c)) {
this.i++;
} else {
break;
}
}
return this.string.substring(start, this.i);
}

public String readLetters() {

int start = this.i;
while (this.i < this.len) {
int step = 0;
char c = this.string.charAt(this.i);
if (CharCategory.isLetter(c)) {
step = 1;
} else if ((this.i > start) && CharCategory.isLetterSeparator(c)) {
int j = this.i + 1;
if (j < this.len) {
char next = this.string.charAt(j);
if (CharCategory.isLetter(next)) {
step = 2;
}
}
}
if (step == 0) {
break;
}
this.i = this.i + step;
}
return this.string.substring(start, this.i);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.devonfw.tools.ide.version;

/**
* Result of {@link VersionObject#compareVersion(Object)}.
*/
public enum VersionComparisonResult {

/** The first version is smaller than the second one. */
LESS,

/** {@link #LESS Less} but {@link #isUnsafe() unsafe}. */
LESS_UNSAFE,

/** Both versions are equal. */
EQUAL,

/** {@link #EQUAL} but {@link #isUnsafe() unsafe}. */
EQUAL_UNSAFE,

/** The second version is larger than the second one. */
GREATER,

/** {@link #GREATER Greater} but {@link #isUnsafe() unsafe}. */
GREATER_UNSAFE;

/**
* @return {@code true} if the versions are not strictly comparable (e.g. "apple" and "banana", also for "1.0" and
* "1-0"), {@code false} otherwise.
*
* @see #LESS_UNSAFE
* @see #GREATER_UNSAFE
*/
public boolean isUnsafe() {

return (this == LESS_UNSAFE) || (this == GREATER_UNSAFE);
}

/**
* @return {@code true} if the first version was smaller than the second one, {@code false} otherwise.
*/
public boolean isLess() {

return (this == LESS) || (this == LESS_UNSAFE);
}

/**
* @return {@code true} if both versions were equal, {@code false} otherwise.
*/
public boolean isEqual() {

return (this == EQUAL) || (this == EQUAL_UNSAFE);
}

/**
* @return {@code true} if the first version was larger than the second one, {@code false} otherwise.
*/
public boolean isGreater() {

return (this == GREATER) || (this == GREATER_UNSAFE);
}

/**
* @return an integer value equivalent with the {@link VersionComparisonResult} and compliant with
* {@link VersionObject#compareTo(Object)}.
*/
public int asValue() {

switch (this) {
case LESS:
case LESS_UNSAFE:
return -1;
case EQUAL:
case EQUAL_UNSAFE:
return 0;
case GREATER:
case GREATER_UNSAFE:
return 1;
default:
throw new IllegalStateException(toString());
}
}

/**
* @param unsafe the new value of {@link #isUnsafe()}.
* @return an equivalent {@link VersionComparisonResult} with the given {@link #isUnsafe() unsafe} value.
*/
public VersionComparisonResult withUnsafe(boolean unsafe) {

if (unsafe) {
return withUnsafe();
} else {
return withSafe();
}
}

/**
* @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code true}.
*/
public VersionComparisonResult withUnsafe() {

if (isGreater()) {
return GREATER_UNSAFE;
} else if (isLess()) {
return LESS_UNSAFE;
} else {
return EQUAL_UNSAFE;
}
}

/**
* @return an equivalent {@link VersionComparisonResult} with {@link #isUnsafe() unsafe} being {@code false}.
*/
public VersionComparisonResult withSafe() {

if (isGreater()) {
return GREATER;
} else if (isLess()) {
return LESS;
} else {
return EQUAL;
}
}

}
Loading

0 comments on commit 646f11a

Please sign in to comment.