mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Enhance WindowsHgInstaller to use Mercurial packages (source or binary) installed into a Python installation.
This commit is contained in:
@@ -29,8 +29,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.installer;
|
package sonia.scm.installer;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -50,6 +48,8 @@ import sonia.scm.util.SystemUtil;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -62,8 +62,8 @@ public abstract class AbstractHgInstaller implements HgInstaller
|
|||||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||||
|
|
||||||
/** the logger for AbstractHgInstaller */
|
/** the logger for AbstractHgInstaller */
|
||||||
private static final Logger logger =
|
private static final Logger logger = LoggerFactory
|
||||||
LoggerFactory.getLogger(AbstractHgInstaller.class);
|
.getLogger(AbstractHgInstaller.class);
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
@@ -91,10 +91,8 @@ public abstract class AbstractHgInstaller implements HgInstaller
|
|||||||
@Override
|
@Override
|
||||||
public void install(HgConfig config) throws IOException
|
public void install(HgConfig config) throws IOException
|
||||||
{
|
{
|
||||||
File repoDirectory = new File(
|
File repoDirectory = new File(baseDirectory, DIRECTORY_REPOSITORY.concat(
|
||||||
baseDirectory,
|
File.separator).concat(HgRepositoryHandler.TYPE_NAME));
|
||||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
|
||||||
HgRepositoryHandler.TYPE_NAME));
|
|
||||||
|
|
||||||
IOUtil.mkdirs(repoDirectory);
|
IOUtil.mkdirs(repoDirectory);
|
||||||
config.setRepositoryDirectory(repoDirectory);
|
config.setRepositoryDirectory(repoDirectory);
|
||||||
@@ -124,27 +122,18 @@ public abstract class AbstractHgInstaller implements HgInstaller
|
|||||||
cmdPath = cmd;
|
cmdPath = cmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex) {}
|
catch (IOException ex)
|
||||||
|
{}
|
||||||
|
|
||||||
if (cmdPath == null)
|
if (cmdPath == null)
|
||||||
{
|
{
|
||||||
for (String pathPart : path)
|
for (String pathPart : path)
|
||||||
{
|
{
|
||||||
File file = null;
|
List<String> extensions = getExecutableSearchExtensions();
|
||||||
|
File file = findFileByExtension(pathPart, cmd, extensions);
|
||||||
if (SystemUtil.isWindows())
|
if (file != null)
|
||||||
{
|
|
||||||
file = new File(pathPart, cmd.concat(".exe"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file = new File(pathPart, cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.exists())
|
|
||||||
{
|
{
|
||||||
cmdPath = file.getAbsolutePath();
|
cmdPath = file.getAbsolutePath();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,6 +154,41 @@ public abstract class AbstractHgInstaller implements HgInstaller
|
|||||||
return cmdPath;
|
return cmdPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of file extensions to use when searching for executables.
|
||||||
|
* The list is in priority order, with the highest priority first.
|
||||||
|
*/
|
||||||
|
protected List<String> getExecutableSearchExtensions()
|
||||||
|
{
|
||||||
|
List<String> extensions;
|
||||||
|
if (SystemUtil.isWindows())
|
||||||
|
{
|
||||||
|
extensions = Arrays.asList(".exe");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extensions = Arrays.asList("");
|
||||||
|
}
|
||||||
|
return extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File findFileByExtension(String parentPath, String cmd,
|
||||||
|
List<String> potentialExtensions)
|
||||||
|
{
|
||||||
|
File file = null;
|
||||||
|
for (String potentialExtension : potentialExtensions)
|
||||||
|
{
|
||||||
|
String fileName = cmd.concat(potentialExtension);
|
||||||
|
File potentialFile = new File(parentPath, fileName);
|
||||||
|
if (potentialFile.exists())
|
||||||
|
{
|
||||||
|
file = potentialFile;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.installer;
|
package sonia.scm.installer;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -63,11 +61,20 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
private static final String FILE_LIBRARY_ZIP = "library.zip";
|
private static final String FILE_LIBRARY_ZIP = "library.zip";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String FILE_MERCURIAL = "hg.exe";
|
private static final String FILE_MERCURIAL_EXE = "hg.exe";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String FILE_MERCURIAL_SCRIPT = "hg.bat";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String FILE_TEMPLATES = "templates";
|
private static final String FILE_TEMPLATES = "templates";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String FILE_SCRIPTS = "Scripts";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String FILE_LIB_MERCURIAL = "Lib\\site-packages\\mercurial";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String[] REGISTRY_HG = new String[]
|
private static final String[] REGISTRY_HG = new String[]
|
||||||
{
|
{
|
||||||
@@ -80,12 +87,11 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String REGISTRY_PYTHON =
|
private static final String REGISTRY_PYTHON = "HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command";
|
||||||
"HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command";
|
|
||||||
|
|
||||||
/** the logger for WindowsHgInstaller */
|
/** the logger for WindowsHgInstaller */
|
||||||
private static final Logger logger =
|
private static final Logger logger = LoggerFactory
|
||||||
LoggerFactory.getLogger(WindowsHgInstaller.class);
|
.getLogger(WindowsHgInstaller.class);
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
@@ -115,15 +121,21 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
{
|
{
|
||||||
super.install(config);
|
super.install(config);
|
||||||
|
|
||||||
File hgDirectory = getMercurialDirectory();
|
String pythonBinary = getPythonBinary();
|
||||||
|
config.setPythonBinary(pythonBinary);
|
||||||
|
|
||||||
if (hgDirectory != null)
|
File hgScript = getMercurialScript(pythonBinary);
|
||||||
|
File hgDirectory = getMercurialDirectory();
|
||||||
|
if (hgScript != null)
|
||||||
|
{
|
||||||
|
config.setHgBinary(hgScript.getAbsolutePath());
|
||||||
|
}
|
||||||
|
else if (hgDirectory != null)
|
||||||
{
|
{
|
||||||
installHg(config, hgDirectory);
|
installHg(config, hgDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForOptimizedByteCode(config);
|
checkForOptimizedByteCode(config);
|
||||||
config.setPythonBinary(getPythonBinary());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +145,8 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(HgConfig config) {}
|
public void update(HgConfig config)
|
||||||
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -220,7 +233,8 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
IOUtil.copy(templateDirectory, new File(libDir, FILE_TEMPLATES));
|
IOUtil.copy(templateDirectory, new File(libDir, FILE_TEMPLATES));
|
||||||
}
|
}
|
||||||
|
|
||||||
config.setHgBinary(new File(hgDirectory, FILE_MERCURIAL).getAbsolutePath());
|
config.setHgBinary(new File(hgDirectory, FILE_MERCURIAL_EXE)
|
||||||
|
.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -257,6 +271,32 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the location of the script to run Mercurial, if Mercurial is
|
||||||
|
* installed as a Python package from source. Only packages that include a
|
||||||
|
* templates directory will be recognized.
|
||||||
|
*/
|
||||||
|
private File getMercurialScript(String pythonBinary)
|
||||||
|
{
|
||||||
|
File hgScript = null;
|
||||||
|
|
||||||
|
if (pythonBinary != null)
|
||||||
|
{
|
||||||
|
File pythonBinaryFile = new File(pythonBinary);
|
||||||
|
if (pythonBinaryFile.exists())
|
||||||
|
{
|
||||||
|
File pythonDir = pythonBinaryFile.getParentFile();
|
||||||
|
File scriptsDir = new File(pythonDir, FILE_SCRIPTS);
|
||||||
|
File potentialHgScript = new File(scriptsDir, FILE_MERCURIAL_SCRIPT);
|
||||||
|
File mercurialPackageDir = new File(pythonDir, FILE_LIB_MERCURIAL);
|
||||||
|
File templatesDir = new File(mercurialPackageDir, FILE_TEMPLATES);
|
||||||
|
if (potentialHgScript.exists() && templatesDir.exists())
|
||||||
|
hgScript = potentialHgScript;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hgScript;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -285,8 +325,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getRegistryValue(String key, String subKey,
|
private String getRegistryValue(String key, String subKey, String defaultValue)
|
||||||
String defaultValue)
|
|
||||||
{
|
{
|
||||||
String programDirectory = defaultValue;
|
String programDirectory = defaultValue;
|
||||||
SimpleCommand command = null;
|
SimpleCommand command = null;
|
||||||
@@ -316,14 +355,13 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
|
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
{
|
{
|
||||||
programDirectory = line.substring(index
|
programDirectory = line.substring(index + "REG_SZ".length()).trim();
|
||||||
+ "REG_SZ".length()).trim();
|
|
||||||
|
|
||||||
if (programDirectory.startsWith("\""))
|
if (programDirectory.startsWith("\""))
|
||||||
{
|
{
|
||||||
programDirectory = programDirectory.substring(1);
|
programDirectory = programDirectory.substring(1);
|
||||||
programDirectory = programDirectory.substring(0,
|
programDirectory = programDirectory.substring(0, programDirectory
|
||||||
programDirectory.indexOf("\""));
|
.indexOf("\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
|
|||||||
Reference in New Issue
Block a user