You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/09/07 19:00:28 UTC

svn commit: r993427 - in /subversion/branches/javahl-ra/subversion/bindings/javahl: native/ src/org/apache/subversion/javahl/ tests/org/apache/subversion/javahl/

Author: hwright
Date: Tue Sep  7 17:00:27 2010
New Revision: 993427

URL: http://svn.apache.org/viewvc?rev=993427&view=rev
Log:
On the javahl-ra branch:
Expose the getDatedRevision() RA API through Java.

[ in subversion/bindings/javahl/ ]
* tests/org/apache/subversion/javahl/SVNRATests.java
  (testDatedRev): New.

* native/SVNReposAccess.h
  (getDatedRev, m_sess_pool, m_ra_session): New.
  (SVNReposAccess): Add repos url param.

* native/JNIUtil.cpp
  (getDate): New.

* native/SVNReposAccess.cpp
  (SVNReposAccess): Add repos url param, and create an ra_session.
  (~SVNReposAccess): Destroy the session pool.
  (getDatedRev): New.

* native/JNIUtil.h
  (getDate): New.

* native/org_apache_subversion_javahl_SVNReposAccess.cpp
  (Java_org_apache_subversion_javahl_SVNReposAccess_ctNative):
    Construct the C++ peer with the repos url.
  (Java_org_apache_subversion_javahl_SVNReposAccess_getDatedRevision): New.

* src/org/apache/subversion/javahl/ISVNReposAccess.java
  (getDatedRevision): New.

* src/org/apache/subversion/javahl/SVNReposAccess.java
  (SVNReposAccess): Pass the reposURI to the native constructor.
  (ctNative): Accept the repos URI.
  (getDatedRevision): New.

Modified:
    subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.h
    subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.cpp
    subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.h
    subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNReposAccess.cpp
    subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNReposAccess.java
    subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNReposAccess.java
    subversion/branches/javahl-ra/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRATests.java

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.cpp?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.cpp Tue Sep  7 17:00:27 2010
@@ -807,6 +807,31 @@ jobject JNIUtil::createDate(apr_time_t t
   return ret;
 }
 
+apr_time_t
+JNIUtil::getDate(jobject jdate)
+{
+  JNIEnv *env = getEnv();
+  jclass clazz = env->FindClass("java/util/Date");
+  if (isJavaExceptionThrown())
+    return 0;
+
+  static jmethodID mid = 0;
+  if (mid == 0)
+    {
+      mid = env->GetMethodID(clazz, "getTime", "()J");
+      if (isJavaExceptionThrown())
+        return 0;
+    }
+
+  jlong jmillis = env->CallLongMethod(jdate, mid);
+  if (isJavaExceptionThrown())
+    return 0;
+
+  env->DeleteLocalRef(clazz);
+
+  return jmillis * 1000;
+}
+
 /**
  * Return the request pool. The request pool will be destroyed after each
  * request (call).

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.h?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.h (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/native/JNIUtil.h Tue Sep  7 17:00:27 2010
@@ -67,6 +67,7 @@ class JNIUtil
   static void setRequestPool(SVN::Pool *pool);
   static SVN::Pool *getRequestPool();
   static jobject createDate(apr_time_t time);
+  static apr_time_t getDate(jobject jdate);
   static void logMessage(const char *message);
   static int getLogLevel();
   static char *getFormatBuffer();

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.cpp?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.cpp (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.cpp Tue Sep  7 17:00:27 2010
@@ -26,15 +26,28 @@
 
 #include "SVNReposAccess.h"
 #include "JNIUtil.h"
+#include "JNICriticalSection.h"
+
 #include "svn_ra.h"
 #include "svn_private_config.h"
 
-SVNReposAccess::SVNReposAccess()
+SVNReposAccess::SVNReposAccess(const char *repos_url)
 {
+  JNICriticalSection criticalSection(*JNIUtil::getGlobalPoolMutex());
+  m_sess_pool = svn_pool_create(JNIUtil::getPool());
+
+  svn_ra_callbacks2_t *cbtable =
+            (svn_ra_callbacks2_t *) apr_pcalloc(m_sess_pool, sizeof(*cbtable));
+
+  SVN_JNI_ERR(svn_ra_open4(&m_ra_session, NULL, repos_url,
+                           NULL, cbtable, NULL, NULL,
+                           m_sess_pool), );
 }
 
 SVNReposAccess::~SVNReposAccess()
 {
+  // This will close the ra session
+  svn_pool_destroy(m_sess_pool);
 }
 
 SVNReposAccess *SVNReposAccess::getCppObject(jobject jthis)
@@ -50,3 +63,16 @@ void SVNReposAccess::dispose()
   static jfieldID fid = 0;
   SVNBase::dispose(&fid, JAVA_PACKAGE"/SVNReposAccess");
 }
+
+svn_revnum_t
+SVNReposAccess::getDatedRev(apr_time_t tm)
+{
+  SVN::Pool requestPool;
+  svn_revnum_t rev;
+
+  SVN_JNI_ERR(svn_ra_get_dated_revision(m_ra_session, &rev, tm,
+                                        requestPool.pool()),
+              SVN_INVALID_REVNUM);
+
+  return rev;
+}

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.h
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.h?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.h (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/native/SVNReposAccess.h Tue Sep  7 17:00:27 2010
@@ -34,12 +34,15 @@
 class SVNReposAccess : public SVNBase
 {
  public:
-  SVNReposAccess();
+  svn_revnum_t getDatedRev(apr_time_t time);
+
+  SVNReposAccess(const char *repos_url);
   virtual ~SVNReposAccess();
   void dispose();
   static SVNReposAccess *getCppObject(jobject jthis);
-
  private:
+  apr_pool_t *m_sess_pool;
+  svn_ra_session_t *m_ra_session;
 };
 
 #endif // SVNREPOSACCESS_H

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNReposAccess.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNReposAccess.cpp?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNReposAccess.cpp (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNReposAccess.cpp Tue Sep  7 17:00:27 2010
@@ -26,6 +26,7 @@
 #include "../include/org_apache_subversion_javahl_SVNReposAccess.h"
 #include "JNIUtil.h"
 #include "JNIStackElement.h"
+#include "JNIStringHolder.h"
 #include "svn_version.h"
 #include "svn_private_config.h"
 #include "version.h"
@@ -35,10 +36,15 @@
 
 JNIEXPORT jlong JNICALL
 Java_org_apache_subversion_javahl_SVNReposAccess_ctNative
-(JNIEnv *env, jobject jthis)
+(JNIEnv *env, jobject jthis, jstring jurl)
 {
   JNIEntry(SVNReposAccess, ctNative);
-  SVNReposAccess *obj = new SVNReposAccess;
+
+  JNIStringHolder url(jurl);
+  if (JNIUtil::isExceptionThrown())
+    return -1;
+
+  SVNReposAccess *obj = new SVNReposAccess(url);
   return obj->getCppAddr();
 }
 
@@ -65,3 +71,22 @@ Java_org_apache_subversion_javahl_SVNRep
   if (ra != NULL)
     ra->finalize();
 }
+
+JNIEXPORT jlong JNICALL
+Java_org_apache_subversion_javahl_SVNReposAccess_getDatedRevision
+(JNIEnv *env, jobject jthis, jobject jdate)
+{
+  JNIEntry(SVNReposAccess, getDatedRevision);
+  SVNReposAccess *ra = SVNReposAccess::getCppObject(jthis);
+  if (ra == NULL)
+    {
+      JNIUtil::throwError("bad C++ this");
+      return -1;
+    }
+
+  apr_time_t date = JNIUtil::getDate(jdate);
+  if (JNIUtil::isExceptionThrown())
+    return -1;
+
+  return ra->getDatedRev(date);
+}

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNReposAccess.java
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNReposAccess.java?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNReposAccess.java (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNReposAccess.java Tue Sep  7 17:00:27 2010
@@ -23,6 +23,8 @@
 
 package org.apache.subversion.javahl;
 
+import java.util.Date;
+
 /**
  * This interface is an interface to interact with a remote Subversion
  * repository via the repository access method.
@@ -39,4 +41,10 @@ public interface ISVNReposAccess
      * @since 1.0
      */
     public Version getVersion();
