create config package

This commit is contained in:
Sebastian Sdorra
2011-05-18 21:53:24 +02:00
parent edc5b78813
commit 5aa833f3de
7 changed files with 41 additions and 9 deletions

View File

@@ -0,0 +1,102 @@
/**
* 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.cli.config;
//~--- non-JDK imports --------------------------------------------------------
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
/**
*
* @author Sebastian Sdorra
*/
public class ConfigOptionHandler extends OptionHandler<ServerConfig>
{
/**
* Constructs ...
*
*
* @param parser
* @param option
* @param setter
*/
public ConfigOptionHandler(CmdLineParser parser, OptionDef option,
Setter<? super ServerConfig> setter)
{
super(parser, option, setter);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param parameters
*
* @return
*
* @throws CmdLineException
*/
@Override
public int parseArguments(Parameters parameters) throws CmdLineException
{
String name = parameters.getParameter(0);
ServerConfig config = ScmClientConfig.getInstance().getConfig(name);
setter.addValue(config);
return 1;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getDefaultMetaVariable()
{
return "metaVar_config";
}
}

View File

@@ -0,0 +1,154 @@
/**
* 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.cli.config;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Sebastian Sdorra
*/
@XmlRootElement(name = "client-config")
public class ScmClientConfig
{
/** Field description */
public static final String DEFAULT_NAME = "default";
/** Field description */
private static volatile ScmClientConfig instance;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public ScmClientConfig()
{
this.serverConfigMap = new HashMap<String, ServerConfig>();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public static ScmClientConfig getInstance()
{
if (instance == null)
{
synchronized (ScmClientConfig.class)
{
if (instance == null)
{
instance = load();
}
}
}
return instance;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private static ScmClientConfig load()
{
// TODO load config
return new ScmClientConfig();
}
/**
* Method description
*
*/
public void store()
{
// TODO
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param name
*
* @return
*/
public ServerConfig getConfig(String name)
{
ServerConfig config = serverConfigMap.get(name);
if (config == null)
{
config = new ServerConfig();
}
return config;
}
/**
* Method description
*
*
* @return
*/
public ServerConfig getDefaultConfig()
{
return getConfig(DEFAULT_NAME);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Map<String, ServerConfig> serverConfigMap;
}

View File

@@ -0,0 +1,162 @@
/**
* 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.cli.config;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Validateable;
/**
*
* @author Sebastian Sdorra
*/
public class ServerConfig implements Validateable
{
/**
* Constructs ...
*
*/
public ServerConfig() {}
/**
* Constructs ...
*
*
* @param serverUrl
* @param username
* @param password
*/
public ServerConfig(String serverUrl, String username, String password)
{
this.serverUrl = serverUrl;
this.username = username;
this.password = password;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getPassword()
{
return password;
}
/**
* Method description
*
*
* @return
*/
public String getServerUrl()
{
return serverUrl;
}
/**
* Method description
*
*
* @return
*/
public String getUsername()
{
return username;
}
/**
* Method description
*
*
* @return
*/
@Override
public boolean isValid()
{
// TODO
return true;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param password
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Method description
*
*
* @param serverUrl
*/
public void setServerUrl(String serverUrl)
{
this.serverUrl = serverUrl;
}
/**
* Method description
*
*
* @param username
*/
public void setUsername(String username)
{
this.username = username;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String password;
/** Field description */
private String serverUrl;
/** Field description */
private String username;
}