Skip to content

Commit

Permalink
Support multiple maven repos.
Browse files Browse the repository at this point in the history
Also fix a bug with the upcoming version. I don't know why, but the upcoming version doesn't like its output redirected.
  • Loading branch information
IntegratedQuantum committed May 2, 2022
1 parent 46a4e9e commit 711aef1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/io/cubyz/dependency/DependencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static ArrayList<String> fetchDependencies(String pomURL, String absolute
if(!dep.classifier.isEmpty()) path += "-"+dep.classifier;
path += ".jar";
paths.add(path);
downloadDependency(dep, path, root.get("project").get("repositories"));
}
downloadDependencies(dependencies, paths, root.get("project").get("repositories").get("repository").get("url").value);
} catch(Exception e) {
e.printStackTrace();
}
Expand All @@ -95,13 +95,14 @@ public static String findMainClass() {
return "io.cubyz.client.GameLauncher";
}

private static void downloadDependencies(ArrayList<Dependency> dependencies, ArrayList<String> paths, String url) {
for(int i = 0; i < dependencies.size(); i++) {
// Check if the library is already present, otherwise download it:
File file = new File(paths.get(i));
if(!file.exists()) {
Dependency dep = dependencies.get(i);
file.getParentFile().mkdirs();
private static void downloadDependency(Dependency dep, String path, MyNode repositories) {
// Check if the library is already present, otherwise download it:
File file = new File(path);
if(!file.exists()) {
file.getParentFile().mkdirs();
ArrayList<Exception> exceptions = new ArrayList<>();
for(MyNode repo: repositories.childs) {
String url = repo.get("url").value;
try {
String depURL = url + "/" + dep.groupId.replaceAll("\\.", "/") + "/" + dep.artifactId.replaceAll("\\.", "/") + "/" + dep.version + "/" + dep.artifactId + "-" + dep.version;
if(!dep.classifier.isEmpty()) depURL += "-"+dep.classifier;
Expand All @@ -112,10 +113,16 @@ private static void downloadDependencies(ArrayList<Dependency> dependencies, Arr
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
System.out.println("Successfully downloaded library from "+depURL+" into "+file.getAbsolutePath());
return;
} catch (IOException e) {
e.printStackTrace();
exceptions.add(e);
}
}
// Couldn't download the thing. Print the exception of every url, as it might be helpful:
System.out.println("Couldn't downloaded library "+dep.groupId+"/"+dep.artifactId+"/"+dep.version+".");
for(Exception e: exceptions) {
e.printStackTrace();
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/io/cubyz/github/GitHubConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static void downloadAndLaunchRelease(File folder) {
try {
DownloadAndFileManager.downloadAndUnzip(folder, link);
} catch(IOException e) {
// That's normal behaviour. Not every release needs this folder.
if(!tag.equals("R1")) {
e.printStackTrace();
}
}

// Dependencies:
Expand Down Expand Up @@ -142,7 +144,6 @@ public static void downloadAndLaunchRelease(File folder) {
ProcessBuilder pb = new ProcessBuilder(javaPath, "-cp", classpath, DependencyManager.findMainClass());
System.out.println("Command: " + pb.command());
pb.directory(folder);
pb.redirectOutput(new File(System.getProperty("user.home") + "/.cubyz/game.log"));
try {
Process p = pb.start();
System.out.println("Started...");
Expand Down

0 comments on commit 711aef1

Please sign in to comment.