You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/03/14 10:33:19 UTC

svn commit: r1456375 - in /subversion/trunk/subversion/bindings/javahl: native/ src/org/apache/subversion/javahl/ src/org/apache/subversion/javahl/callback/ tests/org/apache/subversion/javahl/

Author: brane
Date: Thu Mar 14 09:33:19 2013
New Revision: 1456375

URL: http://svn.apache.org/r1456375
Log:
Working on isue #4326 (update javahl with new 1.8 APIs).
Add wrapper for svn_repos_freeze.

[in subversion/bindings/javahl/src/org/apache/subversion/javahl]
* ISVNRepos.java: (ISVNRepos.freeze): New abstract method.
  (ISVNRepos.recover): Fix docstring.
* SVNRepos.java (SVNRepos.freeze): Declare native method.
* callback/ReposFreezeAction.java (ReposFreezeAction): New; callback used
   by ISVNRepos.freeze.

[in subversion/bindings/javahl/native]
* ReposFreezeAction.h, ReposFreezeAction.cpp: (ReposFreezeAction):
   C++ implementaiton of the ReposFreezeAction callback.
* SVNRepos.h, SVNRepos.cpp (SVNRepos::freeze):
   Implementation of native method SVNRepos.freeze.
* org_apache_subversion_javahl_SVNRepos.cpp
  (Java_org_apache_subversion_javahl_SVNRepos_freeze): New JNI wrapper.

[in subversion/bindings/javahl/tests/org/apache/subversion/javahl]
* SVNReposTests.java: Update docstrings.
  (FreezeAction, testFreeze): New test case for ISVNRepos.freeze.

Added:
    subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.cpp
    subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.h
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ReposFreezeAction.java
Modified:
    subversion/trunk/subversion/bindings/javahl/native/SVNRepos.cpp
    subversion/trunk/subversion/bindings/javahl/native/SVNRepos.h
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNRepos.cpp
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNRepos.java
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNRepos.java
    subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNReposTests.java

Added: subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.cpp?rev=1456375&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.cpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.cpp Thu Mar 14 09:33:19 2013
@@ -0,0 +1,50 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file ReposFreezeAction.h
+ * @brief Native mirror of the ReposFreezeAction callback interface
+ */
+
+#include "ReposFreezeAction.h"
+
+svn_error_t* ReposFreezeAction::callback(void* baton, apr_pool_t*)
+{
+  ReposFreezeAction* that = static_cast<ReposFreezeAction*>(baton);
+  return that->invoke();
+}
+
+svn_error_t* ReposFreezeAction::invoke()
+{
+  JNIEnv *const env = JNIUtil::getEnv();
+
+  static volatile jmethodID mid = 0;
+  if (!mid)
+    {
+      jclass cls = env->FindClass(JAVA_PACKAGE"/callback/ReposFreezeAction");
+      if (!JNIUtil::isJavaExceptionThrown())
+        mid = env->GetMethodID(cls, "invoke", "()V");
+    }
+
+  if (!JNIUtil::isJavaExceptionThrown())
+    env->CallVoidMethod(m_jaction, mid);
+  return SVN_NO_ERROR;
+}

Added: subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.h?rev=1456375&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.h (added)
+++ subversion/trunk/subversion/bindings/javahl/native/ReposFreezeAction.h Thu Mar 14 09:33:19 2013
@@ -0,0 +1,49 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file ReposFreezeAction.h
+ * @brief Native mirror of the ReposFreezeAction callback interface
+ */
+
+#ifndef JAVAHL_REPOS_FREEZE_ACTION_H
+#define JAVAHL_REPOS_FREEZE_ACTION_H
+
+#include <apr_pools.h>
+#include "svn_error.h"
+#include "JNIUtil.h"
+
+class ReposFreezeAction
+{
+ public:
+ ReposFreezeAction(jobject jaction)
+    : m_jaction(jaction)
+  {}
+
+  static svn_error_t* callback(void* baton, apr_pool_t* pool);
+
+ private:
+  svn_error_t* invoke();
+  const jobject m_jaction;
+};
+
+
+#endif /* JAVAHL_REPOS_FREEZE_ACTION_H */

