added FileSystem api

This commit is contained in:
Sebastian Sdorra
2011-01-30 13:48:07 +01:00
parent 6fa341fb0a
commit 5626cf6a77
4 changed files with 189 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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<? extends FileSystem> getFileSystemClass()
{
return fileSystemClass;
}
/**
* Method description
*
@@ -337,6 +358,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor
/** Field description */
private Set<Class<?>> extensions;
/** Field description */
private Class<? extends FileSystem> fileSystemClass;
/** Field description */
private Set<Module> moduleSet;

View File

@@ -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<? extends FileSystem> 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);