subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hwri...@apache.org
Subject svn commit: r918715 - in /subversion/trunk/subversion/bindings/javahl: native/ src/org/apache/subversion/javahl/ src/org/tigris/subversion/javahl/ tests/org/apache/subversion/javahl/
Date Wed, 03 Mar 2010 21:57:46 GMT
Author: hwright
Date: Wed Mar  3 21:57:46 2010
New Revision: 918715

URL: http://svn.apache.org/viewvc?rev=918715&view=rev
Log:
JavaHL: More API updates to use the Collections framework, this time in the
Mergeinfo class.

[ in subversion/bindings/javahl/ ]
* tests/org/apache/subversion/javahl/BasicTests.java:
  Update tests for new datastructures.

* native/CreateJ.cpp,
  native/CreateJ.h
  (RevisionRangeArray): Rename to...
  (RevisionRangeList): ...this, and update to return a List.

* native/SVNClient.cpp
  (getMergeinfo): Create a RevisionRangeList, per the new API.

* src/org/tigris/subversion/javahl/Mergeinfo.java
  (Mergeinfo): Update wrapper to use the new data structures.
 
* src/org/apache/subversion/javahl/Mergeinfo.java
  (addRevisions, getPaths, getRevisionRange): Update to use Java Collections.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
    subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
    subversion/trunk/subversion/bindings/javahl/native/SVNClient.cpp
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/Mergeinfo.java
    subversion/trunk/subversion/bindings/javahl/src/org/tigris/subversion/javahl/Mergeinfo.java
    subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java

Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp Wed Mar  3 21:57:46 2010
@@ -354,36 +354,57 @@
 }
 
 
-jobjectArray
-CreateJ::RevisionRangeArray(apr_array_header_t *ranges)
+jobject
+CreateJ::RevisionRangeList(apr_array_header_t *ranges)
 {
-    JNIEnv *env = JNIUtil::getEnv();
+  JNIEnv *env = JNIUtil::getEnv();
+
+  jclass clazz = env->FindClass("java/util/ArrayList");
+  if (JNIUtil::isJavaExceptionThrown())
+    return NULL;
 
-    jclass clazz = env->FindClass(JAVA_PACKAGE "/RevisionRange");
-    if (JNIUtil::isJavaExceptionThrown())
+  static jmethodID init_mid = 0;
+  if (init_mid == 0)
+    {
+      init_mid = env->GetMethodID(clazz, "<init>", "()V");
+      if (JNIUtil::isJavaExceptionThrown())
         return NULL;
+    }
 
-    jobjectArray jranges = env->NewObjectArray(ranges->nelts, clazz, NULL);
+  static jmethodID add_mid = 0;
+  if (add_mid == 0)
+    {
+      add_mid = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
+      if (JNIUtil::isJavaExceptionThrown())
+        return NULL;
+    }
+
+  jobject jranges = env->NewObject(clazz, init_mid);
 
-    for (int i = 0; i < ranges->nelts; ++i)
+  for (int i = 0; i < ranges->nelts; ++i)
     {
-        // Convert svn_merge_range_t *'s to Java RevisionRange objects.
-        svn_merge_range_t *range =
-            APR_ARRAY_IDX(ranges, i, svn_merge_range_t *);
-        jobject jrange = RevisionRange::makeJRevisionRange(range);
-        if (jrange == NULL)
-            return NULL;
+      // Convert svn_merge_range_t *'s to Java RevisionRange objects.
+      svn_merge_range_t *range =
+          APR_ARRAY_IDX(ranges, i, svn_merge_range_t *);
 
-        env->SetObjectArrayElement(jranges, i, jrange);
-        if (JNIUtil::isJavaExceptionThrown())
-            return NULL;
+      jobject jrange = RevisionRange::makeJRevisionRange(range);
+      if (jrange == NULL)
+        return NULL;
+
+      env->CallObjectMethod(jranges, add_mid, jrange);
+      if (JNIUtil::isJavaExceptionThrown())
+        return NULL;
 
-        env->DeleteLocalRef(jrange);
-        if (JNIUtil::isJavaExceptionThrown())
-            return NULL;
+      env->DeleteLocalRef(jrange);
+      if (JNIUtil::isJavaExceptionThrown())
+        return NULL;
     }
 
-    return jranges;
+  env->DeleteLocalRef(clazz);
+  if (JNIUtil::isJavaExceptionThrown())
+    return NULL;
+
+  return jranges;
 }
 
 jobject

Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.h?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.h Wed Mar  3 21:57:46 2010
@@ -49,8 +49,8 @@
   static jobject
   Lock(const svn_lock_t *lock);
 
-  static jobjectArray
-  RevisionRangeArray(apr_array_header_t *ranges);
+  static jobject
+  RevisionRangeList(apr_array_header_t *ranges);
 
   static jobject
   StringSet(apr_array_header_t *strings);
@@ -66,6 +66,9 @@
  protected:
   static jobject
   ConflictVersion(const svn_wc_conflict_version_t *version);
+
+  static jobject
+  Collection(std::vector<jobject> &object, const char *className);
 };
 
 #endif  // CREATEJ_H

Modified: subversion/trunk/subversion/bindings/javahl/native/SVNClient.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/SVNClient.cpp?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/SVNClient.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/SVNClient.cpp Wed Mar  3 21:57:46 2010
@@ -793,7 +793,7 @@
     {
         addRevisions = env->GetMethodID(clazz, "addRevisions",
                                         "(Ljava/lang/String;"
-                                        "[L"JAVA_PACKAGE"/RevisionRange;)V");
+                                        "Ljava/util/List;)V");
         if (JNIUtil::isJavaExceptionThrown())
             return NULL;
     }
