Skip to content

Commit

Permalink
Merge pull request #1164 from tgvaughan/packagemanager-patch
Browse files Browse the repository at this point in the history
Adds CL packagemanager option to add repositories. Closes #1163
  • Loading branch information
rbouckaert authored Sep 1, 2024
2 parents 3916ce5 + 16afbfa commit 3dbc14a
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/beast/pkgmgmt/PackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.*;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.*;
Expand Down Expand Up @@ -161,7 +158,7 @@ public DependencyResolutionException(String message) {
*/
public static List<URL> getRepositoryURLs() throws MalformedURLException {

List<URL> URLs = new ArrayList<URL>();
List<URL> URLs = new ArrayList<>();
URLs.add(new URL(PACKAGES_XML));

//# url
Expand Down Expand Up @@ -2016,6 +2013,7 @@ private static void printUsageAndExit(Arguments arguments) {
System.out.println("packagemanager -add SNAPP");
System.out.println("packagemanager -useAppDir -add SNAPP");
System.out.println("packagemanager -del SNAPP");
System.out.println("packagemanager -addRepository URL");
System.exit(0);
}

Expand All @@ -2032,6 +2030,7 @@ public static void main(String[] args) {
new Arguments.Option("help", "Show help"),
new Arguments.Option("update", "Check for updates, and ask to install if available"),
new Arguments.Option("updatenow", "Check for updates and install without asking"),
new Arguments.StringOption("addRepository", "URL", "Add an external repository URL"),
});
try {
arguments.parseArguments(args);
Expand Down Expand Up @@ -2166,6 +2165,35 @@ public int compare(String s1, String s2) {
System.out.println("Could not find package '" + name + "' (typo perhaps?)");
}
}

if (arguments.hasOption("addRepository")) {
String urlString = arguments.getStringOption("addRepository");
if (urlString != null) {

URL repoURL;
try {
repoURL = new URI(urlString).toURL();

List<URL> urls = getRepositoryURLs();

if (!urls.contains(repoURL)) {
urls.add(repoURL);
saveRepositoryURLs(urls);
System.out.println("Successfully added repository URL '"
+ repoURL + "' to "
+ getPackageUserDir() + "/beauti.properties.");
} else {
System.out.println("Repository URL '" + repoURL + "' already in "
+ getPackageUserDir() + "/beauti.properties.");
}
} catch (MalformedURLException ex) {
System.err.println("Error: malformed repository URL.");
System.exit(1);
}

}

}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 3dbc14a

Please sign in to comment.