mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
move core plugins back to main repository, because of a broken release management
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractHgInstaller implements HgInstaller
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void install(File baseDirectory, HgConfig config) throws IOException
|
||||
{
|
||||
File repoDirectory = new File(
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
HgRepositoryHandler.TYPE_NAME));
|
||||
|
||||
IOUtil.mkdirs(repoDirectory);
|
||||
config.setRepositoryDirectory(repoDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param handler
|
||||
* @param baseDirectory
|
||||
* @param pkg
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg)
|
||||
{
|
||||
return new HgPackageInstaller(client, handler, baseDirectory,
|
||||
pkg).install();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface HgInstaller
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void install(File baseDirectory, HgConfig config) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param handler
|
||||
* @param baseDirectory
|
||||
* @param pkg
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void update(File baseDirectory, HgConfig config) throws IOException;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getHgInstallations();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getPythonInstallations();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.SystemUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgInstallerFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HgInstaller createInstaller()
|
||||
{
|
||||
HgInstaller installer = null;
|
||||
|
||||
if (SystemUtil.isWindows())
|
||||
{
|
||||
installer = new WindowsHgInstaller();
|
||||
}
|
||||
else
|
||||
{
|
||||
installer = new UnixHgInstaller();
|
||||
}
|
||||
|
||||
return installer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "package")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class HgPackage
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getArch()
|
||||
{
|
||||
return arch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgConfig getHgConfigTemplate()
|
||||
{
|
||||
return hgConfigTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getHgVersion()
|
||||
{
|
||||
return hgVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPlatform()
|
||||
{
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPythonVersion()
|
||||
{
|
||||
return pythonVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param arch
|
||||
*/
|
||||
public void setArch(String arch)
|
||||
{
|
||||
this.arch = arch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param hgConfigTemplate
|
||||
*/
|
||||
public void setHgConfigTemplate(HgConfig hgConfigTemplate)
|
||||
{
|
||||
this.hgConfigTemplate = hgConfigTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param hgVersion
|
||||
*/
|
||||
public void setHgVersion(String hgVersion)
|
||||
{
|
||||
this.hgVersion = hgVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param platform
|
||||
*/
|
||||
public void setPlatform(String platform)
|
||||
{
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pythonVersion
|
||||
*/
|
||||
public void setPythonVersion(String pythonVersion)
|
||||
{
|
||||
this.pythonVersion = pythonVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
public void setSize(long size)
|
||||
{
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String arch;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "hg-config-template")
|
||||
private HgConfig hgConfigTemplate;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "hg-version")
|
||||
private String hgVersion;
|
||||
|
||||
/** Field description */
|
||||
private String id;
|
||||
|
||||
/** Field description */
|
||||
private String platform;
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "python-version")
|
||||
private String pythonVersion;
|
||||
|
||||
/** Field description */
|
||||
private long size;
|
||||
|
||||
/** Field description */
|
||||
private String url;
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.io.ZipUnArchiver;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgPackageInstaller implements Runnable
|
||||
{
|
||||
|
||||
/** the logger for HgPackageInstaller */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HgPackageInstaller.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param handler
|
||||
* @param baseDirectory
|
||||
* @param pkg
|
||||
*/
|
||||
public HgPackageInstaller(HttpClient client, HgRepositoryHandler handler,
|
||||
File baseDirectory, HgPackage pkg)
|
||||
{
|
||||
this.client = client;
|
||||
this.handler = handler;
|
||||
this.baseDirectory = baseDirectory;
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean install()
|
||||
{
|
||||
boolean success = false;
|
||||
File downloadedFile = downloadFile();
|
||||
|
||||
if ((downloadedFile != null) && downloadedFile.exists())
|
||||
{
|
||||
File directory = extractPackage(downloadedFile);
|
||||
|
||||
if ((directory != null) && directory.exists())
|
||||
{
|
||||
updateConfig(directory);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!install())
|
||||
{
|
||||
logger.error("installation of pkg {} failed", pkg.getId());
|
||||
}
|
||||
else if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("successfully installed pkg {}", pkg.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File downloadFile()
|
||||
{
|
||||
File file = null;
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
file = File.createTempFile("scm-hg-", ".pkg");
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("download package to {}", file.getAbsolutePath());
|
||||
}
|
||||
|
||||
// TODO error handling
|
||||
input = client.get(pkg.getUrl()).getContent();
|
||||
output = new FileOutputStream(file);
|
||||
IOUtil.copy(input, output);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not downlaod file ".concat(pkg.getUrl()), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File extractPackage(File file)
|
||||
{
|
||||
File directory = new File(baseDirectory,
|
||||
"pkg".concat(File.separator).concat(pkg.getId()));
|
||||
|
||||
IOUtil.mkdirs(directory);
|
||||
|
||||
try
|
||||
{
|
||||
IOUtil.extract(file, directory, ZipUnArchiver.EXTENSION);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
directory = null;
|
||||
logger.error("could not extract pacakge ".concat(pkg.getId()), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
// delete temp file
|
||||
try
|
||||
{
|
||||
IOUtil.delete(file, true);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
private void updateConfig(File directory)
|
||||
{
|
||||
String path = directory.getAbsolutePath();
|
||||
HgConfig template = pkg.getHgConfigTemplate();
|
||||
HgConfig config = handler.getConfig();
|
||||
|
||||
config.setHgBinary(getTemplateValue(template.getHgBinary(), path));
|
||||
config.setPythonBinary(getTemplateValue(template.getPythonBinary(), path));
|
||||
config.setPythonPath(getTemplateValue(template.getPythonPath(), path));
|
||||
config.setUseOptimizedBytecode(template.isUseOptimizedBytecode());
|
||||
handler.storeConfig();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param template
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getTemplateValue(String template, String path)
|
||||
{
|
||||
String result = null;
|
||||
|
||||
if (template != null)
|
||||
{
|
||||
result = MessageFormat.format(template, path);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private HttpClient client;
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private HgPackage pkg;
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.PlatformType;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgPackageReader
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String CACHENAME = "sonia.scm.hg.packages";
|
||||
|
||||
/** Field description */
|
||||
public static final String PACKAGEURL =
|
||||
"http://download.scm-manager.org/pkg/mercurial/packages.xml.gz";
|
||||
|
||||
/** the logger for HgPackageReader */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(HgPackageReader.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param cacheManager
|
||||
*/
|
||||
public HgPackageReader(CacheManager cacheManager)
|
||||
{
|
||||
cache = cacheManager.getCache(String.class, HgPackages.class, CACHENAME);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgPackage getPackage(String id)
|
||||
{
|
||||
HgPackage pkg = null;
|
||||
|
||||
for (HgPackage p : getPackages())
|
||||
{
|
||||
if (id.equals(p.getId()))
|
||||
{
|
||||
pkg = p;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgPackages getPackages()
|
||||
{
|
||||
HgPackages packages = cache.get(HgPackages.class.getName());
|
||||
|
||||
if (packages == null)
|
||||
{
|
||||
packages = getRemptePackages();
|
||||
filterPackage(packages);
|
||||
cache.put(HgPackages.class.getName(), packages);
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param packages
|
||||
*/
|
||||
private void filterPackage(HgPackages packages)
|
||||
{
|
||||
List<HgPackage> pkgList = new ArrayList<HgPackage>();
|
||||
|
||||
for (HgPackage pkg : packages)
|
||||
{
|
||||
boolean add = true;
|
||||
|
||||
if (Util.isNotEmpty(pkg.getPlatform()))
|
||||
{
|
||||
PlatformType pt = PlatformType.createPlatformType(pkg.getPlatform());
|
||||
|
||||
if (SystemUtil.getPlatform().getType() != pt)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong platform {}",
|
||||
pkg.getId(), pkg.getPlatform());
|
||||
}
|
||||
|
||||
add = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (add && Util.isNotEmpty(pkg.getArch()))
|
||||
{
|
||||
if (!SystemUtil.getArch().equals(pkg.getArch()))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong arch {}",
|
||||
pkg.getId(), pkg.getArch());
|
||||
}
|
||||
|
||||
add = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (add)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("added HgPackage {}", pkg.getId());
|
||||
}
|
||||
|
||||
pkgList.add(pkg);
|
||||
}
|
||||
}
|
||||
|
||||
packages.setPackages(pkgList);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private HgPackages getRemptePackages()
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("fetch HgPackages from {}", PACKAGEURL);
|
||||
}
|
||||
|
||||
HgPackages packages = null;
|
||||
InputStream input = null;
|
||||
|
||||
try
|
||||
{
|
||||
URL url = new URL(PACKAGEURL);
|
||||
|
||||
if (PACKAGEURL.endsWith(".gz"))
|
||||
{
|
||||
input = new GZIPInputStream(url.openStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
input = url.openStream();
|
||||
}
|
||||
|
||||
packages = JAXB.unmarshal(input, HgPackages.class);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not read HgPackages from {}", PACKAGEURL);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
}
|
||||
|
||||
if (packages == null)
|
||||
{
|
||||
packages = new HgPackages();
|
||||
packages.setPackages(new ArrayList<HgPackage>());
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Cache<String, HgPackages> cache;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "packages")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class HgPackages implements Iterable<HgPackage>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Iterator<HgPackage> iterator()
|
||||
{
|
||||
return packages.iterator();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<HgPackage> getPackages()
|
||||
{
|
||||
return packages;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param packages
|
||||
*/
|
||||
public void setPackages(List<HgPackage> packages)
|
||||
{
|
||||
this.packages = packages;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "package")
|
||||
private List<HgPackage> packages;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UnixHgInstaller extends AbstractHgInstaller
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String COMMAND_HG = "hg";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMMAND_PYTHON = "python";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void install(File baseDirectory, HgConfig config) throws IOException
|
||||
{
|
||||
super.install(baseDirectory, config);
|
||||
|
||||
// search mercurial (hg)
|
||||
|
||||
if (Util.isEmpty(config.getHgBinary()))
|
||||
{
|
||||
String hg = IOUtil.search(COMMAND_HG);
|
||||
|
||||
if (Util.isNotEmpty(hg))
|
||||
{
|
||||
config.setHgBinary(hg);
|
||||
|
||||
// search python in the same folder
|
||||
File hgFile = new File(hg);
|
||||
|
||||
if (hgFile.exists())
|
||||
{
|
||||
File pythonFile = new File(hgFile.getParentFile(), COMMAND_PYTHON);
|
||||
|
||||
if (pythonFile.exists())
|
||||
{
|
||||
config.setPythonBinary(pythonFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search python
|
||||
|
||||
if (Util.isEmpty(config.getPythonBinary()))
|
||||
{
|
||||
config.setPythonBinary(IOUtil.search(COMMAND_PYTHON));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*/
|
||||
@Override
|
||||
public void update(File baseDirectory, HgConfig config)
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getHgInstallations()
|
||||
{
|
||||
return IOUtil.searchAll(COMMAND_HG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPythonInstallations()
|
||||
{
|
||||
return IOUtil.searchAll(COMMAND_PYTHON);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.installer;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.RegistryUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WindowsHgInstaller extends AbstractHgInstaller
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_LIBRARY_ZIP = "library.zip";
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_LIB_MERCURIAL =
|
||||
"Lib\\site-packages\\mercurial";
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_MERCURIAL_EXE = "hg.exe";
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_MERCURIAL_SCRIPT = "hg.bat";
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_SCRIPTS = "Scripts";
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_TEMPLATES = "templates";
|
||||
|
||||
/** Field description */
|
||||
private static final String[] REGISTRY_HG = new String[]
|
||||
{
|
||||
|
||||
// TortoiseHg
|
||||
"HKEY_CURRENT_USER\\Software\\TortoiseHg",
|
||||
|
||||
// Mercurial
|
||||
"HKEY_CURRENT_USER\\Software\\Mercurial\\InstallDir"
|
||||
};
|
||||
|
||||
/** Field description */
|
||||
private static final String[] REGISTRY_PYTHON = new String[]
|
||||
{
|
||||
|
||||
// .py files
|
||||
"HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command"
|
||||
};
|
||||
|
||||
/** the logger for WindowsHgInstaller */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(WindowsHgInstaller.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void install(File baseDirectory, HgConfig config) throws IOException
|
||||
{
|
||||
super.install(baseDirectory, config);
|
||||
|
||||
if (Util.isEmpty(config.getPythonBinary()))
|
||||
{
|
||||
String pythonBinary = getPythonBinary();
|
||||
|
||||
config.setPythonBinary(pythonBinary);
|
||||
}
|
||||
|
||||
if (Util.isEmpty(config.getHgBinary()))
|
||||
{
|
||||
File hgScript = getMercurialScript(config.getPythonBinary());
|
||||
|
||||
if (hgScript != null)
|
||||
{
|
||||
config.setHgBinary(hgScript.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
File hgDirectory = getMercurialDirectory(config.getHgBinary());
|
||||
|
||||
if (hgDirectory != null)
|
||||
{
|
||||
installHg(baseDirectory, config, hgDirectory);
|
||||
}
|
||||
|
||||
checkForOptimizedByteCode(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
*/
|
||||
@Override
|
||||
public void update(File baseDirectory, HgConfig config) {}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getHgInstallations()
|
||||
{
|
||||
return getInstallations(REGISTRY_HG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPythonInstallations()
|
||||
{
|
||||
return getInstallations(REGISTRY_PYTHON);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
private void checkForOptimizedByteCode(HgConfig config)
|
||||
{
|
||||
boolean optimized = false;
|
||||
String path = config.getPythonPath();
|
||||
|
||||
if (Util.isNotEmpty(path))
|
||||
{
|
||||
for (String part : path.split(";"))
|
||||
{
|
||||
if (checkForOptimizedByteCode(part))
|
||||
{
|
||||
optimized = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.setUseOptimizedBytecode(optimized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param part
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean checkForOptimizedByteCode(String part)
|
||||
{
|
||||
File libDir = new File(part);
|
||||
String[] pyoFiles = libDir.list(new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file, String name)
|
||||
{
|
||||
return name.toLowerCase().endsWith(".pyo");
|
||||
}
|
||||
});
|
||||
|
||||
return Util.isNotEmpty(pyoFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param config
|
||||
* @param hgDirectory
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void installHg(File baseDirectory, HgConfig config, File hgDirectory)
|
||||
throws IOException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("installing mercurial {}", hgDirectory.getAbsolutePath());
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
File hg = new File( hgDirectory, FILE_MERCURIAL_EXE );
|
||||
if ( hg.exists() )
|
||||
{
|
||||
config.setHgBinary(hg.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param registryKeys
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<String> getInstallations(String[] registryKeys)
|
||||
{
|
||||
List<String> installations = new ArrayList<String>();
|
||||
|
||||
for (String registryKey : registryKeys)
|
||||
{
|
||||
String path = RegistryUtil.getRegistryValue(registryKey);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
File file = new File(path, FILE_MERCURIAL_EXE);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
installations.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return installations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hgBinary
|
||||
* @return
|
||||
*/
|
||||
private File getMercurialDirectory(String hgBinary)
|
||||
{
|
||||
File directory = null;
|
||||
|
||||
if ( Util.isNotEmpty(hgBinary) )
|
||||
{
|
||||
File hg = new File(hgBinary);
|
||||
|
||||
if (hg.exists() && hg.isFile())
|
||||
{
|
||||
directory = hg.getParentFile();
|
||||
}
|
||||
}
|
||||
|
||||
if ( directory == null )
|
||||
{
|
||||
directory = getMercurialDirectoryFromRegistry();
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File getMercurialDirectoryFromRegistry()
|
||||
{
|
||||
File directory = null;
|
||||
|
||||
for (String registryKey : REGISTRY_HG)
|
||||
{
|
||||
String path = RegistryUtil.getRegistryValue(registryKey);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
directory = new File(path);
|
||||
|
||||
if (!directory.exists())
|
||||
{
|
||||
directory = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @param pythonBinary
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getPythonBinary()
|
||||
{
|
||||
String python = RegistryUtil.getRegistryValue(REGISTRY_PYTHON[0]);
|
||||
|
||||
if (python == null)
|
||||
{
|
||||
python = IOUtil.search(new String[0], "python");
|
||||
}
|
||||
|
||||
return python;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user