@@ -812,8 +812,8 @@
         apr_hash_this(hi, &path, NULL, &val);
 
         jstring jpath = JNIUtil::makeJString((const char *) path);
-        jobjectArray jranges =
-            CreateJ::RevisionRangeArray((apr_array_header_t *) val);
+        jobject jranges =
+            CreateJ::RevisionRangeList((apr_array_header_t *) val);
 
         env->CallVoidMethod(jmergeinfo, addRevisions, jpath, jranges);
 
@@ -825,6 +825,10 @@
             return NULL;
     }
 
+    env->DeleteLocalRef(clazz);
+    if (JNIUtil::isJavaExceptionThrown())
+        return NULL;
+
     return jmergeinfo;
 }
 

Modified: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/Mergeinfo.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/Mergeinfo.java?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/Mergeinfo.java
(original)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/Mergeinfo.java
Wed Mar  3 21:57:46 2010
@@ -77,7 +77,7 @@
      * @throws SubversionException If range list contains objects of
      * type other than RevisionRange.
      */
-    public void addRevisions(String mergeSrc, RevisionRange[] ranges)
+    public void addRevisions(String mergeSrc, List<RevisionRange> ranges)
     {
         for (RevisionRange range : ranges)
             addRevisionRange(mergeSrc, range);
@@ -103,12 +103,9 @@
      * Get the merge source URLs.
      * @return The merge source URLs.
      */
-    public String[] getPaths()
+    public Set<String> getPaths()
     {
-        Set<String> pathSet = mergeSources.keySet();
-        if (pathSet == null)
-            return null;
-        return pathSet.toArray(new String[pathSet.size()]);
+        return mergeSources.keySet();
     }
 
     /**
@@ -128,12 +125,9 @@
      * @param mergeSrc The merge source URL, or <code>null</code>.
      * @return Array of RevisionRange objects, or <code>null</code>.
      */
-    public RevisionRange[] getRevisionRange(String mergeSrc)
+    public List<RevisionRange> getRevisionRange(String mergeSrc)
     {
-        List<RevisionRange> revisions = this.getRevisions(mergeSrc);
-        if (revisions == null)
-            return null;
-        return revisions.toArray(new RevisionRange[revisions.size()]);
+        return this.getRevisions(mergeSrc);
     }
 
     /**

Modified: subversion/trunk/subversion/bindings/javahl/src/org/tigris/subversion/javahl/Mergeinfo.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/tigris/subversion/javahl/Mergeinfo.java?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/tigris/subversion/javahl/Mergeinfo.java
(original)
+++ subversion/trunk/subversion/bindings/javahl/src/org/tigris/subversion/javahl/Mergeinfo.java
Wed Mar  3 21:57:46 2010
@@ -74,19 +74,19 @@
     public Mergeinfo(org.apache.subversion.javahl.Mergeinfo aMergeinfo)
     {
         this();
-        String[] srcPaths = aMergeinfo.getPaths();
+        Set<String> srcPaths = aMergeinfo.getPaths();
 
-        for (int i = 0; i < srcPaths.length; i++)
+        for (String srcPath : srcPaths)
         {
-            org.apache.subversion.javahl.RevisionRange[] aRange =
-                                    aMergeinfo.getRevisionRange(srcPaths[i]);
+            List<org.apache.subversion.javahl.RevisionRange> aRanges =
+                                    aMergeinfo.getRevisionRange(srcPath);
             List<RevisionRange> list = new ArrayList<RevisionRange>();
 
-            for (int j = 0; j < aRange.length; j++)
+            for (org.apache.subversion.javahl.RevisionRange range : aRanges)
             {
-                list.add(new RevisionRange(aRange[j]));
+                list.add(new RevisionRange(range));
             }
-            mergeSources.put(srcPaths[i], list);
+            mergeSources.put(srcPath, list);
         }
     }
 

Modified: subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java?rev=918715&r1=918714&r2=918715&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java
(original)
+++ subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java
Wed Mar  3 21:57:46 2010
@@ -189,17 +189,17 @@
         String mergeInfoPropertyValue =
             "/trunk:1-300,305,307,400-405\n/branches/branch:308-400";
         Mergeinfo info = new Mergeinfo(mergeInfoPropertyValue);
-        String[] paths = info.getPaths();
-        assertEquals(2, paths.length);
-        RevisionRange[] trunkRange = info.getRevisionRange("/trunk");
-        assertEquals(4, trunkRange.length);
-        assertEquals("1-300", trunkRange[0].toString());
-        assertEquals("305", trunkRange[1].toString());
-        assertEquals("307", trunkRange[2].toString());
-        assertEquals("400-405", trunkRange[3].toString());
-        RevisionRange[] branchRange =
+        Set<String> paths = info.getPaths();
+        assertEquals(2, paths.size());
+        List<RevisionRange> trunkRange = info.getRevisionRange("/trunk");
+        assertEquals(4, trunkRange.size());
+        assertEquals("1-300", trunkRange.get(0).toString());
+        assertEquals("305", trunkRange.get(1).toString());
+        assertEquals("307", trunkRange.get(2).toString());
+        assertEquals("400-405", trunkRange.get(3).toString());
+        List<RevisionRange> branchRange =
             info.getRevisionRange("/branches/branch");
-        assertEquals(1, branchRange.length);
+        assertEquals(1, branchRange.size());
     }
 
     /**



Mime
View raw message