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 2014/01/04 07:05:28 UTC

svn commit: r1555324 - in /subversion/trunk/subversion/bindings/javahl: native/EditorProxy.cpp src/org/apache/subversion/javahl/ISVNEditor.java tests/org/apache/subversion/javahl/SVNRemoteTests.java

Author: brane
Date: Sat Jan  4 06:05:28 2014
New Revision: 1555324

URL: http://svn.apache.org/r1555324
Log:
Fixed an omission in JavaHL's status/update editor proxy: the file contents
stream was not being properly wrapped into Java.

[in subversion/bindings/javahl]
* src/org/apache/subversion/javahl/ISVNEditor.java
  (ISVNEditor.addFile, ISVNEditor.alterFile): Update docstring with a note
   that the contents stream's lifetime does not extend beyond the lifetime
   of the function invocation.

* native/EditorProxy.cpp (wrap_input_stream): New helper function.
   Uses jniwrapper's new-style native-to-java InputStream mapper.
  (EditorProxy::cb_add_file, EditorProxy::cb_alter_file):
   Wrap the contents stream so that the Java editor implementatino can use it.

* tests/org/apache/subversion/javahl/SVNRemoteTests.java
  (SVNRemoteTests.testTextchangeStatus): New test case.
  (SVNRemoteTests.testPropchangeStatus): Annotate the assertions.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/EditorProxy.cpp
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
    subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/SVNRemoteTests.java

Modified: subversion/trunk/subversion/bindings/javahl/native/EditorProxy.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/EditorProxy.cpp?rev=1555324&r1=1555323&r2=1555324&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/EditorProxy.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/EditorProxy.cpp Sat Jan  4 06:05:28 2014
@@ -34,6 +34,11 @@
 #include "svn_error.h"
 #include "svn_private_config.h"
 
+// Newstyle: stream wrapper
+#include <memory>
+#include "NativeStream.hpp"
+#include "jniwrapper/jni_stack.hpp"
+
 
 EditorProxy::EditorProxy(jobject jeditor, apr_pool_t* edit_pool,
                          const char* repos_root_url, const char* base_relpath,
@@ -125,6 +130,17 @@ get_editor_method(jmethodID& mid, const 
                  SVN_ERR_RA_SVN_EDIT_ABORTED);
   return SVN_NO_ERROR;
 }
+
+jobject wrap_input_stream(svn_stream_t* stream)
+{
+  std::auto_ptr<JavaHL::NativeInputStream>
+    wrapped(new JavaHL::NativeInputStream());
+  apr_pool_t* const wrapped_pool = wrapped->get_pool().getPool();
+  wrapped->set_stream(svn_stream_disown(stream, wrapped_pool));
+  const jobject jstream = wrapped->create_java_wrapper();
+  wrapped.release();
+  return jstream;
+}
 } // anonymous namespace
 
 svn_error_t*
