mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
change default plugin url to new plugin backend
This commit is contained in:
@@ -63,6 +63,10 @@ public class ScmConfiguration
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String DEFAULT_PLUGINURL =
|
public static final String DEFAULT_PLUGINURL =
|
||||||
|
"http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String OLD_PLUGINURL =
|
||||||
"http://plugins.scm-manager.org/plugins.xml.gz";
|
"http://plugins.scm-manager.org/plugins.xml.gz";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.util;
|
package sonia.scm.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,11 +40,49 @@ package sonia.scm.util;
|
|||||||
public class SystemUtil
|
public class SystemUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String PROPERTY_ARCH = "sun.arch.data.model";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String PROPERTY_OSNAME = "os.name";
|
public static final String PROPERTY_OSNAME = "os.name";
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean is32bit()
|
||||||
|
{
|
||||||
|
return "32".equals(System.getProperty(PROPERTY_ARCH));
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getArch()
|
||||||
|
{
|
||||||
|
return System.getProperty(PROPERTY_ARCH, "32");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getOS()
|
||||||
|
{
|
||||||
|
return System.getProperty(PROPERTY_OSNAME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -84,9 +124,4 @@ public class SystemUtil
|
|||||||
// windows
|
// windows
|
||||||
return (os.indexOf("win") >= 0);
|
return (os.indexOf("win") >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean is32bit()
|
|
||||||
{
|
|
||||||
return "32".equals(System.getProperty("sun.arch.data.model"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,6 +359,11 @@ public class ScmServletModule extends ServletModule
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = JAXB.unmarshal(file, ScmConfiguration.class);
|
config = JAXB.unmarshal(file, ScmConfiguration.class);
|
||||||
|
|
||||||
|
if (ScmConfiguration.OLD_PLUGINURL.equals(config.getPluginUrl()))
|
||||||
|
{
|
||||||
|
config.setPluginUrl(ScmConfiguration.DEFAULT_PLUGINURL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import sonia.scm.ConfigurationException;
|
import sonia.scm.ConfigurationException;
|
||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.cache.Cache;
|
import sonia.scm.cache.Cache;
|
||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
import sonia.scm.config.ScmConfiguration;
|
import sonia.scm.config.ScmConfiguration;
|
||||||
@@ -51,13 +52,17 @@ import sonia.scm.security.SecurityContext;
|
|||||||
import sonia.scm.util.AssertUtil;
|
import sonia.scm.util.AssertUtil;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.SecurityUtil;
|
import sonia.scm.util.SecurityUtil;
|
||||||
|
import sonia.scm.util.SystemUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -65,7 +70,6 @@ import java.util.HashSet;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
@@ -82,6 +86,9 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String CACHE_NAME = "sonia.cache.plugins";
|
public static final String CACHE_NAME = "sonia.cache.plugins";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String ENCODING = "UTF-8";
|
||||||
|
|
||||||
/** the logger for DefaultPluginManager */
|
/** the logger for DefaultPluginManager */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(DefaultPluginManager.class);
|
LoggerFactory.getLogger(DefaultPluginManager.class);
|
||||||
@@ -98,6 +105,8 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param securityContextProvicer
|
* @param securityContextProvicer
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* @param pluginLoader
|
* @param pluginLoader
|
||||||
@@ -105,10 +114,12 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public DefaultPluginManager(
|
public DefaultPluginManager(
|
||||||
|
SCMContextProvider context,
|
||||||
Provider<SecurityContext> securityContextProvicer,
|
Provider<SecurityContext> securityContextProvicer,
|
||||||
ScmConfiguration configuration, PluginLoader pluginLoader,
|
ScmConfiguration configuration, PluginLoader pluginLoader,
|
||||||
CacheManager cacheManager)
|
CacheManager cacheManager)
|
||||||
{
|
{
|
||||||
|
this.context = context;
|
||||||
this.securityContextProvicer = securityContextProvicer;
|
this.securityContextProvicer = securityContextProvicer;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
|
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
|
||||||
@@ -390,16 +401,20 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
*/
|
*/
|
||||||
private String buildPluginUrl(String url)
|
private String buildPluginUrl(String url)
|
||||||
{
|
{
|
||||||
if (url.contains("?"))
|
String os = SystemUtil.getOS();
|
||||||
|
String arch = SystemUtil.getArch();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
url = url.concat("&scm.version=");
|
os = URLEncoder.encode(os, ENCODING);
|
||||||
}
|
}
|
||||||
else
|
catch (UnsupportedEncodingException ex)
|
||||||
{
|
{
|
||||||
url = url.concat("?scm.version=");
|
logger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return url.concat(SCMContext.getContext().getVersion());
|
return url.replace("{version}", context.getVersion()).replace("{os}",
|
||||||
|
os).replace("{arch}", arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -492,7 +507,6 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
synchronized (DefaultPluginManager.class)
|
synchronized (DefaultPluginManager.class)
|
||||||
{
|
{
|
||||||
String pluginUrl = configuration.getPluginUrl();
|
String pluginUrl = configuration.getPluginUrl();
|
||||||
boolean gzip = pluginUrl.endsWith(".gz");
|
|
||||||
|
|
||||||
pluginUrl = buildPluginUrl(pluginUrl);
|
pluginUrl = buildPluginUrl(pluginUrl);
|
||||||
|
|
||||||
@@ -507,13 +521,18 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
input = new URL(pluginUrl).openStream();
|
URLConnection connection = new URL(pluginUrl).openConnection();
|
||||||
|
|
||||||
if (gzip)
|
input = connection.getInputStream();
|
||||||
{
|
|
||||||
input = new GZIPInputStream(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: add gzip support
|
||||||
|
*
|
||||||
|
* if (gzip)
|
||||||
|
* {
|
||||||
|
* input = new GZIPInputStream(input);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
center = (PluginCenter) unmarshaller.unmarshal(input);
|
center = (PluginCenter) unmarshaller.unmarshal(input);
|
||||||
preparePlugins(center);
|
preparePlugins(center);
|
||||||
cache.put(PluginCenter.class.getName(), center);
|
cache.put(PluginCenter.class.getName(), center);
|
||||||
@@ -587,6 +606,9 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private ScmConfiguration configuration;
|
private ScmConfiguration configuration;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private SCMContextProvider context;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Map<String, Plugin> installedPlugins;
|
private Map<String, Plugin> installedPlugins;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user