// core managers
IRuntimeManager.class,
+ IPluginManager.class,
INotificationManager.class,
IUserManager.class,
IAuthenticationManager.class,
return runtimeManager;
}
+ @Provides @Singleton IPluginManager providePluginManager() {
+ return pluginManager;
+ }
+
@Provides @Singleton INotificationManager provideNotificationManager() {
return notificationManager;
}
@Provides @Singleton NullTicketService provideNullTicketService() {
return new NullTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
@Provides @Singleton FileTicketService provideFileTicketService() {
return new FileTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
@Provides @Singleton BranchTicketService provideBranchTicketService() {
return new BranchTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
@Provides @Singleton RedisTicketService provideRedisTicketService() {
return new RedisTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
Class<?> serviceClass = Class.forName(serviceName);
if (RedisTicketService.class.isAssignableFrom(serviceClass)) {
// Redis ticket service
- ticketService = new RedisTicketService(runtimeManager, null, null, repositoryManager).start();
+ ticketService = new RedisTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else if (BranchTicketService.class.isAssignableFrom(serviceClass)) {
// Branch ticket service
- ticketService = new BranchTicketService(runtimeManager, null, null, repositoryManager).start();
+ ticketService = new BranchTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else if (FileTicketService.class.isAssignableFrom(serviceClass)) {
// File ticket service
- ticketService = new FileTicketService(runtimeManager, null, null, repositoryManager).start();
+ ticketService = new FileTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else {
System.err.println("Unknown ticket service " + serviceName);
System.exit(1);
--- /dev/null
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.extensions;
+
+import ro.fortsoft.pf4j.ExtensionPoint;
+
+import com.gitblit.models.TicketModel;
+import com.gitblit.models.TicketModel.Change;
+
+/**
+ * Extension point for plugins to respond to Ticket changes.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class TicketHook implements ExtensionPoint {
+
+ /**
+ * Called when a new ticket is created.
+ *
+ * @param ticket
+ */
+ public abstract void onNewTicket(TicketModel ticket);
+
+ /**
+ * Called when an existing ticket is updated. Tickets can be updated for
+ * many, many reasons like state changes votes, watches, etc.
+ *
+ * @param ticket
+ * @param change
+ */
+ public abstract void onUpdateTicket(TicketModel ticket, Change change);
+}
import com.gitblit.Constants;
import com.gitblit.git.ReceiveCommandEvent;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
public BranchTicketService(
IRuntimeManager runtimeManager,
+ IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IRepositoryManager repositoryManager) {
super(runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
import com.gitblit.Constants;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
public FileTicketService(
IRuntimeManager runtimeManager,
+ IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IRepositoryManager repositoryManager) {
super(runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.extensions.TicketHook;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
protected final IRepositoryManager repositoryManager;
+ protected final IPluginManager pluginManager;
+
protected final TicketIndexer indexer;
private final Cache<TicketKey, TicketModel> ticketsCache;
*/
public ITicketService(
IRuntimeManager runtimeManager,
+ IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IRepositoryManager repositoryManager) {
this.log = LoggerFactory.getLogger(getClass());
this.settings = runtimeManager.getSettings();
this.runtimeManager = runtimeManager;
+ this.pluginManager = pluginManager;
this.notificationManager = notificationManager;
this.userManager = userManager;
this.repositoryManager = repositoryManager;
if (success) {
TicketModel ticket = getTicket(repository, ticketId);
indexer.index(ticket);
+
+ // call the ticket hooks
+ if (pluginManager != null) {
+ for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
+ try {
+ hook.onNewTicket(ticket);
+ } catch (Exception e) {
+ log.error("Failed to execute extension", e);
+ }
+ }
+ }
return ticket;
}
return null;
TicketModel ticket = getTicket(repository, ticketId);
ticketsCache.put(key, ticket);
indexer.index(ticket);
+
+ // call the ticket hooks
+ if (pluginManager != null) {
+ for (TicketHook hook : pluginManager.getExtensions(TicketHook.class)) {
+ try {
+ hook.onUpdateTicket(ticket, change);
+ } catch (Exception e) {
+ log.error("Failed to execute extension", e);
+ }
+ }
+ }
return ticket;
}
return null;
import java.util.List;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
public NullTicketService(
IRuntimeManager runtimeManager,
+ IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IRepositoryManager repositoryManager) {
super(runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
import com.gitblit.Keys;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
public RedisTicketService(
IRuntimeManager runtimeManager,
+ IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IRepositoryManager repositoryManager) {
super(runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager);
}
```
+### Extension Point: Ticket Hook
+
+You can provide your own custom ticket hook by extending the *TicketHook* class.
+
+```java
+import com.gitblit.extensions.TicketHook;
+import com.gitblit.models.TicketModel;
+import com.gitblit.models.TicketModel.Change;
+import ro.fortsoft.pf4j.Extension;
+
+@Extension
+public class MyTicketHook extends TicketHook {
+
+ @Override
+ public void onNewTicket(TicketModel ticket) {
+ }
+
+ @Override
+ public void onUpdateTicket(TicketModel ticket, Change change) {
+ }
+}
+```
+
### Mac OSX Fonts
Gitblit's core SSH commands and those in the *powertools* plugin rely on use of ANSI border characters to provide a pretty presentation of data. Unfortunately, the fonts provided by Apple - while very nice - don't work well with ANSI border characters. The following public domain fixed-width, fixed-point, bitmapped fonts work very nicely. I find the 6x12 font with a line spacing of ~0.8 to be quite acceptable.
import com.gitblit.IStoredSettings;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
IStoredSettings settings = getSettings(deleteAll);
IRuntimeManager runtimeManager = new RuntimeManager(settings).start();
+ IPluginManager pluginManager = new PluginManager(runtimeManager).start();
INotificationManager notificationManager = new NotificationManager(settings).start();
IUserManager userManager = new UserManager(runtimeManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start();
BranchTicketService service = new BranchTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager).start();
import com.gitblit.IStoredSettings;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
IStoredSettings settings = getSettings(deleteAll);
IRuntimeManager runtimeManager = new RuntimeManager(settings).start();
+ IPluginManager pluginManager = new PluginManager(runtimeManager).start();
INotificationManager notificationManager = new NotificationManager(settings).start();
IUserManager userManager = new UserManager(runtimeManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start();
FileTicketService service = new FileTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager).start();
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
IStoredSettings settings = getSettings(deleteAll);
IRuntimeManager runtimeManager = new RuntimeManager(settings).start();
+ IPluginManager pluginManager = new PluginManager(runtimeManager).start();
INotificationManager notificationManager = new NotificationManager(settings).start();
IUserManager userManager = new UserManager(runtimeManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start();
RedisTicketService service = new RedisTicketService(
runtimeManager,
+ pluginManager,
notificationManager,
userManager,
repositoryManager).start();