subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1497746 - in /subversion/trunk/subversion/bindings/javahl: native/OperationContext.cpp native/OperationContext.h src/org/apache/subversion/javahl/ISVNConfig.java src/org/apache/subversion/javahl/callback/ConfigEvent.java
Date Fri, 28 Jun 2013 12:18:01 GMT
Author: brane
Date: Fri Jun 28 12:18:01 2013
New Revision: 1497746

URL: http://svn.apache.org/r1497746
Log:
Add a framework for manipulating in-memory configuration data in JavaHL.

[in subversion/bindings/javahl/src/org/apache/subversion/javahl]
* ISVNConfig.java (ISVNConfig): New interface for reading and modifying
   in-memory configuration data.
* callback/ConfigEvent.java (ConfigEvent): Callback interface for
   configuration change notification hooks.

[in subversion/bindings/javahl/native]
* OperationContext.h, OperationContext.cpp
  (OperationContext::setConfigCallback,
   OperationContext::getConfigCallback,
   OperationContext::notifyConfigLoad): New; native configuration change
    notification framework.
* OperationContext.cpp
  (OperationContext::OperationContext, OperationContext::!OperationContext):
   Manage the lifetime of the ConfigEvent callback object.
  (OperationContext::getConfigData): Call notifyConfigLoad when the
   configuration data has been loaded into memory.

Added:
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNConfig.java
    subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ConfigEvent.java
Modified:
    subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp
    subversion/trunk/subversion/bindings/javahl/native/OperationContext.h

Modified: subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp?rev=1497746&r1=1497745&r2=1497746&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp Fri Jun 28 12:18:01
2013
@@ -42,7 +42,8 @@ OperationContext::OperationContext(SVN::
     m_prompter(NULL),
     m_cancelOperation(0),
     m_pool(&pool),
-    m_jctx(NULL)
+    m_jctx(NULL),
+    m_jcfgcb(NULL)
 {}
 
 void
@@ -84,6 +85,8 @@ OperationContext::~OperationContext()
 
   JNIEnv *env = JNIUtil::getEnv();
   env->DeleteGlobalRef(m_jctx);
+  if (m_jcfgcb)
+    env->DeleteGlobalRef(m_jcfgcb);
 }
 
 apr_hash_t *
@@ -101,6 +104,7 @@ OperationContext::getConfigData()
         configDir = NULL;
       SVN_JNI_ERR(
           svn_config_get_config(&m_config, configDir, m_pool->getPool()), NULL);
+      notifyConfigLoad();
     }
 
   return m_config;
@@ -250,12 +254,34 @@ OperationContext::setConfigDirectory(con
   m_config = NULL;
 }
 
+void
+OperationContext::setConfigCallback(jobject configCallback)
+{
+  JNIEnv* env = JNIUtil::getEnv();
+
+  if (m_jcfgcb)
+    {
+      env->DeleteGlobalRef(m_jcfgcb);
+      m_jcfgcb = NULL;
+    }
+  if (configCallback)
+    {
+      m_jcfgcb = env->NewGlobalRef(configCallback);
+      env->DeleteLocalRef(configCallback);
+    }
+}
+
 const char *
 OperationContext::getConfigDirectory() const
 {
   return (m_configDir.empty() ? NULL : m_configDir.c_str());
 }
 
