James Moger
2013-11-13 c44dd099a432094a12131cf60dfc8a19f5aa8101
src/main/java/com/gitblit/GitBlit.java
@@ -32,7 +32,6 @@
import java.nio.charset.Charset;
import java.security.Principal;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -62,6 +61,9 @@
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -162,7 +164,7 @@
   private final Logger logger = LoggerFactory.getLogger(GitBlit.class);
   private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(5);
   private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10);
   private final List<FederationModel> federationRegistrations = Collections
         .synchronizedList(new ArrayList<FederationModel>());
@@ -204,6 +206,8 @@
   private LuceneExecutor luceneExecutor;
   private GCExecutor gcExecutor;
   private MirrorExecutor mirrorExecutor;
   private TimeZone timezone;
@@ -2013,7 +2017,6 @@
         model.verifyCommitter = getConfig(config, "verifyCommitter", false);
         model.showRemoteBranches = getConfig(config, "showRemoteBranches", hasOrigin);
         model.isFrozen = getConfig(config, "isFrozen", false);
         model.showReadme = getConfig(config, "showReadme", false);
         model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false);
         model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false);
         model.commitMessageRenderer = CommitMessageRenderer.fromName(getConfig(config, "commitMessageRenderer",
@@ -2034,6 +2037,7 @@
         model.origin = config.getString("remote", "origin", "url");
         if (model.origin != null) {
            model.origin = model.origin.replace('\\', '/');
            model.isMirror = config.getBoolean("remote", "origin", "mirror", false);
         }
         model.preReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(
               Constants.CONFIG_GITBLIT, null, "preReceiveScript")));
@@ -2576,7 +2580,6 @@
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "verifyCommitter", repository.verifyCommitter);
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches);
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen);
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "showReadme", repository.showReadme);
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation);
      config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics);
      config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy",
@@ -2710,7 +2713,7 @@
         try {
            String prepared = processCommitMessageRegex(repository.name, text);
            return MarkdownUtils.transformMarkdown(prepared);
         } catch (ParseException e) {
         } catch (Exception e) {
            logger.error("Failed to render commit message as markdown", e);
         }
         break;
@@ -3505,6 +3508,7 @@
      mailExecutor = new MailExecutor(settings);
      luceneExecutor = new LuceneExecutor(settings, repositoriesFolder);
      gcExecutor = new GCExecutor(settings);
      mirrorExecutor = new MirrorExecutor(settings);
      // initialize utilities
      String prefix = settings.getString(Keys.git.userRepositoryPrefix, "~");
@@ -3544,6 +3548,7 @@
      configureMailExecutor();
      configureLuceneIndexing();
      configureGarbageCollector();
      configureMirrorExecutor();
      if (startFederation) {
         configureFederation();
      }
@@ -3592,6 +3597,19 @@
         }
         logger.info(MessageFormat.format("Next scheculed GC scan is in {0}", when));
         scheduledExecutor.scheduleAtFixedRate(gcExecutor, delay, 60*24, TimeUnit.MINUTES);
      }
   }
   protected void configureMirrorExecutor() {
      if (mirrorExecutor.isReady()) {
         int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.git.mirrorPeriod, "30 mins"));
         if (mins < 5) {
            mins = 5;
         }
         int delay = 1;
         scheduledExecutor.scheduleAtFixedRate(mirrorExecutor, delay, mins,  TimeUnit.MINUTES);
         logger.info("Mirror executor is scheduled to fetch updates every {} minutes.", mins);
         logger.info("Next scheduled mirror fetch is in {} minutes", delay);
      }
   }
@@ -3776,6 +3794,18 @@
               logger.error("");
            }
            try {
               // try to lookup JNDI env-entry for the baseFolder
               InitialContext ic = new InitialContext();
               Context env = (Context) ic.lookup("java:comp/env");
               String val = (String) env.lookup("baseFolder");
               if (!StringUtils.isEmpty(val)) {
                  path = val;
               }
            } catch (NamingException n) {
               logger.error("Failed to get JNDI env-entry: " + n.getExplanation());
            }
            File base = com.gitblit.utils.FileUtils.resolveParameter(Constants.contextFolder$, contextFolder, path);
            base.mkdirs();
@@ -3852,6 +3882,7 @@
      scheduledExecutor.shutdownNow();
      luceneExecutor.close();
      gcExecutor.close();
      mirrorExecutor.close();
      if (fanoutService != null) {
         fanoutService.stop();
      }