├── .gitignore ├── COPYING ├── README.md ├── mini-git-server-httpd ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── google │ │ └── gerrit │ │ └── httpd │ │ ├── CookieBase64.java │ │ ├── HtmlDomUtil.java │ │ ├── HttpCanonicalWebUrlProvider.java │ │ ├── HttpIdentifiedUserProvider.java │ │ ├── HttpRemotePeerProvider.java │ │ ├── ProjectServlet.java │ │ ├── RequestCleanupFilter.java │ │ ├── RequireSslFilter.java │ │ ├── UrlModule.java │ │ ├── WebModule.java │ │ └── raw │ │ └── SshInfoServlet.java │ └── resources │ └── com │ └── google │ └── gerrit │ └── httpd │ ├── auth │ ├── become │ │ └── BecomeAnyAccount.html │ └── container │ │ ├── ConfigurationError.html │ │ └── LoginRedirect.html │ └── raw │ ├── HostPage.html │ └── LegacyGerrit.html ├── mini-git-server-server ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── google │ │ └── gerrit │ │ ├── common │ │ ├── CollectionsUtil.java │ │ └── Version.java │ │ ├── lifecycle │ │ ├── LifecycleListener.java │ │ ├── LifecycleManager.java │ │ └── LifecycleModule.java │ │ └── server │ │ ├── AccessPath.java │ │ ├── AnonymousUser.java │ │ ├── CurrentUser.java │ │ ├── GerritPersonIdent.java │ │ ├── GerritPersonIdentProvider.java │ │ ├── IdentifiedUser.java │ │ ├── RemotePeer.java │ │ ├── RequestCleanup.java │ │ ├── UrlEncoded.java │ │ ├── account │ │ ├── AccountException.java │ │ └── AccountUserNameException.java │ │ ├── cache │ │ ├── Cache.java │ │ ├── CacheModule.java │ │ ├── CachePool.java │ │ ├── CacheProvider.java │ │ ├── EntryCreator.java │ │ ├── EvictionPolicy.java │ │ ├── NamedCacheBinding.java │ │ ├── PopulatingCache.java │ │ ├── ProxyEhcache.java │ │ ├── SimpleCache.java │ │ └── UnnamedCacheBinding.java │ │ ├── config │ │ ├── CanonicalWebUrl.java │ │ ├── CanonicalWebUrlModule.java │ │ ├── CanonicalWebUrlProvider.java │ │ ├── ConfigUtil.java │ │ ├── FactoryModule.java │ │ ├── GerritGlobalModule.java │ │ ├── GerritRequestModule.java │ │ ├── GerritServerConfig.java │ │ ├── GerritServerConfigModule.java │ │ ├── GerritServerConfigProvider.java │ │ ├── SitePath.java │ │ ├── SitePaths.java │ │ └── ToyGerritGlobalModule.java │ │ ├── git │ │ ├── CommitMergeStatus.java │ │ ├── DefaultQueueOp.java │ │ ├── GitRepositoryManager.java │ │ ├── LocalDiskRepositoryManager.java │ │ ├── MergeException.java │ │ ├── ProjectRunnable.java │ │ ├── TransferConfig.java │ │ └── WorkQueue.java │ │ ├── ioutil │ │ └── BasicSerialization.java │ │ ├── project │ │ ├── CanSubmitResult.java │ │ ├── NoSuchProjectException.java │ │ └── NoSuchRefException.java │ │ ├── ssh │ │ └── SshInfo.java │ │ └── util │ │ ├── HostPlatform.java │ │ ├── IdGenerator.java │ │ └── SocketUtil.java │ └── test │ └── java │ └── com │ └── google │ └── gerrit │ └── server │ ├── config │ ├── ConfigUtilTest.java │ └── SitePathsTest.java │ ├── ioutil │ └── BasicSerializationTest.java │ ├── tools │ └── hooks │ │ └── HookTestCase.java │ └── util │ ├── IdGeneratorTest.java │ └── SocketUtilTest.java ├── mini-git-server-sshd ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── google │ └── gerrit │ └── sshd │ ├── AbstractGitCommand.java │ ├── AdminCommand.java │ ├── AdminHighPriorityCommand.java │ ├── BaseCommand.java │ ├── CommandExecutor.java │ ├── CommandExecutorProvider.java │ ├── CommandExecutorQueueProvider.java │ ├── CommandFactoryProvider.java │ ├── CommandModule.java │ ├── CommandName.java │ ├── Commands.java │ ├── DispatchCommand.java │ ├── DispatchCommandProvider.java │ ├── HostKeyProvider.java │ ├── NoShell.java │ ├── QueueProvider.java │ ├── SshCurrentUserProvider.java │ ├── SshDaemon.java │ ├── SshIdentifiedUserProvider.java │ ├── SshLog.java │ ├── SshModule.java │ ├── SshRemotePeerProvider.java │ ├── SshScope.java │ ├── SshSession.java │ ├── SshUtil.java │ ├── StreamCommandExecutor.java │ ├── StreamCommandExecutorProvider.java │ ├── ToyPubKeyAuth.java │ ├── ToySshModule.java │ ├── args4j │ ├── SocketAddressHandler.java │ └── SubcommandHandler.java │ └── commands │ ├── AdminKill.java │ ├── AdminShowConnections.java │ ├── DefaultCommandModule.java │ ├── Receive.java │ ├── ShowQueue.java │ ├── ToyDefaultCommandModule.java │ └── Upload.java ├── mini-git-server-util-cli ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── google │ └── gerrit │ └── util │ └── cli │ ├── CmdLineParser.java │ ├── EndOfOptionsHandler.java │ ├── OptionHandlerFactory.java │ └── OptionHandlerUtil.java ├── mini-git-server-util-ssl ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── google │ └── gerrit │ └── util │ └── ssl │ └── BlindSSLSocketFactory.java ├── mini-git-server-war ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── google │ │ └── gerrit │ │ └── httpd │ │ └── WebAppInitializer.java │ ├── resources │ └── log4j.properties │ └── webapp │ ├── WEB-INF │ ├── extra │ │ └── jetty7 │ │ │ ├── gerrit-jetty.sh │ │ │ ├── gerrit.xml │ │ │ └── jetty_sslproxy.xml │ └── web.xml │ ├── favicon.ico │ └── robots.txt └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | /.settings/org.eclipse.jdt.core.prefs 4 | /.settings/org.maven.ide.eclipse.prefs 5 | /test_site 6 | target 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mini-git-server 2 | =============== 3 | 4 | Pure-Java WAR capable of hosting git repos and exposing them with git+ssh. 5 | Basically a copy of Gerrit (http://code.google.com/p/gerrit/) - with all the review-related 6 | functionality stripped away and the dependency on a database removed (making it entirely filesystem based). 7 | 8 | I use it for integration-testing my git client. 9 | 10 | Just as with Gerrit, the location of the server site is passed to the war using the 'gerrit.site_path' system 11 | property (will probably rename that at some point), and the format of the directory structure and the 12 | [gerrit.site_path]/etc/gerrit.config file is just the same. My gerrit.config file is just: 13 | 14 | [gerrit] 15 | basePath = "repos" 16 | 17 | ...and which means the server will expect to find all the repos in [gerrit.site_path]/repos 18 | 19 | -------------------------------------------------------------------------------- /mini-git-server-httpd/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-httpd/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-httpd/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-httpd/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-httpd/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | com.madgag 22 | mini-git-server-parent 23 | 0.5-SNAPSHOT 24 | 25 | 26 | mini-git-server-httpd 27 | mini-git-server - HTTPd 28 | 29 | 30 | Servlet context for components run inside of an HTTP environment. 31 | 32 | 33 | 34 | 35 | org.apache.tomcat 36 | servlet-api 37 | provided 38 | 39 | 40 | 41 | com.google.code.findbugs 42 | jsr305 43 | 44 | 45 | 46 | com.madgag 47 | org.eclipse.jgit.http.server 48 | 49 | 50 | 51 | com.madgag 52 | org.eclipse.jgit.junit 53 | 54 | 55 | 56 | com.madgag 57 | mini-git-server-server 58 | ${project.version} 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/CookieBase64.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // This code is based heavily on Robert Harder's 16 | // public domain Base64 class, version 2.1. 17 | // 18 | 19 | package com.google.gerrit.httpd; 20 | 21 | /** Base64 encoder which uses a language safe within HTTP cookies. */ 22 | class CookieBase64 { 23 | private static final char[] enc; 24 | 25 | static { 26 | enc = new char[64]; 27 | int o = 0; 28 | o = fill(enc, o, 'a', 'z'); 29 | o = fill(enc, o, 'A', 'Z'); 30 | o = fill(enc, o, '0', '9'); 31 | enc[o++] = '-'; 32 | enc[o++] = '.'; 33 | } 34 | 35 | private static int fill(final char[] out, int o, final char f, final int l) { 36 | for (char c = f; c <= l; c++) 37 | out[o++] = c; 38 | return o; 39 | } 40 | 41 | static String encode(final byte[] in) { 42 | final StringBuilder out = new StringBuilder(in.length * 4 / 3); 43 | final int len2 = in.length - 2; 44 | int d = 0; 45 | for (; d < len2; d += 3) { 46 | encode3to4(out, in, d, 3); 47 | } 48 | if (d < in.length) { 49 | encode3to4(out, in, d, in.length - d); 50 | } 51 | return out.toString(); 52 | } 53 | 54 | private static void encode3to4(final StringBuilder out, final byte[] in, 55 | final int inOffset, final int numSigBytes) { 56 | // 1 2 3 57 | // 01234567890123456789012345678901 Bit position 58 | // --------000000001111111122222222 Array position from threeBytes 59 | // --------| || || || | Six bit groups to index ALPHABET 60 | // >>18 >>12 >> 6 >> 0 Right shift necessary 61 | // 0x3f 0x3f 0x3f Additional AND 62 | 63 | // Create buffer with zero-padding if there are only one or two 64 | // significant bytes passed in the array. 65 | // We have to shift left 24 in order to flush out the 1's that appear 66 | // when Java treats a value as negative that is cast from a byte to an int. 67 | // 68 | int inBuff = ( numSigBytes > 0 ? ((in[ inOffset ] << 24) >>> 8) : 0 ) 69 | | ( numSigBytes > 1 ? ((in[ inOffset + 1 ] << 24) >>> 16) : 0 ) 70 | | ( numSigBytes > 2 ? ((in[ inOffset + 2 ] << 24) >>> 24) : 0 ); 71 | 72 | switch (numSigBytes) { 73 | case 3: 74 | out.append(enc[(inBuff >>> 18)]); 75 | out.append(enc[(inBuff >>> 12) & 0x3f]); 76 | out.append(enc[(inBuff >>> 6) & 0x3f]); 77 | out.append(enc[(inBuff) & 0x3f]); 78 | break; 79 | 80 | case 2: 81 | out.append(enc[(inBuff >>> 18)]); 82 | out.append(enc[(inBuff >>> 12) & 0x3f]); 83 | out.append(enc[(inBuff >>> 6) & 0x3f]); 84 | break; 85 | 86 | case 1: 87 | out.append(enc[(inBuff >>> 18)]); 88 | out.append(enc[(inBuff >>> 12) & 0x3f]); 89 | break; 90 | 91 | default: 92 | break; 93 | } 94 | } 95 | 96 | private CookieBase64() { 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/HttpCanonicalWebUrlProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.server.config.CanonicalWebUrl; 18 | import com.google.gerrit.server.config.CanonicalWebUrlProvider; 19 | import com.google.gerrit.server.config.GerritServerConfig; 20 | import com.google.inject.Inject; 21 | import com.google.inject.OutOfScopeException; 22 | import com.google.inject.Provider; 23 | import com.google.inject.ProvisionException; 24 | 25 | import org.eclipse.jgit.lib.Config; 26 | 27 | import javax.servlet.http.HttpServletRequest; 28 | 29 | /** Sets {@link CanonicalWebUrl} to current HTTP request if not configured. */ 30 | public class HttpCanonicalWebUrlProvider extends CanonicalWebUrlProvider { 31 | private Provider requestProvider; 32 | 33 | @Inject 34 | HttpCanonicalWebUrlProvider(@GerritServerConfig final Config config) { 35 | super(config); 36 | } 37 | 38 | @Inject(optional = true) 39 | public void setHttpServletRequest(final Provider hsr) { 40 | requestProvider = hsr; 41 | } 42 | 43 | @Override 44 | public String get() { 45 | String canonicalUrl = super.get(); 46 | if (canonicalUrl != null) { 47 | return canonicalUrl; 48 | } 49 | 50 | if (requestProvider != null) { 51 | // No canonical URL configured? Maybe we can get a reasonable 52 | // guess from the incoming HTTP request, if we are currently 53 | // inside of an HTTP request scope. 54 | // 55 | final HttpServletRequest req; 56 | try { 57 | req = requestProvider.get(); 58 | } catch (ProvisionException noWeb) { 59 | if (noWeb.getCause() instanceof OutOfScopeException) { 60 | // We can't obtain the request as we are not inside of 61 | // an HTTP request scope. Callers must handle null. 62 | // 63 | return null; 64 | } else { 65 | throw noWeb; 66 | } 67 | } 68 | 69 | final StringBuffer url = req.getRequestURL(); 70 | url.setLength(url.length() - req.getServletPath().length()); 71 | if (url.charAt(url.length() - 1) != '/') { 72 | url.append('/'); 73 | } 74 | return url.toString(); 75 | } 76 | 77 | // We have no way of guessing our HTTP url. 78 | // 79 | return null; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/HttpIdentifiedUserProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.server.CurrentUser; 18 | import com.google.gerrit.server.IdentifiedUser; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Provider; 21 | import com.google.inject.ProvisionException; 22 | import com.google.inject.servlet.RequestScoped; 23 | 24 | @RequestScoped 25 | class HttpIdentifiedUserProvider implements Provider { 26 | private final CurrentUser user; 27 | 28 | @Inject 29 | HttpIdentifiedUserProvider(final CurrentUser u) { 30 | user = u; 31 | } 32 | 33 | @Override 34 | public IdentifiedUser get() { 35 | if (user instanceof IdentifiedUser) { 36 | return (IdentifiedUser) user; 37 | } 38 | throw new ProvisionException("Not signed in, dear fellow."); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/HttpRemotePeerProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Provider; 19 | import com.google.inject.ProvisionException; 20 | import com.google.inject.servlet.RequestScoped; 21 | 22 | import java.net.InetAddress; 23 | import java.net.InetSocketAddress; 24 | import java.net.SocketAddress; 25 | import java.net.UnknownHostException; 26 | 27 | import javax.servlet.http.HttpServletRequest; 28 | 29 | @RequestScoped 30 | class HttpRemotePeerProvider implements Provider { 31 | private final HttpServletRequest req; 32 | 33 | @Inject 34 | HttpRemotePeerProvider(final HttpServletRequest r) { 35 | req = r; 36 | } 37 | 38 | @Override 39 | public SocketAddress get() { 40 | final String addr = req.getRemoteAddr(); 41 | final int port = req.getRemotePort(); 42 | try { 43 | return new InetSocketAddress(InetAddress.getByName(addr), port); 44 | } catch (UnknownHostException e) { 45 | throw new ProvisionException("Cannot get @RemotePeer", e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/RequestCleanupFilter.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.server.RequestCleanup; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Provider; 20 | import com.google.inject.Singleton; 21 | 22 | import java.io.IOException; 23 | 24 | import javax.servlet.Filter; 25 | import javax.servlet.FilterChain; 26 | import javax.servlet.FilterConfig; 27 | import javax.servlet.ServletException; 28 | import javax.servlet.ServletRequest; 29 | import javax.servlet.ServletResponse; 30 | 31 | /** Executes any pending {@link RequestCleanup} at the end of a request. */ 32 | @Singleton 33 | class RequestCleanupFilter implements Filter { 34 | private final Provider cleanup; 35 | 36 | @Inject 37 | RequestCleanupFilter(final Provider r) { 38 | cleanup = r; 39 | } 40 | 41 | @Override 42 | public void init(FilterConfig filterConfig) { 43 | } 44 | 45 | @Override 46 | public void destroy() { 47 | } 48 | 49 | @Override 50 | public void doFilter(final ServletRequest request, 51 | final ServletResponse response, final FilterChain chain) 52 | throws IOException, ServletException { 53 | try { 54 | chain.doFilter(request, response); 55 | } finally { 56 | cleanup.get().run(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/RequireSslFilter.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.server.config.CanonicalWebUrl; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Provider; 20 | import com.google.inject.Singleton; 21 | import com.google.inject.servlet.ServletModule; 22 | 23 | import java.io.IOException; 24 | 25 | import javax.annotation.Nullable; 26 | import javax.servlet.Filter; 27 | import javax.servlet.FilterChain; 28 | import javax.servlet.FilterConfig; 29 | import javax.servlet.ServletException; 30 | import javax.servlet.ServletRequest; 31 | import javax.servlet.ServletResponse; 32 | import javax.servlet.http.HttpServletRequest; 33 | import javax.servlet.http.HttpServletResponse; 34 | 35 | /** Requires the connection to use SSL, redirects if not. */ 36 | @Singleton 37 | class RequireSslFilter implements Filter { 38 | static class Module extends ServletModule { 39 | @Override 40 | protected void configureServlets() { 41 | filter("/*").through(RequireSslFilter.class); 42 | } 43 | } 44 | 45 | private final Provider urlProvider; 46 | 47 | @Inject 48 | RequireSslFilter(@CanonicalWebUrl @Nullable final Provider urlProvider) { 49 | this.urlProvider = urlProvider; 50 | } 51 | 52 | @Override 53 | public void init(FilterConfig filterConfig) { 54 | } 55 | 56 | @Override 57 | public void destroy() { 58 | } 59 | 60 | @Override 61 | public void doFilter(final ServletRequest request, 62 | final ServletResponse response, final FilterChain chain) 63 | throws IOException, ServletException { 64 | final HttpServletRequest req = (HttpServletRequest) request; 65 | final HttpServletResponse rsp = (HttpServletResponse) response; 66 | 67 | if (isSecure(req)) { 68 | chain.doFilter(request, response); 69 | 70 | } else { 71 | // If we wanted SSL, but the user didn't come to us over it, 72 | // force SSL by issuing a protocol redirect. Try to keep the 73 | // name "localhost" in case this is an SSH port tunnel. 74 | // 75 | final String url; 76 | if (isLocalHost(req)) { 77 | final StringBuffer b = req.getRequestURL(); 78 | b.replace(0, b.indexOf(":"), "https"); 79 | url = b.toString(); 80 | 81 | } else { 82 | url = urlProvider.get() + req.getServletPath(); 83 | } 84 | rsp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); 85 | rsp.setHeader("Location", url); 86 | } 87 | } 88 | 89 | private static boolean isSecure(final HttpServletRequest req) { 90 | return "https".equals(req.getScheme()) || req.isSecure(); 91 | } 92 | 93 | private static boolean isLocalHost(final HttpServletRequest req) { 94 | return "localhost".equals(req.getServerName()) 95 | || "127.0.0.1".equals(req.getServerName()); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.httpd.raw.SshInfoServlet; 18 | import com.google.inject.Key; 19 | import com.google.inject.Provider; 20 | import com.google.inject.internal.UniqueAnnotations; 21 | import com.google.inject.servlet.ServletModule; 22 | 23 | import javax.servlet.http.HttpServlet; 24 | import javax.servlet.http.HttpServletRequest; 25 | import javax.servlet.http.HttpServletResponse; 26 | import java.io.IOException; 27 | 28 | import static com.google.inject.Scopes.SINGLETON; 29 | 30 | class UrlModule extends ServletModule { 31 | @Override 32 | protected void configureServlets() { 33 | serve("/ssh_info").with(SshInfoServlet.class); 34 | 35 | serve("/p/*").with(ProjectServlet.class); 36 | 37 | serve("/servlet/*").with(notFound()); 38 | } 39 | 40 | private Key notFound() { 41 | return key(new HttpServlet() { 42 | private static final long serialVersionUID = 1L; 43 | 44 | @Override 45 | protected void doGet(final HttpServletRequest req, 46 | final HttpServletResponse rsp) throws IOException { 47 | rsp.sendError(HttpServletResponse.SC_NOT_FOUND); 48 | } 49 | }); 50 | } 51 | 52 | private Key screen(final String target) { 53 | return key(new HttpServlet() { 54 | private static final long serialVersionUID = 1L; 55 | 56 | @Override 57 | protected void doGet(final HttpServletRequest req, 58 | final HttpServletResponse rsp) throws IOException { 59 | toGerrit(target, req, rsp); 60 | } 61 | }); 62 | } 63 | 64 | private Key legacyGerritScreen() { 65 | return key(new HttpServlet() { 66 | private static final long serialVersionUID = 1L; 67 | 68 | @Override 69 | protected void doGet(final HttpServletRequest req, 70 | final HttpServletResponse rsp) throws IOException { 71 | final String token = req.getPathInfo().substring(1); 72 | toGerrit(token, req, rsp); 73 | } 74 | }); 75 | } 76 | 77 | private Key key(final HttpServlet servlet) { 78 | final Key srv = 79 | Key.get(HttpServlet.class, UniqueAnnotations.create()); 80 | bind(srv).toProvider(new Provider() { 81 | @Override 82 | public HttpServlet get() { 83 | return servlet; 84 | } 85 | }).in(SINGLETON); 86 | return srv; 87 | } 88 | 89 | private void toGerrit(final String target, final HttpServletRequest req, 90 | final HttpServletResponse rsp) throws IOException { 91 | final StringBuilder url = new StringBuilder(); 92 | url.append(req.getContextPath()); 93 | url.append('/'); 94 | url.append('#'); 95 | url.append(target); 96 | rsp.sendRedirect(url.toString()); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd; 16 | 17 | import com.google.gerrit.server.IdentifiedUser; 18 | import com.google.gerrit.server.RemotePeer; 19 | import com.google.gerrit.server.config.CanonicalWebUrl; 20 | import com.google.gerrit.server.config.FactoryModule; 21 | import com.google.gerrit.server.config.GerritRequestModule; 22 | import com.google.gerrit.server.ssh.SshInfo; 23 | import com.google.inject.Inject; 24 | import com.google.inject.Injector; 25 | import com.google.inject.Provider; 26 | import com.google.inject.servlet.RequestScoped; 27 | import com.google.inject.servlet.ServletModule; 28 | 29 | import javax.annotation.Nullable; 30 | import java.net.SocketAddress; 31 | 32 | public class WebModule extends FactoryModule { 33 | private final Provider sshInfoProvider; 34 | private final boolean wantSSL; 35 | 36 | @Inject 37 | WebModule(final Provider sshInfoProvider, 38 | @CanonicalWebUrl @Nullable final String canonicalUrl, 39 | final Injector creatingInjector) { 40 | this.sshInfoProvider = sshInfoProvider; 41 | this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:"); 42 | } 43 | 44 | @Override 45 | protected void configure() { 46 | install(new ServletModule() { 47 | @Override 48 | protected void configureServlets() { 49 | filter("/*").through(RequestCleanupFilter.class); 50 | } 51 | }); 52 | 53 | if (wantSSL) { 54 | install(new RequireSslFilter.Module()); 55 | } 56 | 57 | install(new UrlModule()); 58 | install(new GerritRequestModule()); 59 | install(new ProjectServlet.Module()); 60 | 61 | bind(SshInfo.class).toProvider(sshInfoProvider); 62 | 63 | bind(SocketAddress.class).annotatedWith(RemotePeer.class).toProvider( 64 | HttpRemotePeerProvider.class).in(RequestScoped.class); 65 | 66 | bind(IdentifiedUser.class).toProvider(HttpIdentifiedUserProvider.class).in( 67 | RequestScoped.class); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/java/com/google/gerrit/httpd/raw/SshInfoServlet.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.httpd.raw; 16 | 17 | import com.google.gerrit.server.ssh.SshInfo; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Singleton; 20 | 21 | import com.jcraft.jsch.HostKey; 22 | 23 | import java.io.IOException; 24 | import java.io.PrintWriter; 25 | import java.util.List; 26 | 27 | import javax.servlet.http.HttpServlet; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | /** 32 | * Servlet hosting an SSH daemon on another port. During a standard HTTP GET 33 | * request the servlet returns the hostname and port number back to the client 34 | * in the form ${host} ${port}. 35 | *

36 | * Use a Git URL such as ssh://${email}@${host}:${port}/${path}, 37 | * e.g. ssh://sop@google.com@gerrit.com:8010/tools/gerrit.git to 38 | * access the SSH daemon itself. 39 | *

40 | * Versions of Git before 1.5.3 may require setting the username and port 41 | * properties in the user's ~/.ssh/config file, and using a host 42 | * alias through a URL such as gerrit-alias:/tools/gerrit.git: 43 | *

 44 |  * Host gerrit-alias
 45 |  *  User sop@google.com
 46 |  *  Hostname gerrit.com
 47 |  *  Port 8010
 48 |  * 
49 | */ 50 | @SuppressWarnings("serial") 51 | @Singleton 52 | public class SshInfoServlet extends HttpServlet { 53 | private final SshInfo sshd; 54 | 55 | @Inject 56 | SshInfoServlet(final SshInfo daemon) { 57 | sshd = daemon; 58 | } 59 | 60 | @Override 61 | protected void doGet(final HttpServletRequest req, 62 | final HttpServletResponse rsp) throws IOException { 63 | rsp.setHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT"); 64 | rsp.setHeader("Pragma", "no-cache"); 65 | rsp.setHeader("Cache-Control", "no-cache, must-revalidate"); 66 | 67 | final List hostKeys = sshd.getHostKeys(); 68 | final String out; 69 | if (!hostKeys.isEmpty()) { 70 | String host = hostKeys.get(0).getHost(); 71 | String port = "22"; 72 | 73 | if (host.contains(":")) { 74 | final int p = host.lastIndexOf(':'); 75 | port = host.substring(p + 1); 76 | host = host.substring(0, p); 77 | } 78 | 79 | if (host.equals("*")) { 80 | host = req.getServerName(); 81 | 82 | } else if (host.startsWith("[") && host.endsWith("]")) { 83 | host = host.substring(1, host.length() - 1); 84 | } 85 | 86 | out = host + " " + port; 87 | } else { 88 | out = "NOT_AVAILABLE"; 89 | } 90 | 91 | rsp.setCharacterEncoding("UTF-8"); 92 | rsp.setContentType("text/plain"); 93 | final PrintWriter w = rsp.getWriter(); 94 | try { 95 | w.write(out); 96 | } finally { 97 | w.close(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/resources/com/google/gerrit/httpd/auth/become/BecomeAnyAccount.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gerrit Code Review 4 | 32 | 33 | 34 |

Sign In

35 | 36 | 37 | 38 | 44 | 45 | 46 | 47 | 48 | 54 | 55 | 56 | 57 | 58 | 64 | 65 |
Username: 39 |
40 | 41 | 42 |
43 |
Email Address: 49 |
50 | 51 | 52 |
53 |
Account ID: 59 |
60 | 61 | 62 |
63 |
66 | 67 |
68 |

Register

69 |
70 | 71 | 72 |
73 | 74 | 75 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/resources/com/google/gerrit/httpd/auth/container/ConfigurationError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Configuration Error - Gerrit Code Review 4 | 30 | 31 | 32 |

Configuration Error

33 |
34 | Check the HTTP server's authentication settings. 35 |
36 | 37 |

38 | The HTTP server did not provide the username in the 39 | HEADER header when it 40 | forwarded the request to Gerrit Code Review. 41 |

42 | 43 |

44 | If the HTTP server is Apache HTTPd, check the proxy 45 | configuration includes an authorization directive with 46 | the proper location, ensuring it ends with '/': 47 |

48 |
49 | <VirtualHost review.example.com:80>
50 |     ServerName review.example.com
51 | 
52 |     ProxyRequests Off
53 |     ProxyVia Off
54 |     ProxyPreserveHost On
55 | 
56 |     <Proxy *>
57 |           Order deny,allow
58 |           Allow from all
59 |     </Proxy>
60 | 
61 | 
<Location /r/login/> 62 | AuthType Basic 63 | AuthName "Gerrit Code Review" 64 | Require valid-user 65 | ... 66 | </Location>
67 | ProxyPass /r/ http://.../r/ 68 | </VirtualHost> 69 |
70 | 71 | 72 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/resources/com/google/gerrit/httpd/auth/container/LoginRedirect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Gerrit Code Review 5 | 17 | 18 | 19 |

Redirecting to Gerrit Code Review.

20 | 21 | 22 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/resources/com/google/gerrit/httpd/raw/HostPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gerrit Code Review 4 | 5 | 33 | 34 | 35 | 36 | 37 | 38 |
39 |
40 |
41 |

Loading Gerrit Code Review ...

42 | 45 |
46 |
47 |
48 | 49 |
50 |
51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /mini-git-server-httpd/src/main/resources/com/google/gerrit/httpd/raw/LegacyGerrit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Gerrit Code Review 5 | 23 | 24 | 25 |

Redirecting to Gerrit Code Review.

26 | 27 | 28 | -------------------------------------------------------------------------------- /mini-git-server-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-server/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-server/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-server/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/common/CollectionsUtil.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License 14 | 15 | package com.google.gerrit.common; 16 | 17 | import java.util.Collection; 18 | 19 | /** Utilities for manipulating Collections . */ 20 | public class CollectionsUtil { 21 | /** 22 | * Checks if any of the elements in the first collection can be found in the 23 | * second collection. 24 | * 25 | * @param findAnyOfThese which elements to look for. 26 | * @param inThisCollection where to look for them. 27 | * @param type of the elements in question. 28 | * @return {@code true} if any of the elements in {@code findAnyOfThese} can 29 | * be found in {@code inThisCollection}, {@code false} otherwise. 30 | */ 31 | public static boolean isAnyIncludedIn(Collection findAnyOfThese, 32 | Collection inThisCollection) { 33 | for (E findThisItem : findAnyOfThese) { 34 | if (inThisCollection.contains(findThisItem)) { 35 | return true; 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | private CollectionsUtil() { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/common/Version.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.common; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.InputStreamReader; 21 | 22 | public class Version { 23 | private static final String version; 24 | 25 | public static String getVersion() { 26 | return version; 27 | } 28 | 29 | static { 30 | version = loadVersion(); 31 | } 32 | 33 | private static String loadVersion() { 34 | InputStream in = Version.class.getResourceAsStream("Version"); 35 | if (in == null) { 36 | return null; 37 | } 38 | try { 39 | BufferedReader r = new BufferedReader(new InputStreamReader(in, "UTF-8")); 40 | try { 41 | String vs = r.readLine(); 42 | if (vs != null && vs.startsWith("v")) { 43 | vs = vs.substring(1); 44 | } 45 | if (vs != null && vs.isEmpty()) { 46 | vs = null; 47 | } 48 | return vs; 49 | } finally { 50 | r.close(); 51 | } 52 | } catch (IOException e) { 53 | return null; 54 | } 55 | } 56 | 57 | private Version() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/lifecycle/LifecycleListener.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.lifecycle; 16 | 17 | import java.util.EventListener; 18 | 19 | /** Listener interested in server startup and shutdown events. */ 20 | public interface LifecycleListener extends EventListener { 21 | /** Invoke when the server is starting. */ 22 | public void start(); 23 | 24 | /** Invoked when the server is stopping. */ 25 | public void stop(); 26 | } 27 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/lifecycle/LifecycleManager.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.lifecycle; 16 | 17 | import com.google.inject.Binding; 18 | import com.google.inject.Injector; 19 | import com.google.inject.TypeLiteral; 20 | 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.util.ArrayList; 24 | import java.util.LinkedHashMap; 25 | import java.util.List; 26 | 27 | /** Tracks and executes registered {@link LifecycleListener}s. */ 28 | public class LifecycleManager { 29 | private final LinkedHashMap listeners = 30 | new LinkedHashMap(); 31 | 32 | private boolean started; 33 | 34 | /** Add a single listener. */ 35 | public void add(final LifecycleListener listener) { 36 | listeners.put(listener, true); 37 | } 38 | 39 | /** Add all {@link LifecycleListener}s registered in the Injector. */ 40 | public void add(final Injector injector) { 41 | if (started) { 42 | throw new IllegalStateException("Already started"); 43 | } 44 | for (final Binding binding : get(injector)) { 45 | add(binding.getProvider().get()); 46 | } 47 | } 48 | 49 | /** Add all {@link LifecycleListener}s registered in the Injectors. */ 50 | public void add(final Injector... injectors) { 51 | for (final Injector i : injectors) { 52 | add(i); 53 | } 54 | } 55 | 56 | /** Start all listeners, in the order they were registered. */ 57 | public void start() { 58 | if (!started) { 59 | started = true; 60 | for (LifecycleListener obj : listeners.keySet()) { 61 | obj.start(); 62 | } 63 | } 64 | } 65 | 66 | /** Stop all listeners, in the reverse order they were registered. */ 67 | public void stop() { 68 | if (started) { 69 | final List t = 70 | new ArrayList(listeners.keySet()); 71 | 72 | for (int i = t.size() - 1; 0 <= i; i--) { 73 | final LifecycleListener obj = t.get(i); 74 | try { 75 | obj.stop(); 76 | } catch (Throwable err) { 77 | LoggerFactory.getLogger(obj.getClass()).warn("Failed to stop", err); 78 | } 79 | } 80 | 81 | started = false; 82 | } 83 | } 84 | 85 | private static List> get(Injector i) { 86 | return i.findBindingsByType(new TypeLiteral() {}); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/lifecycle/LifecycleModule.java: -------------------------------------------------------------------------------- 1 | package com.google.gerrit.lifecycle; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Singleton; 5 | import com.google.inject.binder.LinkedBindingBuilder; 6 | import com.google.inject.internal.UniqueAnnotations; 7 | 8 | import java.lang.annotation.Annotation; 9 | 10 | /** Module to support registering a unique LifecyleListener. */ 11 | public abstract class LifecycleModule extends AbstractModule { 12 | /** 13 | * Create a unique listener binding. 14 | *

15 | * To create a listener binding use: 16 | * 17 | *

18 |    * listener().to(MyListener.class);
19 |    * 
20 | * 21 | * where {@code MyListener} is a {@link Singleton} implementing the 22 | * {@link LifecycleListener} interface. 23 | */ 24 | protected LinkedBindingBuilder listener() { 25 | final Annotation id = UniqueAnnotations.create(); 26 | return bind(LifecycleListener.class).annotatedWith(id); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/AccessPath.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | /** How the {@link CurrentUser} is accessing Gerrit. */ 18 | public enum AccessPath { 19 | /** An unknown access path, probably should not be special. */ 20 | UNKNOWN, 21 | 22 | /** Access through the web UI. */ 23 | WEB_UI, 24 | 25 | /** Access through an SSH command that is not invoked by Git. */ 26 | SSH_COMMAND, 27 | 28 | /** Access from a Git client using any Git protocol. */ 29 | GIT, 30 | 31 | /** Access through replication */ 32 | REPLICATION; 33 | } 34 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/AnonymousUser.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Singleton; 19 | 20 | /** An anonymous user who has not yet authenticated. */ 21 | @Singleton 22 | public class AnonymousUser extends CurrentUser { 23 | 24 | @Override 25 | public String toString() { 26 | return "ANONYMOUS"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/CurrentUser.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import com.google.inject.servlet.RequestScoped; 18 | 19 | /** 20 | * Information about the currently logged in user. 21 | *

22 | * This is a {@link RequestScoped} property managed by Guice. 23 | * 24 | * @see AnonymousUser 25 | * @see IdentifiedUser 26 | */ 27 | public abstract class CurrentUser { 28 | 29 | @Deprecated 30 | public final boolean isAdministrator() { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/GerritPersonIdent.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | 23 | /** 24 | * Marker on a {@link org.eclipse.jgit.lib.PersonIdent} pointing to the identity representing Gerrit 25 | * server itself. 26 | */ 27 | @Retention(RUNTIME) 28 | @BindingAnnotation 29 | public @interface GerritPersonIdent { 30 | } 31 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/GerritPersonIdentProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import com.google.gerrit.server.config.GerritServerConfig; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Provider; 20 | import com.google.inject.Singleton; 21 | 22 | import org.eclipse.jgit.lib.Config; 23 | import org.eclipse.jgit.lib.PersonIdent; 24 | import org.eclipse.jgit.lib.UserConfig; 25 | 26 | /** Provides {@link PersonIdent} annotated with {@link GerritPersonIdent}. */ 27 | @Singleton 28 | public class GerritPersonIdentProvider implements Provider { 29 | private final String name; 30 | private final String email; 31 | 32 | @Inject 33 | public GerritPersonIdentProvider(@GerritServerConfig final Config cfg) { 34 | String name = cfg.getString("user", null, "name"); 35 | if (name == null) { 36 | name = "Gerrit Code Review"; 37 | } 38 | this.name = name; 39 | email = cfg.get(UserConfig.KEY).getCommitterEmail(); 40 | } 41 | 42 | @Override 43 | public PersonIdent get() { 44 | return new PersonIdent(name, email); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/IdentifiedUser.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import com.google.gerrit.server.config.CanonicalWebUrl; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Provider; 20 | import com.google.inject.Singleton; 21 | 22 | import org.eclipse.jgit.lib.PersonIdent; 23 | import org.eclipse.jgit.util.SystemReader; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.net.InetAddress; 28 | import java.net.InetSocketAddress; 29 | import java.net.MalformedURLException; 30 | import java.net.SocketAddress; 31 | import java.net.URL; 32 | import java.util.Date; 33 | import java.util.TimeZone; 34 | 35 | /** An authenticated user. */ 36 | public class IdentifiedUser extends CurrentUser { 37 | private final String username; 38 | 39 | /** Create an IdentifiedUser, ignoring any per-request state. */ 40 | @Singleton 41 | public static class GenericFactory { 42 | public IdentifiedUser create(String username) { 43 | return new IdentifiedUser(username); 44 | } 45 | } 46 | 47 | private static final Logger log = 48 | LoggerFactory.getLogger(IdentifiedUser.class); 49 | 50 | private IdentifiedUser(String username) { 51 | this.username = username; 52 | } 53 | 54 | /** @return the user's user name; null if one has not been selected/assigned. */ 55 | public String getUserName() { 56 | return username; 57 | } 58 | 59 | public PersonIdent newRefLogIdent() { 60 | return newRefLogIdent(new Date(), TimeZone.getDefault()); 61 | } 62 | 63 | public PersonIdent newRefLogIdent(final Date when, final TimeZone tz) { 64 | String user = getUserName(); 65 | 66 | String host = "unknown"; 67 | 68 | return new PersonIdent(user, user + "@" + host, when, tz); 69 | } 70 | 71 | public PersonIdent newCommitterIdent(final Date when, final TimeZone tz) { 72 | 73 | String user = getUserName(); 74 | 75 | String host= "unknown"; 76 | 77 | String email = user + "@" + host; 78 | 79 | return new PersonIdent(user, email, when, tz); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "IdentifiedUser[" + getUserName() + "]"; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/RemotePeer.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.net.SocketAddress; 23 | 24 | /** Marker on a {@link SocketAddress} pointing to the remote client. */ 25 | @Retention(RUNTIME) 26 | @BindingAnnotation 27 | public @interface RemotePeer { 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/RequestCleanup.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server; 16 | 17 | import com.google.inject.servlet.RequestScoped; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.util.Iterator; 23 | import java.util.LinkedList; 24 | import java.util.List; 25 | 26 | 27 | /** 28 | * Registers cleanup activities to be completed when a scope ends. 29 | */ 30 | @RequestScoped 31 | public class RequestCleanup implements Runnable { 32 | private static final Logger log = 33 | LoggerFactory.getLogger(RequestCleanup.class); 34 | 35 | private final List cleanup = new LinkedList(); 36 | 37 | /** Register a task to be completed after the request ends. */ 38 | public void add(final Runnable task) { 39 | synchronized (cleanup) { 40 | cleanup.add(task); 41 | } 42 | } 43 | 44 | public void run() { 45 | synchronized (cleanup) { 46 | for (final Iterator i = cleanup.iterator(); i.hasNext();) { 47 | try { 48 | i.next().run(); 49 | } catch (Throwable err) { 50 | log.error("Failed to execute per-request cleanup", err); 51 | } 52 | i.remove(); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/UrlEncoded.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | package com.google.gerrit.server; 17 | 18 | import java.io.UnsupportedEncodingException; 19 | import java.net.URLEncoder; 20 | import java.util.LinkedHashMap; 21 | import java.util.Map; 22 | 23 | public class UrlEncoded extends LinkedHashMap { 24 | private static final long serialVersionUID = 1L; 25 | 26 | private String url; 27 | 28 | public UrlEncoded() { 29 | } 30 | 31 | public UrlEncoded(final String url) { 32 | this.url = url; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | final StringBuilder buffer = new StringBuilder(); 38 | char separator = 0; 39 | if (url != null) { 40 | separator = '?'; 41 | buffer.append(url); 42 | } 43 | for (final Map.Entry entry : entrySet()) { 44 | final String key = entry.getKey(); 45 | final String val = entry.getValue(); 46 | if (separator != 0) { 47 | buffer.append(separator); 48 | } 49 | buffer.append(encode(key)); 50 | buffer.append('='); 51 | if (val != null) { 52 | buffer.append(encode(val)); 53 | } 54 | separator = '&'; 55 | } 56 | return buffer.toString(); 57 | } 58 | 59 | private static String encode(final String str) { 60 | try { 61 | return URLEncoder.encode(str, "UTF-8"); 62 | } catch (UnsupportedEncodingException e) { 63 | throw new RuntimeException(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/account/AccountException.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.account; 16 | 17 | /** An account processing error thrown by {@link AccountManager}. */ 18 | public class AccountException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public AccountException(final String message) { 22 | super(message); 23 | } 24 | 25 | public AccountException(final String message, final Throwable why) { 26 | super(message, why); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/account/AccountUserNameException.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.account; 16 | 17 | /** 18 | * Thrown by {@link AccountManager} if the user name for a newly created account 19 | * could not be set and the realm does not allow the user to set a user name 20 | * manually. 21 | */ 22 | public class AccountUserNameException extends AccountException { 23 | private static final long serialVersionUID = 1L; 24 | 25 | public AccountUserNameException(final String message, final Throwable why) { 26 | super(message, why); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/Cache.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | 20 | /** 21 | * A fast in-memory and/or on-disk based cache. 22 | * 23 | * @type type of key used to lookup entries in the cache. 24 | * @type type of value stored within each cache entry. 25 | */ 26 | public interface Cache { 27 | /** Get the element from the cache, or null if not stored in the cache. */ 28 | public V get(K key); 29 | 30 | /** Put one element into the cache, replacing any existing value. */ 31 | public void put(K key, V value); 32 | 33 | /** Remove any existing value from the cache, no-op if not present. */ 34 | public void remove(K key); 35 | 36 | /** Remove all cached items. */ 37 | public void removeAll(); 38 | 39 | /** 40 | * Get the time an element will survive in the cache. 41 | * 42 | * @param unit desired units of the return value. 43 | * @return time an item can live before being purged. 44 | */ 45 | public long getTimeToLive(TimeUnit unit); 46 | } 47 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/EntryCreator.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | /** 18 | * Creates a cache entry on demand when its not found. 19 | * 20 | * @param type of the cache's key. 21 | * @param type of the cache's value element. 22 | */ 23 | public abstract class EntryCreator { 24 | /** 25 | * Invoked on a cache miss, to compute the cache entry. 26 | * 27 | * @param key entry whose content needs to be obtained. 28 | * @return new cache content. The caller will automatically put this object 29 | * into the cache. 30 | * @throws Exception the cache content cannot be computed. No entry will be 31 | * stored in the cache, and {@link #missing(Object)} will be invoked 32 | * instead. Future requests for the same key will retry this method. 33 | */ 34 | public abstract V createEntry(K key) throws Exception; 35 | 36 | /** Invoked when {@link #createEntry(Object)} fails, by default return null. */ 37 | public V missing(K key) { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/EvictionPolicy.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | /** How entries should be evicted from the cache. */ 18 | public enum EvictionPolicy { 19 | /** Least recently used is evicted first. */ 20 | LRU, 21 | 22 | /** Least frequently used is evicted first. */ 23 | LFU; 24 | } 25 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/NamedCacheBinding.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | /** Configure a cache declared within a {@link CacheModule} instance. */ 20 | public interface NamedCacheBinding { 21 | /** Set the number of objects to cache in memory. */ 22 | public NamedCacheBinding memoryLimit(int objects); 23 | 24 | /** Set the number of objects to cache in memory. */ 25 | public NamedCacheBinding diskLimit(int objects); 26 | 27 | /** Set the time an element lives before being expired. */ 28 | public NamedCacheBinding maxAge(long duration, TimeUnit durationUnits); 29 | 30 | /** Set the eviction policy for elements when the cache is full. */ 31 | public NamedCacheBinding evictionPolicy(EvictionPolicy policy); 32 | 33 | /** Populate the cache with items from the EntryCreator. */ 34 | public NamedCacheBinding populateWith(Class> creator); 35 | } 36 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/SimpleCache.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | import static java.util.concurrent.TimeUnit.SECONDS; 18 | 19 | import net.sf.ehcache.CacheException; 20 | import net.sf.ehcache.Ehcache; 21 | import net.sf.ehcache.Element; 22 | 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import java.util.concurrent.TimeUnit; 27 | 28 | /** 29 | * A fast in-memory and/or on-disk based cache. 30 | * 31 | * @type type of key used to lookup entries in the cache. 32 | * @type type of value stored within each cache entry. 33 | */ 34 | final class SimpleCache implements Cache { 35 | private static final Logger log = LoggerFactory.getLogger(SimpleCache.class); 36 | 37 | private final Ehcache self; 38 | 39 | SimpleCache(final Ehcache self) { 40 | this.self = self; 41 | } 42 | 43 | Ehcache getEhcache() { 44 | return self; 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | public V get(final K key) { 49 | if (key == null) { 50 | return null; 51 | } 52 | final Element m; 53 | try { 54 | m = self.get(key); 55 | } catch (IllegalStateException err) { 56 | log.error("Cannot lookup " + key + " in \"" + self.getName() + "\"", err); 57 | return null; 58 | } catch (CacheException err) { 59 | log.error("Cannot lookup " + key + " in \"" + self.getName() + "\"", err); 60 | return null; 61 | } 62 | return m != null ? (V) m.getObjectValue() : null; 63 | } 64 | 65 | public void put(final K key, final V value) { 66 | self.put(new Element(key, value)); 67 | } 68 | 69 | public void remove(final K key) { 70 | if (key != null) { 71 | self.remove(key); 72 | } 73 | } 74 | 75 | public void removeAll() { 76 | self.removeAll(); 77 | } 78 | 79 | @Override 80 | public long getTimeToLive(final TimeUnit unit) { 81 | final long maxAge = self.getCacheConfiguration().getTimeToLiveSeconds(); 82 | return unit.convert(maxAge, SECONDS); 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Cache[" + self.getName() + "]"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/cache/UnnamedCacheBinding.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.cache; 16 | 17 | 18 | /** Configure a cache declared within a {@link CacheModule} instance. */ 19 | public interface UnnamedCacheBinding { 20 | /** Set the name of the cache. */ 21 | public NamedCacheBinding name(String cacheName); 22 | } 23 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/CanonicalWebUrl.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | 23 | /** 24 | * Marker on a {@link String} holding the canonical address for this server. 25 | *

26 | * Note that the String may be null, if the administrator has not configured the 27 | * value and we are not in an HTTP request where the URL can be guessed from the 28 | * request state. Clients must handle such cases explicitly. 29 | */ 30 | @Retention(RUNTIME) 31 | @BindingAnnotation 32 | public @interface CanonicalWebUrl { 33 | } 34 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/CanonicalWebUrlModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static com.google.inject.Scopes.SINGLETON; 18 | 19 | import com.google.inject.AbstractModule; 20 | import com.google.inject.Provider; 21 | 22 | /** Supports binding the {@link CanonicalWebUrl} annotation. */ 23 | public abstract class CanonicalWebUrlModule extends AbstractModule { 24 | @Override 25 | protected void configure() { 26 | // Note that the CanonicalWebUrl itself must not be a singleton, but its 27 | // provider must be. 28 | // 29 | // If the value was not configured in the system configuration data the 30 | // provider may try to guess it from the current HTTP request, if we are 31 | // running in an HTTP environment. 32 | // 33 | final Class> provider = provider(); 34 | bind(provider).in(SINGLETON); 35 | bind(String.class).annotatedWith(CanonicalWebUrl.class) 36 | .toProvider(provider); 37 | } 38 | 39 | protected abstract Class> provider(); 40 | } 41 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/CanonicalWebUrlProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Provider; 19 | 20 | import org.eclipse.jgit.lib.Config; 21 | 22 | /** Provides {@link CanonicalWebUrl} from {@code gerrit.canonicalWebUrl}. */ 23 | public class CanonicalWebUrlProvider implements Provider { 24 | private final String canonicalUrl; 25 | 26 | @Inject 27 | public CanonicalWebUrlProvider(@GerritServerConfig final Config config) { 28 | String u = config.getString("gerrit", null, "canonicalweburl"); 29 | if (u != null && !u.endsWith("/")) { 30 | u += "/"; 31 | } 32 | canonicalUrl = u; 33 | } 34 | 35 | @Override 36 | public String get() { 37 | return canonicalUrl; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/FactoryModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.inject.AbstractModule; 18 | import com.google.inject.Key; 19 | import com.google.inject.assistedinject.FactoryProvider; 20 | 21 | import java.lang.reflect.Method; 22 | import java.lang.reflect.Modifier; 23 | 24 | public abstract class FactoryModule extends AbstractModule { 25 | /** 26 | * Register an assisted injection factory. 27 | *

28 | * This function provides an automatic way to define a factory that creates a 29 | * concrete type through assisted injection. For example to configure the 30 | * following assisted injection case: 31 | * 32 | *

 33 |    * public class Foo {
 34 |    *   public interface Factory {
 35 |    *     Foo create(int a);
 36 |    *   }
 37 |    *   @Inject
 38 |    *   Foo(Logger log, @Assisted int a) {...}
 39 |    * }
 40 |    * 
41 | * 42 | * Just pass {@code Foo.Factory.class} to this method. The factory will be 43 | * generated to return its one return type as declared in the creation method. 44 | * 45 | * @param 46 | * @param factory interface which specifies the bean factory method. 47 | */ 48 | protected void factory(final Class factory) { 49 | factory(Key.get(factory), factory); 50 | } 51 | 52 | /** 53 | * Register an assisted injection factory. 54 | *

55 | * This function provides an automatic way to define a factory that creates a 56 | * concrete type through assited injection. For example to configure the 57 | * following assisted injection case: 58 | * 59 | *

 60 |    * public class Foo {
 61 |    *   public interface Factory {
 62 |    *     Foo create(int a);
 63 |    *   }
 64 |    *   @Inject
 65 |    *   Foo(Logger log, @Assisted int a) {...}
 66 |    * }
 67 |    * 
68 | * 69 | * Just pass {@code Foo.Factory.class} to this method. The factory will be 70 | * generated to return its one return type as declared in the creation method. 71 | * 72 | * @param 73 | * @param key key to bind with in Guice bindings. 74 | * @param factory interface which specifies the bean factory method. 75 | */ 76 | protected void factory(final Key key, final Class factory) { 77 | final Method[] methods = factory.getDeclaredMethods(); 78 | switch (methods.length) { 79 | case 1: { 80 | final Class result = methods[0].getReturnType(); 81 | if (isAbstract(result)) { 82 | addError("Factory " + factory.getName() + " returns abstract result."); 83 | } else { 84 | bind(key).toProvider(FactoryProvider.newFactory(factory, result)); 85 | } 86 | break; 87 | } 88 | 89 | case 0: 90 | addError("Factory " + factory.getName() + " has no create method."); 91 | break; 92 | 93 | default: 94 | addError("Factory " + factory.getName() 95 | + " has more than one create method."); 96 | break; 97 | } 98 | } 99 | 100 | private static boolean isAbstract(final Class result) { 101 | return result.isInterface() 102 | || (result.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.gerrit.lifecycle.LifecycleListener; 18 | import com.google.gerrit.lifecycle.LifecycleModule; 19 | import com.google.gerrit.server.AnonymousUser; 20 | import com.google.gerrit.server.GerritPersonIdent; 21 | import com.google.gerrit.server.GerritPersonIdentProvider; 22 | import com.google.gerrit.server.IdentifiedUser; 23 | import com.google.gerrit.server.cache.CachePool; 24 | import com.google.gerrit.server.git.GitRepositoryManager; 25 | import com.google.gerrit.server.git.LocalDiskRepositoryManager; 26 | import com.google.gerrit.server.git.TransferConfig; 27 | import com.google.gerrit.server.git.WorkQueue; 28 | import com.google.gerrit.server.util.IdGenerator; 29 | import com.google.inject.Inject; 30 | import org.apache.velocity.app.Velocity; 31 | import org.apache.velocity.runtime.RuntimeConstants; 32 | import org.eclipse.jgit.lib.Config; 33 | import org.eclipse.jgit.lib.PersonIdent; 34 | 35 | import java.util.Properties; 36 | 37 | import static com.google.inject.Scopes.SINGLETON; 38 | 39 | 40 | /** Starts global state with standard dependencies. */ 41 | public class GerritGlobalModule extends FactoryModule { 42 | 43 | public static class VelocityLifecycle implements LifecycleListener { 44 | private final SitePaths site; 45 | 46 | @Inject 47 | VelocityLifecycle(final SitePaths site) { 48 | this.site = site; 49 | } 50 | 51 | @Override 52 | public void start() { 53 | String rl = "resource.loader"; 54 | String pkg = "org.apache.velocity.runtime.resource.loader"; 55 | Properties p = new Properties(); 56 | 57 | p.setProperty(rl, "file, class"); 58 | p.setProperty("file." + rl + ".class", pkg + ".FileResourceLoader"); 59 | p.setProperty("file." + rl + ".path", site.mail_dir.getAbsolutePath()); 60 | p.setProperty("class." + rl + ".class", pkg + ".ClasspathResourceLoader"); 61 | p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, 62 | "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" ); 63 | p.setProperty("runtime.log.logsystem.log4j.category", "velocity"); 64 | 65 | try { 66 | Velocity.init(p); 67 | } catch(Exception e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | 72 | @Override 73 | public void stop() { 74 | } 75 | } 76 | 77 | @Inject 78 | GerritGlobalModule(@GerritServerConfig final Config config) { 79 | } 80 | 81 | @Override 82 | protected void configure() { 83 | 84 | bind(AnonymousUser.class); 85 | 86 | bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toProvider( 87 | GerritPersonIdentProvider.class); 88 | 89 | bind(IdGenerator.class); 90 | bind(CachePool.class); 91 | // install(ProjectCacheImpl.module()); 92 | 93 | bind(GitRepositoryManager.class).to(LocalDiskRepositoryManager.class); 94 | bind(WorkQueue.class); 95 | bind(TransferConfig.class); 96 | 97 | bind(IdentifiedUser.GenericFactory.class).in(SINGLETON); 98 | 99 | install(new LifecycleModule() { 100 | @Override 101 | protected void configure() { 102 | listener().to(LocalDiskRepositoryManager.Lifecycle.class); 103 | listener().to(CachePool.Lifecycle.class); 104 | listener().to(WorkQueue.Lifecycle.class); 105 | listener().to(VelocityLifecycle.class); 106 | } 107 | }); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.gerrit.server.IdentifiedUser; 18 | import com.google.gerrit.server.RequestCleanup; 19 | import com.google.inject.servlet.RequestScoped; 20 | 21 | import static com.google.inject.Scopes.SINGLETON; 22 | 23 | /** Bindings for {@link RequestScoped} entities. */ 24 | public class GerritRequestModule extends FactoryModule { 25 | @Override 26 | protected void configure() { 27 | bind(RequestCleanup.class).in(RequestScoped.class); 28 | //bind(IdentifiedUser.RequestFactory.class).in(SINGLETON); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/GerritServerConfig.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | 23 | /** 24 | * Marker on {@link org.eclipse.jgit.lib.Config} holding {@code gerrit.config} . 25 | *

26 | * The {@code gerrit.config} file contains almost all site-wide configuration 27 | * settings for the Gerrit Code Review server. 28 | */ 29 | @Retention(RUNTIME) 30 | @BindingAnnotation 31 | public @interface GerritServerConfig { 32 | } 33 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/GerritServerConfigModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static com.google.inject.Scopes.SINGLETON; 18 | 19 | import com.google.inject.AbstractModule; 20 | 21 | import org.eclipse.jgit.lib.Config; 22 | 23 | /** Creates {@link GerritServerConfig}. */ 24 | public class GerritServerConfigModule extends AbstractModule { 25 | @Override 26 | protected void configure() { 27 | bind(SitePaths.class); 28 | bind(Config.class).annotatedWith(GerritServerConfig.class).toProvider( 29 | GerritServerConfigProvider.class).in(SINGLETON); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/GerritServerConfigProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Provider; 19 | import com.google.inject.ProvisionException; 20 | 21 | import org.eclipse.jgit.errors.ConfigInvalidException; 22 | import org.eclipse.jgit.lib.Config; 23 | import org.eclipse.jgit.storage.file.FileBasedConfig; 24 | import org.eclipse.jgit.util.FS; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import java.io.IOException; 29 | 30 | /** Provides {@link Config} annotated with {@link GerritServerConfig}. */ 31 | class GerritServerConfigProvider implements Provider { 32 | private static final Logger log = 33 | LoggerFactory.getLogger(GerritServerConfigProvider.class); 34 | 35 | private final SitePaths site; 36 | 37 | @Inject 38 | GerritServerConfigProvider(final SitePaths site) { 39 | this.site = site; 40 | } 41 | 42 | @Override 43 | public Config get() { 44 | FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED); 45 | 46 | if (!cfg.getFile().exists()) { 47 | log.info("No " + site.gerrit_config.getAbsolutePath() 48 | + "; assuming defaults"); 49 | return cfg; 50 | } 51 | 52 | try { 53 | cfg.load(); 54 | } catch (IOException e) { 55 | throw new ProvisionException(e.getMessage(), e); 56 | } catch (ConfigInvalidException e) { 57 | throw new ProvisionException(e.getMessage(), e); 58 | } 59 | 60 | if (site.secure_config.exists()) { 61 | cfg = new FileBasedConfig(cfg, site.secure_config, FS.DETECTED); 62 | try { 63 | cfg.load(); 64 | } catch (IOException e) { 65 | throw new ProvisionException(e.getMessage(), e); 66 | } catch (ConfigInvalidException e) { 67 | throw new ProvisionException(e.getMessage(), e); 68 | } 69 | } 70 | 71 | return cfg; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/config/SitePath.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | 23 | /** 24 | * Marker on a {@link java.io.File} pointing to the site path. 25 | *

26 | * The site path is where Gerrit Code Review stores most of its configuration. 27 | */ 28 | @Retention(RUNTIME) 29 | @BindingAnnotation 30 | public @interface SitePath { 31 | } 32 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/CommitMergeStatus.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.git; 16 | 17 | enum CommitMergeStatus { 18 | /** */ 19 | CLEAN_MERGE, 20 | 21 | /** */ 22 | CLEAN_PICK, 23 | 24 | /** */ 25 | ALREADY_MERGED, 26 | 27 | /** */ 28 | PATH_CONFLICT, 29 | 30 | /** */ 31 | MISSING_DEPENDENCY, 32 | 33 | /** */ 34 | NO_PATCH_SET, 35 | 36 | /** */ 37 | REVISION_GONE, 38 | 39 | /** */ 40 | CRISS_CROSS_MERGE, 41 | 42 | /** */ 43 | CANNOT_CHERRY_PICK_ROOT, 44 | 45 | /** */ 46 | NOT_FAST_FORWARD; 47 | } 48 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/DefaultQueueOp.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.git; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | public abstract class DefaultQueueOp implements Runnable { 20 | private final WorkQueue workQueue; 21 | 22 | protected DefaultQueueOp(final WorkQueue wq) { 23 | workQueue = wq; 24 | } 25 | 26 | public void start(final int delay, final TimeUnit unit) { 27 | workQueue.getDefaultQueue().schedule(this, delay, unit); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/GitRepositoryManager.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.git; 16 | 17 | import com.google.inject.Singleton; 18 | 19 | import org.eclipse.jgit.errors.RepositoryNotFoundException; 20 | import org.eclipse.jgit.lib.Repository; 21 | 22 | import java.io.IOException; 23 | 24 | 25 | /** 26 | * Manages Git repositories for the Gerrit server process. 27 | *

28 | * Implementations of this interface should be a {@link Singleton} and 29 | * registered in Guice so they are globally available within the server 30 | * environment. 31 | */ 32 | public interface GitRepositoryManager { 33 | /** Note tree listing commits we refuse {@code refs/meta/reject-commits} */ 34 | public static final String REF_REJECT_COMMITS = "refs/meta/reject-commits"; 35 | 36 | /** 37 | * Get (or open) a repository by name. 38 | * 39 | * @param name the repository name, relative to the base directory. 40 | * @return the cached Repository instance. Caller must call {@code close()} 41 | * when done to decrement the resource handle. 42 | * @throws RepositoryNotFoundException the name does not denote an existing 43 | * repository, or the name cannot be read as a repository. 44 | */ 45 | public abstract Repository openRepository(String name) 46 | throws RepositoryNotFoundException; 47 | 48 | /** 49 | * Create (and open) a repository by name. 50 | * 51 | * @param name the repository name, relative to the base directory. 52 | * @return the cached Repository instance. Caller must call {@code close()} 53 | * when done to decrement the resource handle. 54 | * @throws RepositoryNotFoundException the name does not denote an existing 55 | * repository, or the name cannot be read as a repository. 56 | */ 57 | public abstract Repository createRepository(String name) 58 | throws RepositoryNotFoundException; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/MergeException.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.git; 16 | 17 | /** Indicates the current branch's queue cannot be processed at this time. */ 18 | class MergeException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | 21 | MergeException(final String msg) { 22 | super(msg, null); 23 | } 24 | 25 | MergeException(final String msg, final Throwable why) { 26 | super(msg, why); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/ProjectRunnable.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package com.google.gerrit.server.git; 15 | 16 | /** Used to retrieve the project name from an operation **/ 17 | public interface ProjectRunnable extends Runnable { 18 | String getProjectNameKey(); 19 | 20 | String getRemoteName(); 21 | 22 | boolean hasCustomizedPrint(); 23 | } -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/git/TransferConfig.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.git; 16 | 17 | import com.google.gerrit.server.config.ConfigUtil; 18 | import com.google.gerrit.server.config.GerritServerConfig; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Singleton; 21 | 22 | import org.eclipse.jgit.lib.Config; 23 | import org.eclipse.jgit.storage.pack.PackConfig; 24 | 25 | import java.util.concurrent.TimeUnit; 26 | 27 | @Singleton 28 | public class TransferConfig { 29 | private final int timeout; 30 | private final PackConfig packConfig; 31 | 32 | @Inject 33 | TransferConfig(@GerritServerConfig final Config cfg) { 34 | timeout = (int) ConfigUtil.getTimeUnit(cfg, "transfer", null, "timeout", // 35 | 0, TimeUnit.SECONDS); 36 | 37 | packConfig = new PackConfig(); 38 | packConfig.setDeltaCompress(false); 39 | packConfig.setThreads(1); 40 | packConfig.fromConfig(cfg); 41 | } 42 | 43 | /** @return configured timeout, in seconds. 0 if the timeout is infinite. */ 44 | public int getTimeout() { 45 | return timeout; 46 | } 47 | 48 | public PackConfig getPackConfig() { 49 | return packConfig; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/project/CanSubmitResult.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.project; 16 | 17 | /** 18 | * Result from {@code ChangeControl.canSubmit()}. 19 | * 20 | * @see ChangeControl#canSubmit(com.google.gerrit.reviewdb.PatchSet.Id, 21 | * com.google.gerrit.reviewdb.ReviewDb, 22 | * com.google.gerrit.common.data.ApprovalTypes, 23 | * com.google.gerrit.server.workflow.FunctionState.Factory) 24 | */ 25 | public class CanSubmitResult { 26 | /** Magic constant meaning submitting is possible. */ 27 | public static final CanSubmitResult OK = new CanSubmitResult("OK"); 28 | 29 | private final String errorMessage; 30 | 31 | CanSubmitResult(String error) { 32 | this.errorMessage = error; 33 | } 34 | 35 | public String getMessage() { 36 | return errorMessage; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "CanSubmitResult[" + getMessage() + "]"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/project/NoSuchProjectException.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.project; 16 | 17 | /** Indicates the project does not exist. */ 18 | public class NoSuchProjectException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public NoSuchProjectException(final String key) { 22 | this(key, null); 23 | } 24 | 25 | public NoSuchProjectException(final String key, final Throwable why) { 26 | super(key, why); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/project/NoSuchRefException.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.project; 16 | 17 | /** Indicates the reference does not exist. */ 18 | public class NoSuchRefException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public NoSuchRefException(final String ref) { 22 | this(ref, null); 23 | } 24 | 25 | public NoSuchRefException(final String ref, final Throwable why) { 26 | super(ref, why); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/ssh/SshInfo.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.ssh; 16 | 17 | import com.jcraft.jsch.HostKey; 18 | 19 | import java.util.List; 20 | 21 | public interface SshInfo { 22 | List getHostKeys(); 23 | } 24 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/util/HostPlatform.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.util; 16 | 17 | import java.security.AccessController; 18 | import java.security.PrivilegedAction; 19 | 20 | public final class HostPlatform { 21 | private static final boolean win32 = computeWin32(); 22 | 23 | /** @return true if this JVM is running on a Windows platform. */ 24 | public static final boolean isWin32() { 25 | return win32; 26 | } 27 | 28 | private static final boolean computeWin32() { 29 | final String osDotName = 30 | AccessController.doPrivileged(new PrivilegedAction() { 31 | public String run() { 32 | return System.getProperty("os.name"); 33 | } 34 | }); 35 | return osDotName != null 36 | && osDotName.toLowerCase().indexOf("windows") != -1; 37 | } 38 | 39 | private HostPlatform() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mini-git-server-server/src/main/java/com/google/gerrit/server/util/IdGenerator.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.util; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Singleton; 19 | 20 | import java.util.Random; 21 | import java.util.concurrent.atomic.AtomicInteger; 22 | 23 | /** Simple class to produce 4 billion keys randomly distributed. */ 24 | @Singleton 25 | public class IdGenerator { 26 | /** Format an id created by this class as a hex string. */ 27 | public static String format(int id) { 28 | final char[] r = new char[8]; 29 | for (int p = 7; 0 <= p; p--) { 30 | final int h = id & 0xf; 31 | r[p] = h < 10 ? (char) ('0' + h) : (char) ('a' + (h - 10)); 32 | id >>= 4; 33 | } 34 | return new String(r); 35 | } 36 | 37 | private final AtomicInteger gen; 38 | 39 | @Inject 40 | IdGenerator() { 41 | gen = new AtomicInteger(new Random().nextInt()); 42 | } 43 | 44 | /** Produce the next identifier. */ 45 | public int next() { 46 | return mix(gen.getAndIncrement()); 47 | } 48 | 49 | private static final int salt = 0x9e3779b9; 50 | 51 | /** A very simple bit permutation to mask a simple incrementer. */ 52 | static int mix(final int in) { 53 | short v0 = hi16(in); 54 | short v1 = lo16(in); 55 | v0 += ((v1 << 2) + 0 ^ v1) + (salt ^ (v1 >>> 3)) + 1; 56 | v1 += ((v0 << 2) + 2 ^ v0) + (salt ^ (v0 >>> 3)) + 3; 57 | return result(v0, v1); 58 | } 59 | 60 | /* For testing only. */ 61 | static int unmix(final int in) { 62 | short v0 = hi16(in); 63 | short v1 = lo16(in); 64 | v1 -= ((v0 << 2) + 2 ^ v0) + (salt ^ (v0 >>> 3)) + 3; 65 | v0 -= ((v1 << 2) + 0 ^ v1) + (salt ^ (v1 >>> 3)) + 1; 66 | return result(v0, v1); 67 | } 68 | 69 | private static short hi16(final int in) { 70 | return (short) ( // 71 | ((in >>> 24 & 0xff)) | // 72 | ((in >>> 16 & 0xff) << 8) // 73 | ); 74 | } 75 | 76 | private static short lo16(final int in) { 77 | return (short) ( // 78 | ((in >>> 8 & 0xff)) | // 79 | ((in & 0xff) << 8) // 80 | ); 81 | } 82 | 83 | private static int result(final short v0, final short v1) { 84 | return ((v0 & 0xff) << 24) | // 85 | (((v0 >>> 8) & 0xff) << 16) | // 86 | ((v1 & 0xff) << 8) | // 87 | ((v1 >>> 8) & 0xff); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /mini-git-server-server/src/test/java/com/google/gerrit/server/config/ConfigUtilTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import static java.util.concurrent.TimeUnit.DAYS; 18 | import static java.util.concurrent.TimeUnit.*; 19 | 20 | import junit.framework.TestCase; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | public class ConfigUtilTest extends TestCase { 25 | public void testTimeUnit() { 26 | assertEquals(ms(2, MILLISECONDS), parse("2ms")); 27 | assertEquals(ms(200, MILLISECONDS), parse("200 milliseconds")); 28 | 29 | assertEquals(ms(2, SECONDS), parse("2s")); 30 | assertEquals(ms(231, SECONDS), parse("231sec")); 31 | assertEquals(ms(1, SECONDS), parse("1second")); 32 | assertEquals(ms(300, SECONDS), parse("300 seconds")); 33 | 34 | assertEquals(ms(2, MINUTES), parse("2m")); 35 | assertEquals(ms(2, MINUTES), parse("2min")); 36 | assertEquals(ms(1, MINUTES), parse("1 minute")); 37 | assertEquals(ms(10, MINUTES), parse("10 minutes")); 38 | 39 | assertEquals(ms(5, HOURS), parse("5h")); 40 | assertEquals(ms(5, HOURS), parse("5hr")); 41 | assertEquals(ms(1, HOURS), parse("1hour")); 42 | assertEquals(ms(48, HOURS), parse("48hours")); 43 | 44 | assertEquals(ms(5, HOURS), parse("5 h")); 45 | assertEquals(ms(5, HOURS), parse("5 hr")); 46 | assertEquals(ms(1, HOURS), parse("1 hour")); 47 | assertEquals(ms(48, HOURS), parse("48 hours")); 48 | assertEquals(ms(48, HOURS), parse("48 \t \r hours")); 49 | 50 | assertEquals(ms(4, DAYS), parse("4d")); 51 | assertEquals(ms(1, DAYS), parse("1day")); 52 | assertEquals(ms(14, DAYS), parse("14days")); 53 | 54 | assertEquals(ms(7, DAYS), parse("1w")); 55 | assertEquals(ms(7, DAYS), parse("1week")); 56 | assertEquals(ms(14, DAYS), parse("2w")); 57 | assertEquals(ms(14, DAYS), parse("2weeks")); 58 | 59 | assertEquals(ms(30, DAYS), parse("1mon")); 60 | assertEquals(ms(30, DAYS), parse("1month")); 61 | assertEquals(ms(60, DAYS), parse("2mon")); 62 | assertEquals(ms(60, DAYS), parse("2months")); 63 | 64 | assertEquals(ms(365, DAYS), parse("1y")); 65 | assertEquals(ms(365, DAYS), parse("1year")); 66 | assertEquals(ms(365 * 2, DAYS), parse("2years")); 67 | } 68 | 69 | private static long ms(int cnt, TimeUnit unit) { 70 | return MILLISECONDS.convert(cnt, unit); 71 | } 72 | 73 | private static long parse(String string) { 74 | return ConfigUtil.getTimeUnit(string, 1, MILLISECONDS); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /mini-git-server-server/src/test/java/com/google/gerrit/server/config/SitePathsTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.config; 16 | 17 | import com.google.gerrit.server.util.HostPlatform; 18 | 19 | import junit.framework.TestCase; 20 | 21 | import java.io.File; 22 | import java.io.FileNotFoundException; 23 | import java.io.IOException; 24 | import java.util.UUID; 25 | 26 | public class SitePathsTest extends TestCase { 27 | public void testCreate_NotExisting() throws FileNotFoundException { 28 | final File root = random(); 29 | final SitePaths site = new SitePaths(root); 30 | assertTrue(site.isNew); 31 | assertEquals(root, site.site_path); 32 | assertEquals(new File(root, "etc"), site.etc_dir); 33 | } 34 | 35 | public void testCreate_Empty() throws FileNotFoundException { 36 | final File root = random(); 37 | try { 38 | assertTrue(root.mkdir()); 39 | 40 | final SitePaths site = new SitePaths(root); 41 | assertTrue(site.isNew); 42 | assertEquals(root, site.site_path); 43 | } finally { 44 | root.delete(); 45 | } 46 | } 47 | 48 | public void testCreate_NonEmpty() throws IOException { 49 | final File root = random(); 50 | final File txt = new File(root, "test.txt"); 51 | try { 52 | assertTrue(root.mkdir()); 53 | assertTrue(txt.createNewFile()); 54 | 55 | final SitePaths site = new SitePaths(root); 56 | assertFalse(site.isNew); 57 | assertEquals(root, site.site_path); 58 | } finally { 59 | txt.delete(); 60 | root.delete(); 61 | } 62 | } 63 | 64 | public void testCreate_NotDirectory() throws IOException { 65 | final File root = random(); 66 | try { 67 | assertTrue(root.createNewFile()); 68 | try { 69 | new SitePaths(root); 70 | fail("Did not throw exception"); 71 | } catch (FileNotFoundException e) { 72 | assertEquals("Not a directory: " + root.getPath(), e.getMessage()); 73 | } 74 | } finally { 75 | root.delete(); 76 | } 77 | } 78 | 79 | public void testResolve() throws FileNotFoundException { 80 | final File root = random(); 81 | final SitePaths site = new SitePaths(root); 82 | 83 | assertNull(site.resolve(null)); 84 | assertNull(site.resolve("")); 85 | 86 | assertNotNull(site.resolve("a")); 87 | assertEquals(new File(root, "a"), site.resolve("a")); 88 | 89 | final String pfx = HostPlatform.isWin32() ? "C:/" : "/"; 90 | assertNotNull(site.resolve(pfx + "a")); 91 | assertEquals(new File(pfx + "a"), site.resolve(pfx + "a")); 92 | } 93 | 94 | private File random() { 95 | final File t = new File("target"); 96 | return new File(t, "random-name-" + UUID.randomUUID().toString()); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /mini-git-server-server/src/test/java/com/google/gerrit/server/util/IdGeneratorTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.server.util; 16 | 17 | import junit.framework.TestCase; 18 | 19 | import java.util.HashSet; 20 | 21 | public class IdGeneratorTest extends TestCase { 22 | public void test1234() { 23 | final HashSet seen = new HashSet(); 24 | for (int i = 0; i < 1 << 16; i++) { 25 | final int e = IdGenerator.mix(i); 26 | assertTrue("no duplicates", seen.add(e)); 27 | assertEquals("mirror image", i, IdGenerator.unmix(e)); 28 | } 29 | assertEquals(0x801234ab, IdGenerator.unmix(IdGenerator.mix(0x801234ab))); 30 | assertEquals(0xc0ffee12, IdGenerator.unmix(IdGenerator.mix(0xc0ffee12))); 31 | assertEquals(0xdeadbeef, IdGenerator.unmix(IdGenerator.mix(0xdeadbeef))); 32 | assertEquals(0x0b966b11, IdGenerator.unmix(IdGenerator.mix(0x0b966b11))); 33 | } 34 | 35 | public void testFormat() { 36 | assertEquals("0000000f", IdGenerator.format(0xf)); 37 | assertEquals("801234ab", IdGenerator.format(0x801234ab)); 38 | assertEquals("deadbeef", IdGenerator.format(0xdeadbeef)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mini-git-server-sshd/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-sshd/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-sshd/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-sshd/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-sshd/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | com.madgag 22 | mini-git-server-parent 23 | 0.5-SNAPSHOT 24 | 25 | 26 | mini-git-server-sshd 27 | mini-git-server - SSHd 28 | 29 | 30 | Java SSH daemon with Gerrit commands and Git support 31 | 32 | 33 | 34 | 35 | net.schmizz 36 | sshj 37 | 0.3.1 38 | 39 | 40 | 41 | org.bouncycastle 42 | bcprov-jdk16 43 | 1.45 44 | 45 | 46 | 47 | log4j 48 | log4j 49 | 50 | 51 | 52 | com.madgag 53 | org.eclipse.jgit.junit 54 | 55 | 56 | 57 | org.apache.sshd 58 | sshd-core 59 | 60 | 61 | com.jcraft 62 | jsch 63 | 64 | 65 | org.slf4j 66 | slf4j-api 67 | 68 | 69 | 70 | com.madgag 71 | mini-git-server-util-cli 72 | ${project.version} 73 | 74 | 75 | 76 | com.madgag 77 | mini-git-server-server 78 | ${project.version} 79 | 80 | 81 | 82 | commons-codec 83 | commons-codec 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/AbstractGitCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.IdentifiedUser; 18 | import com.google.gerrit.server.git.GitRepositoryManager; 19 | import com.google.gerrit.sshd.SshScope.Context; 20 | import com.google.inject.Inject; 21 | import org.apache.sshd.server.Environment; 22 | import org.eclipse.jgit.errors.RepositoryNotFoundException; 23 | import org.eclipse.jgit.lib.Repository; 24 | import org.kohsuke.args4j.Argument; 25 | 26 | import java.io.IOException; 27 | 28 | public abstract class AbstractGitCommand extends BaseCommand { 29 | @Argument(index = 0, metaVar = "PROJECT.git", required = true, usage = "project name") 30 | private String repoPath; 31 | 32 | protected String projectName() { 33 | String projectName = repoPath; 34 | 35 | if (projectName.endsWith(".git")) { 36 | // Be nice and drop the trailing ".git" suffix, which we never keep 37 | // in our database, but clients might mistakenly provide anyway. 38 | // 39 | projectName = projectName.substring(0, projectName.length() - 4); 40 | } 41 | 42 | if (projectName.startsWith("/")) { 43 | // Be nice and drop the leading "/" if supplied by an absolute path. 44 | // We don't have a file system hierarchy, just a flat namespace in 45 | // the database's Project entities. We never encode these with a 46 | // leading '/' but users might accidentally include them in Git URLs. 47 | // 48 | projectName = projectName.substring(1); 49 | } 50 | 51 | return projectName; 52 | } 53 | 54 | @Inject 55 | private GitRepositoryManager repoManager; 56 | 57 | @Inject 58 | private SshSession session; 59 | 60 | @Inject 61 | private SshScope.Context context; 62 | 63 | @Inject 64 | private IdentifiedUser user; 65 | 66 | @Inject 67 | private IdentifiedUser.GenericFactory userFactory; 68 | 69 | protected Repository repo; 70 | 71 | @Override 72 | public void start(final Environment env) { 73 | Context ctx = context.subContext(newSession(), context.getCommandLine()); 74 | final Context old = SshScope.set(ctx); 75 | try { 76 | startThread(new ProjectCommandRunnable() { 77 | @Override 78 | public void executeParseCommand() throws Exception { 79 | parseCommandLine(); 80 | } 81 | 82 | @Override 83 | public void run() throws Exception { 84 | AbstractGitCommand.this.service(); 85 | } 86 | 87 | @Override 88 | public String getProjectName() { 89 | return projectName(); 90 | } 91 | }); 92 | } finally { 93 | SshScope.set(old); 94 | } 95 | } 96 | 97 | private SshSession newSession() { 98 | return new SshSession(session, session.getRemoteAddress(), userFactory 99 | .create(user.getUserName())); 100 | } 101 | 102 | private void service() throws IOException, Failure { 103 | 104 | try { 105 | repo = repoManager.openRepository(projectName()); 106 | } catch (RepositoryNotFoundException e) { 107 | throw new Failure(1, "fatal: '" + projectName() + "': not a git archive", e); 108 | } 109 | 110 | try { 111 | runImpl(); 112 | } finally { 113 | repo.close(); 114 | } 115 | } 116 | 117 | protected abstract void runImpl() throws IOException, Failure; 118 | } 119 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/AdminCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Annotation tagged on a concrete Command that requires administrator access. 25 | *

26 | * Currently this annotation is only enforced by DispatchCommand after it has 27 | * created the command object, but before it populates it or starts execution. 28 | */ 29 | @Target( {ElementType.TYPE}) 30 | @Retention(RUNTIME) 31 | public @interface AdminCommand { 32 | } 33 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/AdminHighPriorityCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Annotation tagged on a concrete Command that requires 25 | * high priority thread creation whenever called by administrators users. 26 | *

27 | */ 28 | @Target( {ElementType.TYPE}) 29 | @Retention(RUNTIME) 30 | public @interface AdminHighPriorityCommand { 31 | } 32 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutor.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.gerrit.server.git.WorkQueue.Executor; 20 | import com.google.inject.BindingAnnotation; 21 | 22 | import java.lang.annotation.Retention; 23 | 24 | /** Marker on {@link Executor} used by SSH threads. */ 25 | @Retention(RUNTIME) 26 | @BindingAnnotation 27 | public @interface CommandExecutor { 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.CurrentUser; 18 | import com.google.gerrit.server.config.GerritServerConfig; 19 | import com.google.gerrit.server.git.WorkQueue; 20 | import com.google.inject.Inject; 21 | import com.google.inject.Provider; 22 | 23 | import org.eclipse.jgit.lib.Config; 24 | 25 | import java.util.concurrent.ThreadFactory; 26 | 27 | class CommandExecutorProvider implements Provider { 28 | 29 | private final QueueProvider queues; 30 | private final CurrentUser user; 31 | 32 | @Inject 33 | CommandExecutorProvider(QueueProvider queues, 34 | CurrentUser user) { 35 | this.queues = queues; 36 | this.user = user; 37 | } 38 | 39 | @Override 40 | public WorkQueue.Executor get() { 41 | WorkQueue.Executor executor; 42 | executor = queues.getInteractiveQueue(); 43 | return executor; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/CommandExecutorQueueProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.config.GerritServerConfig; 18 | import com.google.gerrit.server.git.WorkQueue; 19 | import com.google.inject.Inject; 20 | 21 | import org.eclipse.jgit.lib.Config; 22 | 23 | import java.util.concurrent.ThreadFactory; 24 | 25 | public class CommandExecutorQueueProvider implements QueueProvider { 26 | 27 | private int poolSize; 28 | private final int batchThreads; 29 | private final WorkQueue.Executor interactiveExecutor; 30 | private final WorkQueue.Executor batchExecutor; 31 | 32 | @Inject 33 | public CommandExecutorQueueProvider(@GerritServerConfig final Config config, 34 | final WorkQueue queues) { 35 | final int cores = Runtime.getRuntime().availableProcessors(); 36 | poolSize = config.getInt("sshd", "threads", 3 * cores / 2); 37 | batchThreads = config.getInt("sshd", "batchThreads", 0); 38 | if (batchThreads > poolSize) { 39 | poolSize += batchThreads; 40 | } 41 | int interactiveThreads = Math.max(1, poolSize - batchThreads); 42 | interactiveExecutor = queues.createQueue(interactiveThreads, 43 | "SSH-Interactive-Worker"); 44 | if (batchThreads != 0) { 45 | batchExecutor = queues.createQueue(batchThreads, "SSH-Batch-Worker"); 46 | setThreadFactory(batchExecutor); 47 | } else { 48 | batchExecutor = interactiveExecutor; 49 | } 50 | setThreadFactory(interactiveExecutor); 51 | 52 | } 53 | 54 | private void setThreadFactory(WorkQueue.Executor executor) { 55 | final ThreadFactory parent = executor.getThreadFactory(); 56 | executor.setThreadFactory(new ThreadFactory() { 57 | @Override 58 | public Thread newThread(final Runnable task) { 59 | final Thread t = parent.newThread(task); 60 | t.setPriority(Thread.MIN_PRIORITY); 61 | return t; 62 | } 63 | }); 64 | } 65 | 66 | @Override 67 | public WorkQueue.Executor getInteractiveQueue() { 68 | return interactiveExecutor; 69 | } 70 | 71 | @Override 72 | public WorkQueue.Executor getBatchQueue() { 73 | return batchExecutor; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/CommandModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.inject.AbstractModule; 18 | import com.google.inject.binder.LinkedBindingBuilder; 19 | 20 | import org.apache.sshd.server.Command; 21 | 22 | /** Module to register commands in the SSH daemon. */ 23 | public abstract class CommandModule extends AbstractModule { 24 | /** 25 | * Configure a command to be invoked by name. 26 | * 27 | * @param name the name of the command the client will provide in order to 28 | * call the command. 29 | * @return a binding that must be bound to a non-singleton provider for a 30 | * {@link Command} object. 31 | */ 32 | protected LinkedBindingBuilder command(final String name) { 33 | return bind(Commands.key(name)); 34 | } 35 | 36 | /** 37 | * Configure a command to be invoked by name. 38 | * 39 | * @param name the name of the command the client will provide in order to 40 | * call the command. 41 | * @return a binding that must be bound to a non-singleton provider for a 42 | * {@link Command} object. 43 | */ 44 | protected LinkedBindingBuilder command(final CommandName name) { 45 | return bind(Commands.key(name)); 46 | } 47 | 48 | /** 49 | * Configure a command to be invoked by name. 50 | * 51 | *@param parent context of the parent command, that this command is a 52 | * subcommand of. 53 | * @param name the name of the command the client will provide in order to 54 | * call the command. 55 | * @return a binding that must be bound to a non-singleton provider for a 56 | * {@link Command} object. 57 | */ 58 | protected LinkedBindingBuilder command(final CommandName parent, 59 | final String name) { 60 | return bind(Commands.key(parent, name)); 61 | } 62 | 63 | /** 64 | * Alias one command to another. 65 | * 66 | * @param from the new command name that when called will actually delegate to 67 | * {@code to}'s implementation. 68 | * @param to name of an already registered command that will perform the 69 | * action when {@code from} is invoked by a client. 70 | */ 71 | protected void alias(final String from, final String to) { 72 | bind(Commands.key(from)).to(Commands.key(to)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/CommandName.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | 21 | import java.lang.annotation.Retention; 22 | 23 | /** 24 | * Name of a command registered in an SSH daemon. 25 | *

26 | * Use {@link Commands#key(String)} to construct a key for a command name. 27 | * 28 | * @see CommandModule#command(String) 29 | * @see Commands#key(String) 30 | */ 31 | @Retention(RUNTIME) 32 | @BindingAnnotation 33 | public @interface CommandName { 34 | String value(); 35 | } 36 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.inject.Binding; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Injector; 20 | import com.google.inject.Provider; 21 | import com.google.inject.TypeLiteral; 22 | 23 | import org.apache.sshd.server.Command; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collections; 27 | import java.util.LinkedHashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.TreeMap; 31 | 32 | /** 33 | * Creates DispatchCommand using commands registered by {@link CommandModule}. 34 | */ 35 | public class DispatchCommandProvider implements Provider { 36 | @Inject 37 | private Injector injector; 38 | 39 | @Inject 40 | private DispatchCommand.Factory factory; 41 | 42 | private final String dispatcherName; 43 | private final CommandName parent; 44 | 45 | private volatile Map> map; 46 | 47 | public DispatchCommandProvider(final CommandName cn) { 48 | this(Commands.nameOf(cn), cn); 49 | } 50 | 51 | public DispatchCommandProvider(final String dispatcherName, 52 | final CommandName cn) { 53 | this.dispatcherName = dispatcherName; 54 | this.parent = cn; 55 | } 56 | 57 | @Override 58 | public DispatchCommand get() { 59 | return factory.create(dispatcherName, getMap()); 60 | } 61 | 62 | private Map> getMap() { 63 | if (map == null) { 64 | synchronized (this) { 65 | if (map == null) { 66 | map = createMap(); 67 | } 68 | } 69 | } 70 | return map; 71 | } 72 | 73 | @SuppressWarnings("unchecked") 74 | private Map> createMap() { 75 | final Map> m = 76 | new TreeMap>(); 77 | 78 | for (final Binding b : allCommands()) { 79 | final Annotation annotation = b.getKey().getAnnotation(); 80 | if (annotation instanceof CommandName) { 81 | final CommandName n = (CommandName) annotation; 82 | if (!Commands.CMD_ROOT.equals(n) && Commands.isChild(parent, n)) { 83 | m.put(n.value(), (Provider) b.getProvider()); 84 | } 85 | } 86 | } 87 | 88 | return Collections.unmodifiableMap(new LinkedHashMap(m)); 89 | } 90 | 91 | private static final TypeLiteral type = 92 | new TypeLiteral() {}; 93 | 94 | private List> allCommands() { 95 | return injector.findBindingsByType(type); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/HostKeyProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.config.SitePaths; 18 | import com.google.inject.Inject; 19 | import com.google.inject.Provider; 20 | import com.google.inject.ProvisionException; 21 | 22 | import org.apache.sshd.common.KeyPairProvider; 23 | import org.apache.sshd.common.keyprovider.FileKeyPairProvider; 24 | import org.apache.sshd.common.util.SecurityUtils; 25 | import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; 26 | 27 | import java.io.File; 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | class HostKeyProvider implements Provider { 32 | private final SitePaths site; 33 | 34 | @Inject 35 | HostKeyProvider(final SitePaths site) { 36 | this.site = site; 37 | } 38 | 39 | @Override 40 | public KeyPairProvider get() { 41 | final File objKey = site.ssh_key; 42 | final File rsaKey = site.ssh_rsa; 43 | final File dsaKey = site.ssh_dsa; 44 | 45 | final List stdKeys = new ArrayList(2); 46 | if (rsaKey.exists()) { 47 | stdKeys.add(rsaKey.getAbsolutePath()); 48 | } 49 | if (dsaKey.exists()) { 50 | stdKeys.add(dsaKey.getAbsolutePath()); 51 | } 52 | 53 | if (objKey.exists()) { 54 | if (stdKeys.isEmpty()) { 55 | SimpleGeneratorHostKeyProvider p = new SimpleGeneratorHostKeyProvider(); 56 | p.setPath(objKey.getAbsolutePath()); 57 | return p; 58 | 59 | } else { 60 | // Both formats of host key exist, we don't know which format 61 | // should be authoritative. Complain and abort. 62 | // 63 | stdKeys.add(objKey.getAbsolutePath()); 64 | throw new ProvisionException("Multiple host keys exist: " + stdKeys); 65 | } 66 | 67 | } else { 68 | if (stdKeys.isEmpty()) { 69 | throw new ProvisionException("No SSH keys under " + site.etc_dir); 70 | } 71 | if (!SecurityUtils.isBouncyCastleRegistered()) { 72 | throw new ProvisionException("Bouncy Castle Crypto not installed;" 73 | + " needed to read server host keys: " + stdKeys + ""); 74 | } 75 | return new FileKeyPairProvider(stdKeys 76 | .toArray(new String[stdKeys.size()])); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/QueueProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.gerrit.sshd; 2 | 3 | import com.google.gerrit.server.git.WorkQueue; 4 | 5 | public interface QueueProvider { 6 | 7 | public WorkQueue.Executor getInteractiveQueue(); 8 | 9 | public WorkQueue.Executor getBatchQueue(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/SshCurrentUserProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.CurrentUser; 18 | import com.google.gerrit.server.IdentifiedUser; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Provider; 21 | import com.google.inject.Singleton; 22 | 23 | @Singleton 24 | class SshCurrentUserProvider implements Provider { 25 | private final Provider session; 26 | private final Provider identifiedProvider; 27 | 28 | @Inject 29 | SshCurrentUserProvider(Provider s, Provider p) { 30 | session = s; 31 | identifiedProvider = p; 32 | } 33 | 34 | @Override 35 | public CurrentUser get() { 36 | final CurrentUser user = session.get().getCurrentUser(); 37 | if (user instanceof IdentifiedUser) { 38 | return identifiedProvider.get(); 39 | } 40 | return session.get().getCurrentUser(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/SshIdentifiedUserProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.CurrentUser; 18 | import com.google.gerrit.server.IdentifiedUser; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Provider; 21 | import com.google.inject.ProvisionException; 22 | import com.google.inject.Singleton; 23 | 24 | @Singleton 25 | class SshIdentifiedUserProvider implements Provider { 26 | private final Provider session; 27 | private final IdentifiedUser.GenericFactory factory; 28 | 29 | @Inject 30 | SshIdentifiedUserProvider(Provider s, 31 | IdentifiedUser.GenericFactory f) { 32 | session = s; 33 | factory = f; 34 | } 35 | 36 | @Override 37 | public IdentifiedUser get() { 38 | final CurrentUser user = session.get().getCurrentUser(); 39 | if (user instanceof IdentifiedUser) { 40 | return factory.create(((IdentifiedUser) user).getUserName()); 41 | } 42 | throw new ProvisionException("Not signed in SshIdentifiedUserProvider"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/SshRemotePeerProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Provider; 19 | import com.google.inject.Singleton; 20 | 21 | import java.net.SocketAddress; 22 | 23 | @Singleton 24 | class SshRemotePeerProvider implements Provider { 25 | private final Provider session; 26 | 27 | @Inject 28 | SshRemotePeerProvider(final Provider s) { 29 | session = s; 30 | } 31 | 32 | @Override 33 | public SocketAddress get() { 34 | return session.get().getRemoteAddress(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/SshSession.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.CurrentUser; 18 | 19 | import org.apache.sshd.common.Session.AttributeKey; 20 | 21 | import java.net.InetAddress; 22 | import java.net.InetSocketAddress; 23 | import java.net.SocketAddress; 24 | 25 | /** Global data related to an active SSH connection. */ 26 | public class SshSession { 27 | /** ServerSession attribute key for this object instance. */ 28 | public static final AttributeKey KEY = 29 | new AttributeKey(); 30 | 31 | private final int sessionId; 32 | private final SocketAddress remoteAddress; 33 | private final String remoteAsString; 34 | 35 | private volatile CurrentUser identity; 36 | private volatile String username; 37 | private volatile String authError; 38 | 39 | SshSession(final int sessionId, SocketAddress peer) { 40 | this.sessionId = sessionId; 41 | this.remoteAddress = peer; 42 | this.remoteAsString = format(remoteAddress); 43 | } 44 | 45 | SshSession(SshSession parent, SocketAddress peer, CurrentUser user) { 46 | this.sessionId = parent.sessionId; 47 | this.remoteAddress = peer; 48 | if (parent.remoteAddress == peer) { 49 | this.remoteAsString = parent.remoteAsString; 50 | } else { 51 | this.remoteAsString = format(peer) + "/" + parent.remoteAsString; 52 | } 53 | this.identity = user; 54 | } 55 | 56 | /** Unique session number, assigned during connect. */ 57 | public int getSessionId() { 58 | return sessionId; 59 | } 60 | 61 | /** Identity of the authenticated user account on the socket. */ 62 | public CurrentUser getCurrentUser() { 63 | return identity; 64 | } 65 | 66 | String getUsername() { 67 | return username; 68 | } 69 | 70 | String getAuthenticationError() { 71 | return authError; 72 | } 73 | 74 | void authenticationSuccess(String user, CurrentUser id) { 75 | username = user; 76 | identity = id; 77 | authError = null; 78 | } 79 | 80 | void authenticationError(String user, String error) { 81 | username = user; 82 | identity = null; 83 | authError = error; 84 | } 85 | 86 | /** @return {@code true} if the authentication did not succeed. */ 87 | boolean isAuthenticationError() { 88 | return authError != null; 89 | } 90 | 91 | SocketAddress getRemoteAddress() { 92 | return remoteAddress; 93 | } 94 | 95 | String getRemoteAddressAsString() { 96 | return remoteAsString; 97 | } 98 | 99 | private static String format(final SocketAddress remote) { 100 | if (remote instanceof InetSocketAddress) { 101 | final InetSocketAddress sa = (InetSocketAddress) remote; 102 | 103 | final InetAddress in = sa.getAddress(); 104 | if (in != null) { 105 | return in.getHostAddress(); 106 | } 107 | 108 | final String hostName = sa.getHostName(); 109 | if (hostName != null) { 110 | return hostName; 111 | } 112 | } 113 | return remote.toString(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/StreamCommandExecutor.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import com.google.gerrit.server.git.WorkQueue.Executor; 20 | import com.google.inject.BindingAnnotation; 21 | 22 | import java.lang.annotation.Retention; 23 | 24 | /** Marker on {@link Executor} used by delayed event streaming. */ 25 | @Retention(RUNTIME) 26 | @BindingAnnotation 27 | public @interface StreamCommandExecutor { 28 | } 29 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/StreamCommandExecutorProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.config.GerritServerConfig; 18 | import com.google.gerrit.server.git.WorkQueue; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Provider; 21 | 22 | import org.eclipse.jgit.lib.Config; 23 | 24 | import java.util.concurrent.ThreadFactory; 25 | 26 | class StreamCommandExecutorProvider implements Provider { 27 | private final int poolSize; 28 | private final WorkQueue queues; 29 | 30 | @Inject 31 | StreamCommandExecutorProvider(@GerritServerConfig final Config config, 32 | final WorkQueue wq) { 33 | final int cores = Runtime.getRuntime().availableProcessors(); 34 | poolSize = config.getInt("sshd", "streamThreads", cores + 1); 35 | queues = wq; 36 | } 37 | 38 | @Override 39 | public WorkQueue.Executor get() { 40 | final WorkQueue.Executor executor; 41 | 42 | executor = queues.createQueue(poolSize, "SSH-Stream-Worker"); 43 | 44 | final ThreadFactory parent = executor.getThreadFactory(); 45 | executor.setThreadFactory(new ThreadFactory() { 46 | @Override 47 | public Thread newThread(final Runnable task) { 48 | final Thread t = parent.newThread(task); 49 | t.setPriority(Thread.MIN_PRIORITY); 50 | return t; 51 | } 52 | }); 53 | return executor; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/ToyPubKeyAuth.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd; 16 | 17 | import com.google.gerrit.server.IdentifiedUser; 18 | import com.google.gerrit.server.config.SitePaths; 19 | import com.google.inject.Inject; 20 | import com.google.inject.Singleton; 21 | import org.apache.commons.io.FileUtils; 22 | import org.apache.sshd.server.PublickeyAuthenticator; 23 | import org.apache.sshd.server.session.ServerSession; 24 | import org.bouncycastle.openssl.PEMReader; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import java.io.File; 29 | import java.io.FileInputStream; 30 | import java.io.IOException; 31 | import java.io.InputStreamReader; 32 | import java.security.NoSuchAlgorithmException; 33 | import java.security.NoSuchProviderException; 34 | import java.security.PublicKey; 35 | import java.security.spec.InvalidKeySpecException; 36 | import java.util.Collection; 37 | 38 | import static org.apache.commons.io.FileUtils.listFiles; 39 | 40 | /** 41 | * Authenticates by public key really permissively 42 | */ 43 | @Singleton 44 | class ToyPubKeyAuth implements PublickeyAuthenticator { 45 | private static final Logger log = 46 | LoggerFactory.getLogger(ToyPubKeyAuth.class); 47 | 48 | private final IdentifiedUser.GenericFactory userFactory; 49 | private final SitePaths sitePaths; 50 | 51 | @Inject 52 | ToyPubKeyAuth(IdentifiedUser.GenericFactory uf, final SitePaths sitePaths) { 53 | userFactory = uf; 54 | this.sitePaths = sitePaths; 55 | } 56 | @Override 57 | public boolean authenticate(String username, PublicKey publicKey, ServerSession serverSession) { 58 | final SshSession sd = serverSession.getAttribute(SshSession.KEY); 59 | File usersDir = new File(sitePaths.etc_dir, "users"); //sitePaths. 60 | File userDir = new File(usersDir,username); 61 | if (!userDir.exists() || !userDir.isDirectory()) { 62 | String error = "User ssh key folder not found " + userDir; 63 | log.warn(error); 64 | sd.authenticationError(username, error); 65 | return false; 66 | } 67 | Collection files = listFiles(userDir, new String[]{"pub"}, false); 68 | for (File publicKeyFile : files) { 69 | log.info("Trying " + publicKeyFile); 70 | try { 71 | PublicKey authorisedKey=SshUtil.parseOpenSSHKey(FileUtils.readFileToString(publicKeyFile)); 72 | 73 | if (authorisedKey.equals(publicKey)) { 74 | sd.authenticationSuccess(username, userFactory.create(username)); 75 | return true; //To change body of implemented methods use File | Settings | File Templates. 76 | } 77 | } catch (Exception e) { 78 | log.error("Problem with " + publicKeyFile, e); 79 | } 80 | } 81 | log.warn("No good keys found from "+files); 82 | sd.authenticationError(username, "No matching key found"); 83 | return false; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/args4j/SocketAddressHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.args4j; 16 | 17 | import com.google.gerrit.server.util.SocketUtil; 18 | import com.google.inject.Inject; 19 | import com.google.inject.assistedinject.Assisted; 20 | 21 | import org.kohsuke.args4j.CmdLineException; 22 | import org.kohsuke.args4j.CmdLineParser; 23 | import org.kohsuke.args4j.OptionDef; 24 | import org.kohsuke.args4j.spi.OptionHandler; 25 | import org.kohsuke.args4j.spi.Parameters; 26 | import org.kohsuke.args4j.spi.Setter; 27 | 28 | import java.net.SocketAddress; 29 | 30 | public class SocketAddressHandler extends OptionHandler { 31 | @SuppressWarnings("unchecked") 32 | @Inject 33 | public SocketAddressHandler(@Assisted final CmdLineParser parser, 34 | @Assisted final OptionDef option, @Assisted final Setter setter) { 35 | super(parser, option, setter); 36 | } 37 | 38 | @Override 39 | public final int parseArguments(final Parameters params) 40 | throws CmdLineException { 41 | final String token = params.getParameter(0); 42 | try { 43 | setter.addValue(SocketUtil.parse(token, 0)); 44 | } catch (IllegalArgumentException e) { 45 | throw new CmdLineException(owner.toString(), e); 46 | } 47 | return 1; 48 | } 49 | 50 | @Override 51 | public final String getDefaultMetaVariable() { 52 | return "HOST:PORT"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/args4j/SubcommandHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.args4j; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.assistedinject.Assisted; 19 | 20 | import org.kohsuke.args4j.CmdLineException; 21 | import org.kohsuke.args4j.CmdLineParser; 22 | import org.kohsuke.args4j.OptionDef; 23 | import org.kohsuke.args4j.spi.OptionHandler; 24 | import org.kohsuke.args4j.spi.Parameters; 25 | import org.kohsuke.args4j.spi.Setter; 26 | 27 | public class SubcommandHandler extends OptionHandler { 28 | @SuppressWarnings("unchecked") 29 | @Inject 30 | public SubcommandHandler(@Assisted final CmdLineParser parser, 31 | @Assisted final OptionDef option, @Assisted final Setter setter) { 32 | super(parser, option, setter); 33 | } 34 | 35 | @Override 36 | public final int parseArguments(final Parameters params) 37 | throws CmdLineException { 38 | setter.addValue(params.getParameter(0)); 39 | owner.stopOptionParsing(); 40 | return 1; 41 | } 42 | 43 | @Override 44 | public final String getDefaultMetaVariable() { 45 | return "COMMAND"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/commands/AdminKill.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.commands; 16 | 17 | import com.google.gerrit.server.git.WorkQueue; 18 | import com.google.gerrit.server.git.WorkQueue.Task; 19 | import com.google.gerrit.server.util.IdGenerator; 20 | import com.google.gerrit.sshd.AdminCommand; 21 | import com.google.gerrit.sshd.BaseCommand; 22 | import com.google.inject.Inject; 23 | 24 | import org.apache.sshd.server.Environment; 25 | import org.kohsuke.args4j.Argument; 26 | 27 | import java.io.PrintWriter; 28 | import java.util.HashSet; 29 | import java.util.Set; 30 | 31 | /** Kill a task in the work queue. */ 32 | @AdminCommand 33 | final class AdminKill extends BaseCommand { 34 | @Inject 35 | private WorkQueue workQueue; 36 | 37 | private final Set taskIds = new HashSet(); 38 | 39 | @Argument(index = 0, multiValued = true, required = true, metaVar = "ID") 40 | void addTaskId(final String taskId) { 41 | int p = 0; 42 | while (p < taskId.length() - 1 && taskId.charAt(p) == '0') { 43 | p++; 44 | } 45 | taskIds.add((int) Long.parseLong(taskId.substring(p), 16)); 46 | } 47 | 48 | @Override 49 | public void start(final Environment env) { 50 | startThread(new CommandRunnable() { 51 | @Override 52 | public void run() throws Exception { 53 | parseCommandLine(); 54 | AdminKill.this.commitMurder(); 55 | } 56 | }); 57 | } 58 | 59 | private void commitMurder() { 60 | final PrintWriter p = toPrintWriter(err); 61 | for (final Integer id : taskIds) { 62 | final Task task = workQueue.getTask(id); 63 | if (task != null) { 64 | task.cancel(true); 65 | } else { 66 | p.print("kill: " + IdGenerator.format(id) + ": No such task\n"); 67 | } 68 | } 69 | p.flush(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/commands/DefaultCommandModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.commands; 16 | 17 | import com.google.gerrit.sshd.CommandModule; 18 | import com.google.gerrit.sshd.CommandName; 19 | import com.google.gerrit.sshd.Commands; 20 | import com.google.gerrit.sshd.DispatchCommandProvider; 21 | 22 | 23 | /** Register the basic commands any Gerrit server should support. */ 24 | public class DefaultCommandModule extends CommandModule { 25 | @Override 26 | protected void configure() { 27 | final CommandName git = Commands.named("git"); 28 | final CommandName gerrit = Commands.named("gerrit"); 29 | 30 | // The following commands can be ran on a server in either Master or Slave 31 | // mode. If a command should only be used on a server in one mode, but not 32 | // both, it should be bound in both MasterCommandModule and 33 | // SlaveCommandModule. 34 | 35 | command(gerrit).toProvider(new DispatchCommandProvider(gerrit)); 36 | command(gerrit, "show-connections").to(AdminShowConnections.class); 37 | command(gerrit, "show-queue").to(ShowQueue.class); 38 | 39 | command(git).toProvider(new DispatchCommandProvider(git)); 40 | command(git, "receive-pack").to(Commands.key(gerrit, "receive-pack")); 41 | command(git, "upload-pack").to(Upload.class); 42 | 43 | command("ps").to(ShowQueue.class); 44 | command("kill").to(AdminKill.class); 45 | 46 | // Honor the legacy hyphenated forms as aliases for the non-hyphenated forms 47 | // 48 | command("git-upload-pack").to(Commands.key(git, "upload-pack")); 49 | command("git-receive-pack").to(Commands.key(git, "receive-pack")); 50 | command("gerrit-receive-pack").to(Commands.key(git, "receive-pack")); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/commands/Receive.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.commands; 16 | 17 | import com.google.gerrit.server.IdentifiedUser; 18 | import com.google.gerrit.server.git.TransferConfig; 19 | import com.google.gerrit.sshd.AbstractGitCommand; 20 | import com.google.inject.Inject; 21 | import org.eclipse.jgit.errors.UnpackException; 22 | import org.eclipse.jgit.transport.ReceivePack; 23 | 24 | import java.io.IOException; 25 | import java.io.InterruptedIOException; 26 | 27 | /** Receives change upload over SSH using the Git receive-pack protocol. */ 28 | final class Receive extends AbstractGitCommand { 29 | 30 | @Inject 31 | private IdentifiedUser currentUser; 32 | 33 | @Inject 34 | private IdentifiedUser.GenericFactory identifiedUserFactory; 35 | 36 | @Inject 37 | private TransferConfig config; 38 | 39 | @Override 40 | protected void runImpl() throws IOException, Failure { 41 | 42 | 43 | final ReceivePack rp = new ReceivePack(repo); 44 | rp.setRefLogIdent(currentUser.newRefLogIdent()); 45 | rp.setTimeout(config.getTimeout()); 46 | try { 47 | rp.receive(in, out, err); 48 | } catch (InterruptedIOException err) { 49 | throw new Failure(128, "fatal: client IO read/write timeout", err); 50 | 51 | } catch (UnpackException badStream) { 52 | // This may have been triggered by branch level access controls. 53 | // Log what the heck is going on, as detailed as we can. 54 | // 55 | StringBuilder msg = new StringBuilder(); 56 | msg.append("Unpack error on project \"" 57 | + projectName() + "\":\n"); 58 | 59 | msg.append("\n"); 60 | 61 | IOException detail = new IOException(msg.toString(), badStream); 62 | throw new Failure(128, "fatal: Unpack error, check server log", detail); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/commands/ToyDefaultCommandModule.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.commands; 16 | 17 | import com.google.gerrit.sshd.CommandModule; 18 | import com.google.gerrit.sshd.CommandName; 19 | import com.google.gerrit.sshd.Commands; 20 | import com.google.gerrit.sshd.DispatchCommandProvider; 21 | 22 | 23 | /** Register the basic commands any Gerrit server should support. */ 24 | public class ToyDefaultCommandModule extends CommandModule { 25 | @Override 26 | protected void configure() { 27 | final CommandName git = Commands.named("git"); 28 | final CommandName gerrit = Commands.named("gerrit"); 29 | 30 | // The following commands can be ran on a server in either Master or Slave 31 | // mode. If a command should only be used on a server in one mode, but not 32 | // both, it should be bound in both MasterCommandModule and 33 | // SlaveCommandModule. 34 | 35 | command(gerrit, "receive-pack").to(Receive.class); 36 | command(gerrit).toProvider(new DispatchCommandProvider(gerrit)); 37 | command(gerrit, "show-connections").to(AdminShowConnections.class); 38 | 39 | command(git).toProvider(new DispatchCommandProvider(git)); 40 | command(git, "receive-pack").to(Commands.key(gerrit, "receive-pack")); 41 | command(git, "upload-pack").to(Upload.class); 42 | 43 | command("kill").to(AdminKill.class); 44 | 45 | // Honor the legacy hyphenated forms as aliases for the non-hyphenated forms 46 | // 47 | command("git-upload-pack").to(Commands.key(git, "upload-pack")); 48 | command("git-receive-pack").to(Commands.key(git, "receive-pack")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mini-git-server-sshd/src/main/java/com/google/gerrit/sshd/commands/Upload.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.sshd.commands; 16 | 17 | import com.google.gerrit.server.git.TransferConfig; 18 | import com.google.gerrit.sshd.AbstractGitCommand; 19 | import com.google.inject.Inject; 20 | import org.eclipse.jgit.transport.UploadPack; 21 | 22 | import java.io.IOException; 23 | import java.io.InterruptedIOException; 24 | 25 | /** Publishes Git repositories over SSH using the Git upload-pack protocol. */ 26 | final class Upload extends AbstractGitCommand { 27 | @Inject 28 | private TransferConfig config; 29 | 30 | @Override 31 | protected void runImpl() throws IOException, Failure { 32 | final UploadPack up = new UploadPack(repo); 33 | 34 | up.setPackConfig(config.getPackConfig()); 35 | up.setTimeout(config.getTimeout()); 36 | try { 37 | up.upload(in, out, err); 38 | } catch (InterruptedIOException err) { 39 | throw new Failure(128, "fatal: client IO read/write timeout", err); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | com.madgag 22 | mini-git-server-parent 23 | 0.5-SNAPSHOT 24 | 25 | 26 | mini-git-server-util-cli 27 | mini-git-server - Utility - CLI 28 | 29 | 30 | Utilities to support command line parsing 31 | 32 | 33 | 34 | 35 | args4j 36 | args4j 37 | 38 | 39 | 40 | com.google.inject 41 | guice 42 | 43 | 44 | 45 | com.google.inject.extensions 46 | guice-assisted-inject 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/src/main/java/com/google/gerrit/util/cli/EndOfOptionsHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.util.cli; 16 | 17 | import org.kohsuke.args4j.CmdLineException; 18 | import org.kohsuke.args4j.CmdLineParser; 19 | import org.kohsuke.args4j.OptionDef; 20 | import org.kohsuke.args4j.spi.OptionHandler; 21 | import org.kohsuke.args4j.spi.Parameters; 22 | import org.kohsuke.args4j.spi.Setter; 23 | 24 | /** Typically used with {@code @Option(name="--")} to signal end of options. */ 25 | public class EndOfOptionsHandler extends OptionHandler { 26 | public EndOfOptionsHandler(CmdLineParser parser, OptionDef option, 27 | Setter setter) { 28 | super(parser, option, setter); 29 | } 30 | 31 | @Override 32 | public String getDefaultMetaVariable() { 33 | return null; 34 | } 35 | 36 | @Override 37 | public int parseArguments(Parameters params) throws CmdLineException { 38 | owner.stopOptionParsing(); 39 | setter.addValue(true); 40 | return 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/src/main/java/com/google/gerrit/util/cli/OptionHandlerFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.util.cli; 16 | 17 | import org.kohsuke.args4j.OptionDef; 18 | import org.kohsuke.args4j.spi.OptionHandler; 19 | import org.kohsuke.args4j.spi.Setter; 20 | 21 | /** Creates an args4j OptionHandler through a Guice Injector. */ 22 | public interface OptionHandlerFactory { 23 | @SuppressWarnings("unchecked") 24 | OptionHandler create(org.kohsuke.args4j.CmdLineParser cmdLineParser, 25 | OptionDef optionDef, Setter setter); 26 | } 27 | -------------------------------------------------------------------------------- /mini-git-server-util-cli/src/main/java/com/google/gerrit/util/cli/OptionHandlerUtil.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.util.cli; 16 | 17 | import com.google.inject.Key; 18 | import com.google.inject.TypeLiteral; 19 | import com.google.inject.internal.MoreTypes.ParameterizedTypeImpl; 20 | 21 | import java.lang.reflect.Type; 22 | 23 | /** Utilities to support creating OptionHandler instances. */ 24 | public class OptionHandlerUtil { 25 | /** Generate a key for an {@link OptionHandlerFactory} in Guice. */ 26 | @SuppressWarnings("unchecked") 27 | public static Key> keyFor(final Class valueType) { 28 | final Type factoryType = 29 | new ParameterizedTypeImpl(null, OptionHandlerFactory.class, valueType); 30 | 31 | return (Key>) Key.get(TypeLiteral.get(factoryType)); 32 | } 33 | 34 | private OptionHandlerUtil() { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | com.madgag 22 | mini-git-server-parent 23 | 0.5-SNAPSHOT 24 | 25 | 26 | mini-git-server-util-ssl 27 | mini-git-server - Utility - SSL 28 | 29 | 30 | Utilities to support SSL based protocols 31 | 32 | 33 | -------------------------------------------------------------------------------- /mini-git-server-util-ssl/src/main/java/com/google/gerrit/util/ssl/BlindSSLSocketFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.google.gerrit.util.ssl; 16 | 17 | import java.io.IOException; 18 | import java.net.InetAddress; 19 | import java.net.Socket; 20 | import java.net.UnknownHostException; 21 | import java.security.GeneralSecurityException; 22 | import java.security.SecureRandom; 23 | import java.security.cert.X509Certificate; 24 | 25 | import javax.net.SocketFactory; 26 | import javax.net.ssl.SSLContext; 27 | import javax.net.ssl.SSLSocketFactory; 28 | import javax.net.ssl.TrustManager; 29 | import javax.net.ssl.X509TrustManager; 30 | 31 | /** SSL socket factory that ignores SSL certificate validation. */ 32 | public class BlindSSLSocketFactory extends SSLSocketFactory { 33 | private static final BlindSSLSocketFactory INSTANCE; 34 | 35 | static { 36 | final X509TrustManager dummyTrustManager = new X509TrustManager() { 37 | public X509Certificate[] getAcceptedIssuers() { 38 | return null; 39 | } 40 | 41 | public void checkClientTrusted(X509Certificate[] chain, String authType) { 42 | } 43 | 44 | public void checkServerTrusted(X509Certificate[] chain, String authType) { 45 | } 46 | }; 47 | 48 | try { 49 | final SSLContext context = SSLContext.getInstance("SSL"); 50 | final TrustManager[] trustManagers = {dummyTrustManager}; 51 | final SecureRandom rng = new SecureRandom(); 52 | context.init(null, trustManagers, rng); 53 | INSTANCE = new BlindSSLSocketFactory(context.getSocketFactory()); 54 | } catch (GeneralSecurityException e) { 55 | throw new RuntimeException("Cannot create BlindSslSocketFactory", e); 56 | } 57 | } 58 | 59 | public static SocketFactory getDefault() { 60 | return INSTANCE; 61 | } 62 | 63 | private final SSLSocketFactory sslFactory; 64 | 65 | private BlindSSLSocketFactory(final SSLSocketFactory sslFactory) { 66 | this.sslFactory = sslFactory; 67 | } 68 | 69 | @Override 70 | public Socket createSocket(Socket s, String host, int port, boolean autoClose) 71 | throws IOException { 72 | return sslFactory.createSocket(s, host, port, autoClose); 73 | } 74 | 75 | @Override 76 | public String[] getDefaultCipherSuites() { 77 | return sslFactory.getDefaultCipherSuites(); 78 | } 79 | 80 | @Override 81 | public String[] getSupportedCipherSuites() { 82 | return sslFactory.getSupportedCipherSuites(); 83 | } 84 | 85 | @Override 86 | public Socket createSocket() throws IOException { 87 | return sslFactory.createSocket(); 88 | } 89 | 90 | @Override 91 | public Socket createSocket(String host, int port) throws IOException, 92 | UnknownHostException { 93 | return sslFactory.createSocket(host, port); 94 | } 95 | 96 | @Override 97 | public Socket createSocket(InetAddress host, int port) throws IOException { 98 | return sslFactory.createSocket(host, port); 99 | } 100 | 101 | @Override 102 | public Socket createSocket(String host, int port, InetAddress localHost, 103 | int localPort) throws IOException, UnknownHostException { 104 | return sslFactory.createSocket(host, port, localHost, localPort); 105 | } 106 | 107 | @Override 108 | public Socket createSocket(InetAddress address, int port, 109 | InetAddress localAddress, int localPort) throws IOException { 110 | return sslFactory.createSocket(address, port, localAddress, localPort); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /mini-git-server-war/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /.settings/org.maven.ide.eclipse.prefs 5 | -------------------------------------------------------------------------------- /mini-git-server-war/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /mini-git-server-war/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 02 16:59:24 PDT 2008 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /mini-git-server-war/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Jul 29 11:31:38 PDT 2009 2 | eclipse.preferences.version=1 3 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 4 | formatter_profile=_Google Format 5 | formatter_settings_version=11 6 | org.eclipse.jdt.ui.ignorelowercasenames=true 7 | org.eclipse.jdt.ui.importorder=com.google;com;junit;net;org;java;javax; 8 | org.eclipse.jdt.ui.ondemandthreshold=99 9 | org.eclipse.jdt.ui.staticondemandthreshold=99 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | sp_cleanup.add_default_serial_version_id=true 12 | sp_cleanup.add_generated_serial_version_id=false 13 | sp_cleanup.add_missing_annotations=false 14 | sp_cleanup.add_missing_deprecated_annotations=true 15 | sp_cleanup.add_missing_methods=false 16 | sp_cleanup.add_missing_nls_tags=false 17 | sp_cleanup.add_missing_override_annotations=true 18 | sp_cleanup.add_serial_version_id=false 19 | sp_cleanup.always_use_blocks=true 20 | sp_cleanup.always_use_parentheses_in_expressions=false 21 | sp_cleanup.always_use_this_for_non_static_field_access=false 22 | sp_cleanup.always_use_this_for_non_static_method_access=false 23 | sp_cleanup.convert_to_enhanced_for_loop=false 24 | sp_cleanup.correct_indentation=false 25 | sp_cleanup.format_source_code=false 26 | sp_cleanup.format_source_code_changes_only=false 27 | sp_cleanup.make_local_variable_final=true 28 | sp_cleanup.make_parameters_final=true 29 | sp_cleanup.make_private_fields_final=true 30 | sp_cleanup.make_type_abstract_if_missing_method=false 31 | sp_cleanup.make_variable_declarations_final=false 32 | sp_cleanup.never_use_blocks=false 33 | sp_cleanup.never_use_parentheses_in_expressions=true 34 | sp_cleanup.on_save_use_additional_actions=true 35 | sp_cleanup.organize_imports=false 36 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 38 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 39 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 40 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 41 | sp_cleanup.remove_private_constructors=true 42 | sp_cleanup.remove_trailing_whitespaces=true 43 | sp_cleanup.remove_trailing_whitespaces_all=true 44 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 45 | sp_cleanup.remove_unnecessary_casts=false 46 | sp_cleanup.remove_unnecessary_nls_tags=false 47 | sp_cleanup.remove_unused_imports=false 48 | sp_cleanup.remove_unused_local_variables=false 49 | sp_cleanup.remove_unused_private_fields=true 50 | sp_cleanup.remove_unused_private_members=false 51 | sp_cleanup.remove_unused_private_methods=true 52 | sp_cleanup.remove_unused_private_types=true 53 | sp_cleanup.sort_members=false 54 | sp_cleanup.sort_members_all=false 55 | sp_cleanup.use_blocks=false 56 | sp_cleanup.use_blocks_only_for_return_and_throw=false 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | log4j.rootCategory=DEBUG, stderr 16 | log4j.appender.stderr=org.apache.log4j.ConsoleAppender 17 | log4j.appender.stderr.target=System.err 18 | log4j.appender.stderr.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.stderr.layout.ConversionPattern=[%d] %-5p %c %x: %m%n 20 | 21 | log4j.logger.com.google.gerrit=INFO 22 | 23 | # Silence non-critical messages from MINA SSHD. 24 | # 25 | log4j.logger.org.apache.mina=WARN 26 | log4j.logger.org.apache.sshd.common=WARN 27 | log4j.logger.org.apache.sshd.server=INFO 28 | log4j.logger.org.apache.sshd.common.keyprovider.FileKeyPairProvider=INFO 29 | log4j.logger.com.google.gerrit.server.ssh.GerritServerSession=WARN 30 | 31 | # Silence non-critical messages from Jetty. 32 | # 33 | log4j.logger.org.eclipse.jetty=INFO 34 | 35 | # Silence non-critical messages from mime-util. 36 | # 37 | log4j.logger.eu.medsea.mimeutil=WARN 38 | 39 | # Silence non-critical messages from openid4java 40 | # 41 | log4j.logger.org.apache.xml=WARN 42 | log4j.logger.httpclient.wire=WARN 43 | log4j.logger.org.apache.commons.httpclient=WARN 44 | log4j.logger.org.apache.commons.httpclient.HttpMethodBase=ERROR 45 | 46 | # Silence non-critical messages from ehcache 47 | # 48 | log4j.logger.net.sf.ehcache=WARN 49 | 50 | # Silence non-critical messages from Velocity 51 | # 52 | log4j.logger.velocity=WARN 53 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit-jetty.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export JETTY_HOST=127.0.0.1 4 | export JETTY_PORT=8081 5 | export JETTY_USER=gerrit2 6 | export JETTY_PID=/var/run/jetty$JETTY_PORT.pid 7 | export JETTY_HOME=/home/$JETTY_USER/jetty 8 | export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.07/jre 9 | 10 | JAVA_OPTIONS="" 11 | JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=$JETTY_HOST" 12 | export JAVA_OPTIONS 13 | 14 | JETTY_ARGS="" 15 | JETTY_ARGS="$JETTY_ARGS OPTIONS=Server,plus,ext,rewrite" 16 | export JETTY_ARGS 17 | 18 | C="jetty-logging jetty" 19 | [ -f "$JETTY_HOME/etc/jetty_sslproxy.xml" ] && C="$C jetty_sslproxy" 20 | 21 | exec $JETTY_HOME/bin/jetty.sh "$@" $C 22 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/WEB-INF/extra/jetty7/gerrit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | / 21 | /webapps/gerrit.war 22 | 23 | true 24 | true 25 | /etc/webdefault.xml 26 | 27 | 28 | 29 | org.eclipse.jetty.webapp.WebInfConfiguration 30 | org.eclipse.jetty.webapp.WebXmlConfiguration 31 | org.eclipse.jetty.plus.webapp.EnvConfiguration 32 | org.eclipse.jetty.plus.webapp.Configuration 33 | org.eclipse.jetty.webapp.JettyWebXmlConfiguration 34 | 35 | 36 | 37 | 38 | 39 | jdbc/ReviewDb 40 | 41 | 42 | 48 | 52 | 56 | 4 57 | 8 58 | 4 59 | 4 60 | 30000 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/WEB-INF/extra/jetty7/jetty_sslproxy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | X-Forwarded-Scheme 30 | https 31 | https 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | guiceFilter 5 | com.google.inject.servlet.GuiceFilter 6 | 7 | 8 | guiceFilter 9 | /* 10 | 11 | 12 | 13 | com.google.gerrit.httpd.WebAppInitializer 14 | 15 | 16 | -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtyley/mini-git-server/6ffc187caaf1f3cb7402ca79fdbc5905f7285453/mini-git-server-war/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /mini-git-server-war/src/main/webapp/robots.txt: -------------------------------------------------------------------------------- 1 | # Directions for web crawlers. 2 | # See http://www.robotstxt.org/wc/norobots.html. 3 | 4 | User-agent: HTTrack 5 | User-agent: puf 6 | User-agent: MSIECrawler 7 | User-agent: Nutch 8 | Disallow: / 9 | --------------------------------------------------------------------------------