+jobject OperationContext::getConfigCallback() const
+{
+  return m_jcfgcb;
+}
+
 const char *
 OperationContext::getUsername() const
 {
@@ -364,3 +390,54 @@ OperationContext::clientName(void *baton
 
   return SVN_NO_ERROR;
 }
+
+void
+OperationContext::notifyConfigLoad()
+{
+  if (!m_jcfgcb)
+    return;
+
+  JNIEnv *env = JNIUtil::getEnv();
+
+  static jmethodID onload_mid = 0;
+  if (0 == onload_mid)
+    {
+      jclass cls = env->FindClass(JAVA_PACKAGE"/callback/ConfigEvent");
+      if (JNIUtil::isJavaExceptionThrown())
+        return;
+      onload_mid = env->GetMethodID(cls, "onLoad",
+                                    "(L"JAVA_PACKAGE"/ISVNConfig;)V");
+      if (JNIUtil::isJavaExceptionThrown())
+        return;
+    }
+
+  jclass cfg_cls = env->FindClass(JAVA_PACKAGE"/ConfigImpl");
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+
+  static jmethodID ctor_mid = 0;
+  if (0 == ctor_mid)
+    {
+      ctor_mid = env->GetMethodID(cfg_cls, "<init>", "(J)V");
+      if (JNIUtil::isJavaExceptionThrown())
+        return;
+    }
+
+  static jmethodID dispose_mid = 0;
+  if (0 == dispose_mid)
+    {
+      dispose_mid = env->GetMethodID(cfg_cls, "dispose", "()V");
+      if (JNIUtil::isJavaExceptionThrown())
+        return;
+    }
+
+  jobject jcbimpl = env->NewObject(cfg_cls, ctor_mid,
+                                   reinterpret_cast<jlong>(this));
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  env->CallVoidMethod(m_jcfgcb, onload_mid, jcbimpl);
+  if (JNIUtil::isJavaExceptionThrown())
+    return;
+  env->CallVoidMethod(jcbimpl, dispose_mid);
+  env->DeleteLocalRef(jcbimpl);
+}

Modified: subversion/trunk/subversion/bindings/javahl/native/OperationContext.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/OperationContext.h?rev=1497746&r1=1497745&r2=1497746&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/OperationContext.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/OperationContext.h Fri Jun 28 12:18:01
2013
@@ -58,8 +58,10 @@ class OperationContext
   SVN::Pool *m_pool;
 
   jobject m_jctx;
+  jobject m_jcfgcb;
   static void progress(apr_off_t progressVal, apr_off_t total,
                        void *baton, apr_pool_t *pool);
+  void notifyConfigLoad();
  public:
   OperationContext(SVN::Pool &pool);
   void attachJavaObject(jobject contextHolder, const char *contextClassType, const char *contextFieldName,
jfieldID * ctxFieldID);
@@ -77,6 +79,7 @@ class OperationContext
   virtual bool isCancelledOperation();
   jobject getSelf() const;
   const char *getConfigDirectory() const;
+  jobject getConfigCallback() const;
   const char *getUsername() const;
   const char *getPassword() const;
   const Prompter& getPrompter() const;
@@ -89,6 +92,12 @@ class OperationContext
   void setConfigDirectory(const char *configDir);
 
   /**
+   * Set the config ConfigCallback instance to call when configuration
+   * is loaded..
+   */
+  void setConfigCallback(jobject configCallback);
+
+  /**
    * Return configuration data for the context.
    * Read it from config directory if necessary
    */

Added: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNConfig.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNConfig.java?rev=1497746&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNConfig.java
(added)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNConfig.java
Fri Jun 28 12:18:01 2013
@@ -0,0 +1,244 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+package org.apache.subversion.javahl;
+
+import org.apache.subversion.javahl.types.Tristate;
+
+/**
+ * Interface for manipulating the in-memory configuration info.
+ * @since 1.9
+ */
+public interface ISVNConfig
+{
+    /**
+     * Returns a reference to the "config" configuration category.
+     */
+    Category config();
+
+    /*
+     * The following constants are section and option names from the
+     * "config" configuration file.
+     */
+    public static final String SECTION_AUTH          = "auth";
+    public static final String PASSWORD_STORES           = "password-stores";
+    public static final String KWALLET_WALLET            = "kwallet-wallet";
+    public static final String KWALLET_SVN_APPLICATION_NAME_WITH_PID = "kwallet-svn-application-name-with-pid";
+    public static final String SSL_CLIENT_CERT_FILE_PROMPT = "ssl-client-cert-file-prompt";
+
+    public static final String SECTION_HELPERS       = "helpers";
+    public static final String EDITOR_CMD                = "editor-cmd";
+    public static final String DIFF_CMD                  = "diff-cmd";
+    public static final String DIFF_EXTENSIONS           = "diff-extensions";
+    public static final String DIFF3_CMD                 = "diff3-cmd";
+    public static final String DIFF3_HAS_PROGRAM_ARG     = "diff3-has-program-arg";
+    public static final String MERGE_TOOL_CMD            = "merge-tool-cmd";
+
+    public static final String SECTION_MISCELLANY    = "miscellany";
+    public static final String GLOBAL_IGNORES            = "global-ignores";
+    public static final String LOG_ENCODING              = "log-encoding";
+    public static final String USE_COMMIT_TIMES          = "use-commit-times";
+    public static final String ENABLE_AUTO_PROPS         = "enable-auto-props";
+    public static final String NO_UNLOCK                 = "no-unlock";
+    public static final String MIMETYPES_FILE            = "mime-types-file";
+    public static final String PRESERVED_CF_EXTS         = "preserved-conflict-file-exts";
+    public static final String INTERACTIVE_CONFLICTS     = "interactive-conflicts";
+    public static final String MEMORY_CACHE_SIZE         = "memory-cache-size";
+    public static final String DIFF_IGNORE_CONTENT_TYPE  = "diff-ignore-content-type";
+
+    public static final String SECTION_TUNNELS       = "tunnels";
+
+    public static final String SECTION_AUTO_PROPS    = "auto-props";
+
+    public static final String SECTION_WORKING_COPY  = "working-copy";
+    public static final String SQLITE_EXCLUSIVE          = "exclusive-locking";
+    public static final String SQLITE_EXCLUSIVE_CLIENTS  = "exclusive-locking-clients";
+
+    /**
+     * Returns a reference to the "servers" configuration category.
+     */
+    Category servers();
+
+    /*
+     * The following constants are section and option names from the
+     * "servers" configuration file.
+     */
+    public static final String SECTION_GROUPS        = "groups";
+    public static final String SECTION_GLOBAL        = "global";
+
+    public static final String HTTP_PROXY_HOST           = "http-proxy-host";
+    public static final String HTTP_PROXY_PORT           = "http-proxy-port";
+    public static final String HTTP_PROXY_USERNAME       = "http-proxy-username";
+    public static final String HTTP_PROXY_PASSWORD       = "http-proxy-password";
+    public static final String HTTP_PROXY_EXCEPTIONS     = "http-proxy-exceptions";
+    public static final String HTTP_TIMEOUT              = "http-timeout";
+    public static final String HTTP_COMPRESSION          = "http-compression";
+    public static final String NEON_DEBUG_MASK           = "neon-debug-mask";
+    public static final String HTTP_AUTH_TYPES           = "http-auth-types";
+    public static final String SSL_AUTHORITY_FILES       = "ssl-authority-files";
+    public static final String SSL_TRUST_DEFAULT_CA      = "ssl-trust-default-ca";
+    public static final String SSL_CLIENT_CERT_FILE      = "ssl-client-cert-file";
+    public static final String SSL_CLIENT_CERT_PASSWORD  = "ssl-client-cert-password";
+    public static final String SSL_PKCS11_PROVIDER       = "ssl-pkcs11-provider";
+    public static final String HTTP_LIBRARY              = "http-library";
+    public static final String STORE_PASSWORDS           = "store-passwords";
+    public static final String STORE_PLAINTEXT_PASSWORDS = "store-plaintext-passwords";
+    public static final String STORE_AUTH_CREDS          = "store-auth-creds";
+    public static final String STORE_SSL_CLIENT_CERT_PP  = "store-ssl-client-cert-pp";
+    public static final String STORE_SSL_CLIENT_CERT_PP_PLAINTEXT = "store-ssl-client-cert-pp-plaintext";
+    public static final String USERNAME                  = "username";
+    public static final String HTTP_BULK_UPDATES         = "http-bulk-updates";
+    public static final String HTTP_MAX_CONNECTIONS      = "http-max-connections";
+    public static final String HTTP_CHUNKED_REQUESTS     = "http-chunked-requests";
+
+    /**
+     * "true" value in configuraition. One of the values returned by
+     * {@link Category#getYesNoAsk}.
+     */
+    public static final String TRUE = "TRUE";
+
+    /**
+     * "false" value in configuraition. One of the values returned by
+     * {@link Category#getYesNoAsk}.
+     */
+    public static final String FALSE = "FALSE";
+
+    /**
+     * "ask" value in configuraition. One of the values returned by
+     * {@link Category#getYesNoAsk}.
+     */
+    public static final String ASK = "ASK";
+
+    /**
+     * Interface for reading and modifying configuration
+     * categories. Returned by {@link #config()} and
+     * {@link servers()}.
+     */
+    public interface Category
+    {
+        /**
+         * Returns the value of a configuration option.
+         * @param section      The section name
+         * @param option       The option name
+         * @param defaultValue Return this if the option was not found.
+         */
+        String get(String section,
+                   String option,
+                   String defaultValue);
+
+        /**
+         * Returns the boolean value of a configuration option. The
+         * recognized representations are 'true'/'false', 'yes'/'no',
+         * 'on'/'off', '1'/'0'; case does not matter.
+         * @throws ClientException if the value cannot be parsed.
+         * @see #get(String,String,String)
+         */
+        boolean get(String section,
+                    String option,
+                    boolean defaultValue)
+            throws ClientException;
+
+        /**
+         * Returns the long integer value of a configuration option.
+         * @see #get(String,String,Boolean)
+         */
+        long get(String section,
+                 String option,
+                 long defaultValue)
+            throws ClientException;
+
+        /**
+         * Returns the {@link Tristate} value of a configuration option.
+         * @param unknown The value used for {@link Tristate.Unknown}.
+         * @see #get(String,String,Boolean)
+         */
+        Tristate get(String section,
+                     String option,
+                     String unknown,
+                     Tristate defaultValue)
+            throws ClientException;
+
+        /**
+         * Check that the configuration option's value is true, false
+         * or "ask". The boolean representations are the same as those
+         * understood by {@link #get(String,String,Boolean)}. If the
+         * option is not found, the default value will be parsed
+         * instead.
+         * @return {@link ISVNConfig#TRUE}, {@link ISVNConfig#FALSE}
+         *         or {@link ISVNConfig#ASK}
+         * @throws ClientException if the either the value or the
+         *         default cannot be parsed.
+         */
+        String getYesNoAsk(String section,
+                           String option,
+                           String defaultValue)
+            throws ClientException;
+
+        /**
+         * Set the value of a configuration option.
+         * @param section  The section name
+         * @param option   The option name
+         * @param value    The value to set the option to; passing
+         *                 <code>null</code> will delete the option.
+         */
+        void set(String section,
+                 String option,
+                 String value);
+
+        /**
+         * Set the value of a configuration option to represent a boolean.
+         * @see @set(String,String,String)
+         */
+        void set(String section,
+                 String option,
+                 boolean value);
+
+        /**
+         * Set the value of a configuration option to represent a long integer.
+         * @see @set(String,String,String)
+         */
+        void set(String section,
+                 String option,
+                 long value);
+
+        /**
+         * @return the names of all the sections in the
+         * configuration category.
+         */
+        Iterable<String> sections();
+
+        /**
+         * Call <code>handler</code> once for each option in the
+         * configuration category.
+         */
+        void enumerate(String section, Enumerator handler);
+    }
+
+    /**
+     * Interface for {@link Category#enumerate} callback handlers.
+     */
+    public interface Enumerator
+    {
+        void option(String name, String value);
+    }
+}

Added: subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ConfigEvent.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ConfigEvent.java?rev=1497746&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ConfigEvent.java
(added)
+++ subversion/trunk/subversion/bindings/javahl/src/org/apache/subversion/javahl/callback/ConfigEvent.java
Fri Jun 28 12:18:01 2013
@@ -0,0 +1,42 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+package org.apache.subversion.javahl.callback;
+
+import org.apache.subversion.javahl.ISVNConfig;
+
+/**
+ * Interface for configuration-change hooks.
+ * @since 1.9
+ */
+public interface ConfigEvent
+{
+    /**
+     * Called by the native configuration loader every time the
+     * configuration is parsed into memory.
+     * @params configuration A reference to the in-memory configuration
+     *                       data. This object is only valid during the
+     *                       call and must not be accessed otherwise.
+     */
+    void onLoad(ISVNConfig configuration);
+}



Mime
View raw message