3 * ====================================================================
4 * Copyright (c) 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 CopySources.cpp
19 * @brief Implementation of the class CopySources
22 #include <apr_pools.h>
23 #include "svn_client.h"
27 #include "JNIStringHolder.h"
29 #include "CopySources.h"
31 CopySources::CopySources(jobjectArray jcopySources
)
33 m_copySources
= jcopySources
;
36 CopySources::~CopySources()
38 // m_copySources does not need to be destroyed, because it is a
39 // parameter to the Java SVNClient.copy() method, and thus not
40 // explicitly managed.
44 CopySources::makeJCopySource(const char *path
, svn_revnum_t rev
, Pool
&pool
)
46 JNIEnv
*env
= JNIUtil::getEnv();
48 jobject jpath
= JNIUtil::makeJString(path
);
49 if (JNIUtil::isJavaExceptionThrown())
52 jobject jrevision
= Revision::makeJRevision(rev
);
53 if (JNIUtil::isJavaExceptionThrown())
56 jclass clazz
= env
->FindClass(JAVA_PACKAGE
"/CopySource");
57 if (JNIUtil::isJavaExceptionThrown())
60 static jmethodID ctor
= 0;
63 ctor
= env
->GetMethodID(clazz
, "<init>",
65 "L" JAVA_PACKAGE
"/Revision;"
66 "L" JAVA_PACKAGE
"/Revision;)V");
67 if (JNIUtil::isExceptionThrown())
71 jobject jcopySource
= env
->NewObject(clazz
, ctor
, jpath
, jrevision
, NULL
);
72 if (JNIUtil::isJavaExceptionThrown())
75 env
->DeleteLocalRef(jpath
);
76 if (JNIUtil::isJavaExceptionThrown())
79 env
->DeleteLocalRef(jrevision
);
80 if (JNIUtil::isJavaExceptionThrown())
87 CopySources::array(Pool
&pool
)
89 apr_pool_t
*p
= pool
.pool();
90 if (m_copySources
== NULL
)
91 return apr_array_make(p
, 0, sizeof(svn_client_copy_source_t
*));
93 JNIEnv
*env
= JNIUtil::getEnv();
94 jint nbrSources
= env
->GetArrayLength(m_copySources
);
95 if (JNIUtil::isJavaExceptionThrown())
98 jclass clazz
= env
->FindClass(JAVA_PACKAGE
"/CopySource");
99 if (JNIUtil::isJavaExceptionThrown())
102 apr_array_header_t
*copySources
=
103 apr_array_make(p
, nbrSources
, sizeof(svn_client_copy_source_t
*));
104 for (int i
= 0; i
< nbrSources
; ++i
)
106 jobject copySource
= env
->GetObjectArrayElement(m_copySources
, i
);
107 if (JNIUtil::isJavaExceptionThrown())
110 if (env
->IsInstanceOf(copySource
, clazz
))
112 svn_client_copy_source_t
*src
=
113 (svn_client_copy_source_t
*) apr_palloc(p
, sizeof(*src
));
115 // Extract the path or URL from the copy source.
116 static jmethodID getPath
= 0;
119 getPath
= env
->GetMethodID(clazz
, "getPath",
120 "()Ljava/lang/String;");
121 if (JNIUtil::isJavaExceptionThrown() || getPath
== 0)
124 jstring jpath
= (jstring
)
125 env
->CallObjectMethod(copySource
, getPath
);
126 if (JNIUtil::isJavaExceptionThrown())
129 JNIStringHolder
path(jpath
);
130 if (JNIUtil::isJavaExceptionThrown())
133 src
->path
= apr_pstrdup(p
, (const char *) path
);
134 SVN_JNI_ERR(JNIUtil::preprocessPath(src
->path
, pool
.pool()),
136 env
->DeleteLocalRef(jpath
);
137 if (JNIUtil::isJavaExceptionThrown())
140 // Extract source revision from the copy source.
141 static jmethodID getRevision
= 0;
142 if (getRevision
== 0)
144 getRevision
= env
->GetMethodID(clazz
, "getRevision",
145 "()L"JAVA_PACKAGE
"/Revision;");
146 if (JNIUtil::isJavaExceptionThrown() || getRevision
== 0)
149 jobject jrev
= env
->CallObjectMethod(copySource
, getRevision
);
150 if (JNIUtil::isJavaExceptionThrown())
153 // TODO: Default this to svn_opt_revision_undefined (or HEAD)
155 src
->revision
= (const svn_opt_revision_t
*)
156 apr_palloc(p
, sizeof(*src
->revision
));
157 memcpy((void *) src
->revision
, rev
.revision(),
158 sizeof(*src
->revision
));
159 env
->DeleteLocalRef(jrev
);
160 if (JNIUtil::isJavaExceptionThrown())
163 // Extract pegRevision from the copy source.
164 static jmethodID getPegRevision
= 0;
165 if (getPegRevision
== 0)
167 getPegRevision
= env
->GetMethodID(clazz
, "getRevision",
168 "()L"JAVA_PACKAGE
"/Revision;");
169 if (JNIUtil::isJavaExceptionThrown() || getPegRevision
== 0)
172 jobject jPegRev
= env
->CallObjectMethod(copySource
,
174 if (JNIUtil::isJavaExceptionThrown())
177 Revision
pegRev(jPegRev
, true);
178 src
->peg_revision
= (const svn_opt_revision_t
*)
179 apr_palloc(p
, sizeof(*src
->peg_revision
));
180 memcpy((void *) src
->peg_revision
, pegRev
.revision(),
181 sizeof(*src
->peg_revision
));
182 env
->DeleteLocalRef(jPegRev
);
183 if (JNIUtil::isJavaExceptionThrown())
186 APR_ARRAY_PUSH(copySources
, svn_client_copy_source_t
*) = src
;
188 env
->DeleteLocalRef(copySource
);
189 if (JNIUtil::isJavaExceptionThrown())
193 env
->DeleteLocalRef(clazz
);
194 if (JNIUtil::isJavaExceptionThrown())