From 0078411301c0bdbbfd79675c88a180f866ff9265 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 25 Apr 2011 12:45:49 +0200 Subject: [PATCH] added HgInstallerFactory --- .../scm/installer/AbstractHgInstaller.java | 22 +----- .../java/sonia/scm/installer/HgInstaller.java | 18 ++++- .../scm/installer/HgInstallerFactory.java | 68 +++++++++++++++++++ .../sonia/scm/installer/UnixHgInstaller.java | 23 ++----- .../scm/installer/WindowsHgInstaller.java | 30 ++++---- .../scm/repository/HgRepositoryHandler.java | 22 ++---- 6 files changed, 111 insertions(+), 72 deletions(-) create mode 100644 plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstallerFactory.java diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/AbstractHgInstaller.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/AbstractHgInstaller.java index a647368358..71e4f7660c 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/AbstractHgInstaller.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/AbstractHgInstaller.java @@ -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; } diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstaller.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstaller.java index 7a78601701..1a7b98a0ae 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstaller.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstaller.java @@ -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; } diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstallerFactory.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstallerFactory.java new file mode 100644 index 0000000000..588cb55f12 --- /dev/null +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/HgInstallerFactory.java @@ -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; + } +} diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/UnixHgInstaller.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/UnixHgInstaller.java index cbef81f569..6004ed91e6 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/UnixHgInstaller.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/UnixHgInstaller.java @@ -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 diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/WindowsHgInstaller.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/WindowsHgInstaller.java index bf8d2c0d68..9deadbb33a 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/WindowsHgInstaller.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/installer/WindowsHgInstaller.java @@ -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()) { diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java index 5a10f8b87e..c690b92127 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java @@ -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) {