subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1496861 - in /subversion/trunk/subversion/bindings/javahl: native/CommitEditor.cpp native/Iterator.cpp native/Iterator.h tests/org/apache/subversion/javahl/SVNRemoteTests.java
Date Wed, 26 Jun 2013 09:51:15 GMT
Author: brane
Date: Wed Jun 26 09:51:15 2013
New Revision: 1496861

URL: http://svn.apache.org/r1496861
Log:
Implement EV2 add_directory and alter_directory in the JavaHL commit editor.

[in subversion/bindings/javahl/native]
* Iterator.h, Iterator.cpp (Iterator, PersistentIterator): New helper classes
   that provide an interface to java.lang.Iterable.
* CommitEditor.cpp (build_children): Helper to build a directory children table.
  (CommitEditor::addDirectory, CommitEditor::alterDirectory): Implement.

[in subversion/bindings/javahl/tests/org/apache/subversion/javahl]
* SVNRemoteTests.java
  (SVNRemoteTests.testEditorMkdir,
   SVNRemoteTests.testEditorSetDirProps): New tests cases.

Added:
    subversion/trunk/subversion/bindings/javahl/native/Iterator.cpp
    subversion/trunk/subversion/bindings/javahl/native/Iterator.h
Modified:
    subversion/trunk/subversion/bindings/javahl/native/CommitEditor.cpp
    subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java

Modified: subversion/trunk/subversion/bindings/javahl/native/CommitEditor.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CommitEditor.cpp?rev=1496861&r1=1496860&r2=1496861&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CommitEditor.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CommitEditor.cpp Wed Jun 26 09:51:15
2013
@@ -26,10 +26,12 @@
 
 #include "EnumMapper.h"
 #include "CommitEditor.h"
+#include "Iterator.h"
 #include "LockTokenTable.h"
 #include "RevpropTable.h"
 #include "RemoteSession.h"
 
+#include <apr_tables.h>
 #include "private/svn_editor.h"
 #include "private/svn_ra_private.h"
 #include "svn_private_config.h"
@@ -160,6 +162,22 @@ void throw_not_implemented(const char* f
   msg += fname;
   throw_illegal_state(msg.c_str());
 }
+
+const apr_array_header_t*
+build_children(const Iterator& iter, SVN::Pool& pool)
+{
+  apr_pool_t* result_pool = pool.getPool();
+  apr_array_header_t* children = apr_array_make(
+      result_pool, 0, sizeof(const char*));
+  while (iter.hasNext())
+    {
+      JNIStringHolder path((jstring)iter.next());
+      if (JNIUtil::isJavaExceptionThrown())
+        return NULL;
+      APR_ARRAY_PUSH(children, const char*) = path.pstrdup(result_pool);
+    }
+  return children;
+}
 } // anonymous namespace
 
 
@@ -173,7 +191,22 @@ void CommitEditor::addDirectory(jstring 
       return;
     }
   SVN_JNI_ERR(m_session->m_context->checkCancel(m_session->m_context),);
