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:29 UTC

[commons-vfs] 08/18: added testbase module and three submodules to test the comparison of jar archives

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

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

commit d13515164e61c02b6b0a9a63313eaa9536fc4d8d
Author: siom79 <ma...@googlemail.com>
AuthorDate: Mon Sep 30 22:20:16 2013 +0200

    added testbase module and three submodules to test the comparison of jar archives
---
 README.md                                          |  3 +-
 japicmp-testbase/japicmp-test-v1/pom.xml           | 13 ++++
 .../src/main/java/japicmp/test/Removed.java        |  4 ++
 japicmp-testbase/japicmp-test-v2/pom.xml           | 13 ++++
 .../src/main/java/japicmp/test/Added.java          |  4 ++
 japicmp-testbase/japicmp-test/pom.xml              | 71 ++++++++++++++++++++++
 .../src/test/java/japicmp/test/BasicTest.java      | 40 ++++++++++++
 japicmp-testbase/pom.xml                           | 20 ++++++
 japicmp/src/main/java/japicmp/JApiCmp.java         |  5 +-
 .../output/stdout/StdoutOutputGenerator.java       |  2 +-
 .../java/japicmp/util/StringArrayEnumeration.java  |  4 +-
 pom.xml                                            |  1 +
 12 files changed, 174 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 339b18e..58f16a9 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,9 @@ japicmp is a tool to compare two versions of a jar archive:
 
     java -jar japicmp-0.0.1-SNAPSHOT.jar -n new-version.jar -o old-version.jar
 
-It can also be used as a library to integration its functionality in some other kind of software:
+It can also be used as a library to integrate its functionality in some other kind of software:
 
+	JarArchiveComparator jarArchiveComparator = new JarArchiveComparator();
     List<JApiClass> jApiClasses = jarArchiveComparator.compare(oldArchive, newArchive);
 
 ##Motivation##
