3 * ====================================================================
4 * Copyright (c) 2003-2007 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 BlameCallback.cpp
19 * @brief Implementation of the class BlameCallback
22 #include "BlameCallback.h"
26 * Create a BlameCallback object
27 * @param jcallback the Java callback object.
29 BlameCallback::BlameCallback(jobject jcallback
)
31 m_callback
= jcallback
;
34 * Destroy a BlameCallback object
36 BlameCallback::~BlameCallback()
38 // the m_callback does not need to be destroyed, because it is the passed
39 // in parameter to the Java SVNClient.blame method.
43 BlameCallback::callback(void *baton
,
45 svn_revnum_t revision
,
48 svn_revnum_t merged_revision
,
49 const char *merged_author
,
50 const char *merged_date
,
51 const char *merged_path
,
56 return ((BlameCallback
*)baton
)->singleLine(revision
, author
, date
,
57 merged_revision
, merged_author
,
58 merged_date
, merged_path
, line
,
65 * Callback called for a single line in the file, for which the blame
66 * information was requested
67 * @param revision the revision number, when the line was last changed
68 * or -1, if not changed during the request revision
70 * @param author the author, who performed the last change of the line
71 * @param date the date of the last change of the line
72 * @param line the content of the line
73 * @param pool memory pool for the use of this function
76 BlameCallback::singleLine(svn_revnum_t revision
, const char *author
,
77 const char *date
, svn_revnum_t mergedRevision
,
78 const char *mergedAuthor
, const char *mergedDate
,
79 const char *mergedPath
, const char *line
,
82 JNIEnv
*env
= JNIUtil::getEnv();
84 // The method id will not change during the time this library is
85 // loaded, so it can be cached.
86 static jmethodID mid
= 0;
89 jclass clazz
= env
->FindClass(JAVA_PACKAGE
"/BlameCallback2");
90 if (JNIUtil::isJavaExceptionThrown())
93 mid
= env
->GetMethodID(clazz
, "singleLine",
94 "(Ljava/util/Date;JLjava/lang/String;"
95 "Ljava/util/Date;JLjava/lang/String;"
96 "Ljava/lang/String;Ljava/lang/String;)V");
97 if (JNIUtil::isJavaExceptionThrown() || mid
== 0)
100 env
->DeleteLocalRef(clazz
);
101 if (JNIUtil::isJavaExceptionThrown())
105 // convert the parameters to their Java relatives
106 jstring jauthor
= JNIUtil::makeJString(author
);
107 if (JNIUtil::isJavaExceptionThrown())
110 jobject jdate
= NULL
;
111 if (date
!= NULL
&& *date
!= '\0')
114 svn_error_t
*err
= svn_time_from_cstring(&timeTemp
, date
, pool
);
115 if (err
!= SVN_NO_ERROR
)
118 jdate
= JNIUtil::createDate(timeTemp
);
119 if (JNIUtil::isJavaExceptionThrown())
123 jstring jmergedAuthor
= JNIUtil::makeJString(mergedAuthor
);
124 if (JNIUtil::isJavaExceptionThrown())
127 jobject jmergedDate
= NULL
;
128 if (mergedDate
!= NULL
&& *mergedDate
!= '\0')
131 svn_error_t
*err
= svn_time_from_cstring(&timeTemp
, mergedDate
, pool
);
132 if (err
!= SVN_NO_ERROR
)
135 jmergedDate
= JNIUtil::createDate(timeTemp
);
136 if (JNIUtil::isJavaExceptionThrown())
140 jstring jmergedPath
= JNIUtil::makeJString(mergedPath
);
141 if (JNIUtil::isJavaExceptionThrown())
144 jstring jline
= JNIUtil::makeJString(line
);
145 if (JNIUtil::isJavaExceptionThrown())
148 // call the Java method
149 env
->CallVoidMethod(m_callback
, mid
, jdate
, (jlong
)revision
, jauthor
,
150 jmergedDate
, (jlong
)mergedRevision
, jmergedAuthor
,
152 if (JNIUtil::isJavaExceptionThrown())
155 // cleanup the temporary Java objects
156 env
->DeleteLocalRef(jauthor
);
157 if (JNIUtil::isJavaExceptionThrown())
160 env
->DeleteLocalRef(jdate
);
161 if (JNIUtil::isJavaExceptionThrown())
164 env
->DeleteLocalRef(jmergedAuthor
);
165 if (JNIUtil::isJavaExceptionThrown())
168 env
->DeleteLocalRef(jmergedDate
);
169 if (JNIUtil::isJavaExceptionThrown())
172 env
->DeleteLocalRef(jmergedPath
);
173 if (JNIUtil::isJavaExceptionThrown())
176 env
->DeleteLocalRef(jline
);
177 // No need to check for an exception here, because we return anyway.