svn_error_t * BlameCallback::setRange() { if (m_start_revnum == SVN_INVALID_REVNUM || m_end_revnum == SVN_INVALID_REVNUM) return svn_error_create(SVN_ERR_CLIENT_BAD_REVISION, NULL, _("Blame revision range was not resolved")); JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; // The method id will not change during the time this library is // loaded, so it can be cached. static jmethodID mid = 0; if (mid == 0) { jclass clazz = env->FindClass(JAVAHL_CLASS("/callback/BlameRangeCallback")); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); mid = env->GetMethodID(clazz, "setRange", "(JJ)V"); if (JNIUtil::isJavaExceptionThrown() || mid == 0) POP_AND_RETURN(SVN_NO_ERROR); } // call the Java method env->CallVoidMethod(m_range_callback, mid, (jlong)m_start_revnum, (jlong)m_end_revnum); POP_AND_RETURN_EXCEPTION_AS_SVNERROR(); }
svn_error_t * ClientContext::resolve(svn_wc_conflict_result_t **result, const svn_wc_conflict_description2_t *desc, void *baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { jobject jctx = (jobject) baton; JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; static jmethodID mid = 0; if (mid == 0) { jclass clazz = env->GetObjectClass(jctx); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); mid = env->GetMethodID(clazz, "resolve", "(" JAVAHL_ARG("/ConflictDescriptor;") ")" JAVAHL_ARG("/ConflictResult;")); if (JNIUtil::isJavaExceptionThrown() || mid == 0) POP_AND_RETURN(SVN_NO_ERROR); } // Create an instance of the conflict descriptor. jobject jdesc = CreateJ::ConflictDescriptor(desc); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); // Invoke the Java conflict resolver callback method using the descriptor. jobject jresult = env->CallObjectMethod(jctx, mid, jdesc); if (JNIUtil::isJavaExceptionThrown()) { // If an exception is thrown by our conflict resolver, remove it // from the JNI env, and convert it into a Subversion error. SVN::Pool tmpPool(scratch_pool); const char *msg = JNIUtil::thrownExceptionToCString(tmpPool); svn_error_t *err = svn_error_create(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL, msg); env->PopLocalFrame(NULL); return err; } *result = javaResultToC(jresult, result_pool); if (*result == NULL) { // Unable to convert the result into a C representation. env->PopLocalFrame(NULL); return svn_error_create(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL, NULL); } env->PopLocalFrame(NULL); return SVN_NO_ERROR; }
/** * Callback called for a single status item. */ svn_error_t * StatusCallback::doStatus(const char *local_abspath, const svn_client_status_t *status, apr_pool_t *pool) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; static jmethodID mid = 0; // the method id will not change during // the time this library is loaded, so // it can be cached. if (mid == 0) { jclass clazz = env->FindClass(JAVAHL_CLASS("/callback/StatusCallback")); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); mid = env->GetMethodID(clazz, "doStatus", "(Ljava/lang/String;" JAVAHL_ARG("/types/Status;") ")V"); if (JNIUtil::isJavaExceptionThrown() || mid == 0) POP_AND_RETURN(SVN_NO_ERROR); } jstring jPath = JNIUtil::makeJString(local_abspath); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jobject jStatus = CreateJ::Status(wc_ctx, status, pool); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); env->CallVoidMethod(m_callback, mid, jPath, jStatus); POP_AND_RETURN_EXCEPTION_AS_SVNERROR(); }
/** * Callback called for a single line in the file, for which the blame * information was requested. See the Java-doc for more information. */ svn_error_t * BlameCallback::singleLine(apr_int64_t line_no, svn_revnum_t revision, apr_hash_t *revProps, svn_revnum_t mergedRevision, apr_hash_t *mergedRevProps, const char *mergedPath, const svn_string_t *line, svn_boolean_t localChange, apr_pool_t *pool) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; // The method id will not change during the time this library is // loaded, so it can be cached. static jmethodID mid = 0; if (mid == 0) { jclass clazz = env->FindClass(JAVAHL_CLASS("/callback/BlameLineCallback")); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); mid = env->GetMethodID(clazz, "singleLine", "(JJLjava/util/Map;JLjava/util/Map;" "Ljava/lang/String;Z[B)V"); if (JNIUtil::isJavaExceptionThrown() || mid == 0) POP_AND_RETURN(SVN_NO_ERROR); } // convert the parameters to their Java relatives jobject jrevProps = CreateJ::PropertyMap(revProps, pool); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jobject jmergedRevProps = NULL; if (mergedRevProps != NULL) { jmergedRevProps = CreateJ::PropertyMap(mergedRevProps, pool); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); } jstring jmergedPath = JNIUtil::makeJString(mergedPath); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jbyteArray jline = JNIUtil::makeJByteArray(line); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); // call the Java method env->CallVoidMethod(m_line_callback, mid, (jlong)line_no, (jlong)revision, jrevProps, (jlong)mergedRevision, jmergedRevProps, jmergedPath, (jboolean)localChange, jline); POP_AND_RETURN_EXCEPTION_AS_SVNERROR(); }
int EnumMapper::getOrdinal(const char *clazzName, jobject jenum) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return -1; jclass clazz = env->FindClass(clazzName); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(-1); jmethodID mid = env->GetMethodID(clazz, "ordinal", "()I"); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(-1); jint jorder = env->CallIntMethod(jenum, mid); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(-1); env->PopLocalFrame(NULL); return static_cast<int>(jorder); }
svn_error_t * PatchCallback::singlePatch(svn_boolean_t *filtered, const char *canon_path_from_patchfile, const char *patch_abspath, const char *reject_abspath, apr_pool_t *pool) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; // The method id will not change during the time this library is // loaded, so it can be cached. static jmethodID mid = 0; if (mid == 0) { jclass clazz = env->FindClass(JAVA_PACKAGE"/callback/PatchCallback"); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); mid = env->GetMethodID(clazz, "singlePatch", "(Ljava/lang/String;Ljava/lang/String;" "Ljava/lang/String;)Z"); if (JNIUtil::isJavaExceptionThrown() || mid == 0) POP_AND_RETURN(SVN_NO_ERROR); } jstring jcanonPath = JNIUtil::makeJString(canon_path_from_patchfile); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jstring jpatchAbsPath = JNIUtil::makeJString(patch_abspath); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jstring jrejectAbsPath = JNIUtil::makeJString(reject_abspath); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jboolean jfiltered = env->CallBooleanMethod(m_callback, mid, jcanonPath, jpatchAbsPath, jrejectAbsPath); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); *filtered = (jfiltered ? TRUE : FALSE); env->PopLocalFrame(NULL); return SVN_NO_ERROR; }
svn_error_t * DiffSummaryReceiver::onSummary(const svn_client_diff_summarize_t *diff, apr_pool_t *pool) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; // As Java method IDs will not change during the time this library // is loaded, they can be cached. static jmethodID callback = 0; jclass clazz; if (callback == 0) { // Initialize the method ID. clazz = env->FindClass(JAVAHL_CLASS("/callback/DiffSummaryCallback")); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); callback = env->GetMethodID(clazz, "onSummary", "(" JAVAHL_ARG("/DiffSummary;") ")V"); if (JNIUtil::isJavaExceptionThrown() || callback == 0) POP_AND_RETURN(SVN_NO_ERROR); } // Do some prep work for tranforming the DIFF parameter into a // Java equivalent. static jmethodID ctor = 0; clazz = env->FindClass(JAVAHL_CLASS("/DiffSummary")); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); if (ctor == 0) { ctor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;" JAVAHL_ARG("/DiffSummary$DiffKind;") "Z" JAVAHL_ARG("/types/NodeKind;") ")V"); if (JNIUtil::isJavaExceptionThrown() || ctor == 0) POP_AND_RETURN(SVN_NO_ERROR); } // Convert the arguments into their Java equivalent, jstring jPath = JNIUtil::makeJString(diff->path); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jobject jNodeKind = EnumMapper::mapNodeKind(diff->node_kind); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); jobject jSummarizeKind = EnumMapper::mapSummarizeKind(diff->summarize_kind); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); // Actually tranform the DIFF parameter into a Java equivalent. jobject jDiffSummary = env->NewObject(clazz, ctor, jPath, jSummarizeKind, (jboolean) diff->prop_changed, jNodeKind); if (JNIUtil::isJavaExceptionThrown() || jDiffSummary == NULL) POP_AND_RETURN(SVN_NO_ERROR); // Invoke the Java DiffSummaryReceiver callback. env->CallVoidMethod(m_receiver, callback, jDiffSummary); POP_AND_RETURN_EXCEPTION_AS_SVNERROR(); }
/** * Callback called for a single log message */ svn_error_t * LogMessageCallback::singleMessage(svn_log_entry_t *log_entry, apr_pool_t *pool) { JNIEnv *env = JNIUtil::getEnv(); // Create a local frame for our references env->PushLocalFrame(LOCAL_FRAME_SIZE); if (JNIUtil::isJavaExceptionThrown()) return SVN_NO_ERROR; // The method id will not change during the time this library is // loaded, so it can be cached. static jmethodID sm_mid = 0; if (sm_mid == 0) { jclass clazz = env->FindClass(JAVA_PACKAGE"/callback/LogMessageCallback"); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); sm_mid = env->GetMethodID(clazz, "singleMessage", "(Ljava/util/Set;JLjava/util/Map;Z)V"); if (JNIUtil::isJavaExceptionThrown()) POP_AND_RETURN(SVN_NO_ERROR); } jobject jChangedPaths = NULL; if (log_entry->changed_paths) { apr_hash_index_t *hi; std::vector<jobject> jcps; for (hi = apr_hash_first(pool, log_entry->changed_paths); hi; hi = apr_hash_next(hi)) { const char *path = (const char *) svn__apr_hash_index_key(hi); svn_log_changed_path2_t *log_item = (svn_log_changed_path2_t *) svn__apr_hash_index_val(hi); jobject cp = CreateJ::ChangedPath(path, log_item); jcps.push_back(cp); } jChangedPaths = CreateJ::Set(jcps); } jobject jrevprops = NULL; if (log_entry->revprops != NULL && apr_hash_count(log_entry->revprops) > 0) jrevprops = CreateJ::PropertyMap(log_entry->revprops); env->CallVoidMethod(m_callback, sm_mid, jChangedPaths, (jlong)log_entry->revision, jrevprops, (jboolean)log_entry->has_children); // No need to check for an exception here, because we return anyway. env->PopLocalFrame(NULL); return SVN_NO_ERROR; }