Commits

Sebastian Sdorra committed 7245f04

added repository browser support for nested repositories

Comments (0)

Files changed (4)

src/main/java/sonia/scm/hgnested/HgNestedFileObjectPreProcessor.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. Neither the name of SCM-Manager; nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.hgnested;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sonia.scm.repository.FileObject;
+import sonia.scm.repository.FileObjectPreProcessor;
+import sonia.scm.repository.SubRepository;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class HgNestedFileObjectPreProcessor implements FileObjectPreProcessor
+{
+
+  /** the logger for HgNestedFileObjectPreProcessor */
+  private static final Logger logger =
+    LoggerFactory.getLogger(HgNestedFileObjectPreProcessor.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param configuration
+   * @param request
+   */
+  public HgNestedFileObjectPreProcessor(HgNestedConfiguration configuration,
+          HttpServletRequest request)
+  {
+    this.configuration = configuration;
+    this.request = request;
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param fo
+   */
+  @Override
+  public void process(FileObject fo)
+  {
+    if (configuration.isNestedRepositoryConfigured())
+    {
+      if (logger.isTraceEnabled())
+      {
+        logger.trace("check file object {} for nested repository",
+                     fo.getPath());
+      }
+
+      SubRepository sub = fo.getSubRepository();
+
+      if (sub != null)
+      {
+        if (logger.isTraceEnabled())
+        {
+          logger.trace("check sub repository {} for nested repository",
+                       fo.getPath());
+        }
+
+        HgNestedRepository repository =
+          configuration.getNestedRepository(fo.getPath());
+
+        if (repository != null)
+        {
+          String url = HgNestedUtil.createUrl(request, repository);
+
+          if (logger.isDebugEnabled())
+          {
+            logger.debug("set sub repsoitory url to {}", url);
+          }
+
+          sub.setRepositoryUrl(url);
+        }
+      }
+    }
+    else if (logger.isTraceEnabled())
+    {
+      logger.trace(
+          "skip nested repository check, because no nested repository is configured");
+    }
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private HgNestedConfiguration configuration;
+
+  /** Field description */
+  private HttpServletRequest request;
+}

src/main/java/sonia/scm/hgnested/HgNestedFileObjectPreProcessorFactory.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. Neither the name of SCM-Manager; nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.hgnested;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import sonia.scm.plugin.ext.Extension;
+import sonia.scm.repository.FileObjectPreProcessor;
+import sonia.scm.repository.FileObjectPreProcessorFactory;
+import sonia.scm.repository.Repository;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@Extension
+public class HgNestedFileObjectPreProcessorFactory
+        implements FileObjectPreProcessorFactory
+{
+
+  /** the logger for HgNestedFileObjectPreProcessorFactory */
+  private static final Logger logger =
+    LoggerFactory.getLogger(HgNestedFileObjectPreProcessorFactory.class);
+
+  //~--- constructors ---------------------------------------------------------
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param requestProvider
+   */
+  @Inject
+  public HgNestedFileObjectPreProcessorFactory(
+          Provider<HttpServletRequest> requestProvider)
+  {
+    this.requestProvider = requestProvider;
+  }
+
+  //~--- methods --------------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param repository
+   *
+   * @return
+   */
+  @Override
+  public FileObjectPreProcessor createPreProcessor(Repository repository)
+  {
+    if (logger.isTraceEnabled())
+    {
+      logger.trace("create file object pre processor for repository {}",
+                   repository.getName());
+    }
+
+    HgNestedConfiguration config = new HgNestedConfiguration(repository);
+
+    return new HgNestedFileObjectPreProcessor(config, requestProvider.get());
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private Provider<HttpServletRequest> requestProvider;
+}

src/main/java/sonia/scm/hgnested/HgNestedRepositoryRequestListener.java

 
           if (r != null)
           {
-            String url = createUrl(request, r);
+            String url = HgNestedUtil.createUrl(request, r);
 
             if (logger.isDebugEnabled())
             {
     return process;
   }
 
-  /**
-   * Method description
-   *
-   *
-   * @param request
-   * @param r
-   *
-   * @return
-   */
-  private String createUrl(HttpServletRequest request, HgNestedRepository r)
-  {
-    String url = r.getUrl();
-
-    if (!url.startsWith("http"))
-    {
-      StringBuilder buffer = new StringBuilder(request.getScheme());
-
-      buffer.append("://").append(request.getServerName()).append(":");
-      buffer.append(String.valueOf(request.getServerPort()));
-      buffer.append(request.getContextPath()).append("/hg");
-
-      if (!url.startsWith("/"))
-      {
-        buffer.append("/");
-      }
-
-      buffer.append(url);
-      url = buffer.toString();
-    }
-
-    return url;
-  }
-
   //~--- get methods ----------------------------------------------------------
 
   /**

src/main/java/sonia/scm/hgnested/HgNestedUtil.java

+/**
+ * Copyright (c) 2010, Sebastian Sdorra
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. Neither the name of SCM-Manager; nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+
+
+
+package sonia.scm.hgnested;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class HgNestedUtil
+{
+
+  /**
+   * Method description
+   *
+   *
+   * @param request
+   * @param r
+   *
+   * @return
+   */
+  public static String createUrl(HttpServletRequest request,
+                                 HgNestedRepository r)
+  {
+    String url = r.getUrl();
+
+    if (!url.startsWith("http"))
+    {
+      StringBuilder buffer = new StringBuilder(request.getScheme());
+
+      buffer.append("://").append(request.getServerName()).append(":");
+      buffer.append(String.valueOf(request.getServerPort()));
+      buffer.append(request.getContextPath()).append("/hg");
+
+      if (!url.startsWith("/"))
+      {
+        buffer.append("/");
+      }
+
+      buffer.append(url);
+      url = buffer.toString();
+    }
+
+    return url;
+  }
+}