@@ -188,11 +204,15 @@ EditorProxy::cb_add_file(void *baton,
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
   jobject jchecksum = CreateJ::Checksum(checksum);
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
-  jobject jcontents = NULL;     // FIXME: input stream proxy
+  jobject jcontents = NULL;
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
   jobject jprops = CreateJ::PropertyMap(props, scratch_pool);
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
 
+  if (contents != NULL)
+    SVN_JAVAHL_CATCH(Java::Env(), SVN_ERR_RA_SVN_EDIT_ABORTED,
+                     jcontents = wrap_input_stream(contents));
+
   SVN_JNI_CATCH(
       JNIUtil::getEnv()->CallVoidMethod(ep->m_jeditor, mid,
                                         jrelpath, jchecksum, jcontents,
@@ -331,11 +351,15 @@ EditorProxy::cb_alter_file(void *baton,
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
   jobject jchecksum = CreateJ::Checksum(checksum);
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
-  jobject jcontents = NULL;     // FIXME: input stream proxy
+  jobject jcontents = NULL;
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
   jobject jprops = CreateJ::PropertyMap(props, scratch_pool);
   SVN_JNI_CATCH(,SVN_ERR_RA_SVN_EDIT_ABORTED);
 
+  if (contents != NULL)
+    SVN_JAVAHL_CATCH(Java::Env(), SVN_ERR_RA_SVN_EDIT_ABORTED,
+                     jcontents = wrap_input_stream(contents));
+
   SVN_JNI_CATCH(
       JNIUtil::getEnv()->CallVoidMethod(ep->m_jeditor, mid,
                                         jrelpath, jlong(revision),

Modified: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java?rev=1555324&r1=1555323&r2=1555324&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java (original)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java Sat Jan  4 06:05:28 2014
@@ -89,6 +89,9 @@ public interface ISVNEditor
      * <b>Note:</b> It is not allowed to call a "delete" followed by
      * an "add" on the same path. Instead, an "add" with
      * <code>replacesRevision</code> set accordingly <em>must</em> be used.
+     * <p>
+     * <b>Note:</b> The <code>contents</code> stream's lifetime must not
+     *      extend beyond the scope of this function.
      *
      * @throws ClientException
      */
@@ -185,6 +188,9 @@ public interface ISVNEditor
      * This function allows <code>properties</code> to be
      * <code>null</code>, but the parameter is otherwise described by
      * #addFile().
+     * <p>
+     * <b>Note:</b> The <code>contents</code> stream's lifetime must not
+     *      extend beyond the scope of this function.
      *
      * @throws ClientException
      */

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=1555324&r1=1555323&r2=1555324&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 Sat Jan  4 06:05:28 2014
@@ -38,7 +38,9 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.security.MessageDigest;
@@ -1141,6 +1143,46 @@ public class SVNRemoteTests extends SVNT
         assertEquals(21, receiver.status.size());
     }
 
+    public void testTextchangeStatus() throws Exception
+    {
+        ISVNRemote session = getSession();
+
+        CommitMessageCallback cmcb = new CommitMessageCallback() {
+                public String getLogMessage(Set<CommitItem> x) {
+                    return "Content change on A/B/E/alpha";
+                }
+            };
+
+        File alpha = new File(thisTest.getWorkingCopy(), "A/B/E/alpha");
+        FileOutputStream writer = new FileOutputStream(alpha);
+        writer.write("changed alpha text".getBytes());
+        writer.close();
+        client.commit(thisTest.getWCPathSet(), Depth.infinity, false, false,
+                      null, null, cmcb, null);
+
+        RemoteStatusReceiver receiver = new RemoteStatusReceiver();
+        ISVNReporter rp = session.status(null, Revision.SVN_INVALID_REVNUM,
+                                         Depth.infinity, receiver);
+        try {
+            rp.setPath("", 1, Depth.infinity, false, null);
+            assertEquals(2, rp.finishReport());
+        } finally {
+            rp.dispose();
+        }
+
+        assertEquals(5, receiver.status.size());
+
+        // ra_serf returns the entries in inverted order compared to ra_local.
+        Collections.sort(receiver.status);
+        RemoteStatusReceiver.StatInfo mod = receiver.status.get(4);
+        assertEquals("A/B/E/alpha", mod.relpath);
+        assertEquals('F', mod.kind);
+        assertEquals("Text Changed", true, mod.textChanged);
+        assertEquals("Props Changed", false, mod.propsChanged);
+        assertEquals("Node Deleted", false, mod.deleted);
+        assertEquals(2, mod.info.getCommittedRevision());
+    }
+
     public void testPropchangeStatus() throws Exception
     {
         ISVNRemote session = getSession();
@@ -1171,9 +1213,9 @@ public class SVNRemoteTests extends SVNT
         RemoteStatusReceiver.StatInfo mod = receiver.status.get(3);
         assertEquals("A/D/gamma", mod.relpath);
         assertEquals('F', mod.kind);
-        assertEquals(false, mod.textChanged);
-        assertEquals(true, mod.propsChanged);
-        assertEquals(false, mod.deleted);
+        assertEquals("TextChanged", false, mod.textChanged);
+        assertEquals("Props Changed", true, mod.propsChanged);
+        assertEquals("Node Deleted", false, mod.deleted);
         assertEquals(2, mod.info.getCommittedRevision());
     }