mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25: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 */
|
||||
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";
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.util;
|
||||
|
||||
/**
|
||||
@@ -38,11 +40,49 @@ package sonia.scm.util;
|
||||
public class SystemUtil
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PROPERTY_ARCH = "sun.arch.data.model";
|
||||
|
||||
/** Field description */
|
||||
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 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -84,9 +124,4 @@ public class SystemUtil
|
||||
// windows
|
||||
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
|
||||
{
|
||||
config = JAXB.unmarshal(file, ScmConfiguration.class);
|
||||
|
||||
if (ScmConfiguration.OLD_PLUGINURL.equals(config.getPluginUrl()))
|
||||
{
|
||||
config.setPluginUrl(ScmConfiguration.DEFAULT_PLUGINURL);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
@@ -51,13 +52,17 @@ import sonia.scm.security.SecurityContext;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.SecurityUtil;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -65,7 +70,6 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
@@ -82,6 +86,9 @@ public class DefaultPluginManager implements PluginManager
|
||||
/** Field description */
|
||||
public static final String CACHE_NAME = "sonia.cache.plugins";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENCODING = "UTF-8";
|
||||
|
||||
/** the logger for DefaultPluginManager */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(DefaultPluginManager.class);
|
||||
@@ -98,6 +105,8 @@ public class DefaultPluginManager implements PluginManager
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param securityContextProvicer
|
||||
* @param configuration
|
||||
* @param pluginLoader
|
||||
@@ -105,10 +114,12 @@ public class DefaultPluginManager implements PluginManager
|
||||
*/
|
||||
@Inject
|
||||
public DefaultPluginManager(
|
||||
SCMContextProvider context,
|
||||
Provider<SecurityContext> securityContextProvicer,
|
||||
ScmConfiguration configuration, PluginLoader pluginLoader,
|
||||
CacheManager cacheManager)
|
||||
{
|
||||
this.context = context;
|
||||
this.securityContextProvicer = securityContextProvicer;
|
||||
this.configuration = configuration;
|
||||
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
|
||||
@@ -390,16 +401,20 @@ public class DefaultPluginManager implements PluginManager
|
||||
*/
|
||||
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)
|
||||
{
|
||||
String pluginUrl = configuration.getPluginUrl();
|
||||
boolean gzip = pluginUrl.endsWith(".gz");
|
||||
|
||||
pluginUrl = buildPluginUrl(pluginUrl);
|
||||
|
||||
@@ -507,13 +521,18 @@ public class DefaultPluginManager implements PluginManager
|
||||
|
||||
try
|
||||
{
|
||||
input = new URL(pluginUrl).openStream();
|
||||
URLConnection connection = new URL(pluginUrl).openConnection();
|
||||
|
||||
if (gzip)
|
||||
{
|
||||
input = new GZIPInputStream(input);
|
||||
}
|
||||
input = connection.getInputStream();
|
||||
|
||||
/*
|
||||
* TODO: add gzip support
|
||||
*
|
||||
* if (gzip)
|
||||
* {
|
||||
* input = new GZIPInputStream(input);
|
||||
* }
|
||||
*/
|
||||
center = (PluginCenter) unmarshaller.unmarshal(input);
|
||||
preparePlugins(center);
|
||||
cache.put(PluginCenter.class.getName(), center);
|
||||
@@ -587,6 +606,9 @@ public class DefaultPluginManager implements PluginManager
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private SCMContextProvider context;
|
||||
|
||||
/** Field description */
|
||||
private Map<String, Plugin> installedPlugins;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user