improve WindowsHgInstaller

This commit is contained in:
Sebastian Sdorra
2010-12-26 13:12:07 +01:00
parent d544722a65
commit ed0ae9d977
3 changed files with 82 additions and 68 deletions

View File

@@ -60,39 +60,33 @@ public class WindowsHgInstaller extends AbstractHgInstaller
{ {
/** Field description */ /** Field description */
public static String[] PATH_HG = new String[] private static final String FILE_LIBRARY_ZIP = "library.zip";
/** Field description */
private static final String FILE_MERCURIAL = "hg.exe";
/** Field description */
private static final String FILE_TEMPLATES = "templates";
/** Field description */
private static final String[] REGISTRY_HG = new String[]
{ {
// TortoiseHg // TortoiseHg
"TortoiseHg" "HKEY_CURRENT_USER\\Software\\TortoiseHg",
// Mercurial
"HKEY_CURRENT_USER\\Software\\Mercurial\\InstallDir"
}; };
/** Field description */ /** Field description */
public static String[] PATH_LIBRARY_ZIP = new String[] private static final String REGISTRY_PYTHON =
{ "HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command";
// TortoiseHg
"TortoiseHg\\library.zip"
};
/** Field description */
public static String[] PATH_TEMPLATE = new String[]
{
// TortoiseHg
"TortoiseHg\\templates"
};
/** Field description */
private static final String DEFAULT_PROGRAMMDIRECTORY =
"C:\\Programm Files\\";
/** the logger for WindowsHgInstaller */ /** the logger for WindowsHgInstaller */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(WindowsHgInstaller.class); LoggerFactory.getLogger(WindowsHgInstaller.class);
public static String BINARY_MERCURIAL = "hg";
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
/** /**
@@ -121,30 +115,15 @@ public class WindowsHgInstaller extends AbstractHgInstaller
{ {
super.install(config); super.install(config);
String progDir = getProgrammDirectory(); File hgDirectory = getMercurialDirectory();
File libraryZip = find(progDir, PATH_LIBRARY_ZIP);
File libDir = null; if (hgDirectory != null)
if (libraryZip != null)
{ {
libDir = new File(baseDirectory, "lib\\hg"); installHg(config, hgDirectory);
IOUtil.extract(libraryZip, libDir);
config.setPythonPath(libDir.getAbsolutePath());
} }
if ( libDir != null )
{
File templateDir = find(progDir, PATH_TEMPLATE);
if (templateDir != null)
{
IOUtil.copy(templateDir, new File(libDir, "templates"));
}
}
checkForOptimizedByteCode(config); checkForOptimizedByteCode(config);
config.setPythonBinary(getPythonBinary()); config.setPythonBinary(getPythonBinary());
config.setHgBinary( search(PATH_HG, BINARY_MERCURIAL) );
} }
/** /**
@@ -210,28 +189,38 @@ public class WindowsHgInstaller extends AbstractHgInstaller
* Method description * Method description
* *
* *
* @param prefix * @param config
* @param path * @param hgDirectory
* *
* @return * @throws IOException
*/ */
private File find(String prefix, String[] path) private void installHg(HgConfig config, File hgDirectory) throws IOException
{ {
File result = null; if (logger.isInfoEnabled())
for (String pathPart : path)
{ {
File file = new File(prefix, pathPart); logger.info("installing mercurial {}", hgDirectory.getAbsolutePath());
if (file.exists())
{
result = file;
break;
}
} }
return result; File libDir = new File(baseDirectory, "lib\\hg");
IOUtil.mkdirs(libDir);
File libraryZip = new File(hgDirectory, FILE_LIBRARY_ZIP);
if (libraryZip.exists())
{
IOUtil.extract(libraryZip, libDir);
config.setPythonPath(libDir.getAbsolutePath());
}
File templateDirectory = new File(hgDirectory, FILE_TEMPLATES);
if (templateDirectory.exists())
{
IOUtil.copy(templateDirectory, new File(libDir, FILE_TEMPLATES));
}
config.setHgBinary(new File(hgDirectory, FILE_MERCURIAL).getAbsolutePath());
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@@ -242,11 +231,30 @@ public class WindowsHgInstaller extends AbstractHgInstaller
* *
* @return * @return
*/ */
private String getProgrammDirectory() private File getMercurialDirectory()
{ {
return getRegistryValue( File directory = null;
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
"ProgramFilesDir", DEFAULT_PROGRAMMDIRECTORY); for (String registryKey : REGISTRY_HG)
{
String path = getRegistryValue(registryKey, null, null);
if (path != null)
{
directory = new File(path);
if (!directory.exists())
{
directory = null;
}
else
{
break;
}
}
}
return directory;
} }
/** /**
@@ -257,9 +265,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
*/ */
private String getPythonBinary() private String getPythonBinary()
{ {
String python = String python = getRegistryValue(REGISTRY_PYTHON, null, null);
getRegistryValue(
"HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command", null, null);
if (python == null) if (python == null)
{ {
@@ -313,10 +319,18 @@ public class WindowsHgInstaller extends AbstractHgInstaller
programmDirectory = line.substring(index programmDirectory = line.substring(index
+ "REG_SZ".length()).trim(); + "REG_SZ".length()).trim();
if (programmDirectory.startsWith("\""))
{
programmDirectory = programmDirectory.substring(1);
programmDirectory = programmDirectory.substring(0,
programmDirectory.indexOf("\""));
}
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("use programm directory {}", programmDirectory); logger.debug("use programm directory {}", programmDirectory);
} }
break; break;
} }
} }

View File

@@ -51,6 +51,11 @@ registerConfigPanel({
name: 'repositoryDirectory', name: 'repositoryDirectory',
fieldLabel: 'Repository directory', fieldLabel: 'Repository directory',
allowBlank : false allowBlank : false
},{
xtype: 'checkbox',
name: 'useOptimizedBytecode',
fieldLabel: 'Optimized Bytecode (.pyo)',
inputValue: 'true'
}], }],
onSubmit: function(values){ onSubmit: function(values){

View File

@@ -179,11 +179,6 @@ public class ZipUnArchiver extends AbstractUnArchiver
private void extractFile(ZipInputStream input, File outputFile) private void extractFile(ZipInputStream input, File outputFile)
throws IOException throws IOException
{ {
if (logger.isDebugEnabled())
{
logger.debug("extract file {}", outputFile.getPath());
}
FileOutputStream output = null; FileOutputStream output = null;
try try