Skip to content

Commit 0aa8e9a

Browse files
committed
Updated to fix the issue when there are versions with "beta" tags
Got rid of legacy code...
1 parent 74c5fd2 commit 0aa8e9a

9 files changed

Lines changed: 84 additions & 85 deletions

File tree

build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,26 @@ jar {
8484
)
8585
}
8686
}
87+
task runInstaler(type: JavaExec) {
88+
group = 'Installer Tasks'
89+
description = 'Runs the main class in the build/run directory'
90+
91+
mainClass.set('org.mangorage.installer.Installer') // replace with your actual main class
92+
classpath = sourceSets.main.runtimeClasspath
93+
94+
workingDir = file("$buildDir/run")
95+
doFirst {
96+
workingDir.mkdirs() // Make sure the directory exists
97+
}
98+
}
8799

88100
shadowJar {
89101
group "main tasks"
90102
archiveClassifier.set('')
91103

92104
excludes.remove('module-info.class')
93-
relocate('com.google.gson', 'internal.mango.gson')
105+
relocate('com.google.gson', 'internal.shaded.com.google.gson')
106+
relocate('joptsimple', 'internal.shaded.joptsimple')
94107
}
95108

96109
publishing {

gradle/wrapper/gradle-wrapper.jar

-16.8 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Wed Oct 25 15:49:45 PDT 2023
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 31 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
requires static com.google.gson;
33
requires static jopt.simple;
44
requires jdk.unsupported;
5+
requires java.xml;
56

67
uses org.mangorage.installer.Installer;
78
}

src/main/java/org/mangorage/installer/Installer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import joptsimple.OptionSet;
77
import joptsimple.OptionSpec;
88
import joptsimple.util.PathConverter;
9-
import org.mangorage.installer.core.LogUtil;
109
import org.mangorage.installer.core.UpdateChecker;
1110
import org.mangorage.installer.core.data.*;
1211
import java.io.*;
1312
import java.lang.reflect.Method;
14-
import java.net.MalformedURLException;
1513
import java.net.URL;
1614
import java.net.URLClassLoader;
1715
import java.nio.file.Path;
@@ -21,14 +19,12 @@
2119
import java.util.jar.Manifest;
2220
import java.util.stream.Collectors;
2321
import java.util.zip.ZipEntry;
24-
import java.util.zip.ZipInputStream;
2522

2623
public class Installer {
2724
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
2825
private static final ExecutorService TASKS = Executors.newSingleThreadExecutor();
2926

3027
private static final String DEPENDENCIES_PATH = "installer-data/dependencies.json";
31-
private static final String SERVICE_PATH = "installer-data/services.launch";
3228
private static final Path LIBRARIES_PATH = Path.of("libraries/").toAbsolutePath();
3329

3430
public static void main(String[] args) {

src/main/java/org/mangorage/installer/core/data/Maven.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
* @param groupId (io.github.realmangorage)
3030
* @param artifactId (mangobot)
3131
*/
32-
public record Maven(String repository, String groupId, String artifactId) { }
32+
public record Maven(String repository, String groupId, String artifactId) {}

src/main/java/org/mangorage/installer/core/data/Version.java

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@
88
public final class Version implements Comparable<Version> {
99

1010
public static List<Version> parseMetadata(String metadata) {
11-
return Version.parseVersions(metadata).stream().map(a -> {
12-
if (a.contains("c"))
13-
return Version.of(Version.transformVersion(a), a);
14-
return Version.of(a);
15-
}).toList();
16-
}
17-
18-
public static Version parseVersion(String version) {
19-
if (version.contains("c"))
20-
return Version.of(Version.transformVersion(version), version);
21-
return Version.of(version);
11+
return Version.parseVersions(metadata)
12+
.stream()
13+
.filter(a -> a.matches("\\d+\\.\\d+\\.\\d+")) // Only x.y.z...
14+
.map(Version::of)
15+
.toList();
2216
}
2317

2418
public static Version of(String version) {
@@ -27,57 +21,28 @@ public static Version of(String version) {
2721
return new Version(Integer.parseInt(param[0]), Integer.parseInt(param[1]), Integer.parseInt(param[2]));
2822
}
2923

30-
public static Version of(String version, String original) {
31-
String[] param = version.split("\\.");
32-
if (param.length != 3) throw new IllegalStateException("Version needs to be major.minor.patch");
33-
return new Version(Integer.parseInt(param[0]), Integer.parseInt(param[1]), Integer.parseInt(param[2]), original);
34-
}
35-
36-
public static Version getLatestVersion(List<Version> versions, String versionPattern) {
37-
Pattern pattern = Pattern.compile(versionPattern.replace(".", "\\.").replace("+", ".*"));
38-
return versions.stream()
39-
.filter(version -> {
40-
Matcher matcher = pattern.matcher(version.toString());
41-
return matcher.matches();
42-
})
43-
.max(Version::compareTo)
44-
.orElse(null);
45-
}
46-
4724
public static List<String> parseVersions(String input) {
4825
List<String> matchingVersions = new ArrayList<>();
4926

50-
// Define the pattern
5127
Pattern regexPattern = Pattern.compile("<version>(.*?)<\\/version>");
52-
53-
// Create a matcher with the input string
5428
Matcher matcher = regexPattern.matcher(input);
5529

56-
// Find all matches in the input string
5730
while (matcher.find()) {
5831
matchingVersions.add(matcher.group(1)); // Capture only the version part
5932
}
6033

6134
return matchingVersions;
6235
}
6336

64-
public static String transformVersion(String version) {
65-
// Define the pattern
66-
Pattern regexPattern = Pattern.compile("(\\d+\\.\\d+\\.\\d+)-c(\\d+)");
67-
68-
// Create a matcher with the input version
69-
Matcher matcher = regexPattern.matcher(version);
70-
71-
// Check if the pattern matches
72-
if (matcher.matches()) {
73-
// Combine the matched groups, removing leading zeros from the third part
74-
String mainPart = matcher.group(1);
75-
String thirdPart = matcher.group(2).replaceFirst("^0+(?!$)", "");
76-
return String.format("%s%s", mainPart.substring(0, mainPart.length() - 1), thirdPart);
77-
} else {
78-
// Return the original version if no match
79-
return version;
80-
}
37+
public static Version getLatestVersion(List<Version> versions, String versionPattern) {
38+
Pattern pattern = Pattern.compile(versionPattern.replace(".", "\\.").replace("+", ".*"));
39+
return versions.stream()
40+
.filter(version -> {
41+
Matcher matcher = pattern.matcher(version.toString());
42+
return matcher.matches();
43+
})
44+
.max(Version::compareTo)
45+
.orElse(null);
8146
}
8247

8348
private final int major;

0 commit comments

Comments
 (0)