You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2025/08/12 10:57:38 UTC

(maven-scm) branch i1298 created (now 625f37ea2)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch i1298
in repository https://gitbox.apache.org/repos/asf/maven-scm.git


      at 625f37ea2 cleanup runtime exceptions

This branch includes the following new commits:

     new 625f37ea2 cleanup runtime exceptions

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-scm) 01/01: cleanup runtime exceptions

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch i1298
in repository https://gitbox.apache.org/repos/asf/maven-scm.git

commit 625f37ea27f4d7a3484f8f17768744afa155bc81
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Tue Aug 12 06:57:26 2025 -0400

    cleanup runtime exceptions
---
 .../scm/provider/git/gitexe/GpgTestUtils.java      | 55 ++++++++++++----------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/GpgTestUtils.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/GpgTestUtils.java
index ffeeb0083..53d76215f 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/GpgTestUtils.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/GpgTestUtils.java
@@ -23,6 +23,7 @@
 import java.nio.file.Files;
 import java.nio.file.Path;
 
+import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 import org.codehaus.plexus.util.cli.StreamConsumer;
@@ -40,29 +41,25 @@ private static Commandline createCommandline() {
         return commandLine;
     }
 
-    private static void execute(Commandline commandLine) {
-        try {
-            int exitCode = CommandLineUtils.executeCommandLine(
-                    commandLine,
-                    new StreamConsumer() {
-                        @Override
-                        public void consumeLine(String line) {
-                            // Handle output from the command if needed
-                            System.out.println(line);
-                        }
-                    },
-                    new StreamConsumer() {
-                        @Override
-                        public void consumeLine(String line) {
-                            // Handle error output from the command if needed
-                            System.err.println(line);
-                        }
-                    });
-            if (exitCode != 0) {
-                throw new RuntimeException("GPG command failed with exit code: " + exitCode);
-            }
-        } catch (Exception e) {
-            throw new RuntimeException("Failed to execute GPG command", e);
+    private static void execute(Commandline commandLine) throws CommandLineException {
+        int exitCode = CommandLineUtils.executeCommandLine(
+                commandLine,
+                new StreamConsumer() {
+                    @Override
+                    public void consumeLine(String line) {
+                        // Handle output from the command if needed
+                        System.out.println(line);
+                    }
+                },
+                new StreamConsumer() {
+                    @Override
+                    public void consumeLine(String line) {
+                        // Handle error output from the command if needed
+                        System.err.println(line);
+                    }
+                });
+        if (exitCode != 0) {
+            throw new CommandLineException("GPG command failed with exit code: " + exitCode);
         }
     }
 
@@ -70,7 +67,7 @@ public static void importKey(String pgpKeyResourceName) throws IOException {
         Path tmpFile = Files.createTempFile("gpg-secret-key", ".key");
         try (InputStream input = GpgTestUtils.class.getResourceAsStream(pgpKeyResourceName)) {
             if (input == null) {
-                throw new IllegalArgumentException("Secret GPG file not found: " + pgpKeyResourceName);
+                throw new IOException("Secret GPG file not found: " + pgpKeyResourceName);
             }
             Files.copy(input, tmpFile, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
         }
@@ -79,16 +76,22 @@ public static void importKey(String pgpKeyResourceName) throws IOException {
             cmdLine.createArg().setValue("--import");
             cmdLine.createArg().setFile(tmpFile.toFile());
             execute(cmdLine);
+        } catch (CommandLineException e) {
+            throw new IOException("Importing key failed", e);
         } finally {
             Files.delete(tmpFile);
         }
     }
 
-    public static void deleteSecretKey(String fingerprint) {
+    public static void deleteSecretKey(String fingerprint) throws IOException {
         Commandline cmdLine = createCommandline();
         cmdLine.createArg().setValue("--yes");
         cmdLine.createArg().setValue("--delete-secret-key");
         cmdLine.createArg().setValue(fingerprint);
-        execute(cmdLine);
+        try {
+            execute(cmdLine);
+        } catch (CommandLineException e) {
+            throw new IOException("Deleting key failed", e);
+        }
     }
 }