/war
/*.war
/proposals
+/*.jar
+/federation.properties
\ No newline at end of file
New BSD License\r
\r
http://code.google.com/p/ant-googlecode\r
+\r
+---------------------------------------------------------------------------\r
+GenJar\r
+---------------------------------------------------------------------------\r
+ GenJar, released under the\r
+ Apache Software License, Version 1.1.\r
+ \r
+ http://genjar.sourceforge.net\r
\r
---------------------------------------------------------------------------\r
Fancybox image viewer\r
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask" \r
classpath="${basedir}/tools/ant-googlecode-0.0.3.jar" name="gcupload"/>\r
\r
+ <!-- GenJar task -->\r
+ <taskdef resource="genjar.properties" classpath="${basedir}/tools/GenJar.jar" />\r
+\r
<!-- Project Properties -->\r
<property name="project.jar" value="gitblit.jar" />\r
<property name="project.mainclass" value="com.gitblit.Launcher" />\r
</loadfile> \r
<property name="distribution.zipfile" value="gitblit-${gb.version}.zip" />\r
<property name="distribution.warfile" value="gitblit-${gb.version}.war" />\r
+ <property name="fedclient.zipfile" value="fedclient-${gb.version}.zip" />\r
</target>\r
\r
\r
\r
<delete dir="${project.build.dir}" />\r
<mkdir dir="${project.build.dir}" />\r
- <javac srcdir="${basedir}/src" destdir="${project.build.dir}">\r
+ <javac debug="true" srcdir="${basedir}/src" destdir="${project.build.dir}">\r
<include name="com/gitblit/build/Build.java" /> \r
<include name="com/gitblit/Constants.java" />\r
<include name="com/gitblit/utils/StringUtils.java" /> \r
<fileset dir="${basedir}/ext">\r
<include name="*.jar" />\r
</fileset>\r
+ <pathelement path="${project.build.dir}" /> \r
</path>\r
- <javac destdir="${project.build.dir}" failonerror="false">\r
+ <javac debug="true" destdir="${project.build.dir}" failonerror="false">\r
<src path="${basedir}/src" />\r
<classpath refid="master-classpath" />\r
</javac>\r
<copy todir="${project.deploy.dir}">\r
<fileset dir="${basedir}/distrib">\r
<include name="**/*" />\r
+ <exclude name="federation.properties" />\r
</fileset>\r
<fileset dir="${basedir}">\r
<include name="LICENSE" />\r
<arg value="--substitute" />\r
<arg value="%WAR%=${distribution.warfile}" />\r
\r
+ <arg value="--substitute" />\r
+ <arg value="%FEDCLIENT%=${fedclient.zipfile}" />\r
+\r
<arg value="--substitute" />\r
<arg value="%BUILDDATE%=${gb.versionDate}" />\r
\r
</target>\r
\r
\r
+ <!-- \r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ Build the stand-alone, command-line Gitblit Federation Client\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ -->\r
+ <target name="buildFederationClient" depends="compile" description="Builds the stand-alone Gitblit federation client">\r
+ <echo>Building Gitblit Federation Client ${gb.version}</echo>\r
+ \r
+ <genjar jarfile="fedclient.jar">\r
+ <class name="com.gitblit.FederationClientLauncher" />\r
+ <resource file="${project.build.dir}/log4j.properties" />\r
+ <classfilter>\r
+ <exclude name="org.apache." />\r
+ <exclude name="org.bouncycastle." />\r
+ <exclude name="org.eclipse." />\r
+ <exclude name="org.slf4j." />\r
+ <exclude name="com.beust." />\r
+ <exclude name="com.google." />\r
+ </classfilter>\r
+ <classpath refid="master-classpath" />\r
+ <manifest>\r
+ <attribute name="Main-Class" value="com.gitblit.FederationClientLauncher" />\r
+ <attribute name="Specification-Version" value="${gb.version}" /> \r
+ <attribute name="Release-Date" value="${gb.versionDate}" />\r
+ </manifest>\r
+ </genjar>\r
+ \r
+ <!-- Build the federation client zip file -->\r
+ <zip destfile="${fedclient.zipfile}">\r
+ <fileset dir="${basedir}">\r
+ <include name="fedclient.jar" /> \r
+ </fileset>\r
+ <fileset dir="${basedir}/distrib">\r
+ <include name="federation.properties" /> \r
+ </fileset>\r
+ </zip>\r
+ </target>\r
+\r
+ \r
<!-- \r
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
Build the Gitblit Website\r
<arg value="--substitute" />\r
<arg value="%WAR%=${distribution.warfile}" />\r
\r
+ <arg value="--substitute" />\r
+ <arg value="%FEDCLIENT%=${fedclient.zipfile}" />\r
+\r
<arg value="--substitute" />\r
<arg value="%BUILDDATE%=${gb.versionDate}" />\r
\r
Compile from source, publish binaries, and build & deploy site\r
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
-->\r
- <target name="buildAll" depends="buildGO,buildWAR,buildSite"> \r
+ <target name="buildAll" depends="buildGO,buildWAR,buildFederationClient,buildSite"> \r
<!-- Cleanup -->\r
<delete dir="${project.build.dir}" />\r
<delete dir="${project.war.dir}" />\r
targetfilename="gitblit-${gb.version}.war"\r
summary="Gitblit WAR v${gb.version} (standard WAR webapp for servlet containers)"\r
labels="Featured, Type-Package, OpSys-All" />\r
+ \r
+ <!-- Upload FedClient -->\r
+ <gcupload \r
+ username="${googlecode.user}" \r
+ password="${googlecode.password}" \r
+ projectname="gitblit" \r
+ filename="${fedclient.zipfile}" \r
+ targetfilename="fedclient-${gb.version}.zip"\r
+ summary="Gitblit Federation Client v${gb.version} (command-line tool to clone data from federated Gitblit instances)"\r
+ labels="Featured, Type-Package, OpSys-All" />\r
</target>\r
\r
\r
--- /dev/null
+#\r
+# Git Repository Settings\r
+#\r
+\r
+# Base folder for repositories\r
+# Use forward slashes even on Windows!!\r
+# e.g. c:/gitrepos\r
+#\r
+# SINCE 0.5.0\r
+# RESTART REQUIRED\r
+git.repositoriesFolder = git\r
+\r
+# Search the repositories folder subfolders for other repositories.\r
+# Repositories MAY NOT be nested (i.e. one repository within another)\r
+# but they may be grouped together in subfolders.\r
+# e.g. c:/gitrepos/libraries/mylibrary.git\r
+# c:/gitrepos/libraries/myotherlibrary.git\r
+#\r
+# SINCE 0.5.0\r
+git.searchRepositoriesSubfolders = true\r
+\r
+# Your federation name is used for federation status acknowledgments. If it is\r
+# unset, and you elect to send a status acknowledgment, your Gitblit instance\r
+# will be identified by its hostname, if available, else your internal ip address.\r
+# The source Gitblit instance will also append your external IP address to your\r
+# identification to differentiate multiple pulling systems behind a single proxy.\r
+#\r
+# SINCE 0.6.0\r
+federation.name =\r
+\r
+# Federation pull registrations\r
+# Registrations are read once, at startup.\r
+#\r
+# RESTART REQUIRED\r
+#\r
+# frequency:\r
+# The shortest frequency allowed is every 5 minutes\r
+# Decimal frequency values are cast to integers\r
+# Frequency values may be specified in mins, hours, or days\r
+# Values that can not be parsed default to *federation.defaultFrequency*\r
+#\r
+# folder:\r
+# if blank, the folder is *git.repositoriesFolder*\r
+# if specified, the folder is relative to *git.repositoriesFolder*\r
+#\r
+# mergeAccounts:\r
+# if true, remote accounts and their permissions are merged into your \r
+# users.properties file \r
+#\r
+# notifyOnError:\r
+# if true and the mail configuration is properly set, administrators will be\r
+# notified by email of pull failures\r
+#\r
+# include and exclude:\r
+# space-separated list of repositories to include or exclude from pull\r
+# may be * wildcard to include or exclude all\r
+# may use fuzzy match (e.g. org.eclipse.*)\r
+\r
+#\r
+# (Nearly) Perfect Mirror example\r
+#\r
+\r
+#federation.example1.url = https://go.gitblit.com\r
+#federation.example1.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4\r
+#federation.example1.frequency = 120 mins\r
+#federation.example1.folder =\r
+#federation.example1.bare = true\r
+#federation.example1.mirror = true \r
+#federation.example1.mergeAccounts = true\r
#federation.example1.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4\r
#federation.example1.frequency = 120 mins\r
#federation.example1.folder =\r
+#federation.example1.bare = true \r
#federation.example1.mirror = true \r
#federation.example1.mergeAccounts = true\r
\r
accessRestriction = clone\r
isFrozen = false\r
showReadme = false\r
- excludeFromFederation = false\r
+ federationStrategy = FEDERATE_THIS\r
isFederated = false\r
federationSets = \r
\r
\r
If you want your repositories (and optionally users accounts and settings) to be pulled by another Gitblit instance, you need to register your origin Gitblit instance with a pulling Gitblit instance by providing the url of your Gitblit instance and a federation token.\r
\r
-Gitblit generates the following federation tokens:\r
+Gitblit generates the following standard federation tokens:\r
%BEGINCODE%\r
String allToken = SHA1(passphrase + "-ALL");\r
String usersAndRepositoriesToken = SHA1(passphrase + "-USERS_AND_REPOSITORIES");\r
\r
If *federation.passphrase* has a non-empty value, the federation tokens are displayed in the log file and are visible, to administrators, in the web ui.\r
\r
+The three standard tokens grant access to ALL your non-excluded repositories. However, if you only want to specify different groups of repositories to be federated then you need to define *federation sets*. \r
+\r
#### Federation Sets\r
\r
-Federation Sets (*federation.sets*) are named groups of repositories. The Federation Sets are defined in `gitblit.properties` and are available for selection in the repository settings page. You can assign a repository to one or more sets and then distribute the token for the set. This allows you to grant federation pull access to a subset of your available repositories. Tokens for federation sets only grant pull access for the member repositories.\r
+Federation Sets (*federation.sets*) are named groups of repositories. The Federation Sets are defined in `gitblit.properties` and are available for selection in the repository settings page. You can assign a repository to one or more sets and then distribute the federation token for the set. This allows you to grant federation pull access to a subset of your available repositories. Tokens for federation sets only grant pull access for the member repositories.\r
\r
### Federation Proposals (Origin Gitblit Instance)\r
\r
\r
### Excluding Repositories (Origin Gitblit Instance)\r
\r
-You may exclude a repository from being pulled by a federated Gitblit instance by setting its *federation strategy* to EXCLUDE in the repository's settings page.\r
+You may exclude a repository from being pulled by any federated Gitblit instance by setting its *federation strategy* to EXCLUDE in the repository's settings page.\r
\r
### Excluding Repositories (Pulling Gitblit Instance)\r
\r
federation.example4.bare = true\r
federation.example4.mirror = true\r
federation.example4.exclude = *\r
- federation.example4.include = somerepo.git
\ No newline at end of file
+ federation.example4.include = somerepo.git\r
+ \r
+## Federation Client\r
+\r
+Instead of setting up a full-blown pulling Gitblit instance, you can also use the [federation client](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) command-line utility. This is a packaged subset of the federation feature in a smaller, simpler command-line only tool.\r
+\r
+The *federation client* relies on many of the same dependencies as Gitblit and will download them on first execution.\r
+\r
+### federation.properties\r
+You may use the `federation.properties` file to configure one or more Gitblit instances that you want to pull from. This file is a subset of the standard `gitblit.properties` file.\r
+\r
+By default this tool does not daemonize itself; it executes and then quits. This allows you to use the native scheduling feature of your OS. Of course, if you'd rather use Gitblit's scheduler you may use that by specifying the `--daemon` parameter.\r
+\r
+### Command-Line Parameters\r
+Instead of using `federation.properties` you may directly specify a Gitblit instance to pull from with command-line parameters.\r
+\r
+ java -jar fedclient.jar --url https://go.gitblit.com --mirror --bare --token 123456789\r
+ --repositoriesFolder c:/mymirror\r
+ \r
+ java -jar fedclient.jar --url https://go.gitblit.com --mirror --bare --token 123456789\r
+ --repositoriesFolder c:/mymirror --daemon --frequency "24 hours"\r
+ \r
- [JUnit](http://junit.org) (Common Public License)\r
- [commons-net](http://commons.apache.org/net) (Apache 2.0)\r
- [ant-googlecode](http://code.google.com/p/ant-googlecode) (New BSD)\r
+- [GenJar](http://genjar.sourceforge.net) (Apache 1.1)\r
\r
## Building from Source\r
[Eclipse](http://eclipse.org) is recommended for development as the project settings are preconfigured.\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+import com.gitblit.models.FederationModel;\r
+import com.gitblit.utils.FederationUtils;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+/**\r
+ * Command-line client to pull federated Gitblit repositories.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class FederationClient {\r
+\r
+ public static void main(String[] args) {\r
+ Params params = new Params();\r
+ JCommander jc = new JCommander(params);\r
+ try {\r
+ jc.parse(args);\r
+ } catch (ParameterException t) {\r
+ usage(jc, t);\r
+ }\r
+\r
+ IStoredSettings settings = new FileSettings(params.registrationsFile);\r
+ List<FederationModel> registrations = new ArrayList<FederationModel>();\r
+ if (StringUtils.isEmpty(params.url)) {\r
+ registrations.addAll(FederationUtils.getFederationRegistrations(settings));\r
+ } else {\r
+ if (StringUtils.isEmpty(params.token)) {\r
+ System.out.println("Must specify --token parameter!");\r
+ System.exit(0);\r
+ }\r
+ FederationModel model = new FederationModel("Gitblit");\r
+ model.url = params.url;\r
+ model.token = params.token;\r
+ model.mirror = params.mirror;\r
+ model.bare = params.bare;\r
+ model.frequency = params.frequency;\r
+ model.folder = "";\r
+ registrations.add(model);\r
+ }\r
+ if (registrations.size() == 0) {\r
+ System.out.println("No Federation Registrations! Nothing to do.");\r
+ System.exit(0);\r
+ }\r
+ \r
+ System.out.println("Gitblit Federation Client v" + Constants.VERSION + " (" + Constants.VERSION_DATE + ")");\r
+\r
+ // command-line specified repositories folder\r
+ if (!StringUtils.isEmpty(params.repositoriesFolder)) {\r
+ settings.overrideSetting(Keys.git.repositoriesFolder, new File(\r
+ params.repositoriesFolder).getAbsolutePath());\r
+ }\r
+\r
+ // configure the Gitblit singleton for minimal, non-server operation\r
+ GitBlit.self().configureContext(settings, false);\r
+ FederationPullExecutor executor = new FederationPullExecutor(registrations, params.isDaemon);\r
+ executor.run();\r
+ if (!params.isDaemon) {\r
+ System.out.println("Finished.");\r
+ System.exit(0);\r
+ }\r
+ }\r
+\r
+ private static void usage(JCommander jc, ParameterException t) {\r
+ System.out.println(Constants.getGitBlitVersion());\r
+ System.out.println();\r
+ if (t != null) {\r
+ System.out.println(t.getMessage());\r
+ System.out.println();\r
+ }\r
+\r
+ if (jc != null) {\r
+ jc.usage();\r
+ }\r
+ System.exit(0);\r
+ }\r
+\r
+ /**\r
+ * JCommander Parameters class for FederationClient.\r
+ */\r
+ @Parameters(separators = " ")\r
+ private static class Params {\r
+\r
+ @Parameter(names = { "--registrations" }, description = "Gitblit Federation Registrations File", required = false)\r
+ public String registrationsFile = "federation.properties";\r
+\r
+ @Parameter(names = { "--daemon" }, description = "Runs in daemon mode to schedule and pull repositories", required = false)\r
+ public boolean isDaemon;\r
+\r
+ @Parameter(names = { "--url" }, description = "URL of Gitblit instance to mirror from", required = false)\r
+ public String url;\r
+\r
+ @Parameter(names = { "--mirror" }, description = "Mirror repositories", required = false)\r
+ public boolean mirror;\r
+\r
+ @Parameter(names = { "--bare" }, description = "Create bare repositories", required = false)\r
+ public boolean bare;\r
+\r
+ @Parameter(names = { "--token" }, description = "Federation Token", required = false)\r
+ public String token;\r
+\r
+ @Parameter(names = { "--frequency" }, description = "Period to wait between pull attempts (requires --daemon)", required = false)\r
+ public String frequency = "60 mins";\r
+\r
+ @Parameter(names = { "--repositoriesFolder" }, description = "Destination folder for cloned repositories", required = false)\r
+ public String repositoriesFolder;\r
+\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import com.gitblit.build.Build;\r
+\r
+/**\r
+ * Downloads dependencies and launches command-line Federation client.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class FederationClientLauncher {\r
+\r
+ public static void main(String[] args) {\r
+ // download federation client runtime dependencies\r
+ Build.federationClient();\r
+\r
+ File libFolder = new File("ext");\r
+ List<File> jars = Launcher.findJars(libFolder.getAbsoluteFile());\r
+ \r
+ // sort the jars by name and then reverse the order so the newer version\r
+ // of the library gets loaded in the event that this is an upgrade\r
+ Collections.sort(jars);\r
+ Collections.reverse(jars);\r
+ for (File jar : jars) {\r
+ try {\r
+ Launcher.addJarFile(jar);\r
+ } catch (IOException e) {\r
+\r
+ }\r
+ }\r
+ \r
+ FederationClient.main(args);\r
+ }\r
+}\r
*/\r
package com.gitblit;\r
\r
+import static org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;\r
+\r
import java.io.File;\r
import java.io.FileOutputStream;\r
import java.net.InetAddress;\r
import java.util.Arrays;\r
import java.util.Collection;\r
import java.util.Date;\r
+import java.util.HashSet;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Properties;\r
+import java.util.Set;\r
import java.util.concurrent.TimeUnit;\r
\r
import org.eclipse.jgit.lib.Ref;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.lib.StoredConfig;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
import org.eclipse.jgit.transport.CredentialsProvider;\r
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;\r
import org.slf4j.Logger;\r
\r
private final List<FederationModel> registrations;\r
\r
+ private final boolean isDaemon;\r
+\r
/**\r
* Constructor for specifying a single federation registration. This\r
* constructor is used to schedule the next pull execution.\r
* @param registration\r
*/\r
private FederationPullExecutor(FederationModel registration) {\r
- this(Arrays.asList(registration));\r
+ this(Arrays.asList(registration), true);\r
}\r
\r
/**\r
* on each registrations frequency setting.\r
* \r
* @param registrations\r
+ * @param isDaemon\r
+ * if true, registrations are rescheduled in perpetuity. if false,\r
+ * the federation pull operation is executed once.\r
*/\r
- public FederationPullExecutor(List<FederationModel> registrations) {\r
+ public FederationPullExecutor(List<FederationModel> registrations, boolean isDaemon) {\r
this.registrations = registrations;\r
+ this.isDaemon = isDaemon;\r
}\r
\r
/**\r
"Failed to pull from federated gitblit ({0} @ {1})", registration.name,\r
registration.url), t);\r
} finally {\r
- schedule(registration);\r
+ if (isDaemon) {\r
+ schedule(registration);\r
+ }\r
}\r
}\r
}\r
continue;\r
}\r
\r
+ // Determine local repository name\r
String repositoryName;\r
if (StringUtils.isEmpty(registrationFolder)) {\r
repositoryName = repository.name;\r
} else {\r
repositoryName = registrationFolder + "/" + repository.name;\r
}\r
+ \r
+ if (registration.bare) {\r
+ // bare repository, ensure .git suffix\r
+ if (!repositoryName.toLowerCase().endsWith(DOT_GIT_EXT)) {\r
+ repositoryName += DOT_GIT_EXT;\r
+ }\r
+ } else {\r
+ // normal repository, strip .git suffix\r
+ if (repositoryName.toLowerCase().endsWith(DOT_GIT_EXT)) {\r
+ repositoryName = repositoryName.substring(0, repositoryName.indexOf(DOT_GIT_EXT));\r
+ }\r
+ }\r
\r
// confirm that the origin of any pre-existing repository matches\r
// the clone url\r
StoredConfig config = existingRepository.getConfig();\r
config.load();\r
String origin = config.getString("remote", "origin", "url");\r
- fetchHead = JGitUtils.getCommit(existingRepository, "refs/remotes/origin/master")\r
- .getName();\r
+ RevCommit commit = JGitUtils.getCommit(existingRepository, "refs/remotes/origin/master");\r
+ if (commit != null) {\r
+ fetchHead = commit.getName();\r
+ }\r
existingRepository.close();\r
if (!origin.startsWith(registration.url)) {\r
logger.warn(MessageFormat\r
Constants.FEDERATION_USER, registration.token);\r
logger.info(MessageFormat.format("Pulling federated repository {0} from {1} @ {2}",\r
repository.name, registration.name, registration.url));\r
+ \r
CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,\r
cloneUrl, registration.bare, credentials);\r
Repository r = GitBlit.self().getRepository(repositoryName);\r
} else {\r
// fetch and update\r
boolean fetched = false;\r
- String origin = JGitUtils.getCommit(r, "refs/remotes/origin/master").getName();\r
- fetched = !fetchHead.equals(origin);\r
+ RevCommit commit = JGitUtils.getCommit(r, "refs/remotes/origin/master");\r
+ String origin = commit.getName();\r
+ fetched = fetchHead == null || !fetchHead.equals(origin);\r
\r
if (registration.mirror) {\r
// mirror\r
// preserve local settings\r
repository.isFrozen = rm.isFrozen;\r
repository.federationStrategy = rm.federationStrategy;\r
+ \r
+ // merge federation sets\r
+ Set<String> federationSets = new HashSet<String>();\r
+ if (rm.federationSets != null) {\r
+ federationSets.addAll(rm.federationSets);\r
+ }\r
+ if (repository.federationSets != null) {\r
+ federationSets.addAll(repository.federationSets);\r
+ }\r
+ repository.federationSets = new ArrayList<String>(federationSets);\r
}\r
// only repositories that are actually _cloned_ from the origin\r
// Gitblit repository are marked as federated. If the origin\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.FederationUtils;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.google.gson.Gson;\r
// Schedule the federation executor\r
List<FederationModel> registrations = getFederationRegistrations();\r
if (registrations.size() > 0) {\r
- scheduledExecutor.schedule(new FederationPullExecutor(registrations), 1,\r
- TimeUnit.MINUTES);\r
+ FederationPullExecutor executor = new FederationPullExecutor(registrations, true);\r
+ scheduledExecutor.schedule(executor, 1, TimeUnit.MINUTES);\r
}\r
}\r
\r
*/\r
public List<FederationModel> getFederationRegistrations() {\r
if (federationRegistrations.isEmpty()) {\r
- List<String> keys = settings.getAllKeys(Keys.federation._ROOT);\r
- keys.remove(Keys.federation.name);\r
- keys.remove(Keys.federation.passphrase);\r
- keys.remove(Keys.federation.allowProposals);\r
- keys.remove(Keys.federation.proposalsFolder);\r
- keys.remove(Keys.federation.defaultFrequency);\r
- keys.remove(Keys.federation.sets);\r
- Collections.sort(keys);\r
- Map<String, FederationModel> federatedModels = new HashMap<String, FederationModel>();\r
- for (String key : keys) {\r
- String value = key.substring(Keys.federation._ROOT.length() + 1);\r
- List<String> values = StringUtils.getStringsFromValue(value, "\\.");\r
- String server = values.get(0);\r
- if (!federatedModels.containsKey(server)) {\r
- federatedModels.put(server, new FederationModel(server));\r
- }\r
- String setting = values.get(1);\r
- if (setting.equals("url")) {\r
- // url of the origin Gitblit instance\r
- federatedModels.get(server).url = settings.getString(key, "");\r
- } else if (setting.equals("token")) {\r
- // token for the origin Gitblit instance\r
- federatedModels.get(server).token = settings.getString(key, "");\r
- } else if (setting.equals("frequency")) {\r
- // frequency of the pull operation\r
- federatedModels.get(server).frequency = settings.getString(key, "");\r
- } else if (setting.equals("folder")) {\r
- // destination folder of the pull operation\r
- federatedModels.get(server).folder = settings.getString(key, "");\r
- } else if (setting.equals("bare")) {\r
- // whether pulled repositories should be bare\r
- federatedModels.get(server).bare = settings.getBoolean(key, true);\r
- } else if (setting.equals("mirror")) {\r
- // are the repositories to be true mirrors of the origin\r
- federatedModels.get(server).mirror = settings.getBoolean(key, true);\r
- } else if (setting.equals("mergeAccounts")) {\r
- // merge remote accounts into local accounts\r
- federatedModels.get(server).mergeAccounts = settings.getBoolean(key, false);\r
- } else if (setting.equals("sendStatus")) {\r
- // send a status acknowledgment to source Gitblit instance\r
- // at end of git pull\r
- federatedModels.get(server).sendStatus = settings.getBoolean(key, false);\r
- } else if (setting.equals("notifyOnError")) {\r
- // notify administrators on federation pull failures\r
- federatedModels.get(server).notifyOnError = settings.getBoolean(key, false);\r
- } else if (setting.equals("exclude")) {\r
- // excluded repositories\r
- federatedModels.get(server).exclusions = settings.getStrings(key);\r
- } else if (setting.equals("include")) {\r
- // included repositories\r
- federatedModels.get(server).inclusions = settings.getStrings(key);\r
- }\r
- }\r
-\r
- // verify that registrations have a url and a token\r
- for (FederationModel model : federatedModels.values()) {\r
- if (StringUtils.isEmpty(model.url)) {\r
- logger.warn(MessageFormat.format(\r
- "Dropping federation registration {0}. Missing url.", model.name));\r
- continue;\r
- }\r
- if (StringUtils.isEmpty(model.token)) {\r
- logger.warn(MessageFormat.format(\r
- "Dropping federation registration {0}. Missing token.", model.name));\r
- continue;\r
- }\r
- // set default frequency if unspecified\r
- if (StringUtils.isEmpty(model.frequency)) {\r
- model.frequency = settings.getString(Keys.federation.defaultFrequency,\r
- "60 mins");\r
- }\r
- federationRegistrations.add(model);\r
- }\r
+ federationRegistrations.addAll(FederationUtils.getFederationRegistrations(settings));\r
}\r
return federationRegistrations;\r
}\r
* \r
* @param settings\r
*/\r
- public void configureContext(IStoredSettings settings) {\r
+ public void configureContext(IStoredSettings settings, boolean startFederation) {\r
logger.info("Reading configuration from " + settings.toString());\r
this.settings = settings;\r
repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "git"));\r
loginService = new FileUserService(realmFile);\r
}\r
setUserService(loginService);\r
- configureFederation();\r
mailExecutor = new MailExecutor(settings);\r
if (mailExecutor.isReady()) {\r
scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, 2, TimeUnit.MINUTES);\r
} else {\r
logger.warn("Mail server is not properly configured. Mail services disabled.");\r
}\r
+ if (startFederation) {\r
+ configureFederation();\r
+ }\r
}\r
\r
/**\r
if (settings == null) {\r
// Gitblit WAR is running in a servlet container\r
WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());\r
- configureContext(webxmlSettings);\r
+ configureContext(webxmlSettings, true);\r
}\r
}\r
\r
\r
// Setup the GitBlit context\r
GitBlit gitblit = GitBlit.self();\r
- gitblit.configureContext(settings);\r
+ gitblit.configureContext(settings, true);\r
rootContext.addEventListener(gitblit);\r
\r
try {\r
// needed for site publishing\r
downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);\r
}\r
+ \r
+ public static void federationClient() {\r
+ downloadFromApache(MavenObject.JCOMMANDER, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SERVLET, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.MAIL, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SLF4LOG4J, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.LOG4J, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.GSON, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.JSCH, BuildType.RUNTIME);\r
+ \r
+ downloadFromEclipse(MavenObject.JGIT, BuildType.RUNTIME);\r
+ }\r
\r
/**\r
* Builds the Keys class based on the gitblit.properties file and inserts\r
*/\r
public FederationModel(String serverName) {\r
this.name = serverName;\r
+ bare = true;\r
+ mirror = true;\r
this.lastPull = new Date(0);\r
this.nextPull = new Date(0);\r
}\r
import java.security.SecureRandom;\r
import java.security.cert.CertificateException;\r
import java.security.cert.X509Certificate;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.Collections;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
import javax.net.ssl.X509TrustManager;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
import com.gitblit.Constants.FederationRequest;\r
import com.gitblit.FederationServlet;\r
+import com.gitblit.IStoredSettings;\r
+import com.gitblit.Keys;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.RepositoryModel;\r
private static final SSLContext SSL_CONTEXT;\r
\r
private static final DummyHostnameVerifier HOSTNAME_VERIFIER;\r
+ \r
+ private static final Logger LOGGER = LoggerFactory.getLogger(FederationUtils.class);\r
\r
static {\r
SSLContext context = null;\r
CHARSET = "UTF-8";\r
}\r
\r
+ /**\r
+ * Returns the list of federated gitblit instances that this instance will\r
+ * try to pull.\r
+ * \r
+ * @return list of registered gitblit instances\r
+ */\r
+ public static List<FederationModel> getFederationRegistrations(IStoredSettings settings) {\r
+ List<FederationModel> federationRegistrations = new ArrayList<FederationModel>();\r
+ List<String> keys = settings.getAllKeys(Keys.federation._ROOT);\r
+ keys.remove(Keys.federation.name);\r
+ keys.remove(Keys.federation.passphrase);\r
+ keys.remove(Keys.federation.allowProposals);\r
+ keys.remove(Keys.federation.proposalsFolder);\r
+ keys.remove(Keys.federation.defaultFrequency);\r
+ keys.remove(Keys.federation.sets);\r
+ Collections.sort(keys);\r
+ Map<String, FederationModel> federatedModels = new HashMap<String, FederationModel>();\r
+ for (String key : keys) {\r
+ String value = key.substring(Keys.federation._ROOT.length() + 1);\r
+ List<String> values = StringUtils.getStringsFromValue(value, "\\.");\r
+ String server = values.get(0);\r
+ if (!federatedModels.containsKey(server)) {\r
+ federatedModels.put(server, new FederationModel(server));\r
+ }\r
+ String setting = values.get(1);\r
+ if (setting.equals("url")) {\r
+ // url of the origin Gitblit instance\r
+ federatedModels.get(server).url = settings.getString(key, "");\r
+ } else if (setting.equals("token")) {\r
+ // token for the origin Gitblit instance\r
+ federatedModels.get(server).token = settings.getString(key, "");\r
+ } else if (setting.equals("frequency")) {\r
+ // frequency of the pull operation\r
+ federatedModels.get(server).frequency = settings.getString(key, "");\r
+ } else if (setting.equals("folder")) {\r
+ // destination folder of the pull operation\r
+ federatedModels.get(server).folder = settings.getString(key, "");\r
+ } else if (setting.equals("bare")) {\r
+ // whether pulled repositories should be bare\r
+ federatedModels.get(server).bare = settings.getBoolean(key, true);\r
+ } else if (setting.equals("mirror")) {\r
+ // are the repositories to be true mirrors of the origin\r
+ federatedModels.get(server).mirror = settings.getBoolean(key, true);\r
+ } else if (setting.equals("mergeAccounts")) {\r
+ // merge remote accounts into local accounts\r
+ federatedModels.get(server).mergeAccounts = settings.getBoolean(key, false);\r
+ } else if (setting.equals("sendStatus")) {\r
+ // send a status acknowledgment to source Gitblit instance\r
+ // at end of git pull\r
+ federatedModels.get(server).sendStatus = settings.getBoolean(key, false);\r
+ } else if (setting.equals("notifyOnError")) {\r
+ // notify administrators on federation pull failures\r
+ federatedModels.get(server).notifyOnError = settings.getBoolean(key, false);\r
+ } else if (setting.equals("exclude")) {\r
+ // excluded repositories\r
+ federatedModels.get(server).exclusions = settings.getStrings(key);\r
+ } else if (setting.equals("include")) {\r
+ // included repositories\r
+ federatedModels.get(server).inclusions = settings.getStrings(key);\r
+ }\r
+ }\r
+\r
+ // verify that registrations have a url and a token\r
+ for (FederationModel model : federatedModels.values()) {\r
+ if (StringUtils.isEmpty(model.url)) {\r
+ LOGGER.warn(MessageFormat.format(\r
+ "Dropping federation registration {0}. Missing url.", model.name));\r
+ continue;\r
+ }\r
+ if (StringUtils.isEmpty(model.token)) {\r
+ LOGGER.warn(MessageFormat.format(\r
+ "Dropping federation registration {0}. Missing token.", model.name));\r
+ continue;\r
+ }\r
+ // set default frequency if unspecified\r
+ if (StringUtils.isEmpty(model.frequency)) {\r
+ model.frequency = settings.getString(Keys.federation.defaultFrequency, "60 mins");\r
+ }\r
+ federationRegistrations.add(model);\r
+ }\r
+ return federationRegistrations;\r
+ }\r
+\r
/**\r
* Sends a federation proposal to the Gitblit instance at remoteUrl\r
* \r
import org.eclipse.jgit.api.CloneCommand;\r
import org.eclipse.jgit.api.FetchCommand;\r
import org.eclipse.jgit.api.Git;\r
-import org.eclipse.jgit.api.PullCommand;\r
-import org.eclipse.jgit.api.PullResult;\r
import org.eclipse.jgit.api.ResetCommand;\r
import org.eclipse.jgit.api.ResetCommand.ResetType;\r
import org.eclipse.jgit.diff.DiffEntry;\r
* Encapsulates the result of cloning or pulling from a repository.\r
*/\r
public static class CloneResult {\r
+ public String name;\r
public FetchResult fetchResult;\r
public boolean createdRepository;\r
}\r
* @return CloneResult\r
* @throws Exception\r
*/\r
- public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl, boolean bare,\r
- CredentialsProvider credentialsProvider) throws Exception {\r
+ public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl,\r
+ boolean bare, CredentialsProvider credentialsProvider) throws Exception {\r
CloneResult result = new CloneResult();\r
- if (bare && !name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {\r
- name += Constants.DOT_GIT_EXT;\r
+ if (bare) {\r
+ // bare repository, ensure .git suffix\r
+ if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {\r
+ name += Constants.DOT_GIT_EXT;\r
+ }\r
+ } else {\r
+ // normal repository, strip .git suffix\r
+ if (name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {\r
+ name = name.substring(0, name.indexOf(Constants.DOT_GIT_EXT));\r
+ }\r
}\r
+ result.name = name;\r
+\r
File folder = new File(repositoriesFolder, name);\r
if (folder.exists()) {\r
File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);\r
@Override\r
protected void setUp() throws Exception {\r
FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
- GitBlit.self().configureContext(settings);\r
+ GitBlit.self().configureContext(settings, true);\r
FileUserService loginService = new FileUserService(new File("distrib/users.properties"));\r
GitBlit.self().setUserService(loginService);\r
\r