From d544722a65368a466d21b6241e1df4c012168f29 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 25 Dec 2010 19:23:04 +0100 Subject: [PATCH] copy templates folder into lib/hg folder --- .../scm/installer/WindowsHgInstaller.java | 33 +++++++---------- .../src/main/java/sonia/scm/util/IOUtil.java | 35 +++++++++++++++++++ 2 files changed, 48 insertions(+), 20 deletions(-) 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 86c15544b7..9978aad08c 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 @@ -64,7 +64,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller { // TortoiseHg - "TortoiseHg\\hg.exe" + "TortoiseHg" }; /** Field description */ @@ -80,7 +80,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller { // TortoiseHg - "TortoiseHg\\template" + "TortoiseHg\\templates" }; /** Field description */ @@ -91,6 +91,8 @@ public class WindowsHgInstaller extends AbstractHgInstaller private static final Logger logger = LoggerFactory.getLogger(WindowsHgInstaller.class); + public static String BINARY_MERCURIAL = "hg"; + //~--- constructors --------------------------------------------------------- /** @@ -120,38 +122,29 @@ public class WindowsHgInstaller extends AbstractHgInstaller super.install(config); String progDir = getProgrammDirectory(); - String path = null; File libraryZip = find(progDir, PATH_LIBRARY_ZIP); + File libDir = null; + if (libraryZip != null) { - File libDir = new File(baseDirectory, "lib\\hg"); + libDir = new File(baseDirectory, "lib\\hg"); IOUtil.extract(libraryZip, libDir); - path = libDir.getAbsolutePath(); + config.setPythonPath(libDir.getAbsolutePath()); } - File templateDir = find(progDir, PATH_TEMPLATE); - - if (templateDir != null) + if ( libDir != null ) { - if (path != null) + File templateDir = find(progDir, PATH_TEMPLATE); + if (templateDir != null) { - path = path.concat(";").concat(templateDir.getAbsolutePath()); - } - else - { - path = templateDir.getAbsolutePath(); + IOUtil.copy(templateDir, new File(libDir, "templates")); } } - - if (path != null) - { - config.setPythonPath(path); - } - checkForOptimizedByteCode(config); config.setPythonBinary(getPythonBinary()); + config.setHgBinary( search(PATH_HG, BINARY_MERCURIAL) ); } /** diff --git a/scm-core/src/main/java/sonia/scm/util/IOUtil.java b/scm-core/src/main/java/sonia/scm/util/IOUtil.java index 2b8f5556e3..cdc9350ee8 100644 --- a/scm-core/src/main/java/sonia/scm/util/IOUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/IOUtil.java @@ -44,6 +44,8 @@ import sonia.scm.io.ZipUnArchiver; import java.io.Closeable; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -163,6 +165,39 @@ public class IOUtil } } + public static void copy( File source, File target ) throws IOException + { + if ( source.isDirectory() ) + { + if ( ! target.exists() ) + { + mkdirs(target); + } + + String[] children = source.list(); + for ( String child : children ) + { + copy(new File(source, child), new File(target, child)); + } + } + else + { + FileInputStream input = null; + FileOutputStream output = null; + try + { + input = new FileInputStream( source ); + output = new FileOutputStream( target ); + copy(input, output); + } + finally + { + close(input); + close(output); + } + } + } + /** * Method description *