Modified: subversion/trunk/subversion/bindings/javahl/native/SVNRepos.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/SVNRepos.cpp?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/SVNRepos.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/SVNRepos.cpp Thu Mar 14 09:33:19 2013
@@ -408,6 +408,28 @@ jlong SVNRepos::recover(File &path, Repo
   return youngest_rev;
 }
 
+void SVNRepos::freeze(jobjectArray jpaths, ReposFreezeAction* action)
+{
+  JNIEnv *env = JNIUtil::getEnv();
+  SVN::Pool subPool(pool);
+  const jsize num_paths = env->GetArrayLength(jpaths);
+
+  apr_array_header_t *paths = apr_array_make(subPool.getPool(), num_paths,
+                                             sizeof(const char*));
+  for (jsize i = 0; i < num_paths; ++i)
+    {
+      jobject obj = env->GetObjectArrayElement(jpaths, i);
+      APR_ARRAY_PUSH(paths, const char*) =
+        apr_pstrdup(subPool.getPool(), File(obj).getAbsPath());
+      env->DeleteLocalRef(obj);
+    }
+
+  SVN_JNI_ERR(svn_repos_freeze(paths, action->callback, action,
+                               subPool.getPool()),
+              );
+}
+
+
 void SVNRepos::rmtxns(File &path, StringArray &transactions)
 {
   SVN::Pool requestPool;

Modified: subversion/trunk/subversion/bindings/javahl/native/SVNRepos.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/SVNRepos.h?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/SVNRepos.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/SVNRepos.h Thu Mar 14 09:33:19 2013
@@ -35,6 +35,7 @@
 #include "InputStream.h"
 #include "MessageReceiver.h"
 #include "ReposNotifyCallback.h"
+#include "ReposFreezeAction.h"
 #include "StringArray.h"
 #include "File.h"
 
@@ -51,6 +52,7 @@ class SVNRepos : public SVNBase
                   bool usePostRevPropChangeHook);
   void rmtxns(File &path, StringArray &transactions);
   jlong recover(File &path, ReposNotifyCallback *notifyCallback);
+  void freeze(jobjectArray jpaths, ReposFreezeAction* action);
   void lstxns(File &path, MessageReceiver &messageReceiver);
   void load(File &path, InputStream &dataIn, bool ignoreUUID, bool forceUUID,
             bool usePreCommitHook, bool usePostCommitHook,

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNRepos.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNRepos.cpp?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNRepos.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNRepos.cpp Thu Mar 14 09:33:19 2013
@@ -317,6 +317,28 @@ Java_org_apache_subversion_javahl_SVNRep
 }
 
 JNIEXPORT void JNICALL
