mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
using maven aether for plugin installation
This commit is contained in:
@@ -47,12 +47,19 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -63,6 +70,9 @@ public class BootstrapListener implements ServletContextListener
|
||||
/** Field description */
|
||||
public static final String LISTENER = "sonia.scm.ScmContextListener";
|
||||
|
||||
/** Field description */
|
||||
public static final String PLUGIN_CLASSPATHFILE = "classpath.xml";
|
||||
|
||||
/** Field description */
|
||||
public static final String PLUGIN_DIRECTORY = "plugins";
|
||||
|
||||
@@ -102,32 +112,23 @@ public class BootstrapListener implements ServletContextListener
|
||||
|
||||
if (pluginDirectory.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
File[] jarFiles = pluginDirectory.listFiles(new JarFilenameFilter());
|
||||
File classpathFile = new File(pluginDirectory, PLUGIN_CLASSPATHFILE);
|
||||
|
||||
if (Util.isNotEmpty(jarFiles))
|
||||
if (classpathFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
int size = jarFiles.length;
|
||||
URL[] urls = new URL[size];
|
||||
Classpath classpath = JAXB.unmarshal(classpathFile, Classpath.class);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
if (classpath != null)
|
||||
{
|
||||
urls[i] = jarFiles[i].toURI().toURL();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("added jar {} to classpath",
|
||||
urls[i].toExternalForm());
|
||||
}
|
||||
classLoader = createClassLoader(pluginDirectory, classpath);
|
||||
}
|
||||
|
||||
classLoader = new URLClassLoader(urls, getParentClassLoader());
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +151,51 @@ public class BootstrapListener implements ServletContextListener
|
||||
scmContextListener.contextInitialized(sce);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pluginDirectory
|
||||
* @param classpath
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ClassLoader createClassLoader(File pluginDirectory,
|
||||
Classpath classpath)
|
||||
{
|
||||
List<URL> classpathURLs = new LinkedList<URL>();
|
||||
|
||||
for (String path : classpath)
|
||||
{
|
||||
if (path.startsWith("/"))
|
||||
{
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
File file = new File(pluginDirectory, path);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("append {} to classpath", file.getPath());
|
||||
}
|
||||
|
||||
classpathURLs.add(file.toURI().toURL());
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new URLClassLoader(classpathURLs.toArray(new URL[0]),
|
||||
getParentClassLoader());
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -170,35 +216,6 @@ public class BootstrapListener implements ServletContextListener
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class description
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 2010-12-09
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
private static class JarFilenameFilter implements FilenameFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File file, String name)
|
||||
{
|
||||
return name.endsWith(".jar");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
131
scm-webapp/src/main/java/sonia/scm/boot/Classpath.java
Normal file
131
scm-webapp/src/main/java/sonia/scm/boot/Classpath.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* 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.boot;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
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.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "classpath")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class Classpath implements Iterable<String>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public Classpath() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public void add(String path)
|
||||
{
|
||||
pathSet.add(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
public void add(File file)
|
||||
{
|
||||
pathSet.add(file.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Iterator<String> iterator()
|
||||
{
|
||||
return pathSet.iterator();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<String> getPathSet()
|
||||
{
|
||||
return pathSet;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pathSet
|
||||
*/
|
||||
public void setPathSet(Set<String> pathSet)
|
||||
{
|
||||
this.pathSet = pathSet;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "path")
|
||||
private Set<String> pathSet = new LinkedHashSet<String>();
|
||||
}
|
||||
Reference in New Issue
Block a user