<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
\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
\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] *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] *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
**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
## 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] *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] *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
**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
\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] *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] *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
- 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] *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] *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] *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] *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] *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] *released 2011-06-26*\r
\r
- initial release\r
\r
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
*/\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
@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
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
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
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
--- /dev/null
+//\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
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
*/\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