+Java_org_apache_subversion_javahl_SVNRepos_freeze
+(JNIEnv *env, jobject jthis, jobject jaction, jobjectArray jpaths)
+{
+  JNIEntry(SVNRepos, freeze);
+  SVNRepos *cl = SVNRepos::getCppObject(jthis);
+  if (cl == NULL)
+    {
+      JNIUtil::throwError(_("bad C++ this"));
+      return;
+    }
+
+  if (!jpaths || !env->GetArrayLength(jpaths))
+    {
+      JNIUtil::throwError(_("list of repository paths must not be empty"));
+      return;
+    }
+
+  ReposFreezeAction action(jaction);
+  cl->freeze(jpaths, &action);
+}
+
+JNIEXPORT void JNICALL
 Java_org_apache_subversion_javahl_SVNRepos_rmtxns
 (JNIEnv *env, jobject jthis, jobject jpath, jobjectArray jtransactions)
 {

Modified: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNRepos.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNRepos.java?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNRepos.java (original)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNRepos.java Thu Mar 14 09:33:19 2013
@@ -29,6 +29,7 @@ import java.io.InputStream;
 import java.io.File;
 
 import org.apache.subversion.javahl.callback.ReposNotifyCallback;
+import org.apache.subversion.javahl.callback.ReposFreezeAction;
 import org.apache.subversion.javahl.types.*;
 
 public interface ISVNRepos {
@@ -166,14 +167,34 @@ public interface ISVNRepos {
 			throws ClientException;
 
 	/**
-	 * recover the berkeley db of a repository, returns youngest revision
+	 * recover the filesystem backend of a repository
 	 * @param path              the path to the repository
+         * @return youngest revision
 	 * @throws ClientException  throw in case of problem
 	 */
 	public abstract long recover(File path, ReposNotifyCallback callback)
             throws ClientException;
 
 	/**
+	 * Take an exclusive lock on each of the listed repositories
+	 * to prevent commits; then, while holding all the locks, call
+	 * the action.invoke().
+	 *
+	 * The repositories may or may not be readable by Subversion
+	 * while frozen, depending on implementation details of the
+	 * repository's filesystem backend.
+	 *
+	 * Repositories are locked in the listed order.
+	 * @param action     describes the action to perform
+	 * @param paths	     the set of repository paths
+	 * @throws ClientException
+         * @since 1.8
+	 */
+	public abstract void freeze(ReposFreezeAction action,
+				    File... paths)
+	    throws ClientException;
+
+	/**
 	 * remove open transaction in a repository
 	 * @param path              the path to the repository
 	 * @param transactions      the transactions to be removed

Modified: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNRepos.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNRepos.java?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNRepos.java (original)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/SVNRepos.java Thu Mar 14 09:33:19 2013
@@ -29,6 +29,7 @@ import java.io.InputStream;
 import java.io.File;
 
 import org.apache.subversion.javahl.callback.ReposNotifyCallback;
+import org.apache.subversion.javahl.callback.ReposFreezeAction;
 import org.apache.subversion.javahl.types.*;
 
 /**
@@ -175,6 +176,9 @@ public class SVNRepos implements ISVNRep
     public native long recover(File path, ReposNotifyCallback callback)
             throws ClientException;
 
+    public native void freeze(ReposFreezeAction action, File... paths)
+            throws ClientException;
+
     /**
      * remove open transaction in a repository
      * @param path              the path to the repository

Added: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ReposFreezeAction.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ReposFreezeAction.java?rev=1456375&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ReposFreezeAction.java (added)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ReposFreezeAction.java Thu Mar 14 09:33:19 2013
@@ -0,0 +1,37 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+package org.apache.subversion.javahl.callback;
+
+/**
+ * This interface is used to desfine an action to take while
+ * repositories are frozen by {@link ISVNRepos.freeze}.
+ * @since 1.8
+ */
+public interface ReposFreezeAction
+{
+    /**
+     * The method will be called with frozen repositories
+     */
+    public void invoke();
+}

Modified: subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNReposTests.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNReposTests.java?rev=1456375&r1=1456374&r2=1456375&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNReposTests.java (original)
+++ subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNReposTests.java Thu Mar 14 09:33:19 2013
@@ -34,7 +34,7 @@ import java.net.URI;
 import java.util.Map;
 
 /**
- * This class is used for testing the SVNAdmin class
+ * This class is used for testing the ISVNRepos interface
  *
  * More methodes for testing are still needed
  */
@@ -50,7 +50,7 @@ public class SVNReposTests extends SVNTe
     }
 
     /**
-     * Test the basic SVNAdmin.create functionality
+     * Test the basic ISVNRepos.create functionality
      * @throws SubversionException
      */
     public void testCreate()
@@ -100,10 +100,26 @@ public class SVNReposTests extends SVNTe
         admin.pack(thisTest.getRepository(), null);
     }
 
+    /* Check that the freeze() callback gets invoked. */
+    private class FreezeAction implements ReposFreezeAction
+    {
+        int invoked = 0;
+        public void invoke() { ++invoked; }
+    }
+
+    public void testFreeze()
+        throws SubversionException, IOException
+    {
+        OneTest thisTest = new OneTest(false);
+        FreezeAction action = new FreezeAction();
+        admin.freeze(action, thisTest.getRepository());
+        assertEquals("expect freeze callback to be invoked once", 1, action.invoked);
+    }
+
     public void testLoadRepo()
         throws SubversionException, IOException
     {
-        /* Make sure SVNAdmin.load() works, with a repo dump file known
+        /* Make sure ISVNRepos.load() works, with a repo dump file known
          * to provoke bug 2979
          */
         // makes repos with nothing in it