added HgInstallerFactory

This commit is contained in:
Sebastian Sdorra
2011-04-25 12:45:49 +02:00
parent 10b7eb9f4d
commit 0078411301
6 changed files with 111 additions and 72 deletions

View File

@@ -54,31 +54,20 @@ public abstract class AbstractHgInstaller implements HgInstaller
/** Field description */
public static final String DIRECTORY_REPOSITORY = "repositories";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseDirectory
*/
public AbstractHgInstaller(File baseDirectory)
{
this.baseDirectory = baseDirectory;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
@Override
public void install(HgConfig config) throws IOException
public void install(File baseDirectory, HgConfig config) throws IOException
{
File repoDirectory = new File(
baseDirectory,
@@ -88,9 +77,4 @@ public abstract class AbstractHgInstaller implements HgInstaller
IOUtil.mkdirs(repoDirectory);
config.setRepositoryDirectory(repoDirectory);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected File baseDirectory;
}

View File

@@ -35,9 +35,13 @@ package sonia.scm.installer;
//~--- non-JDK imports --------------------------------------------------------
import java.io.IOException;
import sonia.scm.repository.HgConfig;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
@@ -49,15 +53,23 @@ public interface HgInstaller
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
public void install(HgConfig config) throws IOException;
public void install(File baseDirectory, HgConfig config) throws IOException;
/**
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
public void update(HgConfig config) throws IOException;
public void update(File baseDirectory, HgConfig config) throws IOException;
}

View File

@@ -0,0 +1,68 @@
/**
* 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.installer;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.SystemUtil;
/**
*
* @author Sebastian Sdorra
*/
public class HgInstallerFactory
{
/**
* Method description
*
*
* @return
*/
public static HgInstaller createInstaller()
{
HgInstaller installer = null;
if (SystemUtil.isWindows())
{
installer = new WindowsHgInstaller();
}
else
{
installer = new UnixHgInstaller();
}
return installer;
}
}

View File

@@ -50,31 +50,20 @@ import java.io.IOException;
public class UnixHgInstaller extends AbstractHgInstaller
{
/**
* Constructs ...
*
*
* @param baseDirectory
*/
public UnixHgInstaller(File baseDirectory)
{
super(baseDirectory);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
@Override
public void install(HgConfig config) throws IOException
public void install(File baseDirectory, HgConfig config) throws IOException
{
super.install(config);
super.install(baseDirectory, config);
config.setHgBinary(IOUtil.search("hg"));
config.setPythonBinary(IOUtil.search("python"));
}
@@ -83,10 +72,12 @@ public class UnixHgInstaller extends AbstractHgInstaller
* Method description
*
*
*
* @param baseDirectory
* @param config
*/
@Override
public void update(HgConfig config)
public void update(File baseDirectory, HgConfig config)
{
// do nothing

View File

@@ -94,33 +94,22 @@ public class WindowsHgInstaller extends AbstractHgInstaller
private static final Logger logger =
LoggerFactory.getLogger(WindowsHgInstaller.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param baseDirectory
*/
public WindowsHgInstaller(File baseDirectory)
{
super(baseDirectory);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param baseDirectory
* @param config
*
* @throws IOException
*/
@Override
public void install(HgConfig config) throws IOException
public void install(File baseDirectory, HgConfig config) throws IOException
{
super.install(config);
super.install(baseDirectory, config);
String pythonBinary = getPythonBinary();
@@ -135,7 +124,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
}
else if (hgDirectory != null)
{
installHg(config, hgDirectory);
installHg(baseDirectory, config, hgDirectory);
}
checkForOptimizedByteCode(config);
@@ -145,10 +134,12 @@ public class WindowsHgInstaller extends AbstractHgInstaller
* Method description
*
*
*
* @param baseDirectory
* @param config
*/
@Override
public void update(HgConfig config) {}
public void update(File baseDirectory, HgConfig config) {}
/**
* Method description
@@ -204,12 +195,15 @@ public class WindowsHgInstaller extends AbstractHgInstaller
* Method description
*
*
*
* @param baseDirectory
* @param config
* @param hgDirectory
*
* @throws IOException
*/
private void installHg(HgConfig config, File hgDirectory) throws IOException
private void installHg(File baseDirectory, HgConfig config, File hgDirectory)
throws IOException
{
if (logger.isInfoEnabled())
{

View File

@@ -38,12 +38,12 @@ package sonia.scm.repository;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.Type;
import sonia.scm.installer.HgInstaller;
import sonia.scm.installer.UnixHgInstaller;
import sonia.scm.installer.WindowsHgInstaller;
import sonia.scm.installer.HgInstallerFactory;
import sonia.scm.io.ExtendedCommand;
import sonia.scm.io.FileSystem;
import sonia.scm.io.INIConfiguration;
@@ -52,7 +52,6 @@ import sonia.scm.io.INISection;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.SystemUtil;
import sonia.scm.web.HgWebConfigWriter;
//~--- JDK imports ------------------------------------------------------------
@@ -82,7 +81,7 @@ public class HgRepositoryHandler
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
/** the logger for HgRepositoryHandler */
private static final org.slf4j.Logger logger =
private static final Logger logger =
LoggerFactory.getLogger(HgRepositoryHandler.class);
//~--- constructors ---------------------------------------------------------
@@ -108,16 +107,7 @@ public class HgRepositoryHandler
*/
public void doAutoConfiguration()
{
HgInstaller installer = null;
if (SystemUtil.isWindows())
{
installer = new WindowsHgInstaller(baseDirectory);
}
else
{
installer = new UnixHgInstaller(baseDirectory);
}
HgInstaller installer = HgInstallerFactory.createInstaller();
if (config == null)
{
@@ -131,7 +121,7 @@ public class HgRepositoryHandler
installer.getClass().getName());
}
installer.install(config);
installer.install(baseDirectory, config);
new HgWebConfigWriter(config).write();
}
catch (IOException ioe)
@@ -154,7 +144,7 @@ public class HgRepositoryHandler
installer.getClass().getName());
}
installer.update(config);
installer.update(baseDirectory, config);
}
catch (IOException ex)
{