2010-10-31 19:22:53 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
package sonia.scm.plugin;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
import com.google.inject.Inject;
|
2010-12-16 07:46:02 +01:00
|
|
|
import com.google.inject.Provider;
|
2010-12-13 18:59:00 +01:00
|
|
|
import com.google.inject.Singleton;
|
|
|
|
|
|
2010-10-16 11:03:54 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
import sonia.scm.ConfigurationException;
|
2010-12-13 21:02:39 +01:00
|
|
|
import sonia.scm.SCMContext;
|
2011-03-12 15:19:41 +01:00
|
|
|
import sonia.scm.SCMContextProvider;
|
2011-02-12 10:52:04 +01:00
|
|
|
import sonia.scm.cache.Cache;
|
2010-12-13 18:59:00 +01:00
|
|
|
import sonia.scm.cache.CacheManager;
|
|
|
|
|
import sonia.scm.config.ScmConfiguration;
|
2011-05-09 12:12:20 +02:00
|
|
|
import sonia.scm.net.HttpClient;
|
2010-12-16 07:46:02 +01:00
|
|
|
import sonia.scm.security.SecurityContext;
|
2010-12-18 13:37:34 +01:00
|
|
|
import sonia.scm.util.AssertUtil;
|
2011-01-05 17:18:01 +01:00
|
|
|
import sonia.scm.util.IOUtil;
|
2010-12-16 07:46:02 +01:00
|
|
|
import sonia.scm.util.SecurityUtil;
|
2011-03-12 15:19:41 +01:00
|
|
|
import sonia.scm.util.SystemUtil;
|
2010-12-29 14:05:30 +01:00
|
|
|
import sonia.scm.util.Util;
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
|
|
|
|
|
2011-01-05 17:18:01 +01:00
|
|
|
import java.io.InputStream;
|
2011-03-12 15:19:41 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2011-01-05 17:18:01 +01:00
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
import java.net.URL;
|
2011-03-12 15:19:41 +01:00
|
|
|
import java.net.URLConnection;
|
|
|
|
|
import java.net.URLEncoder;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
import java.util.Collection;
|
2010-12-13 18:59:00 +01:00
|
|
|
import java.util.HashMap;
|
2010-12-17 19:02:32 +01:00
|
|
|
import java.util.HashSet;
|
2011-03-18 19:35:19 +01:00
|
|
|
import java.util.Iterator;
|
2010-12-18 16:25:57 +01:00
|
|
|
import java.util.LinkedHashSet;
|
2010-12-13 18:59:00 +01:00
|
|
|
import java.util.Map;
|
2010-12-17 19:02:32 +01:00
|
|
|
import java.util.Set;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
@Singleton
|
2010-12-01 14:26:29 +01:00
|
|
|
public class DefaultPluginManager implements PluginManager
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
2010-12-13 18:59:00 +01:00
|
|
|
public static final String CACHE_NAME = "sonia.cache.plugins";
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2011-03-12 15:19:41 +01:00
|
|
|
/** Field description */
|
|
|
|
|
public static final String ENCODING = "UTF-8";
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
/** the logger for DefaultPluginManager */
|
2010-10-12 09:16:40 +02:00
|
|
|
private static final Logger logger =
|
2010-12-01 14:26:29 +01:00
|
|
|
LoggerFactory.getLogger(DefaultPluginManager.class);
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/** Field description */
|
|
|
|
|
public static final PluginFilter FILTER_UPDATES =
|
|
|
|
|
new StatePluginFilter(PluginState.UPDATE_AVAILABLE);
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
//~--- constructors ---------------------------------------------------------
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
/**
|
2010-12-01 14:26:29 +01:00
|
|
|
* Constructs ...
|
2010-10-12 09:16:40 +02:00
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
*
|
|
|
|
|
*
|
2010-12-16 07:46:02 +01:00
|
|
|
*
|
2011-03-12 15:19:41 +01:00
|
|
|
*
|
|
|
|
|
* @param context
|
2010-12-16 07:46:02 +01:00
|
|
|
* @param securityContextProvicer
|
2010-12-13 18:59:00 +01:00
|
|
|
* @param configuration
|
|
|
|
|
* @param pluginLoader
|
|
|
|
|
* @param cacheManager
|
2011-05-09 12:12:20 +02:00
|
|
|
* @param client
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
@Inject
|
2010-12-16 07:46:02 +01:00
|
|
|
public DefaultPluginManager(
|
2011-03-12 15:19:41 +01:00
|
|
|
SCMContextProvider context,
|
2010-12-16 07:46:02 +01:00
|
|
|
Provider<SecurityContext> securityContextProvicer,
|
|
|
|
|
ScmConfiguration configuration, PluginLoader pluginLoader,
|
2011-05-09 12:12:20 +02:00
|
|
|
CacheManager cacheManager, HttpClient client)
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2011-03-12 15:19:41 +01:00
|
|
|
this.context = context;
|
2010-12-16 07:46:02 +01:00
|
|
|
this.securityContextProvicer = securityContextProvicer;
|
2010-12-13 18:59:00 +01:00
|
|
|
this.configuration = configuration;
|
2011-02-12 10:52:04 +01:00
|
|
|
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
|
|
|
|
|
CACHE_NAME);
|
2011-05-09 12:12:20 +02:00
|
|
|
this.client = client;
|
2010-12-18 16:25:57 +01:00
|
|
|
installedPlugins = new HashMap<String, Plugin>();
|
2010-12-13 18:59:00 +01:00
|
|
|
|
|
|
|
|
for (Plugin plugin : pluginLoader.getInstalledPlugins())
|
|
|
|
|
{
|
|
|
|
|
PluginInformation info = plugin.getInformation();
|
|
|
|
|
|
2010-12-16 07:46:02 +01:00
|
|
|
if ((info != null) && info.isValid())
|
2010-12-13 18:59:00 +01:00
|
|
|
{
|
2010-12-18 16:25:57 +01:00
|
|
|
installedPlugins.put(info.getId(), plugin);
|
2010-12-13 18:59:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
try
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
unmarshaller =
|
|
|
|
|
JAXBContext.newInstance(PluginCenter.class).createUnmarshaller();
|
2010-12-01 14:26:29 +01:00
|
|
|
}
|
2010-12-13 18:59:00 +01:00
|
|
|
catch (JAXBException ex)
|
2010-12-01 14:26:29 +01:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
throw new ConfigurationException(ex);
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
2010-12-18 14:18:14 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void clearCache()
|
|
|
|
|
{
|
|
|
|
|
cache.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
* @param id
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2010-12-01 14:26:29 +01:00
|
|
|
@Override
|
2010-12-13 18:59:00 +01:00
|
|
|
public void install(String id)
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-16 07:46:02 +01:00
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-29 14:05:30 +01:00
|
|
|
PluginCenter center = getPluginCenter();
|
2010-12-13 21:02:39 +01:00
|
|
|
|
|
|
|
|
pluginHandler.install(id);
|
2010-12-29 14:05:30 +01:00
|
|
|
|
|
|
|
|
for (PluginInformation plugin : center.getPlugins())
|
|
|
|
|
{
|
|
|
|
|
String pluginId = plugin.getId();
|
|
|
|
|
|
|
|
|
|
if (Util.isNotEmpty(pluginId) && pluginId.equals(id))
|
|
|
|
|
{
|
|
|
|
|
plugin.setState(PluginState.INSTALLED);
|
|
|
|
|
|
|
|
|
|
// ugly workaround
|
|
|
|
|
Plugin newPlugin = new Plugin();
|
|
|
|
|
|
|
|
|
|
newPlugin.setInformation(plugin);
|
|
|
|
|
installedPlugins.put(id, newPlugin);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-13 18:59:00 +01:00
|
|
|
}
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void uninstall(String id)
|
|
|
|
|
{
|
2010-12-16 07:46:02 +01:00
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-18 16:25:57 +01:00
|
|
|
Plugin plugin = installedPlugins.get(id);
|
|
|
|
|
|
|
|
|
|
if (plugin == null)
|
|
|
|
|
{
|
2010-12-18 18:21:21 +01:00
|
|
|
throw new PluginNotInstalledException(id.concat(" is not install"));
|
2010-12-18 16:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pluginHandler == null)
|
|
|
|
|
{
|
2010-12-29 14:05:30 +01:00
|
|
|
getPluginCenter();
|
2010-12-18 16:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-29 14:05:30 +01:00
|
|
|
pluginHandler.uninstall(id);
|
|
|
|
|
installedPlugins.remove(id);
|
|
|
|
|
preparePlugins(getPluginCenter());
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void update(String id)
|
|
|
|
|
{
|
|
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-18 18:21:21 +01:00
|
|
|
String[] idParts = id.split(":");
|
|
|
|
|
String groupId = idParts[0];
|
|
|
|
|
String artefactId = idParts[1];
|
|
|
|
|
PluginInformation installed = null;
|
|
|
|
|
|
|
|
|
|
for (PluginInformation info : getInstalled())
|
|
|
|
|
{
|
|
|
|
|
if (groupId.equals(info.getGroupId())
|
|
|
|
|
&& artefactId.equals(info.getArtifactId()))
|
|
|
|
|
{
|
|
|
|
|
installed = info;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (installed == null)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder msg = new StringBuilder(groupId);
|
|
|
|
|
|
|
|
|
|
msg.append(":").append(groupId).append(" is not install");
|
|
|
|
|
|
|
|
|
|
throw new PluginNotInstalledException(msg.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-29 14:08:31 +01:00
|
|
|
uninstall(installed.getId());
|
|
|
|
|
install(id);
|
2010-12-18 13:37:34 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- get methods ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
* @param id
|
|
|
|
|
*
|
2010-10-12 09:16:40 +02:00
|
|
|
* @return
|
|
|
|
|
*/
|
2010-12-01 14:26:29 +01:00
|
|
|
@Override
|
2010-12-13 18:59:00 +01:00
|
|
|
public PluginInformation get(String id)
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-16 07:46:02 +01:00
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-13 21:02:39 +01:00
|
|
|
PluginInformation result = null;
|
|
|
|
|
|
|
|
|
|
for (PluginInformation info : getPluginCenter().getPlugins())
|
|
|
|
|
{
|
|
|
|
|
if (id.equals(info.getId()))
|
|
|
|
|
{
|
|
|
|
|
result = info;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param filter
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Set<PluginInformation> get(PluginFilter filter)
|
|
|
|
|
{
|
|
|
|
|
AssertUtil.assertIsNotNull(filter);
|
|
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
|
|
|
|
Set<PluginInformation> infoSet = new HashSet<PluginInformation>();
|
|
|
|
|
|
2010-12-18 16:25:57 +01:00
|
|
|
filter(infoSet, getInstalled(), filter);
|
2010-12-18 13:37:34 +01:00
|
|
|
filter(infoSet, getPluginCenter().getPlugins(), filter);
|
|
|
|
|
|
|
|
|
|
return infoSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<PluginInformation> getAll()
|
|
|
|
|
{
|
|
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-18 16:25:57 +01:00
|
|
|
Set<PluginInformation> infoSet = getInstalled();
|
2010-12-18 13:37:34 +01:00
|
|
|
|
|
|
|
|
infoSet.addAll(getPluginCenter().getPlugins());
|
|
|
|
|
|
|
|
|
|
return infoSet;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
* @return
|
2010-12-01 14:26:29 +01:00
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
@Override
|
|
|
|
|
public Collection<PluginInformation> getAvailable()
|
2010-12-01 14:26:29 +01:00
|
|
|
{
|
2010-12-16 07:46:02 +01:00
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-17 19:02:32 +01:00
|
|
|
Set<PluginInformation> availablePlugins = new HashSet<PluginInformation>();
|
|
|
|
|
Set<PluginInformation> centerPlugins = getPluginCenter().getPlugins();
|
|
|
|
|
|
|
|
|
|
for (PluginInformation info : centerPlugins)
|
|
|
|
|
{
|
|
|
|
|
if (!installedPlugins.containsKey(info.getId()))
|
|
|
|
|
{
|
|
|
|
|
availablePlugins.add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return availablePlugins;
|
2010-12-01 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2010-12-18 16:25:57 +01:00
|
|
|
public Set<PluginInformation> getAvailableUpdates()
|
2010-12-18 13:37:34 +01:00
|
|
|
{
|
|
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
|
|
|
|
return get(FILTER_UPDATES);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
* @return
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
@Override
|
2010-12-18 16:25:57 +01:00
|
|
|
public Set<PluginInformation> getInstalled()
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-16 07:46:02 +01:00
|
|
|
SecurityUtil.assertIsAdmin(securityContextProvicer);
|
|
|
|
|
|
2010-12-18 16:25:57 +01:00
|
|
|
Set<PluginInformation> infoSet = new LinkedHashSet<PluginInformation>();
|
|
|
|
|
|
|
|
|
|
for (Plugin plugin : installedPlugins.values())
|
|
|
|
|
{
|
|
|
|
|
infoSet.add(plugin.getInformation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return infoSet;
|
2010-12-13 18:59:00 +01:00
|
|
|
}
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
2011-02-10 16:18:45 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param url
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String buildPluginUrl(String url)
|
|
|
|
|
{
|
2011-03-12 15:19:41 +01:00
|
|
|
String os = SystemUtil.getOS();
|
|
|
|
|
String arch = SystemUtil.getArch();
|
|
|
|
|
|
|
|
|
|
try
|
2011-02-10 16:18:45 +01:00
|
|
|
{
|
2011-03-12 15:19:41 +01:00
|
|
|
os = URLEncoder.encode(os, ENCODING);
|
2011-02-10 16:18:45 +01:00
|
|
|
}
|
2011-03-12 15:19:41 +01:00
|
|
|
catch (UnsupportedEncodingException ex)
|
2011-02-10 16:18:45 +01:00
|
|
|
{
|
2011-03-12 15:19:41 +01:00
|
|
|
logger.error(ex.getMessage(), ex);
|
2011-02-10 16:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 15:19:41 +01:00
|
|
|
return url.replace("{version}", context.getVersion()).replace("{os}",
|
|
|
|
|
os).replace("{arch}", arch);
|
2011-02-10 16:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param target
|
|
|
|
|
* @param source
|
|
|
|
|
* @param filter
|
|
|
|
|
*/
|
|
|
|
|
private void filter(Set<PluginInformation> target,
|
|
|
|
|
Collection<PluginInformation> source, PluginFilter filter)
|
|
|
|
|
{
|
|
|
|
|
for (PluginInformation info : source)
|
|
|
|
|
{
|
|
|
|
|
if (filter.accept(info))
|
|
|
|
|
{
|
|
|
|
|
target.add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param available
|
|
|
|
|
*/
|
|
|
|
|
private void preparePlugin(PluginInformation available)
|
|
|
|
|
{
|
|
|
|
|
PluginState state = PluginState.AVAILABLE;
|
|
|
|
|
|
2010-12-18 16:25:57 +01:00
|
|
|
for (PluginInformation installed : getInstalled())
|
2010-12-18 13:37:34 +01:00
|
|
|
{
|
|
|
|
|
if (isSamePlugin(available, installed))
|
|
|
|
|
{
|
|
|
|
|
if (installed.getVersion().equals(available.getVersion()))
|
|
|
|
|
{
|
2010-12-18 18:21:21 +01:00
|
|
|
state = PluginState.INSTALLED;
|
2010-12-18 13:37:34 +01:00
|
|
|
}
|
2011-01-28 17:41:11 +01:00
|
|
|
else if (isNewer(available, installed))
|
2010-12-18 13:37:34 +01:00
|
|
|
{
|
2010-12-18 18:21:21 +01:00
|
|
|
state = PluginState.UPDATE_AVAILABLE;
|
2010-12-18 13:37:34 +01:00
|
|
|
}
|
2011-01-28 17:41:11 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
state = PluginState.NEWER_VERSION_INSTALLED;
|
|
|
|
|
}
|
2010-12-18 18:21:21 +01:00
|
|
|
|
|
|
|
|
break;
|
2010-12-18 13:37:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
available.setState(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param pc
|
|
|
|
|
*/
|
|
|
|
|
private void preparePlugins(PluginCenter pc)
|
|
|
|
|
{
|
|
|
|
|
Set<PluginInformation> infoSet = pc.getPlugins();
|
|
|
|
|
|
|
|
|
|
if (infoSet != null)
|
|
|
|
|
{
|
2011-03-18 19:35:19 +01:00
|
|
|
Iterator<PluginInformation> pit = infoSet.iterator();
|
|
|
|
|
|
|
|
|
|
while (pit.hasNext())
|
2010-12-18 13:37:34 +01:00
|
|
|
{
|
2011-03-18 19:35:19 +01:00
|
|
|
PluginInformation available = pit.next();
|
|
|
|
|
|
|
|
|
|
if (isCorePluging(available))
|
|
|
|
|
{
|
|
|
|
|
pit.remove();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
preparePlugin(available);
|
|
|
|
|
}
|
2010-12-18 13:37:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~--- get methods ----------------------------------------------------------
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private PluginCenter getPluginCenter()
|
|
|
|
|
{
|
|
|
|
|
PluginCenter center = cache.get(PluginCenter.class.getName());
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
if (center == null)
|
|
|
|
|
{
|
2010-12-13 21:02:39 +01:00
|
|
|
synchronized (DefaultPluginManager.class)
|
2010-12-13 18:59:00 +01:00
|
|
|
{
|
2011-02-10 16:18:45 +01:00
|
|
|
String pluginUrl = configuration.getPluginUrl();
|
|
|
|
|
|
|
|
|
|
pluginUrl = buildPluginUrl(pluginUrl);
|
|
|
|
|
|
2010-12-13 21:02:39 +01:00
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
2011-02-10 16:18:45 +01:00
|
|
|
logger.info("fetch plugin informations from {}", pluginUrl);
|
2010-12-13 21:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-05 17:18:01 +01:00
|
|
|
if (Util.isNotEmpty(pluginUrl))
|
2010-12-13 21:02:39 +01:00
|
|
|
{
|
2011-01-05 17:18:01 +01:00
|
|
|
InputStream input = null;
|
2010-12-13 21:02:39 +01:00
|
|
|
|
2011-01-05 17:18:01 +01:00
|
|
|
try
|
2010-12-13 21:02:39 +01:00
|
|
|
{
|
2011-05-09 12:12:20 +02:00
|
|
|
input = client.get(pluginUrl).getContent();
|
2011-03-12 15:19:41 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* TODO: add gzip support
|
|
|
|
|
*
|
|
|
|
|
* if (gzip)
|
|
|
|
|
* {
|
|
|
|
|
* input = new GZIPInputStream(input);
|
|
|
|
|
* }
|
|
|
|
|
*/
|
2011-01-05 17:18:01 +01:00
|
|
|
center = (PluginCenter) unmarshaller.unmarshal(input);
|
|
|
|
|
preparePlugins(center);
|
|
|
|
|
cache.put(PluginCenter.class.getName(), center);
|
|
|
|
|
|
|
|
|
|
if (pluginHandler == null)
|
|
|
|
|
{
|
|
|
|
|
pluginHandler = new AetherPluginHandler(this,
|
|
|
|
|
SCMContext.getContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pluginHandler.setPluginRepositories(center.getRepositories());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new PluginLoadException(ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
IOUtil.close(input);
|
|
|
|
|
}
|
2010-12-13 21:02:39 +01:00
|
|
|
}
|
2010-12-13 18:59:00 +01:00
|
|
|
}
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
return center;
|
|
|
|
|
}
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2011-03-18 19:35:19 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param available
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isCorePluging(PluginInformation available)
|
|
|
|
|
{
|
|
|
|
|
boolean core = false;
|
|
|
|
|
|
|
|
|
|
for (Plugin installedPlugin : installedPlugins.values())
|
|
|
|
|
{
|
|
|
|
|
PluginInformation installed = installedPlugin.getInformation();
|
|
|
|
|
|
|
|
|
|
if (isSamePlugin(available, installed)
|
|
|
|
|
&& (installed.getState() == PluginState.CORE))
|
|
|
|
|
{
|
|
|
|
|
core = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return core;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-28 17:41:11 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param available
|
|
|
|
|
* @param installed
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isNewer(PluginInformation available,
|
|
|
|
|
PluginInformation installed)
|
|
|
|
|
{
|
|
|
|
|
boolean result = false;
|
|
|
|
|
PluginVersion version = PluginVersion.createVersion(installed.getVersion());
|
|
|
|
|
|
|
|
|
|
if (version != null)
|
|
|
|
|
{
|
|
|
|
|
result = version.isNewer(available.getVersion());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-18 13:37:34 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param p1
|
|
|
|
|
* @param p2
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isSamePlugin(PluginInformation p1, PluginInformation p2)
|
|
|
|
|
{
|
|
|
|
|
return p1.getGroupId().equals(p2.getGroupId())
|
|
|
|
|
&& p1.getArtifactId().equals(p2.getArtifactId());
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
2011-02-12 10:52:04 +01:00
|
|
|
private Cache<String, PluginCenter> cache;
|
2010-12-13 18:59:00 +01:00
|
|
|
|
2011-05-09 12:12:20 +02:00
|
|
|
/** Field description */
|
|
|
|
|
private HttpClient client;
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private ScmConfiguration configuration;
|
|
|
|
|
|
2011-03-12 15:19:41 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private SCMContextProvider context;
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
/** Field description */
|
2010-12-18 16:25:57 +01:00
|
|
|
private Map<String, Plugin> installedPlugins;
|
2010-12-13 18:59:00 +01:00
|
|
|
|
2010-12-13 21:02:39 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private AetherPluginHandler pluginHandler;
|
|
|
|
|
|
2010-12-16 07:46:02 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private Provider<SecurityContext> securityContextProvicer;
|
|
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
/** Field description */
|
|
|
|
|
private Unmarshaller unmarshaller;
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|