imporve plugin system

This commit is contained in:
Sebastian Sdorra
2010-12-13 18:59:00 +01:00
parent ab00eabdd4
commit 2df3034309
22 changed files with 1010 additions and 59 deletions

View File

@@ -43,10 +43,12 @@
<plugin>
<information>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>${project.url}</url>
</information>

View File

@@ -43,9 +43,12 @@
<plugin>
<information>
<name>${project.name}</name>
<author>Sebastian Sdorra</author>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<url>${project.url}</url>
</information>

View File

@@ -43,10 +43,12 @@
<plugin>
<information>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>${project.url}</url>
</information>

View File

@@ -43,10 +43,12 @@
<plugin>
<information>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>${project.url}</url>
</information>

View File

@@ -35,10 +35,12 @@
<plugin>
<information>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<name>${project.name}</name>
<description>${project.description}</description>
<author>Sebastian Sdorra</author>
<version>${project.version}</version>
<url>${project.url}</url>
</information>

View File

@@ -0,0 +1,120 @@
/**
* 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.plugin;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Sebastian Sdorra
*/
@XmlRootElement(name = "plugin-center")
@XmlAccessorType(XmlAccessType.FIELD)
public class PluginCenter implements Serializable
{
/** Field description */
private static final long serialVersionUID = -6414175308610267397L;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Set<PluginInformation> getPlugins()
{
return plugins;
}
/**
* Method description
*
*
* @return
*/
public Set<PluginRepository> getRepositories()
{
return repositories;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param plugins
*/
public void setPlugins(Set<PluginInformation> plugins)
{
this.plugins = plugins;
}
/**
* Method description
*
*
* @param repositories
*/
public void setRepositories(Set<PluginRepository> repositories)
{
this.repositories = repositories;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name = "plugin")
@XmlElementWrapper(name = "plugins")
private Set<PluginInformation> plugins = new HashSet<PluginInformation>();
/** Field description */
@XmlElement(name = "repository")
@XmlElementWrapper(name = "repositories")
private Set<PluginRepository> repositories = new HashSet<PluginRepository>();
}

View File

@@ -45,6 +45,17 @@ import javax.xml.bind.annotation.XmlRootElement;
public class PluginInformation
{
/**
* Method description
*
*
* @return
*/
public String getArtifactId()
{
return artifactId;
}
/**
* Method description
*
@@ -67,6 +78,17 @@ public class PluginInformation
return description;
}
/**
* Method description
*
*
* @return
*/
public String getGroupId()
{
return groupId;
}
/**
* Method description
*
@@ -102,6 +124,17 @@ public class PluginInformation
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param artifactId
*/
public void setArtifactId(String artifactId)
{
this.artifactId = artifactId;
}
/**
* Method description
*
@@ -124,6 +157,17 @@ public class PluginInformation
this.description = description;
}
/**
* Method description
*
*
* @param groupId
*/
public void setGroupId(String groupId)
{
this.groupId = groupId;
}
/**
* Method description
*
@@ -159,12 +203,18 @@ public class PluginInformation
//~--- fields ---------------------------------------------------------------
/** Field description */
private String artifactId;
/** Field description */
private String author;
/** Field description */
private String description;
/** Field description */
private String groupId;
/** Field description */
private String name;

View File

@@ -0,0 +1,90 @@
/**
* 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.plugin;
/**
*
* @author Sebastian Sdorra
*/
public class PluginLoadException extends RuntimeException
{
/** Field description */
private static final long serialVersionUID = -8683647962850692519L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public PluginLoadException()
{
super();
}
/**
* Constructs ...
*
*
* @param message
*/
public PluginLoadException(String message)
{
super(message);
}
/**
* Constructs ...
*
*
* @param cause
*/
public PluginLoadException(Throwable cause)
{
super(cause);
}
/**
* Constructs ...
*
*
* @param message
* @param cause
*/
public PluginLoadException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@@ -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.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.ext.ExtensionProcessor;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*/
public interface PluginLoader
{
/**
* Method description
*
*
* @param processor
*/
public void processExtensions(ExtensionProcessor processor);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Collection<Plugin> getInstalledPlugins();
}

View File

@@ -33,14 +33,9 @@
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Binder;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import sonia.scm.plugin.ext.ExtensionProcessor;
/**
*
@@ -53,10 +48,17 @@ public interface PluginManager
* Method description
*
*
* @param binder
* @param id
*/
public void processExtensions(ExtensionProcessor processor);
public void install(String id);
/**
* Method description
*
*
* @param id
*/
public void uninstall(String id);
//~--- get methods ----------------------------------------------------------
@@ -64,7 +66,25 @@ public interface PluginManager
* Method description
*
*
* @param id
*
* @return
*/
public Collection<Plugin> getPlugins();
public PluginInformation get(String id);
/**
* Method description
*
*
* @return
*/
public Collection<PluginInformation> getAvailable();
/**
* Method description
*
*
* @return
*/
public Collection<PluginInformation> getInstalled();
}

View File

@@ -0,0 +1,196 @@
/**
* 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.plugin;
/**
*
* @author Sebastian Sdorra
*/
public class PluginRepository
{
/**
* Constructs ...
*
*/
public PluginRepository() {}
/**
* Constructs ...
*
*
* @param id
* @param url
*/
public PluginRepository(String id, String url)
{
this.id = id;
this.url = url;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final PluginRepository other = (PluginRepository) obj;
if ((this.id == null)
? (other.id != null)
: !this.id.equals(other.id))
{
return false;
}
if ((this.url == null)
? (other.url != null)
: !this.url.equals(other.url))
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 7;
hash = 37 * hash + ((this.id != null)
? this.id.hashCode()
: 0);
hash = 37 * hash + ((this.url != null)
? this.url.hashCode()
: 0);
return hash;
}
/**
* Method description
*
*
* @return
*/
@Override
public String toString()
{
StringBuilder out = new StringBuilder("PluginRepository{id=");
out.append(id).append(", url=").append(url).append(")");
return out.toString();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getId()
{
return id;
}
/**
* Method description
*
*
* @return
*/
public String getUrl()
{
return url;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param id
*/
public void setId(String id)
{
this.id = id;
}
/**
* Method description
*
*
* @param url
*/
public void setUrl(String url)
{
this.url = url;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String id;
/** Field description */
private String url;
}

View File

@@ -58,6 +58,10 @@
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
</exclusions>
</dependency>

View File

@@ -40,8 +40,8 @@ import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.servlet.GuiceServletContextListener;
import sonia.scm.plugin.DefaultPluginManager;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.DefaultPluginLoader;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.store.StoreFactory;
import sonia.scm.user.UserManager;
@@ -101,13 +101,14 @@ public class ScmContextListener extends GuiceServletContextListener
@Override
protected Injector getInjector()
{
PluginManager manager = new DefaultPluginManager();
PluginLoader pluginLoader = new DefaultPluginLoader();
BindingExtensionProcessor bindExtProcessor =
new BindingExtensionProcessor();
manager.processExtensions(bindExtProcessor);
pluginLoader.processExtensions(bindExtProcessor);
ScmServletModule main = new ScmServletModule(manager, bindExtProcessor);
ScmServletModule main = new ScmServletModule(pluginLoader,
bindExtProcessor);
List<Module> moduleList =
new ArrayList<Module>(bindExtProcessor.getModuleSet());

View File

@@ -45,7 +45,9 @@ import sonia.scm.cache.CacheManager;
import sonia.scm.cache.EhCacheManager;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.filter.SecurityFilter;
import sonia.scm.plugin.DefaultPluginManager;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.ScriptResourceServlet;
import sonia.scm.repository.RepositoryManager;
@@ -129,13 +131,13 @@ public class ScmServletModule extends ServletModule
* Constructs ...
*
*
* @param manager
* @param pluginLoader
* @param bindExtProcessor
*/
ScmServletModule(PluginManager manager,
ScmServletModule(PluginLoader pluginLoader,
BindingExtensionProcessor bindExtProcessor)
{
this.pluginManager = manager;
this.pluginLoader = pluginLoader;
this.bindExtProcessor = bindExtProcessor;
}
@@ -156,7 +158,8 @@ public class ScmServletModule extends ServletModule
bind(StoreFactory.class).to(JAXBStoreFactory.class);
bind(ScmConfiguration.class).toInstance(config);
bind(PluginManager.class).toInstance(pluginManager);
bind(PluginLoader.class).toInstance(pluginLoader);
bind(PluginManager.class).to(DefaultPluginManager.class);
bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
bindExtProcessor.bindExtensions(binder());
@@ -276,7 +279,7 @@ public class ScmServletModule extends ServletModule
packageSet.add(SCMContext.DEFAULT_PACKAGE);
Collection<Plugin> plugins = pluginManager.getPlugins();
Collection<Plugin> plugins = pluginLoader.getInstalledPlugins();
if (plugins != null)
{
@@ -341,5 +344,5 @@ public class ScmServletModule extends ServletModule
private BindingExtensionProcessor bindExtProcessor;
/** Field description */
private PluginManager pluginManager;
private PluginLoader pluginLoader;
}

View File

@@ -0,0 +1,106 @@
/**
* 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.api.rest.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginManager;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
@Path("plugins/available")
public class AvailablePluginResource
{
/**
* Constructs ...
*
*
* @param pluginManager
*/
@Inject
public AvailablePluginResource(PluginManager pluginManager)
{
this.pluginManager = pluginManager;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public PluginInformation[] getAvailablePlugins()
{
Collection<PluginInformation> pluginCollection =
pluginManager.getAvailable();
PluginInformation[] plugins = null;
if (pluginCollection != null)
{
plugins = pluginCollection.toArray(new PluginInformation[0]);
}
else
{
plugins = new PluginInformation[0];
}
return plugins;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private PluginManager pluginManager;
}

View File

@@ -38,15 +38,12 @@ package sonia.scm.api.rest.resources;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginManager;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -58,8 +55,8 @@ import javax.ws.rs.core.MediaType;
* @author Sebastian Sdorra
*/
@Singleton
@Path("plugins")
public class PluginResource
@Path("plugins/installed")
public class InstalledPluginResource
{
/**
@@ -69,26 +66,20 @@ public class PluginResource
* @param pluginManager
*/
@Inject
public PluginResource(PluginManager pluginManager)
public InstalledPluginResource(PluginManager pluginManager)
{
Collection<Plugin> pluginCollection = pluginManager.getPlugins();
List<PluginInformation> informations = new ArrayList<PluginInformation>();
Collection<PluginInformation> pluginCollection =
pluginManager.getInstalled();
if (pluginCollection != null)
{
for (Plugin plugin : pluginCollection)
plugins = pluginCollection.toArray(new PluginInformation[0]);
}
else
{
PluginInformation pluginInfo = plugin.getInformation();
if (pluginInfo != null)
{
informations.add(pluginInfo);
plugins = new PluginInformation[0];
}
}
}
plugins = informations.toArray(new PluginInformation[0]);
}
//~--- get methods ----------------------------------------------------------

View File

@@ -43,6 +43,7 @@ import java.io.File;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
@@ -55,6 +56,10 @@ import javax.xml.bind.annotation.XmlRootElement;
public class ScmConfiguration
{
/** Field description */
public static final String DEFAULT_PLUGINURL =
"http://plugins.scm-manager.org/plugins.xml";
/** Field description */
public static final String PATH =
"config".concat(File.separator).concat("config.xml");
@@ -74,6 +79,17 @@ public class ScmConfiguration
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getPluginUrl()
{
return pluginUrl;
}
/**
* Method description
*
@@ -87,6 +103,17 @@ public class ScmConfiguration
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param pluginUrl
*/
public void setPluginUrl(String pluginUrl)
{
this.pluginUrl = pluginUrl;
}
/**
* Method description
*
@@ -100,6 +127,10 @@ public class ScmConfiguration
//~--- fields ---------------------------------------------------------------
/** Field description */
@XmlElement(name = "plugin-url")
private String pluginUrl = DEFAULT_PLUGINURL;
/** Field description */
private String servername = "localhost";
}

View File

@@ -63,15 +63,15 @@ import javax.xml.bind.JAXB;
*
* @author Sebastian Sdorra
*/
public class DefaultPluginManager implements PluginManager
public class DefaultPluginLoader implements PluginLoader
{
/** Field description */
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
/** the logger for DefaultPluginManager */
/** the logger for DefaultPluginLoader */
private static final Logger logger =
LoggerFactory.getLogger(DefaultPluginManager.class);
LoggerFactory.getLogger(DefaultPluginLoader.class);
//~--- constructors ---------------------------------------------------------
@@ -79,7 +79,7 @@ public class DefaultPluginManager implements PluginManager
* Constructs ...
*
*/
public DefaultPluginManager()
public DefaultPluginLoader()
{
ClassLoader classLoader = getClassLoader();
@@ -108,7 +108,7 @@ public class DefaultPluginManager implements PluginManager
ClassLoader classLoader = getClassLoader();
JARExtensionScanner scanner = new JARExtensionScanner();
for (Plugin plugin : plugins)
for (Plugin plugin : installedPlugins)
{
InputStream input = null;
@@ -150,9 +150,9 @@ public class DefaultPluginManager implements PluginManager
* @return
*/
@Override
public Collection<Plugin> getPlugins()
public Collection<Plugin> getInstalledPlugins()
{
return plugins;
return installedPlugins;
}
//~--- methods --------------------------------------------------------------
@@ -204,7 +204,7 @@ public class DefaultPluginManager implements PluginManager
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
plugin.setPath(path);
plugins.add(plugin);
installedPlugins.add(plugin);
}
catch (Exception ex)
{
@@ -235,5 +235,5 @@ public class DefaultPluginManager implements PluginManager
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<Plugin> plugins = new HashSet<Plugin>();
private Set<Plugin> installedPlugins = new HashSet<Plugin>();
}

View File

@@ -0,0 +1,249 @@
/**
* 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.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConfigurationException;
import sonia.scm.cache.CacheManager;
import sonia.scm.cache.SimpleCache;
import sonia.scm.config.ScmConfiguration;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class DefaultPluginManager implements PluginManager
{
/** Field description */
public static final String CACHE_NAME = "sonia.cache.plugins";
/** the logger for DefaultPluginManager */
private static final Logger logger =
LoggerFactory.getLogger(DefaultPluginManager.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
*
* @param configuration
* @param pluginLoader
* @param cacheManager
*/
@Inject
public DefaultPluginManager(ScmConfiguration configuration,
PluginLoader pluginLoader,
CacheManager cacheManager)
{
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());
}
}
try
{
unmarshaller =
JAXBContext.newInstance(PluginCenter.class).createUnmarshaller();
}
catch (JAXBException ex)
{
throw new ConfigurationException(ex);
}
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param id
*/
@Override
public void install(String id)
{
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Method description
*
*
* @param id
*/
@Override
public void uninstall(String id)
{
throw new UnsupportedOperationException("Not supported yet.");
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param id
*
* @return
*/
@Override
public PluginInformation get(String id)
{
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Method description
*
*
* @return
*/
@Override
public Collection<PluginInformation> getAvailable()
{
return getPluginCenter().getPlugins();
}
/**
* Method description
*
*
* @return
*/
@Override
public Collection<PluginInformation> getInstalled()
{
return installedPlugins.values();
}
/**
* Method description
*
*
* @return
*/
private PluginCenter getPluginCenter()
{
PluginCenter center = cache.get(PluginCenter.class.getName());
if (center == null)
{
if (logger.isInfoEnabled())
{
logger.info("fetch plugin informations from {}",
configuration.getPluginUrl());
}
try
{
center = (PluginCenter) unmarshaller.unmarshal(
new URL(configuration.getPluginUrl()));
cache.put(PluginCenter.class.getName(), center);
}
catch (Exception ex)
{
throw new PluginLoadException(ex);
}
}
return center;
}
/**
* Method description
*
*
* @param info
*
* @return
*/
private String getPluginId(PluginInformation info)
{
StringBuilder id = new StringBuilder(info.getGroupId());
id.append(":").append(info.getArtifactId()).append(":");
return id.append(info.getVersion()).toString();
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private SimpleCache<String, PluginCenter> cache;
/** Field description */
private ScmConfiguration configuration;
/** Field description */
private Map<String, PluginInformation> installedPlugins;
/** Field description */
private Unmarshaller unmarshaller;
}

View File

@@ -74,12 +74,12 @@ public class ScriptResourceServlet extends AbstractResourceServlet
* Constructs ...
*
*
* @param manager
* @param pluginLoader
*/
@Inject
public ScriptResourceServlet(PluginManager manager)
public ScriptResourceServlet(PluginLoader pluginLoader)
{
this.manager = manager;
this.pluginLoader = pluginLoader;
}
//~--- methods --------------------------------------------------------------
@@ -222,7 +222,7 @@ public class ScriptResourceServlet extends AbstractResourceServlet
private Collection<String> getScriptResources()
{
Set<String> resources = new TreeSet<String>();
Collection<Plugin> plugins = manager.getPlugins();
Collection<Plugin> plugins = pluginLoader.getInstalledPlugins();
if (plugins != null)
{
@@ -238,5 +238,5 @@ public class ScriptResourceServlet extends AbstractResourceServlet
//~--- fields ---------------------------------------------------------------
/** Field description */
private PluginManager manager;
private PluginLoader pluginLoader;
}

View File

@@ -108,4 +108,15 @@
diskExpiryThreadIntervalSeconds="2400"
/>
<cache
name="sonia.cache.plugins"
maxElementsInMemory="20000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="1200"
timeToLiveSeconds="2400"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="2400"
/>
</ehcache>

View File

@@ -39,7 +39,7 @@ Sonia.plugin.Grid = Ext.extend(Sonia.rest.Grid, {
initComponent: function(){
var pluginStore = new Sonia.rest.JsonStore({
url: restUrl + 'plugins.json',
url: restUrl + 'plugins/installed.json',
root: 'plugin-information',
fields: [ 'name', 'author', 'description', 'url', 'version' ],
sortInfo: {