mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
merge with branch issue-499
This commit is contained in:
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.io.ZipUnArchiver;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgPyFix;
|
||||
import sonia.scm.repository.HgWindowsPackageFix;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -231,7 +231,7 @@ public class HgPackageInstaller implements Runnable
|
||||
config.setUseOptimizedBytecode(template.isUseOptimizedBytecode());
|
||||
|
||||
// fix wrong hg.bat
|
||||
HgPyFix.fixHgPy(SCMContext.getContext(), config);
|
||||
HgWindowsPackageFix.fixHgPackage(SCMContext.getContext(), config);
|
||||
|
||||
handler.storeConfig();
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public class HgRepositoryHandler
|
||||
// fix wrong hg.bat from package installation
|
||||
if (SystemUtil.isWindows())
|
||||
{
|
||||
HgPyFix.fixHgPy(context, getConfig());
|
||||
HgWindowsPackageFix.fixHgPackage(context, getConfig());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
@@ -56,11 +57,20 @@ import java.io.IOException;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class HgPyFix
|
||||
public final class HgWindowsPackageFix
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String PYTHONPATH_WRONG = "set PYTHONPATH=%~dp0..\\lib;%PYTHONHOME%\\Lib";
|
||||
|
||||
/** Field description */
|
||||
private static final String PYTHONPATH_FIXED = "set PYTHONPATH=%~dp0..\\lib;%PYTHONHOME%\\Lib;%PYTHONPATH%";
|
||||
|
||||
/** Field description */
|
||||
static final String MODIFY_MARK = ".setbinary";
|
||||
static final String MODIFY_MARK_01 = ".setbinary";
|
||||
|
||||
/** Field description */
|
||||
static final String MODIFY_MARK_02 = ".setpythonpath";
|
||||
|
||||
/** Field description */
|
||||
private static final String HG_BAT = "hg.bat";
|
||||
@@ -79,7 +89,7 @@ public final class HgPyFix
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private HgPyFix() {}
|
||||
private HgWindowsPackageFix() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -90,7 +100,7 @@ public final class HgPyFix
|
||||
* @param context
|
||||
* @param config
|
||||
*/
|
||||
public static void fixHgPy(SCMContextProvider context, HgConfig config)
|
||||
public static void fixHgPackage(SCMContextProvider context, HgConfig config)
|
||||
{
|
||||
if ((config != null) && config.isValid())
|
||||
{
|
||||
@@ -101,6 +111,7 @@ public final class HgPyFix
|
||||
if (hg.startsWith(basePath) && hg.endsWith(HG_BAT))
|
||||
{
|
||||
File file = new File(hg);
|
||||
fixHgBat(file);
|
||||
|
||||
file = new File(file.getParentFile(), HG_PY);
|
||||
fixHgPy(file);
|
||||
@@ -112,33 +123,75 @@ public final class HgPyFix
|
||||
"could not fix hg.py, because the configuration is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible for testing
|
||||
*
|
||||
* @param hgBat
|
||||
*/
|
||||
static void fixHgBat(File hgBat){
|
||||
if (hgBat.exists())
|
||||
{
|
||||
File binDirectory = hgBat.getParentFile();
|
||||
File modifyMark = new File(binDirectory, MODIFY_MARK_02);
|
||||
if (!modifyMark.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
String content = Files.toString(hgBat, Charsets.UTF_8);
|
||||
if (!content.contains(PYTHONPATH_FIXED))
|
||||
{
|
||||
content = content.replace(PYTHONPATH_WRONG, PYTHONPATH_FIXED);
|
||||
Files.write(content, hgBat, Charsets.UTF_8);
|
||||
}
|
||||
createModifyMark(modifyMark);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not read content of {}", hgBat);
|
||||
throw Throwables.propagate(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("hg.bat allready fixed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("could not find hg.bat at {}", hgBat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Visible for testing
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hgBat
|
||||
* @param hgPy
|
||||
*/
|
||||
static void fixHgPy(File hgBat)
|
||||
static void fixHgPy(File hgPy)
|
||||
{
|
||||
|
||||
if (hgBat.exists())
|
||||
if (hgPy.exists())
|
||||
{
|
||||
|
||||
File binDirectory = hgBat.getParentFile();
|
||||
File modifyMark = new File(binDirectory, MODIFY_MARK);
|
||||
File binDirectory = hgPy.getParentFile();
|
||||
File modifyMark = new File(binDirectory, MODIFY_MARK_01);
|
||||
|
||||
if (!modifyMark.exists())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("check hg.bat for setbinary at {}", hgBat);
|
||||
logger.debug("check hg.py for setbinary at {}", hgPy);
|
||||
}
|
||||
|
||||
if (!isSetBinaryAvailable(hgBat))
|
||||
if (!isSetBinaryAvailable(hgPy))
|
||||
{
|
||||
injectSetBinary(hgBat);
|
||||
injectSetBinary(hgPy);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -147,13 +200,13 @@ public final class HgPyFix
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("hg.bat allready fixed");
|
||||
logger.debug("hg.py allready fixed");
|
||||
}
|
||||
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find hg.bat at {}", hgBat);
|
||||
logger.warn("could not find hg.py at {}", hgPy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +290,7 @@ public final class HgPyFix
|
||||
private static void injectSetBinary(File hg)
|
||||
{
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
File mod = new File(hg.getParentFile(), MODIFY_MARK);
|
||||
File mod = new File(hg.getParentFile(), MODIFY_MARK_01);
|
||||
|
||||
hg.renameTo(mod);
|
||||
|
||||
@@ -55,7 +55,7 @@ import java.net.URL;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgPyFixTest
|
||||
public class HgWindowsPackageFixTest
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -137,10 +137,10 @@ public class HgPyFixTest
|
||||
*/
|
||||
private File testModify(File file)
|
||||
{
|
||||
HgPyFix.fixHgPy(file);
|
||||
assertTrue(HgPyFix.isSetBinaryAvailable(file));
|
||||
HgWindowsPackageFix.fixHgPy(file);
|
||||
assertTrue(HgWindowsPackageFix.isSetBinaryAvailable(file));
|
||||
|
||||
File mod = new File(file.getParentFile(), HgPyFix.MODIFY_MARK);
|
||||
File mod = new File(file.getParentFile(), HgWindowsPackageFix.MODIFY_MARK_01);
|
||||
|
||||
assertTrue(mod.exists());
|
||||
|
||||
Reference in New Issue
Block a user