-  throw_not_implemented("addDirectory");
+
+  JNIStringHolder relpath(jrelpath);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  Iterator children(jchildren);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  RevpropTable properties(jproperties, true);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+
+  SVN::Pool subPool(pool);
+  SVN_JNI_ERR(svn_editor_add_directory(m_editor, relpath,
+                                       build_children(children, subPool),
+                                       properties.hash(subPool, false),
+                                       svn_revnum_t(jreplaces_revision)),);
 }
 
 void CommitEditor::addFile(jstring jrelpath,
@@ -224,7 +257,22 @@ void CommitEditor::alterDirectory(jstrin
       return;
     }
   SVN_JNI_ERR(m_session->m_context->checkCancel(m_session->m_context),);
-  throw_not_implemented("alterDirectory");
+
+  JNIStringHolder relpath(jrelpath);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  Iterator children(jchildren);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  RevpropTable properties(jproperties, true);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+
+  SVN::Pool subPool(pool);
+  SVN_JNI_ERR(svn_editor_alter_directory(
+                  m_editor, relpath, svn_revnum_t(jrevision),
+                  (jchildren ? build_children(children, subPool) : NULL),
+                  properties.hash(subPool, false)),);
 }
 
 void CommitEditor::alterFile(jstring jrelpath, jlong jrevision,

Added: subversion/trunk/subversion/bindings/javahl/native/Iterator.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/Iterator.cpp?rev=1496861&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/Iterator.cpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/Iterator.cpp Wed Jun 26 09:51:15 2013
@@ -0,0 +1,115 @@
+/**
+ * @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 Iterator.cpp
+ * @brief Implementation of the class Iterator
+ */
+
+#include "Iterator.h"
+
+namespace {
+jobject init_iterator(jobject jiterable, bool persistent)
+{
+  // A null iterable is allowed, we'll leave the iterator null and
+  // nothing will happen in hasNext() and next().
+  if (!jiterable)
+    return NULL;
+
+  JNIEnv* env = JNIUtil::getEnv();
+
+  static jmethodID iterator_mid = 0;
+  if (0 == iterator_mid)
+    {
+      jclass cls = env->FindClass("java/lang/Iterable");
+      if (JNIUtil::isExceptionThrown())
+        return NULL;
+      iterator_mid = env->GetMethodID(cls, "iterator",
+                                      "()Ljava/util/Iterator;");
+      if (JNIUtil::isExceptionThrown())
+        return NULL;
+    }
+
+  jobject jiterator = env->CallObjectMethod(jiterable, iterator_mid);
+  if (JNIUtil::isExceptionThrown())
+    return NULL;
+  return (persistent ? env->NewGlobalRef(jiterator) : jiterator);
+}
+} // anonymous namespace
+
+
+Iterator::Iterator(jobject jiterable)
+  : m_persistent(false),
+    m_jiterator(init_iterator(jiterable, false))
+{}
+
+Iterator::Iterator(jobject jiterable, bool)
+  : m_persistent(true),
+    m_jiterator(init_iterator(jiterable, true))
+{}
+
+Iterator::~Iterator()
+{
+  if (m_persistent && m_jiterator)
+    JNIUtil::getEnv()->DeleteGlobalRef(m_jiterator);
+}
+
+bool Iterator::hasNext() const
+{
+  if (!m_jiterator)
+    return false;
+
+  JNIEnv* env = JNIUtil::getEnv();
+
+  static jmethodID hasNext_mid = 0;
+  if (0 == hasNext_mid)
+    {
+      jclass cls = env->FindClass("java/util/Iterator");
+      if (JNIUtil::isExceptionThrown())
+        return false;
+      hasNext_mid = env->GetMethodID(cls, "hasNext", "()Z");
+      if (JNIUtil::isExceptionThrown())
+        return false;
+    }
+
+  return bool(env->CallBooleanMethod(m_jiterator, hasNext_mid));
+}
+
+jobject Iterator::next() const
+{
+  if (!m_jiterator)
+    return NULL;
+
+  JNIEnv* env = JNIUtil::getEnv();
+
+  static jmethodID next_mid = 0;
+  if (0 == next_mid)
+    {
+      jclass cls = env->FindClass("java/util/Iterator");
+      if (JNIUtil::isExceptionThrown())
+        return NULL;
+      next_mid = env->GetMethodID(cls, "next", "()Ljava/lang/Object;");
+      if (JNIUtil::isExceptionThrown())
+        return NULL;
+    }
+
+  return env->CallObjectMethod(m_jiterator, next_mid);
+}

Added: subversion/trunk/subversion/bindings/javahl/native/Iterator.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/Iterator.h?rev=1496861&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/Iterator.h (added)
+++ subversion/trunk/subversion/bindings/javahl/native/Iterator.h Wed Jun 26 09:51:15 2013
@@ -0,0 +1,64 @@
+/**
+ * @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 Iterator.cpp
+ * @brief Interface of the class Iterator
+ */
+
+#ifndef JAVAHL_ITERATOR_H
+#define JAVAHL_ITERATOR_H
+
+#include "JNIUtil.h"
+
+/**
+ * Encapsulates an immutable java.lang.Iterator implementation.
+ */
+class Iterator
+{
+public:
+  Iterator(jobject jiterable);
+  ~Iterator();
+  bool hasNext() const;
+  jobject next() const;
+
+protected:
+  Iterator(jobject jiterable, bool);
+
+private:
+  bool m_persistent;
+  jobject m_jiterator;
+};
+
+
+/**
+ * Like Iterator, but the implementation will hold a global reference
+ * to the internal iterator object to protect it across JNI calls.
+ */
+class PersistentIterator : protected Iterator
+{
+public:
+  PersistentIterator(jobject jiterable) : Iterator(jiterable, true) {}
+  bool hasNext() const { return Iterator::hasNext(); }
+  jobject next() const { return Iterator::next(); }
+};
+
+#endif  // JAVAHL_ITERATOR_H

Modified: subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java?rev=1496861&r1=1496860&r2=1496861&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java
(original)
+++ subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java
Wed Jun 26 09:51:15 2013
@@ -28,6 +28,7 @@ import org.apache.subversion.javahl.call
 import org.apache.subversion.javahl.types.*;
 
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Set;
 import java.util.Map;
@@ -398,6 +399,7 @@ public class SVNRemoteTests extends SVNT
             new CommitContext(session, "Copy A/B/lambda -> A/B/omega");
 
         try {
+            // FIXME: alter dir A/B first
             cc.editor.copy("A/B/lambda", 1, "A/B/omega",
                            Revision.SVN_INVALID_REVNUM);
             cc.editor.complete();
@@ -432,6 +434,7 @@ public class SVNRemoteTests extends SVNT
                                "A/D/H/psi" };
 
         try {
+            // FIXME: alter a bunch of dirs first
             for (String path : filePaths)
                 cc.editor.delete(path, 1);
             cc.editor.complete();
@@ -445,4 +448,53 @@ public class SVNRemoteTests extends SVNT
             assertEquals(NodeKind.none,
                          session.checkPath(path, Revision.SVN_INVALID_REVNUM));
     }
+
+    public void testEditorMkdir() throws Exception
+    {
+        ISVNRemote session = getSession();
+        CommitContext cc = new CommitContext(session, "Make hebrew dir");
+
+        try {
+            // FIXME: alter dir . first
+            cc.editor.addDirectory("ALEPH",
+                                   new ArrayList<String>(),
+                                   new HashMap<String, byte[]>(),
+                                   Revision.SVN_INVALID_REVNUM);
+            cc.editor.complete();
+        } finally {
+            cc.editor.dispose();
+        }
+
+        assertEquals(2, cc.getRevision());
+        assertEquals(2, session.getLatestRevision());
+        assertEquals(NodeKind.dir,
+                     session.checkPath("ALEPH",
+                                       Revision.SVN_INVALID_REVNUM));
+    }
+
+    public void testEditorSetDirProps() throws Exception
+    {
+        Charset UTF8 = Charset.forName("UTF-8");
+        ISVNRemote session = getSession();
+        CommitContext cc = new CommitContext(session, "Add svn:ignore");
+
+        byte[] ignoreval = "*.pyc\n.gitignore\n".getBytes(UTF8);
+        HashMap<String, byte[]> props = new HashMap<String, byte[]>();
+        props.put("svn:ignore", ignoreval);
+
+        try {
+            cc.editor.alterDirectory("", 1, null, props);
+            cc.editor.complete();
+        } finally {
+            cc.editor.dispose();
+        }
+
+        assertEquals(2, cc.getRevision());
+        assertEquals(2, session.getLatestRevision());
+        assertTrue(Arrays.equals(ignoreval,
+                                 client.propertyGet(session.getSessionUrl(),
+                                                    "svn:ignore",
+                                                    Revision.HEAD,
+                                                    Revision.HEAD)));
+    }
 }



Mime
View raw message