mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +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.SCMContext;
|
||||||
import sonia.scm.io.ZipUnArchiver;
|
import sonia.scm.io.ZipUnArchiver;
|
||||||
import sonia.scm.net.HttpClient;
|
import sonia.scm.net.HttpClient;
|
||||||
import sonia.scm.repository.HgPyFix;
|
import sonia.scm.repository.HgWindowsPackageFix;
|
||||||
import sonia.scm.repository.HgConfig;
|
import sonia.scm.repository.HgConfig;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
@@ -231,7 +231,7 @@ public class HgPackageInstaller implements Runnable
|
|||||||
config.setUseOptimizedBytecode(template.isUseOptimizedBytecode());
|
config.setUseOptimizedBytecode(template.isUseOptimizedBytecode());
|
||||||
|
|
||||||
// fix wrong hg.bat
|
// fix wrong hg.bat
|
||||||
HgPyFix.fixHgPy(SCMContext.getContext(), config);
|
HgWindowsPackageFix.fixHgPackage(SCMContext.getContext(), config);
|
||||||
|
|
||||||
handler.storeConfig();
|
handler.storeConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class HgRepositoryHandler
|
|||||||
// fix wrong hg.bat from package installation
|
// fix wrong hg.bat from package installation
|
||||||
if (SystemUtil.isWindows())
|
if (SystemUtil.isWindows())
|
||||||
{
|
{
|
||||||
HgPyFix.fixHgPy(context, getConfig());
|
HgWindowsPackageFix.fixHgPackage(context, getConfig());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
@@ -56,11 +57,20 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public final class HgPyFix
|
public final class HgWindowsPackageFix
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
static final String MODIFY_MARK = ".setbinary";
|
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_01 = ".setbinary";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
static final String MODIFY_MARK_02 = ".setpythonpath";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String HG_BAT = "hg.bat";
|
private static final String HG_BAT = "hg.bat";
|
||||||
@@ -79,7 +89,7 @@ public final class HgPyFix
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private HgPyFix() {}
|
private HgWindowsPackageFix() {}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -90,7 +100,7 @@ public final class HgPyFix
|
|||||||
* @param context
|
* @param context
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
public static void fixHgPy(SCMContextProvider context, HgConfig config)
|
public static void fixHgPackage(SCMContextProvider context, HgConfig config)
|
||||||
{
|
{
|
||||||
if ((config != null) && config.isValid())
|
if ((config != null) && config.isValid())
|
||||||
{
|
{
|
||||||
@@ -101,6 +111,7 @@ public final class HgPyFix
|
|||||||
if (hg.startsWith(basePath) && hg.endsWith(HG_BAT))
|
if (hg.startsWith(basePath) && hg.endsWith(HG_BAT))
|
||||||
{
|
{
|
||||||
File file = new File(hg);
|
File file = new File(hg);
|
||||||
|
fixHgBat(file);
|
||||||
|
|
||||||
file = new File(file.getParentFile(), HG_PY);
|
file = new File(file.getParentFile(), HG_PY);
|
||||||
fixHgPy(file);
|
fixHgPy(file);
|
||||||
@@ -116,29 +127,71 @@ public final class HgPyFix
|
|||||||
/**
|
/**
|
||||||
* Visible for testing
|
* Visible for testing
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hgBat
|
* @param hgBat
|
||||||
*/
|
*/
|
||||||
static void fixHgPy(File hgBat)
|
static void fixHgBat(File hgBat){
|
||||||
{
|
|
||||||
|
|
||||||
if (hgBat.exists())
|
if (hgBat.exists())
|
||||||
{
|
{
|
||||||
|
|
||||||
File binDirectory = hgBat.getParentFile();
|
File binDirectory = hgBat.getParentFile();
|
||||||
File modifyMark = new File(binDirectory, MODIFY_MARK);
|
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 hgPy
|
||||||
|
*/
|
||||||
|
static void fixHgPy(File hgPy)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (hgPy.exists())
|
||||||
|
{
|
||||||
|
|
||||||
|
File binDirectory = hgPy.getParentFile();
|
||||||
|
File modifyMark = new File(binDirectory, MODIFY_MARK_01);
|
||||||
|
|
||||||
if (!modifyMark.exists())
|
if (!modifyMark.exists())
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -147,13 +200,13 @@ public final class HgPyFix
|
|||||||
}
|
}
|
||||||
else if (logger.isDebugEnabled())
|
else if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("hg.bat allready fixed");
|
logger.debug("hg.py allready fixed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (logger.isWarnEnabled())
|
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)
|
private static void injectSetBinary(File hg)
|
||||||
{
|
{
|
||||||
String lineSeparator = System.getProperty("line.separator");
|
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);
|
hg.renameTo(mod);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ import java.net.URL;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class HgPyFixTest
|
public class HgWindowsPackageFixTest
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,10 +137,10 @@ public class HgPyFixTest
|
|||||||
*/
|
*/
|
||||||
private File testModify(File file)
|
private File testModify(File file)
|
||||||
{
|
{
|
||||||
HgPyFix.fixHgPy(file);
|
HgWindowsPackageFix.fixHgPy(file);
|
||||||
assertTrue(HgPyFix.isSetBinaryAvailable(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());
|
assertTrue(mod.exists());
|
||||||
|
|
||||||
Reference in New Issue
Block a user