3 * ====================================================================
4 * Copyright (c) 2003-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 * @file CommitMessage.cpp
19 * @brief Implementation of the class CommitMessage
22 #include "CommitMessage.h"
24 #include <apr_tables.h>
25 #include "svn_client.h"
26 #include "../include/org_tigris_subversion_javahl_CommitItemStateFlags.h"
28 CommitMessage::CommitMessage(jobject jcommitMessage
)
30 m_jcommitMessage
= jcommitMessage
;
33 CommitMessage::~CommitMessage()
35 // Since the m_jcommitMessage is a global reference, it has to be
36 // deleted to allow the Java garbage collector to reclaim the
38 if (m_jcommitMessage
!= NULL
)
40 JNIEnv
*env
= JNIUtil::getEnv();
41 env
->DeleteGlobalRef(m_jcommitMessage
);
45 CommitMessage
*CommitMessage::makeCCommitMessage(jobject jcommitMessage
)
47 // If there is no object passed into this method, there is no need
48 // for a C++ holding object.
49 if (jcommitMessage
== NULL
)
52 // Sanity check, that the passed Java object implements the right
54 JNIEnv
*env
= JNIUtil::getEnv();
55 jclass clazz
= env
->FindClass(JAVA_PACKAGE
"/CommitMessage");
56 if (JNIUtil::isJavaExceptionThrown())
59 if (!env
->IsInstanceOf(jcommitMessage
, clazz
))
61 env
->DeleteLocalRef(clazz
);
64 env
->DeleteLocalRef(clazz
);
65 if (JNIUtil::isJavaExceptionThrown())
68 // Since the reference is longer needed then the duration of the
69 // SVNClient.commtMessage, the local reference has to be converted
70 // to a global reference.
71 jobject myCommitMessage
= env
->NewGlobalRef(jcommitMessage
);
72 if (JNIUtil::isJavaExceptionThrown())
75 // create & return the holding object
76 return new CommitMessage(myCommitMessage
);
80 * Call the Java callback method to retrieve the commit message
81 * @param commit_items the array of the items of this commit
82 * @returns the commit message
85 CommitMessage::getCommitMessage(const apr_array_header_t
*commit_items
)
87 JNIEnv
*env
= JNIUtil::getEnv();
88 // create an Java array for the commit items
89 jclass clazz
= env
->FindClass(JAVA_PACKAGE
"/CommitItem");
90 if (JNIUtil::isExceptionThrown())
93 int count
= commit_items
->nelts
;
94 jobjectArray jitems
= env
->NewObjectArray(count
, clazz
, NULL
);
95 if (JNIUtil::isExceptionThrown())
98 // Java method ids will not change during the time this library is
99 // loaded, so they can be cached.
101 // Get the method id for the CommitItem constructor.
102 static jmethodID midConstructor
= 0;
103 if (midConstructor
== 0)
105 midConstructor
= env
->GetMethodID(clazz
, "<init>",
106 "(Ljava/lang/String;"
107 "IILjava/lang/String;"
108 "Ljava/lang/String;J)V");
109 if (JNIUtil::isExceptionThrown())
113 // get the method if for the CommitMessage callback method
114 static jmethodID midCallback
= 0;
115 if (midCallback
== 0)
117 jclass clazz2
= env
->FindClass(JAVA_PACKAGE
"/CommitMessage");
118 if (JNIUtil::isJavaExceptionThrown())
121 midCallback
= env
->GetMethodID(clazz2
, "getLogMessage",
122 "([L"JAVA_PACKAGE
"/CommitItem;)"
123 "Ljava/lang/String;");
124 if (JNIUtil::isJavaExceptionThrown())
127 env
->DeleteLocalRef(clazz2
);
128 if (JNIUtil::isJavaExceptionThrown())
132 // create a Java CommitItem for each of the passed in commit items
133 for (int i
= 0; i
< count
; ++i
)
135 svn_client_commit_item3_t
*item
=
136 APR_ARRAY_IDX(commit_items
, i
, svn_client_commit_item3_t
*);
138 // convert the commit item members to the match Java members
139 jstring jpath
= JNIUtil::makeJString(item
->path
);
141 jint jnodeKind
= item
->kind
;
143 jint jstateFlags
= 0;
144 if (item
->state_flags
& SVN_CLIENT_COMMIT_ITEM_ADD
)
146 org_tigris_subversion_javahl_CommitItemStateFlags_Add
;
147 if (item
->state_flags
& SVN_CLIENT_COMMIT_ITEM_DELETE
)
149 org_tigris_subversion_javahl_CommitItemStateFlags_Delete
;
150 if (item
->state_flags
& SVN_CLIENT_COMMIT_ITEM_TEXT_MODS
)
152 org_tigris_subversion_javahl_CommitItemStateFlags_TextMods
;
153 if (item
->state_flags
& SVN_CLIENT_COMMIT_ITEM_PROP_MODS
)
155 org_tigris_subversion_javahl_CommitItemStateFlags_PropMods
;
156 if (item
->state_flags
& SVN_CLIENT_COMMIT_ITEM_IS_COPY
)
158 org_tigris_subversion_javahl_CommitItemStateFlags_IsCopy
;
160 jstring jurl
= JNIUtil::makeJString(item
->url
);
162 jstring jcopyUrl
= JNIUtil::makeJString(item
->copyfrom_url
);
164 jlong jcopyRevision
= item
->revision
;
166 // create the Java object
167 jobject jitem
= env
->NewObject(clazz
, midConstructor
, jpath
,
168 jnodeKind
, jstateFlags
, jurl
,
169 jcopyUrl
, jcopyRevision
);
170 if (JNIUtil::isJavaExceptionThrown())
173 // release the tempory Java objects
174 env
->DeleteLocalRef(jpath
);
175 if (JNIUtil::isJavaExceptionThrown())
179 env
->DeleteLocalRef(jurl
);
180 if (JNIUtil::isJavaExceptionThrown())
183 env
->DeleteLocalRef(jcopyUrl
);
184 if (JNIUtil::isJavaExceptionThrown())
187 // store the Java object into the array
188 env
->SetObjectArrayElement(jitems
, i
, jitem
);
189 if (JNIUtil::isJavaExceptionThrown())
192 env
->DeleteLocalRef(clazz
);
193 if (JNIUtil::isJavaExceptionThrown())
196 // call the Java callback method
197 jstring jmessage
= (jstring
)env
->CallObjectMethod(m_jcommitMessage
,
200 if (JNIUtil::isJavaExceptionThrown())
203 // release the Java object array
204 env
->DeleteLocalRef(jitems
);
205 if (JNIUtil::isJavaExceptionThrown())