You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/12/25 03:32:46 UTC

[commons-vfs] 06/09: it is verified that argument for cli option -o and -n is a jar file

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

ggregory pushed a commit to annotated tag japicmp-base-0.0.2
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git

commit 3d58ae7ba59656cd20ccee825c2957126c6917af
Author: siom79 <ma...@googlemail.com>
AuthorDate: Sun Oct 6 11:29:30 2013 +0200

    it is verified that argument for cli option -o and -n is a jar file
---
 japicmp/src/main/java/japicmp/JApiCmp.java | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/japicmp/src/main/java/japicmp/JApiCmp.java b/japicmp/src/main/java/japicmp/JApiCmp.java
index 14a59ec..bcb684d 100644
--- a/japicmp/src/main/java/japicmp/JApiCmp.java
+++ b/japicmp/src/main/java/japicmp/JApiCmp.java
@@ -11,7 +11,9 @@ import japicmp.output.stdout.StdoutOutputGenerator;
 import japicmp.output.xml.XmlOutputGenerator;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
+import java.util.jar.JarFile;
 
 public class JApiCmp {
 
@@ -34,7 +36,7 @@ public class JApiCmp {
         Options options = parseCliOptions(args);
         File oldArchive = new File(options.getOldArchive());
         File newArchive = new File(options.getNewArchive());
-        verifyFilesExist(oldArchive, newArchive);
+        verifyFiles(oldArchive, newArchive);
         JarArchiveComparatorOptions comparatorOptions = new JarArchiveComparatorOptions();
         copyOptions(options, comparatorOptions);
         JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(comparatorOptions);
@@ -70,7 +72,7 @@ public class JApiCmp {
         }
     }
 
-    private void verifyFilesExist(File oldArchive, File newArchive) {
+    private void verifyFiles(File oldArchive, File newArchive) {
         if (!oldArchive.exists()) {
             String msg = String.format("File '%s' does not exist.", oldArchive.getAbsolutePath());
             throw new JApiCmpException(JApiCmpException.Reason.IllegalArgument, msg);
@@ -83,5 +85,16 @@ public class JApiCmp {
             String msg = String.format("Files '%s' and '%s' are the same.", oldArchive.getAbsolutePath(), newArchive.getAbsolutePath());
             throw new JApiCmpException(JApiCmpException.Reason.IllegalArgument, msg);
         }
+        verifyJarArchive(oldArchive);
+        verifyJarArchive(newArchive);
+    }
+
+    private void verifyJarArchive(File file) {
+        try {
+            new JarFile(file);
+        } catch (IOException e) {
+            String msg = String.format("File '%s' could not be opened as a jar file: %s", file.getAbsolutePath(), e.getMessage());
+            throw new JApiCmpException(JApiCmpException.Reason.IllegalArgument, msg);
+        }
     }
 }