+
+    /**
+     * @param date      The date
+     * @return          The latest revision at date
+     */
+    public long getDatedRevision(Date date);
 }

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNReposAccess.java
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNReposAccess.java?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNReposAccess.java (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNReposAccess.java Tue Sep  7 17:00:27 2010
@@ -24,6 +24,7 @@
 package org.apache.subversion.javahl;
 
 import java.net.URI;
+import java.util.Date;
 
 /**
  * This class allows direct access to remote repositories through a
@@ -44,7 +45,7 @@ public class SVNReposAccess implements I
      */
     public SVNReposAccess(URI reposURI)
     {
-        cppAddr = ctNative();
+        cppAddr = ctNative(reposURI.toString());
 /*
         // Ensure that Subversion's config file area and templates exist.
         try
@@ -69,7 +70,7 @@ public class SVNReposAccess implements I
      * Build the native peer
      * @return the adress of the peer
      */
-    private native long ctNative();
+    private native long ctNative(String uri);
 
      /**
      * release the native peer (should not depend on finalize)
@@ -94,4 +95,6 @@ public class SVNReposAccess implements I
     {
         return NativeResources.getVersion();
     }
+
+    public native long getDatedRevision(Date date);
 }

Modified: subversion/branches/javahl-ra/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRATests.java
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRATests.java?rev=993427&r1=993426&r2=993427&view=diff
==============================================================================
--- subversion/branches/javahl-ra/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRATests.java (original)
+++ subversion/branches/javahl-ra/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRATests.java Tue Sep  7 17:00:27 2010
@@ -25,6 +25,7 @@ package org.apache.subversion.javahl;
 import org.apache.subversion.javahl.callback.*;
 
 import java.net.URI;
+import java.util.Date;
 import java.io.IOException;
 
 /**
@@ -64,4 +65,11 @@ public class SVNRATests extends SVNTests
     {
         assertTrue("repository exists", thisTest.getRepository().exists());
     }
+
+    public void testDatedRev()
+        throws SubversionException, IOException
+    {
+        long revision = ra.getDatedRevision(new Date());
+        assertEquals(revision, 1);
+    }
 }