mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 18:46:07 +01:00 
			
		
		
		
	subversion support for directory structures
This commit is contained in:
		| @@ -102,7 +102,7 @@ public class SvnRepositoryHandler | ||||
|     // register hook | ||||
|     if (repositoryManager != null) | ||||
|     { | ||||
|       FSHooks.registerHook(new SvnRepositoryHook(repositoryManager)); | ||||
|       FSHooks.registerHook(new SvnRepositoryHook(repositoryManager, this)); | ||||
|     } | ||||
|     else if (logger.isWarnEnabled()) | ||||
|     { | ||||
|   | ||||
| @@ -46,6 +46,7 @@ import org.tmatesoft.svn.core.internal.io.fs.FSHook; | ||||
| import org.tmatesoft.svn.core.internal.io.fs.FSHookEvent; | ||||
| import org.tmatesoft.svn.core.internal.io.fs.FSHooks; | ||||
|  | ||||
| import sonia.scm.util.IOUtil; | ||||
| import sonia.scm.util.Util; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
| @@ -70,10 +71,13 @@ public class SvnRepositoryHook implements FSHook | ||||
|    * | ||||
|    * | ||||
|    * @param repositoryManager | ||||
|    * @param handler | ||||
|    */ | ||||
|   public SvnRepositoryHook(RepositoryManager repositoryManager) | ||||
|   public SvnRepositoryHook(RepositoryManager repositoryManager, | ||||
|                            SvnRepositoryHandler handler) | ||||
|   { | ||||
|     this.repositoryManager = repositoryManager; | ||||
|     this.handler = handler; | ||||
|   } | ||||
|  | ||||
|   //~--- methods -------------------------------------------------------------- | ||||
| @@ -151,8 +155,14 @@ public class SvnRepositoryHook implements FSHook | ||||
|   { | ||||
|     try | ||||
|     { | ||||
|       repositoryManager.fireHookEvent(SvnRepositoryHandler.TYPE_NAME, | ||||
|                                       directory.getName(), hookEvent); | ||||
|       String name = | ||||
|         directory.getAbsolutePath() | ||||
|           .substring(handler.getConfig().getRepositoryDirectory() | ||||
|             .getAbsolutePath().length()); | ||||
|  | ||||
|       name = IOUtil.trimSeperatorChars(name); | ||||
|       repositoryManager.fireHookEvent(SvnRepositoryHandler.TYPE_NAME, name, | ||||
|                                       hookEvent); | ||||
|     } | ||||
|     catch (Exception ex) | ||||
|     { | ||||
| @@ -168,6 +178,9 @@ public class SvnRepositoryHook implements FSHook | ||||
|  | ||||
|   //~--- fields --------------------------------------------------------------- | ||||
|  | ||||
|   /** Field description */ | ||||
|   private SvnRepositoryHandler handler; | ||||
|  | ||||
|   /** Field description */ | ||||
|   private RepositoryManager repositoryManager; | ||||
| } | ||||
|   | ||||
| @@ -35,10 +35,17 @@ package sonia.scm.web; | ||||
|  | ||||
| //~--- non-JDK imports -------------------------------------------------------- | ||||
|  | ||||
| import com.google.inject.Provider; | ||||
|  | ||||
| import org.tmatesoft.svn.core.internal.server.dav.DAVConfig; | ||||
| import org.tmatesoft.svn.core.internal.server.dav.SVNPathBasedAccess; | ||||
|  | ||||
| import sonia.scm.repository.SvnConfig; | ||||
| import sonia.scm.repository.Repository; | ||||
| import sonia.scm.repository.SvnRepositoryHandler; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -52,12 +59,15 @@ public class SvnDAVConfig extends DAVConfig | ||||
|    * | ||||
|    * | ||||
|    * @param davConfig | ||||
|    * @param config | ||||
|    * @param handler | ||||
|    * @param repositoryProvider | ||||
|    */ | ||||
|   public SvnDAVConfig(DAVConfig davConfig, SvnConfig config) | ||||
|   public SvnDAVConfig(DAVConfig davConfig, SvnRepositoryHandler handler, | ||||
|                       Provider<Repository> repositoryProvider) | ||||
|   { | ||||
|     this.davConfig = davConfig; | ||||
|     this.config = config; | ||||
|     this.handler = handler; | ||||
|     this.repositoryProvider = repositoryProvider; | ||||
|   } | ||||
|  | ||||
|   //~--- get methods ---------------------------------------------------------- | ||||
| @@ -71,7 +81,7 @@ public class SvnDAVConfig extends DAVConfig | ||||
|   @Override | ||||
|   public String getActivitiesDBPath() | ||||
|   { | ||||
|     return davConfig.getActivitiesDBPath(); | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -95,7 +105,19 @@ public class SvnDAVConfig extends DAVConfig | ||||
|   @Override | ||||
|   public String getRepositoryParentPath() | ||||
|   { | ||||
|     return config.getRepositoryDirectory().getAbsolutePath(); | ||||
|     String path = null; | ||||
|     File directory = getRepositoryDirectory(); | ||||
|  | ||||
|     if (directory != null) | ||||
|     { | ||||
|       path = directory.getParent(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       path = davConfig.getRepositoryPath(); | ||||
|     } | ||||
|  | ||||
|     return path; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -107,7 +129,19 @@ public class SvnDAVConfig extends DAVConfig | ||||
|   @Override | ||||
|   public String getRepositoryPath() | ||||
|   { | ||||
|     return davConfig.getRepositoryPath(); | ||||
|     String path = null; | ||||
|     File directory = getRepositoryDirectory(); | ||||
|  | ||||
|     if (directory != null) | ||||
|     { | ||||
|       path = directory.getAbsolutePath(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       path = davConfig.getRepositoryPath(); | ||||
|     } | ||||
|  | ||||
|     return path; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -227,14 +261,36 @@ public class SvnDAVConfig extends DAVConfig | ||||
|   @Override | ||||
|   public boolean isUsingRepositoryPathDirective() | ||||
|   { | ||||
|     return davConfig.isUsingRepositoryPathDirective(); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|    * | ||||
|    * @return | ||||
|    */ | ||||
|   private File getRepositoryDirectory() | ||||
|   { | ||||
|     File directory = null; | ||||
|     Repository repository = repositoryProvider.get(); | ||||
|  | ||||
|     if (repository != null) | ||||
|     { | ||||
|       directory = handler.getDirectory(repository); | ||||
|     } | ||||
|  | ||||
|     return directory; | ||||
|   } | ||||
|  | ||||
|   //~--- fields --------------------------------------------------------------- | ||||
|  | ||||
|   /** Field description */ | ||||
|   private SvnConfig config; | ||||
|   private DAVConfig davConfig; | ||||
|  | ||||
|   /** Field description */ | ||||
|   private DAVConfig davConfig; | ||||
|   private SvnRepositoryHandler handler; | ||||
|  | ||||
|   /** Field description */ | ||||
|   private Provider<Repository> repositoryProvider; | ||||
| } | ||||
|   | ||||
| @@ -36,12 +36,26 @@ package sonia.scm.web; | ||||
| //~--- non-JDK imports -------------------------------------------------------- | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.Singleton; | ||||
|  | ||||
| import org.tmatesoft.svn.core.internal.server.dav.DAVConfig; | ||||
| import org.tmatesoft.svn.core.internal.server.dav.DAVServlet; | ||||
|  | ||||
| import sonia.scm.repository.Repository; | ||||
| import sonia.scm.repository.SvnRepositoryHandler; | ||||
| import sonia.scm.util.AssertUtil; | ||||
| import sonia.scm.util.HttpUtil; | ||||
| import sonia.scm.util.IOUtil; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletRequestWrapper; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -61,11 +75,34 @@ public class SvnDAVServlet extends DAVServlet | ||||
|    * | ||||
|    * | ||||
|    * @param handler | ||||
|    * @param repositoryProvider | ||||
|    */ | ||||
|   @Inject | ||||
|   public SvnDAVServlet(SvnRepositoryHandler handler) | ||||
|   public SvnDAVServlet(SvnRepositoryHandler handler, | ||||
|                        Provider<Repository> repositoryProvider) | ||||
|   { | ||||
|     this.handler = handler; | ||||
|     this.repositoryProvider = repositoryProvider; | ||||
|   } | ||||
|  | ||||
|   //~--- methods -------------------------------------------------------------- | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|    * | ||||
|    * @param request | ||||
|    * @param response | ||||
|    * | ||||
|    * @throws IOException | ||||
|    * @throws ServletException | ||||
|    */ | ||||
|   @Override | ||||
|   public void service(HttpServletRequest request, HttpServletResponse response) | ||||
|           throws ServletException, IOException | ||||
|   { | ||||
|     super.service(new SvnHttpServletRequestWrapper(request, | ||||
|             repositoryProvider), response); | ||||
|   } | ||||
|  | ||||
|   //~--- get methods ---------------------------------------------------------- | ||||
| @@ -79,11 +116,103 @@ public class SvnDAVServlet extends DAVServlet | ||||
|   @Override | ||||
|   protected DAVConfig getDAVConfig() | ||||
|   { | ||||
|     return new SvnDAVConfig(super.getDAVConfig(), handler.getConfig()); | ||||
|     return new SvnDAVConfig(super.getDAVConfig(), handler, repositoryProvider); | ||||
|   } | ||||
|  | ||||
|   //~--- inner classes -------------------------------------------------------- | ||||
|  | ||||
|   /** | ||||
|    * Class description | ||||
|    * | ||||
|    * | ||||
|    * @version        Enter version here..., 11/10/23 | ||||
|    * @author         Enter your name here... | ||||
|    */ | ||||
|   private static class SvnHttpServletRequestWrapper | ||||
|           extends HttpServletRequestWrapper | ||||
|   { | ||||
|  | ||||
|     /** | ||||
|      * Constructs ... | ||||
|      * | ||||
|      * | ||||
|      * @param request | ||||
|      * @param repositoryProvider | ||||
|      */ | ||||
|     public SvnHttpServletRequestWrapper(HttpServletRequest request, | ||||
|             Provider<Repository> repositoryProvider) | ||||
|     { | ||||
|       super(request); | ||||
|       this.repositoryProvider = repositoryProvider; | ||||
|     } | ||||
|  | ||||
|     //~--- get methods -------------------------------------------------------- | ||||
|  | ||||
|     /** | ||||
|      * Method description | ||||
|      * | ||||
|      * | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public String getPathInfo() | ||||
|     { | ||||
|       String pathInfo = super.getPathInfo(); | ||||
|  | ||||
|       AssertUtil.assertIsNotEmpty(pathInfo); | ||||
|  | ||||
|       Repository repository = repositoryProvider.get(); | ||||
|  | ||||
|       if (repository != null) | ||||
|       { | ||||
|         if (pathInfo.startsWith(HttpUtil.SEPARATOR_PATH)) | ||||
|         { | ||||
|           pathInfo = pathInfo.substring(1); | ||||
|         } | ||||
|  | ||||
|         pathInfo = pathInfo.substring(repository.getName().length()); | ||||
|       } | ||||
|  | ||||
|       return pathInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method description | ||||
|      * | ||||
|      * | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public String getServletPath() | ||||
|     { | ||||
|       String servletPath = super.getServletPath(); | ||||
|       Repository repository = repositoryProvider.get(); | ||||
|  | ||||
|       if (repository != null) | ||||
|       { | ||||
|         if (!servletPath.endsWith(HttpUtil.SEPARATOR_PATH)) | ||||
|         { | ||||
|           servletPath = servletPath.concat(HttpUtil.SEPARATOR_PATH); | ||||
|         } | ||||
|  | ||||
|         servletPath = servletPath.concat(repository.getName()); | ||||
|       } | ||||
|  | ||||
|       return servletPath; | ||||
|     } | ||||
|  | ||||
|     //~--- fields ------------------------------------------------------------- | ||||
|  | ||||
|     /** Field description */ | ||||
|     private Provider<Repository> repositoryProvider; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   //~--- fields --------------------------------------------------------------- | ||||
|  | ||||
|   /** Field description */ | ||||
|   private SvnRepositoryHandler handler; | ||||
|  | ||||
|   /** Field description */ | ||||
|   private Provider<Repository> repositoryProvider; | ||||
| } | ||||
|   | ||||
| @@ -39,9 +39,8 @@ import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.Singleton; | ||||
|  | ||||
| import sonia.scm.repository.RepositoryManager; | ||||
| import sonia.scm.repository.SvnRepositoryHandler; | ||||
| import sonia.scm.web.filter.RegexPermissionFilter; | ||||
| import sonia.scm.repository.Repository; | ||||
| import sonia.scm.web.filter.ProviderPermissionFilter; | ||||
| import sonia.scm.web.security.WebSecurityContext; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
| @@ -57,7 +56,7 @@ import javax.servlet.http.HttpServletRequest; | ||||
|  * @author Sebastian Sdorra | ||||
|  */ | ||||
| @Singleton | ||||
| public class SvnPermissionFilter extends RegexPermissionFilter | ||||
| public class SvnPermissionFilter extends ProviderPermissionFilter | ||||
| { | ||||
|  | ||||
|   /** Field description */ | ||||
| @@ -74,30 +73,18 @@ public class SvnPermissionFilter extends RegexPermissionFilter | ||||
|    * | ||||
|    * | ||||
|    * @param securityContextProvider | ||||
|    * @param repositoryManager | ||||
|    * @param repository | ||||
|    */ | ||||
|   @Inject | ||||
|   public SvnPermissionFilter( | ||||
|           Provider<WebSecurityContext> securityContextProvider, | ||||
|           RepositoryManager repositoryManager) | ||||
|           Provider<Repository> repository) | ||||
|   { | ||||
|     super(securityContextProvider, repositoryManager); | ||||
|     super(securityContextProvider, repository); | ||||
|   } | ||||
|  | ||||
|   //~--- get methods ---------------------------------------------------------- | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|    * | ||||
|    * @return | ||||
|    */ | ||||
|   @Override | ||||
|   protected String getType() | ||||
|   { | ||||
|     return SvnRepositoryHandler.TYPE_NAME; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user