]> source.dussan.org Git - gitblit.git/commitdiff
Build gbapi jar. Eliminate unnecessary gbapi runtime dependencies.
authorJames Moger <james.moger@gitblit.com>
Tue, 1 Nov 2011 21:22:43 +0000 (17:22 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 1 Nov 2011 21:22:43 +0000 (17:22 -0400)
build.xml
docs/00_index.mkd
docs/04_releases.mkd
src/com/gitblit/AuthenticationFilter.java
src/com/gitblit/GitBlit.java
src/com/gitblit/models/ServerSettings.java
src/com/gitblit/utils/Base64.java [new file with mode: 0644]
src/com/gitblit/utils/ConnectionUtils.java
src/com/gitblit/utils/RpcUtils.java

index 5c3494bdf2a05807d1924f0db437ea731f893800..854b5f1ea7910ccaf773946f4da16a755282e491 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -85,7 +85,8 @@
                <property name="distribution.zipfile" value="gitblit-${gb.version}.zip" />\r
                <property name="distribution.warfile" value="gitblit-${gb.version}.war" />\r
                <property name="fedclient.zipfile" value="fedclient-${gb.version}.zip" />\r
-               <property name="manager.zipfile" value="manager-${gb.version}.zip" />\r
+               <property name="manager.jarfile" value="manager-${gb.version}.jar" />\r
+               <property name="gbapi.zipfile" value="gbapi-${gb.version}.zip" />\r
        </target>\r
        \r
        \r
                                <arg value="%FEDCLIENT%=${fedclient.zipfile}" />\r
 \r
                                <arg value="--substitute" />\r
-                               <arg value="%MANAGER%=${manager.zipfile}" />\r
+                               <arg value="%MANAGER%=${manager.jarfile}" />\r
+\r
+                               <arg value="--substitute" />\r
+                               <arg value="%API%=${gbapi.zipfile}" />\r
 \r
                                <arg value="--substitute" />\r
                                <arg value="%BUILDDATE%=${gb.versionDate}" />\r
                                <exclude name="com/gitblit/client/**" />\r
                                <exclude name="com/gitblit/GitBlitServer*.class" />\r
                                <exclude name="com/gitblit/Launcher*.class" />\r
-                               <exclude name="com/gitblit/MakeCertificate*.class" />                           \r
+                               <exclude name="com/gitblit/MakeCertificate*.class" />\r
                        </fileset>\r
                </copy>\r
 \r
                        <classpath refid="master-classpath" />\r
                        <manifest>\r
                                <attribute name="Main-Class" value="com.gitblit.FederationClientLauncher" />\r
-                               <attribute name="Specification-Version" value="${gb.version}" />                                \r
+                               <attribute name="Specification-Version" value="${gb.version}" />\r
                                <attribute name="Release-Date" value="${gb.versionDate}" />\r
                        </manifest>\r
                </genjar>\r
                <!-- Build the federation client zip file -->\r
                <zip destfile="${fedclient.zipfile}">\r
                        <fileset dir="${basedir}">\r
-                               <include name="fedclient.jar" />                                \r
+                               <include name="fedclient.jar" />\r
                        </fileset>\r
                        <fileset dir="${basedir}/distrib">\r
-                               <include name="federation.properties" />                                \r
+                               <include name="federation.properties" />\r
                        </fileset>\r
                </zip>\r
        </target>\r
        <target name="buildManager" depends="compile" description="Builds the stand-alone Gitblit Manager">\r
                <echo>Building Gitblit Manager ${gb.version}</echo>\r
        \r
-               <genjar jarfile="manager.jar">\r
+               <genjar jarfile="${manager.jarfile}">\r
                        <resource file="${basedir}/src/com/gitblit/client/splash.png" />\r
                        <resource file="${basedir}/resources/gitblt-favicon.png" />\r
                        <resource file="${basedir}/resources/gitweb-favicon.png" />\r
                        <manifest>\r
                                <attribute name="Main-Class" value="com.gitblit.client.GitblitManagerLauncher" />\r
                                <attribute name="SplashScreen-Image" value="splash.png" />\r
-                               <attribute name="Specification-Version" value="${gb.version}" />                                \r
+                               <attribute name="Specification-Version" value="${gb.version}" />\r
                                <attribute name="Release-Date" value="${gb.versionDate}" />\r
                        </manifest>\r
                </genjar>\r
                \r
-               <!-- Build the Manager zip file -->\r
-               <zip destfile="${manager.zipfile}">\r
-                       <fileset dir="${basedir}">\r
-                               <include name="manager.jar" />                          \r
-                       </fileset>                      \r
-               </zip>\r
        </target>\r
+       \r
+       <!-- \r
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+                       Build the Gitblit API client library\r
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+               -->\r
+               <target name="buildApiLibrary" depends="compile" description="Builds the Gitblit RPC client library">\r
+                       <echo>Building Gitblit API Library ${gb.version}</echo>\r
+               \r
+                       <genjar jarfile="gbapi.jar">\r
+                               <class name="com.gitblit.client.GitblitClient" />\r
+                               <classpath refid="master-classpath" />\r
+                               <classfilter>\r
+                                       <exclude name="com.google.gson." />\r
+                               </classfilter>\r
+                               <manifest>\r
+                                       <attribute name="Specification-Version" value="${gb.version}" />\r
+                                       <attribute name="Release-Date" value="${gb.versionDate}" />\r
+                               </manifest>\r
+                       </genjar>\r
+                       \r
+                       <!-- Build the API library zip file -->\r
+                       <zip destfile="${gbapi.zipfile}">\r
+                               <fileset dir="${basedir}">\r
+                                       <include name="gbapi.jar" />\r
+                               </fileset>\r
+                               <fileset dir="${basedir}/ext">\r
+                                       <include name="gson*.jar" />\r
+                                       <exclude name="gson*-sources.jar" />\r
+                                       <exclude name="gson*-javadoc.jar" />\r
+                               </fileset>\r
+                       </zip>\r
+               </target>\r
                \r
                \r
        <!-- \r
                        <arg value="%FEDCLIENT%=${fedclient.zipfile}" />\r
 \r
                        <arg value="--substitute" />\r
-                       <arg value="%MANAGER%=${manager.zipfile}" />\r
+                       <arg value="%MANAGER%=${manager.jarfile}" />\r
+\r
+                       <arg value="--substitute" />\r
+                       <arg value="%API%=${gbapi.zipfile}" />\r
 \r
                        <arg value="--substitute" />\r
                        <arg value="%BUILDDATE%=${gb.versionDate}" />\r
                Compile from source, publish binaries, and build & deploy site\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
        -->\r
-       <target name="buildAll" depends="buildGO,buildWAR,buildFederationClient,buildManager,buildSite">                \r
+       <target name="buildAll" depends="buildGO,buildWAR,buildFederationClient,buildManager,buildApiLibrary,buildSite">                \r
                <!-- Cleanup -->\r
                <delete dir="${project.build.dir}" />\r
                <delete dir="${project.war.dir}" />\r
                \r
                <echo>Uploading Gitblit ${gb.version} binaries</echo>\r
                \r
-               <!-- Upload ZIP file -->\r
+               <!-- Upload Gitblit GO ZIP file -->\r
                <gcupload \r
                         username="${googlecode.user}" \r
                         password="${googlecode.password}" \r
                         summary="Gitblit GO v${gb.version} (standalone, integrated Gitblit server)"\r
                         labels="Featured, Type-Package, OpSys-All" />\r
                        \r
-               <!-- Upload WAR file -->\r
+               <!-- Upload Gitblit WAR file -->\r
                <gcupload \r
                     username="${googlecode.user}" \r
                     password="${googlecode.password}" \r
                     summary="Gitblit WAR v${gb.version} (standard WAR webapp for servlet containers)"\r
                     labels="Featured, Type-Package, OpSys-All" />\r
                \r
-               <!-- Upload FedClient -->\r
+               <!-- Upload Gitblit FedClient -->\r
                <gcupload \r
                        username="${googlecode.user}" \r
                        password="${googlecode.password}" \r
                        summary="Gitblit Federation Client v${gb.version} (command-line tool to clone data from federated Gitblit instances)"\r
                        labels="Featured, Type-Package, OpSys-All" />\r
 \r
-               <!-- Upload Manager -->\r
+               <!-- Upload Gitblit Manager -->\r
                <gcupload \r
                        username="${googlecode.user}" \r
                        password="${googlecode.password}" \r
                        projectname="gitblit" \r
-                       filename="${manager.zipfile}" \r
-                       targetfilename="manager-${gb.version}.zip"\r
+                       filename="${manager.jarfile}" \r
+                       targetfilename="manager-${gb.version}.jar"\r
                        summary="Gitblit Manager v${gb.version} (Swing tool to remotely administer a Gitblit server)"\r
                        labels="Featured, Type-Package, OpSys-All" />\r
+               \r
+               <!-- Upload Gitblit API Library -->\r
+               <gcupload \r
+                       username="${googlecode.user}" \r
+                       password="${googlecode.password}" \r
+                       projectname="gitblit" \r
+                       filename="${gbapi.zipfile}" \r
+                       targetfilename="gbapi-${gb.version}.zip"\r
+                       summary="Gitblit API Library v${gb.version} (JSON RPC library to integrate with your software)"\r
+                       labels="Featured, Type-Package, OpSys-All" />\r
        </target>\r
 \r
        \r
                Compile from source, publish binaries, and build & deploy site\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
        -->\r
-       <target name="publishAll" depends="publishBinaries,publishSite">                \r
+       <target name="publishAll" depends="publishBinaries,publishSite">\r
                <!-- Cleanup -->\r
                <delete dir="${project.build.dir}" />\r
                <delete dir="${project.war.dir}" />\r
index 1080f09551172bd4e2e6581db38a6d3f2baedf33..8e04b97f9dd5d2f74521c7eae83320575efbc03c 100644 (file)
@@ -18,7 +18,8 @@ Gitblit is available in two variations:
 \r
 ### Tools\r
 \r
-- *Gitblit Manager* - a Java/Swing application for remote administration of a Gitblit server\r
+- *Gitblit API* - a JSON RPC client library for integrating Gitblit into your systems\r
+- *Gitblit Manager* - a Java/Swing application for remote administration of a Gitblit server which uses the Gitblit API library\r
 - *Gitblit Federation Client* - a command line tool to clone/pull groups of repositories and optionally users and settings\r
 \r
 ### Java Runtime Requirement\r
@@ -27,7 +28,7 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit
 \r
 ### Current Release\r
 \r
-**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)|[fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%)|[manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
+**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
 \r
 - **security**: fixed security hole when cloning clone-restricted repository with TortoiseGit (issue 28)\r
 - improved: updated ui with Twitter's Bootstrap CSS toolkit  \r
@@ -38,7 +39,7 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit
     **New:** *web.enableRpcServlet = true*  \r
     **New:** *web.enableRpcManagement = false*  \r
     **New:** *web.enableRpcAdministration = false*\r
-- added: reusable JSON RPC client class\r
+- added: Gitblit API JSON RPC library\r
 - added: Gitblit Manager (Java/Swing Application) for remote administration of a Gitblit server.\r
 - added: per-repository setting to skip size calculation (faster repositories page loading)\r
 - added: per-repository setting to skip summary metrics calculation (faster summary page loading)\r
index 778fd0e89dbeb9251a986258d68e7634029a2b4c..6868b1923dc26c20b6b7cb088ee1ac3eab1025f3 100644 (file)
@@ -1,7 +1,7 @@
 ## Release History\r
 \r
 ### Current Release\r
-**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%)|[war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%)|[fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%)|[manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
+**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
 \r
 - **security**: fixed security hole when cloning clone-restricted repository with TortoiseGit (issue 28)\r
 - improved: updated ui with Twitter's Bootstrap CSS toolkit  \r
@@ -12,7 +12,7 @@
     **New:** *web.enableRpcServlet = true*  \r
     **New:** *web.enableRpcManagement = false*  \r
     **New:** *web.enableRpcAdministration = false*\r
-- added: reusable JSON RPC client class\r
+- added: Gitblit API JSON RPC library\r
 - added: Gitblit Manager (Java/Swing Application) for remote administration of a Gitblit server.\r
 - added: per-repository setting to skip size calculation (faster repositories page loading)\r
 - added: per-repository setting to skip summary metrics calculation (faster summary page loading)\r
@@ -33,7 +33,7 @@
 \r
 ### Older Releases\r
 \r
-**0.6.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.war)|[fedclient](http://code.google.com/p/gitblit/downloads/detail?name=fedclient-0.6.0.zip)) based on [JGit 1.1.0 (201109151100-r)][jgit] &nbsp; *released 2011-09-27*\r
+**0.6.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.war) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=fedclient-0.6.0.zip)) based on [JGit 1.1.0 (201109151100-r)][jgit] &nbsp; *released 2011-09-27*\r
 \r
 - added: federation feature to allow gitblit instances (or gitblit federation clients) to pull repositories and, optionally, settings and accounts from other gitblit instances.  This is something like [svn-sync](http://svnbook.red-bean.com/en/1.5/svn.ref.svnsync.html) for gitblit.  \r
     **New:** *federation.name =*  \r
@@ -52,7 +52,7 @@
 - fixed: syndication urls for WAR deployments\r
 - fixed: authentication for zip downloads\r
 \r
-**0.5.2** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.2.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.2.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-07-27*\r
+**0.5.2** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.2.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.2.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-07-27*\r
 \r
 - fixed: active repositories with a HEAD that pointed to an empty branch caused internal errors (issue 14)\r
 - fixed: bare-cloned repositories were listed as (empty) and were not clickable (issue 13)\r
 - updated: MarkdownPapers 1.1.0\r
 - updated: Jetty 7.4.3\r
 \r
-**0.5.1** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-06-28*\r
+**0.5.1** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.1.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-06-28*\r
 \r
 - clarified SSL certificate generation and configuration for both server-side and client-side\r
 - added some more troubleshooting information to documentation\r
 - replaced JavaService with Apache Commons Daemon\r
 \r
-**0.5.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.zip)|[war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-06-26*\r
+**0.5.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.5.0.war)) based on [JGit 1.0.0 (201106090707-r)][jgit] &nbsp; *released 2011-06-26*\r
 \r
 - initial release\r
 \r
