1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file CommitEditor.h
24  * @brief Interface of the class CommitEditor
25  */
26 
27 #ifndef JAVAHL_COMMIT_EDITOR_H
28 #define JAVAHL_COMMIT_EDITOR_H
29 
30 #include <string>
31 #include <jni.h>
32 
33 #include "svn_ra.h"
34 
35 #include "JNIUtil.h"
36 #include "SVNBase.h"
37 #include "CommitCallback.h"
38 
39 #include "jniwrapper/jni_globalref.hpp"
40 
41 class RemoteSession;
42 
43 // Forward-declare the currently private EV2 editor struct.
44 struct svn_editor_t;
45 
46 /*
47  * This class wraps an EV2 commit editor.
48  */
49 class CommitEditor : public SVNBase
50 {
51 public:
52   static CommitEditor* getCppObject(jobject jthis);
53   static jlong createInstance(jobject jsession,
54                               jobject jrevprops,
55                               jobject jcommit_callback,
56                               jobject jlock_tokens,
57                               jboolean jkeep_locks,
58                               jobject jget_base_cb,
59                               jobject jget_props_cb,
60                               jobject jget_kind_cb);
61   virtual ~CommitEditor();
62 
63   virtual void dispose(jobject jthis);
64 
65   void addDirectory(jstring jrelpath,
66                     jobject jchildren, jobject jproperties,
67                     jlong jreplaces_revision);
68   void addFile(jstring jrelpath,
69                jobject jchecksum, jobject jcontents,
70                jobject jproperties,
71                jlong jreplaces_revision);
72   void addSymlink(jstring jrelpath,
73                   jstring jtarget, jobject jproperties,
74                   jlong jreplaces_revision);
75   void addAbsent(jstring jrelpath,
76                  jobject jkind, jlong jreplaces_revision);
77   void alterDirectory(jstring jrelpath, jlong jrevision,
78                       jobject jchildren, jobject jproperties);
79   void alterFile(jstring jrelpath, jlong jrevision,
80                  jobject jchecksum, jobject jcontents,
81                  jobject jproperties);
82   void alterSymlink(jstring jrelpath, jlong jrevision,
83                     jstring jtarget, jobject jproperties);
84   void remove(jstring jrelpath, jlong jrevision);
85   void copy(jstring jsrc_relpath, jlong jsrc_revision,
86             jstring jdst_relpath, jlong jreplaces_revision);
87   void move(jstring jsrc_relpath, jlong jsrc_revision,
88             jstring jdst_relpath, jlong jreplaces_revision);
89   void complete();
90   void abort();
91 
92 private:
93   CommitEditor(RemoteSession* session,
94                jobject jrevprops, jobject jcommit_callback,
95                jobject jlock_tokens, jboolean jkeep_locks,
96                jobject jget_base_cb, jobject jget_props_cb,
97                jobject jget_kind_cb);
98 
99   // This is our private callbacks for the commit editor.
100   static svn_error_t* provide_base_cb(svn_stream_t **contents,
101                                       svn_revnum_t *revision,
102                                       void *baton,
103                                       const char *repos_relpath,
104                                       apr_pool_t *result_pool,
105                                       apr_pool_t *scratch_pool);
106   static svn_error_t* provide_props_cb(apr_hash_t **props,
107                                        svn_revnum_t *revision,
108                                        void *baton,
109                                        const char *repos_relpath,
110                                        apr_pool_t *result_pool,
111                                        apr_pool_t *scratch_pool);
112   static svn_error_t* get_copysrc_kind_cb(svn_node_kind_t* kind, void* baton,
113                                           const char* repos_relpath,
114                                           svn_revnum_t src_revision,
115                                           apr_pool_t *scratch_pool);
116 
117   bool m_valid;
118   PersistentCommitCallback m_callback;
119   RemoteSession* m_session;
120   svn_editor_t* m_editor;
121 
122   Java::GlobalObject m_get_base_cb;
123   Java::GlobalObject m_get_props_cb;
124   Java::GlobalObject m_get_kind_cb;
125 
126   // Temporary, while EV2 shims are in place
127   svn_ra_session_t* m_callback_session;
128   const char* m_callback_session_url;
129   const char* m_callback_session_uuid;
130 };
131 
132 #endif // JAVAHL_COMMIT_EDITOR_H
133