diff --git a/japicmp-testbase/japicmp-test-v1/pom.xml b/japicmp-testbase/japicmp-test-v1/pom.xml
new file mode 100644
index 0000000..20911a2
--- /dev/null
+++ b/japicmp-testbase/japicmp-test-v1/pom.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>japicmp</groupId>
+        <artifactId>japicmp-testbase</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>japicmp-test-v1</artifactId>
+</project>
\ No newline at end of file
diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/Removed.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/Removed.java
new file mode 100644
index 0000000..6ddead3
--- /dev/null
+++ b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/Removed.java
@@ -0,0 +1,4 @@
+package japicmp.test;
+
+public class Removed {
+}
diff --git a/japicmp-testbase/japicmp-test-v2/pom.xml b/japicmp-testbase/japicmp-test-v2/pom.xml
new file mode 100644
index 0000000..2174ec5
--- /dev/null
+++ b/japicmp-testbase/japicmp-test-v2/pom.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>japicmp</groupId>
+        <artifactId>japicmp-testbase</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>japicmp-test-v2</artifactId>
+</project>
\ No newline at end of file
diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/Added.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/Added.java
new file mode 100644
index 0000000..7c0398c
--- /dev/null
+++ b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/Added.java
@@ -0,0 +1,4 @@
+package japicmp.test;
+
+public class Added {
+}
diff --git a/japicmp-testbase/japicmp-test/pom.xml b/japicmp-testbase/japicmp-test/pom.xml
new file mode 100644
index 0000000..11d5a81
--- /dev/null
+++ b/japicmp-testbase/japicmp-test/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>japicmp</groupId>
+        <artifactId>japicmp-testbase</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>japicmp-test</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>japicmp</groupId>
+            <artifactId>japicmp</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>japicmp</groupId>
+            <artifactId>japicmp-test-v1</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>japicmp</groupId>
+            <artifactId>japicmp-test-v2</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <version>2.8</version>
+                <executions>
+                    <execution>
+                        <id>copy</id>
+                        <phase>process-test-resources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>japicmp</groupId>
+                                    <artifactId>japicmp-test-v1</artifactId>
+                                    <version>${project.version}</version>
+                                    <overWrite>true</overWrite>
+                                    <outputDirectory>${project.build.directory}</outputDirectory>
+                                    <destFileName>japicmp-test-v1.jar</destFileName>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>japicmp</groupId>
+                                    <artifactId>japicmp-test-v2</artifactId>
+                                    <version>${project.version}</version>
+                                    <overWrite>true</overWrite>
+                                    <outputDirectory>${project.build.directory}</outputDirectory>
+                                    <destFileName>japicmp-test-v2.jar</destFileName>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
diff --git a/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/BasicTest.java b/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/BasicTest.java
new file mode 100644
index 0000000..005dbe5
--- /dev/null
+++ b/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/BasicTest.java
@@ -0,0 +1,40 @@
+package japicmp.test;
+
+import japicmp.cmp.JarArchiveComparator;
+import japicmp.model.JApiChangeStatus;
+import japicmp.model.JApiClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class BasicTest {
+
+    @Test
+    public void test() {
+        JarArchiveComparator jarArchiveComparator = new JarArchiveComparator();
+        List<JApiClass> jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
+        assertThat(jApiClasses.size(), is(2));
+        assertThat(getJApiClass(jApiClasses, Removed.class.getName()), is(notNullValue()));
+        assertThat(getJApiClass(jApiClasses, Added.class.getName()), is(notNullValue()));
+        assertThat(getJApiClass(jApiClasses, Removed.class.getName()).getChangeStatus(), is(JApiChangeStatus.REMOVED));
+        assertThat(getJApiClass(jApiClasses, Added.class.getName()).getChangeStatus(), is(JApiChangeStatus.NEW));
+    }
+
+    private File getArchive(String filename) {
+        return new File("target" + File.separator + filename);
+    }
+
+    private JApiClass getJApiClass(List<JApiClass> jApiClasses, String fqn) {
+        for (JApiClass jApiClass : jApiClasses) {
+            if (jApiClass.getFullyQualifiedName().equals(fqn)) {
+                return jApiClass;
+            }
+        }
+        throw new IllegalArgumentException("No class found with name " + fqn + ".");
+    }
+}
diff --git a/japicmp-testbase/pom.xml b/japicmp-testbase/pom.xml
new file mode 100644
index 0000000..b540cc7
--- /dev/null
+++ b/japicmp-testbase/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>japicmp</groupId>
+        <artifactId>japicmp-base</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>japicmp-testbase</artifactId>
+	<packaging>pom</packaging>
+
+    <modules>
+		<module>japicmp-test-v1</module>
+		<module>japicmp-test-v2</module>
+		<module>japicmp-test</module>
+	</modules>
+</project>
\ No newline at end of file
diff --git a/japicmp/src/main/java/japicmp/JApiCmp.java b/japicmp/src/main/java/japicmp/JApiCmp.java
index 70c861f..51496ab 100644
--- a/japicmp/src/main/java/japicmp/JApiCmp.java
+++ b/japicmp/src/main/java/japicmp/JApiCmp.java
@@ -35,10 +35,9 @@ public class JApiCmp {
     }
 
     private static Options parseCliOptions(String[] args) {
-        Options options = new Options();
         try {
             CliParser cliParser = new CliParser();
-            options = cliParser.parse(args);
+            return cliParser.parse(args);
         } catch (IllegalArgumentException e) {
             System.err.println(e.getMessage());
             System.exit(-1);
@@ -46,7 +45,7 @@ public class JApiCmp {
             System.err.println("Failed to parse command line options: " + e.getMessage());
             System.exit(-1);
         }
-        return options;
+        return new Options();
     }
 
     private static void verifyFilesExist(File oldArchive, File newArchive) {
diff --git a/japicmp/src/main/java/japicmp/output/stdout/StdoutOutputGenerator.java b/japicmp/src/main/java/japicmp/output/stdout/StdoutOutputGenerator.java
index cead423..e379095 100644
--- a/japicmp/src/main/java/japicmp/output/stdout/StdoutOutputGenerator.java
+++ b/japicmp/src/main/java/japicmp/output/stdout/StdoutOutputGenerator.java
@@ -17,7 +17,7 @@ public class StdoutOutputGenerator {
             OutputTransformer.removeUnchanged(jApiClasses);
         }
         StringBuilder sb = new StringBuilder();
-        sb.append(String.format("Comparing %s with %s:\n", oldArchive.getAbsolutePath(), newArchive.getAbsolutePath()));
+        sb.append(String.format("Comparing %s with %s:%n", oldArchive.getAbsolutePath(), newArchive.getAbsolutePath()));
         for (JApiClass jApiClass : jApiClasses) {
             processClass(sb, jApiClass);
             processMethods(sb, jApiClass);
diff --git a/japicmp/src/main/java/japicmp/util/StringArrayEnumeration.java b/japicmp/src/main/java/japicmp/util/StringArrayEnumeration.java
index 82c7eb6..050f26c 100644
--- a/japicmp/src/main/java/japicmp/util/StringArrayEnumeration.java
+++ b/japicmp/src/main/java/japicmp/util/StringArrayEnumeration.java
@@ -1,5 +1,6 @@
 package japicmp.util;
 
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
 
@@ -8,7 +9,8 @@ public class StringArrayEnumeration implements Enumeration<String> {
     private int pos = 0;
 
     public StringArrayEnumeration(String[] array) {
-        this.array = array;
+        this.array = new String[array.length];
+        System.arraycopy(array, 0, this.array, 0, array.length);
     }
 
     @Override
diff --git a/pom.xml b/pom.xml
index 701eb8e..3778e4e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,6 +17,7 @@
 
     <modules>
         <module>japicmp</module>
+		<module>japicmp-testbase</module>
     </modules>
 
     <dependencies>