index 6b7a0af269589428bdb633f28808b5b1a9d56405..277b220b3ea6e59807ea192919c7eb94f774804c 100644 (file)
@@ -33,11 +33,11 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;\r
 import javax.servlet.http.HttpSession;\r
 \r
-import org.eclipse.jgit.util.Base64;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.Base64;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
index 19edf2044848c14fafadc4f0a60cfcb4d40952e1..834375b784c6a8567d53942dee7e3d8837f05e16 100644 (file)
@@ -1307,7 +1307,12 @@ public class GitBlit implements ServletContextListener {
         */\r
        public ServerSettings getSettingsModel() {\r
                // ensure that the current values are updated in the setting models\r
-               settingsModel.updateCurrentValues(settings);\r
+               for (String key : settings.getAllKeys(null)) {\r
+                       SettingModel setting = settingsModel.get(key);\r
+                       if (setting != null) {\r
+                               setting.currentValue = settings.getString(key, "");\r
+                       }\r
+               }\r
                return settingsModel;\r
        }\r
 \r
@@ -1433,13 +1438,13 @@ public class GitBlit implements ServletContextListener {
        @Override\r
        public void contextInitialized(ServletContextEvent contextEvent) {\r
                servletContext = contextEvent.getServletContext();\r
-               settingsModel = loadSettingModels();            \r
+               settingsModel = loadSettingModels();\r
                if (settings == null) {\r
                        // Gitblit WAR is running in a servlet container\r
                        WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());\r
                        configureContext(webxmlSettings, true);\r
                }\r
-               \r
+\r
                serverStatus.servletContainer = servletContext.getServerInfo();\r
        }\r
 \r
index 47148d32b2a729364db2e0490f40ecfe2d52a64f..3aae2e3b11bd28bdac488181b4859950c1bc4b3a 100644 (file)
@@ -21,8 +21,6 @@ import java.util.List;
 import java.util.Map;\r
 import java.util.TreeMap;\r
 \r
-import com.gitblit.IStoredSettings;\r
-\r
 /**\r
  * Server settings represents the settings of the Gitblit server including all\r
  * setting metadata such as name, current value, default value, description, and\r
@@ -40,7 +38,7 @@ public class ServerSettings implements Serializable {
        public ServerSettings() {\r
                settings = new TreeMap<String, SettingModel>();\r
        }\r
-       \r
+\r
        public List<String> getKeys() {\r
                return new ArrayList<String>(settings.keySet());\r
        }\r
@@ -52,12 +50,4 @@ public class ServerSettings implements Serializable {
        public SettingModel get(String key) {\r
                return settings.get(key);\r
        }\r
-\r
-       public void updateCurrentValues(IStoredSettings storedSettings) {\r
-               for (String key : storedSettings.getAllKeys(null)) {\r
-                       if (settings.containsKey(key)) {\r
-                               settings.get(key).currentValue = storedSettings.getString(key, "");\r
-                       }\r
-               }\r
-       }\r
 }\r
diff --git a/src/com/gitblit/utils/Base64.java b/src/com/gitblit/utils/Base64.java
new file mode 100644 (file)
index 0000000..6fd2daf
--- /dev/null
@@ -0,0 +1,311 @@
+//\r
+//  NOTE: The following source code is heavily derived from the\r
+//  iHarder.net public domain Base64 library.  See the original at\r
+//  http://iharder.sourceforge.net/current/java/base64/\r
+//\r
+\r
+package com.gitblit.utils;\r
+\r
+import java.io.UnsupportedEncodingException;\r
+import java.text.MessageFormat;\r
+import java.util.Arrays;\r
+\r
+/**\r
+ * Encodes and decodes to and from Base64 notation.\r
+ * <p>\r
+ * I am placing this code in the Public Domain. Do with it as you will. This\r
+ * software comes with no guarantees or warranties but with plenty of\r
+ * well-wishing instead! Please visit <a\r
+ * href="http://iharder.net/base64">http://iharder.net/base64</a> periodically\r
+ * to check for updates or to contribute improvements.\r
+ * </p>\r
+ * \r
+ * @author Robert Harder\r
+ * @author rob@iharder.net\r
+ * @version 2.1, stripped to minimum feature set used by JGit.\r
+ */\r
+public class Base64 {\r
+       /** The equals sign (=) as a byte. */\r
+       private final static byte EQUALS_SIGN = (byte) '=';\r
+\r
+       /** Indicates equals sign in encoding. */\r
+       private final static byte EQUALS_SIGN_DEC = -1;\r
+\r
+       /** Indicates white space in encoding. */\r
+       private final static byte WHITE_SPACE_DEC = -2;\r
+\r
+       /** Indicates an invalid byte during decoding. */\r
+       private final static byte INVALID_DEC = -3;\r
+\r
+       /** Preferred encoding. */\r
+       private final static String UTF_8 = "UTF-8";\r
+\r
+       /** The 64 valid Base64 values. */\r
+       private final static byte[] ENC;\r
+\r
+       /**\r
+        * Translates a Base64 value to either its 6-bit reconstruction value or a\r
+        * negative number indicating some other meaning. The table is only 7 bits\r
+        * wide, as the 8th bit is discarded during decoding.\r
+        */\r
+       private final static byte[] DEC;\r
+\r
+       static {\r
+               try {\r
+                       ENC = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" //\r
+                                       + "abcdefghijklmnopqrstuvwxyz" //\r
+                                       + "0123456789" //\r
+                                       + "+/" //\r
+                       ).getBytes(UTF_8);\r
+               } catch (UnsupportedEncodingException uee) {\r
+                       throw new RuntimeException(uee.getMessage(), uee);\r
+               }\r
+\r
+               DEC = new byte[128];\r
+               Arrays.fill(DEC, INVALID_DEC);\r
+\r
+               for (int i = 0; i < 64; i++)\r
+                       DEC[ENC[i]] = (byte) i;\r
+               DEC[EQUALS_SIGN] = EQUALS_SIGN_DEC;\r
+\r
+               DEC['\t'] = WHITE_SPACE_DEC;\r
+               DEC['\n'] = WHITE_SPACE_DEC;\r
+               DEC['\r'] = WHITE_SPACE_DEC;\r
+               DEC[' '] = WHITE_SPACE_DEC;\r
+       }\r
+\r
+       /** Defeats instantiation. */\r
+       private Base64() {\r
+               // Suppress empty block warning.\r
+       }\r
+\r
+       /**\r
+        * Encodes up to three bytes of the array <var>source</var> and writes the\r
+        * resulting four Base64 bytes to <var>destination</var>. The source and\r
+        * destination arrays can be manipulated anywhere along their length by\r
+        * specifying <var>srcOffset</var> and <var>destOffset</var>. This method\r
+        * does not check to make sure your arrays are large enough to accommodate\r
+        * <var>srcOffset</var> + 3 for the <var>source</var> array or\r
+        * <var>destOffset</var> + 4 for the <var>destination</var> array. The\r
+        * actual number of significant bytes in your array is given by\r
+        * <var>numSigBytes</var>.\r
+        * \r
+        * @param source\r
+        *            the array to convert\r
+        * @param srcOffset\r
+        *            the index where conversion begins\r
+        * @param numSigBytes\r
+        *            the number of significant bytes in your array\r
+        * @param destination\r
+        *            the array to hold the conversion\r
+        * @param destOffset\r
+        *            the index where output will be put\r
+        */\r
+       private static void encode3to4(byte[] source, int srcOffset, int numSigBytes,\r
+                       byte[] destination, int destOffset) {\r
+               // We have to shift left 24 in order to flush out the 1's that appear\r
+               // when Java treats a value as negative that is cast from a byte.\r
+\r
+               int inBuff = 0;\r
+               switch (numSigBytes) {\r
+               case 3:\r
+                       inBuff |= (source[srcOffset + 2] << 24) >>> 24;\r
+                       //$FALL-THROUGH$\r
+\r
+               case 2:\r
+                       inBuff |= (source[srcOffset + 1] << 24) >>> 16;\r
+                       //$FALL-THROUGH$\r
+\r
+               case 1:\r
+                       inBuff |= (source[srcOffset] << 24) >>> 8;\r
+               }\r
+\r
+               switch (numSigBytes) {\r
+               case 3:\r
+                       destination[destOffset] = ENC[(inBuff >>> 18)];\r
+                       destination[destOffset + 1] = ENC[(inBuff >>> 12) & 0x3f];\r
+                       destination[destOffset + 2] = ENC[(inBuff >>> 6) & 0x3f];\r
+                       destination[destOffset + 3] = ENC[(inBuff) & 0x3f];\r
+                       break;\r
+\r
+               case 2:\r
+                       destination[destOffset] = ENC[(inBuff >>> 18)];\r
+                       destination[destOffset + 1] = ENC[(inBuff >>> 12) & 0x3f];\r
+                       destination[destOffset + 2] = ENC[(inBuff >>> 6) & 0x3f];\r
+                       destination[destOffset + 3] = EQUALS_SIGN;\r
+                       break;\r
+\r
+               case 1:\r
+                       destination[destOffset] = ENC[(inBuff >>> 18)];\r
+                       destination[destOffset + 1] = ENC[(inBuff >>> 12) & 0x3f];\r
+                       destination[destOffset + 2] = EQUALS_SIGN;\r
+                       destination[destOffset + 3] = EQUALS_SIGN;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Encodes a byte array into Base64 notation.\r
+        * \r
+        * @param source\r
+        *            The data to convert\r
+        * @return encoded base64 representation of source.\r
+        */\r
+       public static String encodeBytes(byte[] source) {\r
+               return encodeBytes(source, 0, source.length);\r
+       }\r
+\r
+       /**\r
+        * Encodes a byte array into Base64 notation.\r
+        * \r
+        * @param source\r
+        *            The data to convert\r
+        * @param off\r
+        *            Offset in array where conversion should begin\r
+        * @param len\r
+        *            Length of data to convert\r
+        * @return encoded base64 representation of source.\r
+        */\r
+       public static String encodeBytes(byte[] source, int off, int len) {\r
+               final int len43 = len * 4 / 3;\r
+\r
+               byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)];\r
+               int d = 0;\r
+               int e = 0;\r
+               int len2 = len - 2;\r
+\r
+               for (; d < len2; d += 3, e += 4)\r
+                       encode3to4(source, d + off, 3, outBuff, e);\r
+\r
+               if (d < len) {\r
+                       encode3to4(source, d + off, len - d, outBuff, e);\r
+                       e += 4;\r
+               }\r
+\r
+               try {\r
+                       return new String(outBuff, 0, e, UTF_8);\r
+               } catch (UnsupportedEncodingException uue) {\r
+                       return new String(outBuff, 0, e);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Decodes four bytes from array <var>source</var> and writes the resulting\r
+        * bytes (up to three of them) to <var>destination</var>. The source and\r
+        * destination arrays can be manipulated anywhere along their length by\r
+        * specifying <var>srcOffset</var> and <var>destOffset</var>. This method\r
+        * does not check to make sure your arrays are large enough to accommodate\r
+        * <var>srcOffset</var> + 4 for the <var>source</var> array or\r
+        * <var>destOffset</var> + 3 for the <var>destination</var> array. This\r
+        * method returns the actual number of bytes that were converted from the\r
+        * Base64 encoding.\r
+        * \r
+        * @param source\r
+        *            the array to convert\r
+        * @param srcOffset\r
+        *            the index where conversion begins\r
+        * @param destination\r
+        *            the array to hold the conversion\r
+        * @param destOffset\r
+        *            the index where output will be put\r
+        * @return the number of decoded bytes converted\r
+        */\r
+       private static int decode4to3(byte[] source, int srcOffset, byte[] destination, int destOffset) {\r
+               // Example: Dk==\r
+               if (source[srcOffset + 2] == EQUALS_SIGN) {\r
+                       int outBuff = ((DEC[source[srcOffset]] & 0xFF) << 18)\r
+                                       | ((DEC[source[srcOffset + 1]] & 0xFF) << 12);\r
+                       destination[destOffset] = (byte) (outBuff >>> 16);\r
+                       return 1;\r
+               }\r
+\r
+               // Example: DkL=\r
+               else if (source[srcOffset + 3] == EQUALS_SIGN) {\r
+                       int outBuff = ((DEC[source[srcOffset]] & 0xFF) << 18)\r
+                                       | ((DEC[source[srcOffset + 1]] & 0xFF) << 12)\r
+                                       | ((DEC[source[srcOffset + 2]] & 0xFF) << 6);\r
+                       destination[destOffset] = (byte) (outBuff >>> 16);\r
+                       destination[destOffset + 1] = (byte) (outBuff >>> 8);\r
+                       return 2;\r
+               }\r
+\r
+               // Example: DkLE\r
+               else {\r
+                       int outBuff = ((DEC[source[srcOffset]] & 0xFF) << 18)\r
+                                       | ((DEC[source[srcOffset + 1]] & 0xFF) << 12)\r
+                                       | ((DEC[source[srcOffset + 2]] & 0xFF) << 6)\r
+                                       | ((DEC[source[srcOffset + 3]] & 0xFF));\r
+\r
+                       destination[destOffset] = (byte) (outBuff >> 16);\r
+                       destination[destOffset + 1] = (byte) (outBuff >> 8);\r
+                       destination[destOffset + 2] = (byte) (outBuff);\r
+\r
+                       return 3;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Low-level decoding ASCII characters from a byte array.\r
+        * \r
+        * @param source\r
+        *            The Base64 encoded data\r
+        * @param off\r
+        *            The offset of where to begin decoding\r
+        * @param len\r
+        *            The length of characters to decode\r
+        * @return decoded data\r
+        * @throws IllegalArgumentException\r
+        *             the input is not a valid Base64 sequence.\r
+        */\r
+       public static byte[] decode(byte[] source, int off, int len) {\r
+               byte[] outBuff = new byte[len * 3 / 4]; // Upper limit on size of output\r
+               int outBuffPosn = 0;\r
+\r
+               byte[] b4 = new byte[4];\r
+               int b4Posn = 0;\r
+\r
+               for (int i = off; i < off + len; i++) {\r
+                       byte sbiCrop = (byte) (source[i] & 0x7f);\r
+                       byte sbiDecode = DEC[sbiCrop];\r
+\r
+                       if (EQUALS_SIGN_DEC <= sbiDecode) {\r
+                               b4[b4Posn++] = sbiCrop;\r
+                               if (b4Posn > 3) {\r
+                                       outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn);\r
+                                       b4Posn = 0;\r
+\r
+                                       // If that was the equals sign, break out of 'for' loop\r
+                                       if (sbiCrop == EQUALS_SIGN)\r
+                                               break;\r
+                               }\r
+\r
+                       } else if (sbiDecode != WHITE_SPACE_DEC)\r
+                               throw new IllegalArgumentException(MessageFormat.format(\r
+                                               "bad base64 input character {1} at {0}", i, source[i] & 0xff));\r
+               }\r
+\r
+               if (outBuff.length == outBuffPosn)\r
+                       return outBuff;\r
+\r
+               byte[] out = new byte[outBuffPosn];\r
+               System.arraycopy(outBuff, 0, out, 0, outBuffPosn);\r
+               return out;\r
+       }\r
+\r
+       /**\r
+        * Decodes data from Base64 notation.\r
+        * \r
+        * @param s\r
+        *            the string to decode\r
+        * @return the decoded data\r
+        */\r
+       public static byte[] decode(String s) {\r
+               byte[] bytes;\r
+               try {\r
+                       bytes = s.getBytes(UTF_8);\r
+               } catch (UnsupportedEncodingException uee) {\r
+                       bytes = s.getBytes();\r
+               }\r
+               return decode(bytes, 0, bytes.length);\r
+       }\r
+}\r
index 93693ab9c4d61f81435689c3389f7de19864cb84..9ad62d0eafe089b313dc51c814a91529e566a69a 100644 (file)
@@ -29,7 +29,6 @@ import javax.net.ssl.SSLSession;
 import javax.net.ssl.TrustManager;\r
 import javax.net.ssl.X509TrustManager;\r
 \r
-import org.eclipse.jgit.util.Base64;\r
 \r
 /**\r
  * Utility class for establishing HTTP/HTTPS connections.\r
index c2f20d8410033aa5d8dfac0c19bdb04c711a8880..387433a002453a237d7d4cf8c067c3d45889527f 100644 (file)
@@ -146,6 +146,10 @@ public class RpcUtils {
         */\r
        public static boolean createRepository(RepositoryModel repository, String serverUrl,\r
                        String account, char[] password) throws IOException {\r
+               // ensure repository name ends with .git\r
+               if (!repository.name.endsWith(".git")) {\r
+                       repository.name += ".git";\r
+               }\r
                return doAction(RpcRequest.CREATE_REPOSITORY, null, repository, serverUrl, account,\r
                                password);\r
 \r