From 16afbfa9af3b32418f8c64b75bee4b71f3c81ca5 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Fri, 30 Aug 2024 10:31:03 +0200 Subject: [PATCH] Adds CL packagemanager option to add repositories. Closes #1163 --- src/beast/pkgmgmt/PackageManager.java | 38 +++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/beast/pkgmgmt/PackageManager.java b/src/beast/pkgmgmt/PackageManager.java index 6f98bea0..68e364fb 100644 --- a/src/beast/pkgmgmt/PackageManager.java +++ b/src/beast/pkgmgmt/PackageManager.java @@ -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.*; @@ -161,7 +158,7 @@ public DependencyResolutionException(String message) { */ public static List getRepositoryURLs() throws MalformedURLException { - List URLs = new ArrayList(); + List URLs = new ArrayList<>(); URLs.add(new URL(PACKAGES_XML)); //# url @@ -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); } @@ -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); @@ -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 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(); }