/** * Checks the size of the listeners collection retrieved by {@link #getGerritEventListeners()}. * * @param extra number of added listeners, other than the default. */ void assertNrOfEventListeners(int extra) { Collection<GerritEventListener> gerritEventListeners = getGerritEventListeners(); int nbrOfListeners = extra; nbrOfListeners++; // EventListener adds 1 listener nbrOfListeners++; // DependencyQueueTaskDispatcher adds 1 listener nbrOfListeners++; // ReplicationQueueTaskDispatcher adds 1 listener GerritServer server = PluginImpl.getServer_(PluginImpl.DEFAULT_SERVER_NAME); if (server.isConnected() && server.getConfig().isEnableProjectAutoCompletion() && server.isProjectCreatedEventsSupported()) { nbrOfListeners++; // GerritProjectListUpdater adds 1 listener// } assertEquals(nbrOfListeners, gerritEventListeners.size()); }
/** * Get the front end url from a ChangeBasedEvent. * * @param event the event * @param project the project for which the parameters are being set * @return the front end url */ private static String getURL(ChangeBasedEvent event, AbstractProject project) { String url = ""; String serverName = null; // Figure out what serverName to use if (event.getProvider() != null) { serverName = event.getProvider().getName(); } else if (project != null) { String name = GerritTrigger.getTrigger(project).getServerName(); if (!GerritServer.ANY_SERVER.equals(name)) { serverName = name; } } if (serverName == null && PluginImpl.getInstance().getFirstServer() != null) { logger.warn( "No server could be determined from event or project config, " + "defaulting to the first configured server. Event: [{}] Project: [{}]", event, project); serverName = PluginImpl.getInstance().getFirstServer().getName(); } else if (serverName == null) { // We have exhausted all possibilities, time to fail horribly throw new IllegalStateException( "Cannot determine a Gerrit server to link to. Have you configured one?"); } GerritServer server = PluginImpl.getInstance().getServer(serverName); if (server != null) { IGerritHudsonTriggerConfig config = server.getConfig(); if (config != null) { url = config.getGerritFrontEndUrlFor(event); } else { logger.error("Could not find config for Gerrit server {}", serverName); } } else { logger.error("Could not find Gerrit server {}", serverName); } return url; }
/** * Configures the GerritServer config to connect to the provided ssh server. * * @param sshd the server to connect to * @param sshKey the public key location to configure * @param gerritServer the config to configure * @see #getConfigFor(SshServer, IGerritHudsonTriggerConfig) */ public static void configureFor( final SshServer sshd, KeyPairFiles sshKey, GerritServer gerritServer) { gerritServer.setConfig(getConfigFor(sshd, sshKey, gerritServer.getConfig())); }