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;
|
|
|
|
|
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;
|
|
|
|
|
import sonia.scm.cache.CacheManager;
|
|
|
|
|
import sonia.scm.cache.SimpleCache;
|
|
|
|
|
import sonia.scm.config.ScmConfiguration;
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
import java.util.Collection;
|
2010-12-13 18:59:00 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
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
|
|
|
|
|
|
|
|
/** 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-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
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param configuration
|
|
|
|
|
* @param pluginLoader
|
|
|
|
|
* @param cacheManager
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
@Inject
|
|
|
|
|
public DefaultPluginManager(ScmConfiguration configuration,
|
|
|
|
|
PluginLoader pluginLoader,
|
|
|
|
|
CacheManager cacheManager)
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
this.configuration = configuration;
|
|
|
|
|
this.cache = cacheManager.getSimpleCache(String.class, PluginCenter.class,
|
|
|
|
|
CACHE_NAME);
|
|
|
|
|
installedPlugins = new HashMap<String, PluginInformation>();
|
|
|
|
|
|
|
|
|
|
for (Plugin plugin : pluginLoader.getInstalledPlugins())
|
|
|
|
|
{
|
|
|
|
|
PluginInformation info = plugin.getInformation();
|
|
|
|
|
|
|
|
|
|
if (info != null)
|
|
|
|
|
{
|
|
|
|
|
String id = getPluginId(info);
|
|
|
|
|
|
|
|
|
|
installedPlugins.put(id, plugin.getInformation());
|
|
|
|
|
}
|
|
|
|
|
}
|
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-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-13 18:59:00 +01:00
|
|
|
throw new UnsupportedOperationException("Not supported yet.");
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
throw new UnsupportedOperationException("Not supported yet.");
|
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-13 18:59:00 +01:00
|
|
|
throw new UnsupportedOperationException("Not supported yet.");
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
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-13 18:59:00 +01:00
|
|
|
return getPluginCenter().getPlugins();
|
2010-12-01 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
public Collection<PluginInformation> getInstalled()
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
return installedPlugins.values();
|
|
|
|
|
}
|
2010-12-01 14:26:29 +01:00
|
|
|
|
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-10-31 13:07:43 +01:00
|
|
|
if (logger.isInfoEnabled())
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
logger.info("fetch plugin informations from {}",
|
|
|
|
|
configuration.getPluginUrl());
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
2010-10-31 13:07:43 +01:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
center = (PluginCenter) unmarshaller.unmarshal(
|
|
|
|
|
new URL(configuration.getPluginUrl()));
|
|
|
|
|
cache.put(PluginCenter.class.getName(), center);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new PluginLoadException(ex);
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2010-12-13 18:59:00 +01:00
|
|
|
* @param info
|
|
|
|
|
*
|
2010-12-01 14:26:29 +01:00
|
|
|
* @return
|
|
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
private String getPluginId(PluginInformation info)
|
2010-12-01 14:26:29 +01:00
|
|
|
{
|
2010-12-13 18:59:00 +01:00
|
|
|
StringBuilder id = new StringBuilder(info.getGroupId());
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
id.append(":").append(info.getArtifactId()).append(":");
|
2010-12-01 14:26:29 +01:00
|
|
|
|
2010-12-13 18:59:00 +01:00
|
|
|
return id.append(info.getVersion()).toString();
|
2010-12-01 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
2010-12-13 18:59:00 +01:00
|
|
|
private SimpleCache<String, PluginCenter> cache;
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
|
|
|
|
private ScmConfiguration configuration;
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
|
|
|
|
private Map<String, PluginInformation> installedPlugins;
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
|
|
|
|
private Unmarshaller unmarshaller;
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|