From b9afce4d3db8dec34b22b07c952df814efc7335f Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Tue, 02 Apr 2013 10:43:52 -0400 Subject: [PATCH] Simplify resource loading --- src/main/java/com/gitblit/GitBlit.java | 74 ++++++++++++++++++++---------------- 1 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 65dc559..566a917 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -54,6 +54,8 @@ import javax.mail.Message; import javax.mail.MessagingException; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMultipart; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -452,12 +454,13 @@ * advertise alternative urls for Git client repository access. * * @param repositoryName + * @param userName * @return list of non-gitblit clone urls */ - public List<String> getOtherCloneUrls(String repositoryName) { + public List<String> getOtherCloneUrls(String repositoryName, String username) { List<String> cloneUrls = new ArrayList<String>(); for (String url : settings.getStrings(Keys.web.otherUrls)) { - cloneUrls.add(MessageFormat.format(url, repositoryName)); + cloneUrls.add(MessageFormat.format(url, repositoryName, username)); } return cloneUrls; } @@ -1673,6 +1676,8 @@ model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", ""))); model.useTickets = getConfig(config, "useTickets", false); model.useDocs = getConfig(config, "useDocs", false); + model.useIncrementalPushTags = getConfig(config, "useIncrementalPushTags", false); + model.incrementalPushTagPrefix = getConfig(config, "incrementalPushTagPrefix", null); model.allowForks = getConfig(config, "allowForks", true); model.accessRestriction = AccessRestrictionType.fromName(getConfig(config, "accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, null))); @@ -2194,6 +2199,13 @@ config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners)); config.setBoolean(Constants.CONFIG_GITBLIT, null, "useTickets", repository.useTickets); config.setBoolean(Constants.CONFIG_GITBLIT, null, "useDocs", repository.useDocs); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalPushTags", repository.useIncrementalPushTags); + if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) || + repository.incrementalPushTagPrefix.equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) { + config.unset(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix"); + } else { + config.setString(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix", repository.incrementalPushTagPrefix); + } config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks); config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name()); config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl", repository.authorizationControl.name()); @@ -2580,17 +2592,8 @@ } // send an email, if possible - try { - Message message = mailExecutor.createMessageForAdministrators(); - if (message != null) { - message.setSubject("Federation proposal from " + proposal.url); - message.setText("Please review the proposal @ " + gitblitUrl + "/proposal/" - + proposal.token); - mailExecutor.queue(message); - } - } catch (Throwable t) { - logger.error("Failed to notify administrators of proposal", t); - } + sendMailToAdministrators("Federation proposal from " + proposal.url, + "Please review the proposal @ " + gitblitUrl + "/proposal/" + proposal.token); return true; } @@ -2877,16 +2880,8 @@ * @param message */ public void sendMailToAdministrators(String subject, String message) { - try { - Message mail = mailExecutor.createMessageForAdministrators(); - if (mail != null) { - mail.setSubject(subject); - mail.setText(message); - mailExecutor.queue(mail); - } - } catch (MessagingException e) { - logger.error("Messaging error", e); - } + List<String> toAddresses = settings.getStrings(Keys.mail.adminAddresses); + sendMail(subject, message, toAddresses); } /** @@ -2916,7 +2911,16 @@ Message mail = mailExecutor.createMessage(toAddresses); if (mail != null) { mail.setSubject(subject); - mail.setText(message); + + MimeBodyPart messagePart = new MimeBodyPart(); + messagePart.setText(message, "utf-8"); + messagePart.setHeader("Content-Type", "text/plain; charset=\"utf-8\""); + messagePart.setHeader("Content-Transfer-Encoding", "quoted-printable"); + + MimeMultipart multiPart = new MimeMultipart(); + multiPart.addBodyPart(messagePart); + mail.setContent(multiPart); + mailExecutor.queue(mail); } } catch (MessagingException e) { @@ -2951,7 +2955,16 @@ Message mail = mailExecutor.createMessage(toAddresses); if (mail != null) { mail.setSubject(subject); - mail.setContent(message, "text/html"); + + MimeBodyPart messagePart = new MimeBodyPart(); + messagePart.setText(message, "utf-8"); + messagePart.setHeader("Content-Type", "text/html; charset=\"utf-8\""); + messagePart.setHeader("Content-Transfer-Encoding", "quoted-printable"); + + MimeMultipart multiPart = new MimeMultipart(); + multiPart.addBodyPart(messagePart); + mail.setContent(multiPart); + mailExecutor.queue(mail); } } catch (MessagingException e) { @@ -2984,11 +2997,10 @@ * Parse the properties file and aggregate all the comments by the setting * key. A setting model tracks the current value, the default value, the * description of the setting and and directives about the setting. - * @param referencePropertiesInputStream * * @return Map<String, SettingModel> */ - private ServerSettings loadSettingModels(InputStream referencePropertiesInputStream) { + private ServerSettings loadSettingModels() { ServerSettings settingsModel = new ServerSettings(); settingsModel.supportsCredentialChanges = userService.supportsCredentialChanges(); settingsModel.supportsDisplayNameChanges = userService.supportsDisplayNameChanges(); @@ -2998,7 +3010,7 @@ // Read bundled Gitblit properties to extract setting descriptions. // This copy is pristine and only used for populating the setting // models map. - InputStream is = referencePropertiesInputStream; + InputStream is = getClass().getResourceAsStream("/reference.properties"); BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(is)); StringBuilder description = new StringBuilder(); SettingModel setting = new SettingModel(); @@ -3226,10 +3238,6 @@ */ @Override public void contextInitialized(ServletContextEvent contextEvent) { - contextInitialized(contextEvent, contextEvent.getServletContext().getResourceAsStream("/WEB-INF/reference.properties")); - } - - public void contextInitialized(ServletContextEvent contextEvent, InputStream referencePropertiesInputStream) { servletContext = contextEvent.getServletContext(); if (settings == null) { // Gitblit is running in a servlet container @@ -3294,7 +3302,7 @@ } } - settingsModel = loadSettingModels(referencePropertiesInputStream); + settingsModel = loadSettingModels(); serverStatus.servletContainer = servletContext.getServerInfo(); } -- Gitblit v1.9.1