mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
added general configuration
This commit is contained in:
@@ -45,6 +45,7 @@ import sonia.scm.api.rest.UriExtensionsConfig;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.cache.CacheRepositoryManagerDecorator;
|
||||
import sonia.scm.cache.EhCacheManager;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.filter.SecurityFilter;
|
||||
import sonia.scm.plugin.ScriptResourceServlet;
|
||||
import sonia.scm.repository.BasicRepositoryManager;
|
||||
@@ -74,12 +75,16 @@ import com.sun.jersey.api.core.ResourceConfig;
|
||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -152,6 +157,10 @@ public class ScmServletModule extends ServletModule
|
||||
|
||||
bind(SCMContextProvider.class).toInstance(context);
|
||||
|
||||
ScmConfiguration config = getScmConfiguration(context);
|
||||
|
||||
bind(ScmConfiguration.class).toInstance(config);
|
||||
|
||||
// bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
|
||||
// bind(Authenticator.class).to(XmlAuthenticator.class);
|
||||
bind(SecurityContext.class).to(BasicSecurityContext.class);
|
||||
@@ -162,7 +171,8 @@ public class ScmServletModule extends ServletModule
|
||||
bind(RepositoryManager.class).to(CacheRepositoryManagerDecorator.class);
|
||||
bind(UserManager.class).to(BasicUserManager.class);
|
||||
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
||||
//filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
||||
|
||||
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
||||
|
||||
/*
|
||||
* filter(PATTERN_PAGE,
|
||||
@@ -320,6 +330,41 @@ public class ScmServletModule extends ServletModule
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ScmConfiguration getScmConfiguration(SCMContextProvider context)
|
||||
{
|
||||
ScmConfiguration config = null;
|
||||
File file = new File(context.getBaseDirectory(), ScmConfiguration.PATH);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
JAXB.unmarshal(file, ScmConfiguration.class);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
config = new ScmConfiguration();
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* 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.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
@Path("config")
|
||||
public class ConfigurationResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
*/
|
||||
@Inject
|
||||
public ConfigurationResource(ScmConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public ScmConfiguration getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param uriInfo
|
||||
* @param newConfig
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo,
|
||||
ScmConfiguration newConfig)
|
||||
{
|
||||
configuration.load(newConfig);
|
||||
|
||||
synchronized (ScmConfiguration.class)
|
||||
{
|
||||
File file = new File(SCMContext.getContext().getBaseDirectory(),
|
||||
ScmConfiguration.PATH);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
IOUtil.mkdirs(file.getParentFile());
|
||||
}
|
||||
|
||||
JAXB.marshal(configuration, file);
|
||||
}
|
||||
|
||||
return Response.created(uriInfo.getRequestUri()).build();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
public ScmConfiguration configuration;
|
||||
}
|
||||
105
scm-webapp/src/main/java/sonia/scm/config/ScmConfiguration.java
Normal file
105
scm-webapp/src/main/java/sonia/scm/config/ScmConfiguration.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 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.config;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
@XmlRootElement(name = "scm-config")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ScmConfiguration
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PATH =
|
||||
"config".concat(File.separator).concat("config.xml");
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
public void load(ScmConfiguration other)
|
||||
{
|
||||
this.servername = other.servername;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getServername()
|
||||
{
|
||||
return servername;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param servername
|
||||
*/
|
||||
public void setServername(String servername)
|
||||
{
|
||||
this.servername = servername;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String servername = "localhost";
|
||||
}
|
||||
@@ -41,6 +41,8 @@ Ext.ns("Sonia.config");
|
||||
|
||||
Sonia.config.ConfigPanel = Ext.extend(Ext.Panel, {
|
||||
|
||||
panels: null,
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var config = {
|
||||
@@ -52,7 +54,7 @@ Sonia.config.ConfigPanel = Ext.extend(Ext.Panel, {
|
||||
frame: false,
|
||||
collapsible: false,
|
||||
collapsed: false,
|
||||
items: repositoryConfigPanels
|
||||
items: this.panels
|
||||
}
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
@@ -63,6 +65,85 @@ Sonia.config.ConfigPanel = Ext.extend(Ext.Panel, {
|
||||
|
||||
Ext.reg("configPanel", Sonia.config.ConfigPanel);
|
||||
|
||||
Sonia.config.RepositoryConfig = Ext.extend(Sonia.config.ConfigPanel,{
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var config = {
|
||||
panels: repositoryConfigPanels
|
||||
}
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.config.RepositoryConfig.superclass.initComponent.apply(this, arguments);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg("repositoryConfig", Sonia.config.RepositoryConfig);
|
||||
|
||||
Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var config = {
|
||||
panels: [{
|
||||
xtype: 'configForm',
|
||||
title : 'General Settings',
|
||||
items : [{
|
||||
xtype : 'textfield',
|
||||
fieldLabel : 'Servername',
|
||||
name : 'servername',
|
||||
allowBlank : false
|
||||
}],
|
||||
|
||||
onSubmit: function(values){
|
||||
this.el.mask('Submit ...');
|
||||
Ext.Ajax.request({
|
||||
url: restUrl + 'config.json',
|
||||
method: 'POST',
|
||||
jsonData: values,
|
||||
scope: this,
|
||||
disableCaching: true,
|
||||
success: function(response){
|
||||
this.el.unmask();
|
||||
},
|
||||
failure: function(){
|
||||
this.el.unmask();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoad: function(el){
|
||||
var tid = setTimeout( function(){ el.mask('Loading ...'); }, 100);
|
||||
Ext.Ajax.request({
|
||||
url: restUrl + 'config.json',
|
||||
method: 'GET',
|
||||
scope: this,
|
||||
disableCaching: true,
|
||||
success: function(response){
|
||||
var obj = Ext.decode(response.responseText);
|
||||
this.load(obj);
|
||||
clearTimeout(tid);
|
||||
el.unmask();
|
||||
},
|
||||
failure: function(){
|
||||
el.unmask();
|
||||
clearTimeout(tid);
|
||||
alert('failure');
|
||||
}
|
||||
});
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.config.ScmConfigPanel.superclass.initComponent.apply(this, arguments);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg("scmConfig", Sonia.config.ScmConfigPanel);
|
||||
|
||||
Sonia.config.ConfigForm = Ext.extend(Ext.form.FormPanel, {
|
||||
|
||||
title: 'Config Form',
|
||||
|
||||
@@ -121,11 +121,13 @@ Ext.onReady(function(){
|
||||
title: 'Config',
|
||||
items: [{
|
||||
label: 'General',
|
||||
fn: function(){console.debug( 'General Config' );}
|
||||
fn: function(){
|
||||
addTabPanel("scmConfig", "scmConfig", "Scm Config");
|
||||
}
|
||||
},{
|
||||
label: 'Repository Types',
|
||||
fn: function(){
|
||||
addTabPanel('repositoryConfig', 'configPanel', 'Repository Config');
|
||||
addTabPanel('repositoryConfig', 'repositoryConfig', 'Repository Config');
|
||||
}
|
||||
},{
|
||||
label: 'Server',
|
||||
|
||||
Reference in New Issue
Block a user