diff --git a/scm-core/src/main/java/sonia/scm/io/DefaultFileSystem.java b/scm-core/src/main/java/sonia/scm/io/DefaultFileSystem.java new file mode 100644 index 0000000000..5904e92624 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/io/DefaultFileSystem.java @@ -0,0 +1,79 @@ +/** + * 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.io; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.util.IOUtil; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class DefaultFileSystem implements FileSystem +{ + + /** + * Method description + * + * + * @param directory + * + * @throws IOException + */ + @Override + public void create(File directory) throws IOException + { + IOUtil.mkdirs(directory); + } + + /** + * Method description + * + * + * @param directory + * + * @throws IOException + */ + @Override + public void destroy(File directory) throws IOException + { + IOUtil.delete(directory); + } +} diff --git a/scm-core/src/main/java/sonia/scm/io/FileSystem.java b/scm-core/src/main/java/sonia/scm/io/FileSystem.java new file mode 100644 index 0000000000..39c366a512 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/io/FileSystem.java @@ -0,0 +1,74 @@ +/** + * 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.io; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.plugin.ExtensionPoint; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +@ExtensionPoint +public interface FileSystem +{ + + /** + * Method description + * + * + * + * @param directory + * + * @throws IOException + */ + public void create(File directory) throws IOException; + + /** + * Method description + * + * + * + * @param directory + * + * @throws IOException + */ + public void destroy(File directory) throws IOException; +} diff --git a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java index fe9fcc8988..570cdb74d5 100644 --- a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java +++ b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java @@ -43,6 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.group.GroupListener; +import sonia.scm.io.FileSystem; import sonia.scm.plugin.ext.Extension; import sonia.scm.plugin.ext.ExtensionProcessor; import sonia.scm.repository.RepositoryHandler; @@ -188,6 +189,15 @@ public class BindingExtensionProcessor implements ExtensionProcessor resourceHandler.addBinding().to(extensionClass); } + else if (FileSystem.class.isAssignableFrom(extensionClass)) + { + if (logger.isInfoEnabled()) + { + logger.info("bind FileSystem {}", extensionClass.getName()); + } + + fileSystemClass = extensionClass; + } else { if (logger.isInfoEnabled()) @@ -243,6 +253,17 @@ public class BindingExtensionProcessor implements ExtensionProcessor return authenticationListeners; } + /** + * Method description + * + * + * @return + */ + public Class getFileSystemClass() + { + return fileSystemClass; + } + /** * Method description * @@ -337,6 +358,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor /** Field description */ private Set> extensions; + /** Field description */ + private Class fileSystemClass; + /** Field description */ private Set moduleSet; diff --git a/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java b/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java index 8b8845ae77..0be05e5821 100644 --- a/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java +++ b/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java @@ -49,6 +49,8 @@ import sonia.scm.filter.SSLFilter; import sonia.scm.filter.SecurityFilter; import sonia.scm.group.GroupManager; import sonia.scm.group.xml.XmlGroupManager; +import sonia.scm.io.DefaultFileSystem; +import sonia.scm.io.FileSystem; import sonia.scm.plugin.DefaultPluginManager; import sonia.scm.plugin.Plugin; import sonia.scm.plugin.PluginLoader; @@ -175,6 +177,16 @@ public class ScmServletModule extends ServletModule bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class); bindExtProcessor.bindExtensions(binder()); + Class fileSystem = + bindExtProcessor.getFileSystemClass(); + + if (fileSystem == null) + { + fileSystem = DefaultFileSystem.class; + } + + bind(FileSystem.class).to(fileSystem); + // bind security stuff bind(AuthenticationManager.class).to(ChainAuthenticatonManager.class); bind(SecurityContext.class).to(BasicSecurityContext.class);