mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
start implementation of isolated classloaders
This commit is contained in:
@@ -82,4 +82,12 @@ public interface PluginLoader
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<Plugin> getInstalledPlugins();
|
public Collection<Plugin> getInstalledPlugins();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ClassLoader getUberClassLoader();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,33 +33,86 @@ package sonia.scm.plugin;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Wrapper for a {@link Plugin}. The wrapper holds the directory and the
|
||||||
|
* {@link ClassLoader}, which is able to load plugin classes.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class BlacklistDependencyFilter extends AbstractDependencyFilter
|
public final class PluginWrapper
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/**
|
||||||
private static final String BLACKLIST = "/config/blacklist.list";
|
* Constructs a new plugin wrapper.
|
||||||
|
*
|
||||||
|
* @param plugin wrapped plugin
|
||||||
|
* @param classLoader plugin class loader
|
||||||
|
* @param directory plugin directory
|
||||||
|
*/
|
||||||
|
public PluginWrapper(Plugin plugin, ClassLoader classLoader, Path directory)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
this.directory = directory;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Returns plugin class loader.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return plugin class loader
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
@Override
|
public ClassLoader getClassLoader()
|
||||||
protected Set<String> loadExcludeSet() throws IOException
|
|
||||||
{
|
{
|
||||||
return DependencyFilters.loadDependencySet(BLACKLIST);
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns plugin directory.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return plugin directory
|
||||||
|
*/
|
||||||
|
public Path getDirectory()
|
||||||
|
{
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id of the plugin.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return id of plugin
|
||||||
|
*/
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return plugin.getInformation().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the plugin.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return plugin
|
||||||
|
*/
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** plugin class loader */
|
||||||
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
|
/** plugin directory */
|
||||||
|
private final Path directory;
|
||||||
|
|
||||||
|
/** plugin */
|
||||||
|
private final Plugin plugin;
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @since 1.26
|
* @since 1.26
|
||||||
*/
|
*/
|
||||||
boolean isDisableLastCommit()
|
public boolean isDisableLastCommit()
|
||||||
{
|
{
|
||||||
return disableLastCommit;
|
return disableLastCommit;
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,7 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @since 1.26
|
* @since 1.26
|
||||||
*/
|
*/
|
||||||
boolean isDisableSubRepositoryDetection()
|
public boolean isDisableSubRepositoryDetection()
|
||||||
{
|
{
|
||||||
return disableSubRepositoryDetection;
|
return disableSubRepositoryDetection;
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @since 1.26
|
* @since 1.26
|
||||||
*/
|
*/
|
||||||
boolean isRecursive()
|
public boolean isRecursive()
|
||||||
{
|
{
|
||||||
return recursive;
|
return recursive;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @since 1.34
|
* @since 1.34
|
||||||
*/
|
*/
|
||||||
DiffFormat getFormat()
|
public DiffFormat getFormat()
|
||||||
{
|
{
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public abstract class FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getPath()
|
public String getPath()
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ public abstract class FileBaseCommandRequest
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getRevision()
|
public String getRevision()
|
||||||
{
|
{
|
||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getBranch()
|
public String getBranch()
|
||||||
{
|
{
|
||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getEndChangeset()
|
public String getEndChangeset()
|
||||||
{
|
{
|
||||||
return endChangeset;
|
return endChangeset;
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int getPagingLimit()
|
public int getPagingLimit()
|
||||||
{
|
{
|
||||||
return pagingLimit;
|
return pagingLimit;
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int getPagingStart()
|
public int getPagingStart()
|
||||||
{
|
{
|
||||||
return pagingStart;
|
return pagingStart;
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getPath()
|
public String getPath()
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getStartChangeset()
|
public String getStartChangeset()
|
||||||
{
|
{
|
||||||
return startChangeset;
|
return startChangeset;
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ public final class LogCommandRequest implements Serializable, Resetable
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean isPagingUnlimited()
|
public boolean isPagingUnlimited()
|
||||||
{
|
{
|
||||||
return pagingLimit < 0;
|
return pagingLimit < 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@
|
|||||||
|
|
||||||
package sonia.scm.util;
|
package sonia.scm.util;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Util methods for {@link ClassLoader}s.
|
* Util methods for {@link ClassLoader}s.
|
||||||
*
|
*
|
||||||
@@ -46,6 +50,38 @@ public final class ClassLoaders
|
|||||||
*/
|
*/
|
||||||
private ClassLoaders() {}
|
private ClassLoaders() {}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a {@link Runnable} with the given {@link ClassLoader} as context
|
||||||
|
* ClassLoader ({@link Thread#setContextClassLoader(ClassLoader)}).
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader ClassLoader for context
|
||||||
|
* @param runnable runnable
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public static void executeInContext(ClassLoader classLoader,
|
||||||
|
Runnable runnable)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(classLoader, "ClassLoader is required");
|
||||||
|
Preconditions.checkNotNull(runnable, "runnable is required");
|
||||||
|
|
||||||
|
ClassLoader ctxCl = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
|
Thread.currentThread().setContextClassLoader(ctxCl);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Thread.currentThread().setContextClassLoader(ctxCl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ import javax.xml.transform.stream.StreamResult;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "Since16", "Since15" })
|
@SuppressWarnings({ "Since16", "Since15" })
|
||||||
@MetaInfServices(Processor.class)
|
@MetaInfServices(Processor.class)
|
||||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||||
@SupportedAnnotationTypes("*")
|
@SupportedAnnotationTypes("*")
|
||||||
public final class ScmAnnotationProcessor extends AbstractProcessor
|
public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,10 +23,18 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
<version>${servlet.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>sonia.scm</groupId>
|
<groupId>sonia.scm</groupId>
|
||||||
<artifactId>scm-core</artifactId>
|
<artifactId>scm-core</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- annotation processor -->
|
<!-- annotation processor -->
|
||||||
@@ -38,6 +46,15 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test scope -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm</groupId>
|
||||||
|
<artifactId>scm-test</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -67,8 +84,12 @@
|
|||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>sonia.scm.maven</groupId>
|
<groupId>sonia.scm.maven</groupId>
|
||||||
<artifactId>scm-maven-plugin</artifactId>
|
<artifactId>smp-maven-plugin</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<disableCompression>true</disableCompression>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>fix-descriptor</id>
|
<id>fix-descriptor</id>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<artifactId>scm-git-plugin</artifactId>
|
<artifactId>scm-git-plugin</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<name>scm-git-plugin</name>
|
<name>scm-git-plugin</name>
|
||||||
|
<packaging>smp</packaging>
|
||||||
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
||||||
<description>Plugin for the version control system Git</description>
|
<description>Plugin for the version control system Git</description>
|
||||||
|
|
||||||
|
|||||||
@@ -13,41 +13,18 @@
|
|||||||
<artifactId>scm-hg-plugin</artifactId>
|
<artifactId>scm-hg-plugin</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<name>scm-hg-plugin</name>
|
<name>scm-hg-plugin</name>
|
||||||
|
<packaging>smp</packaging>
|
||||||
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
||||||
<description>Plugin for the version control system Mercurial</description>
|
<description>Plugin for the version control system Mercurial</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
<version>${servlet.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aragost.javahg</groupId>
|
<groupId>com.aragost.javahg</groupId>
|
||||||
<artifactId>javahg</artifactId>
|
<artifactId>javahg</artifactId>
|
||||||
<version>0.8-SNAPSHOT</version>
|
<version>0.8-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- fix conflict with javahg -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>${guava.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test scope -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm</groupId>
|
|
||||||
<artifactId>scm-test</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- create test jar -->
|
<!-- create test jar -->
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@@ -99,7 +101,8 @@ public class HgCGIExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public HgCGIExceptionHandler()
|
public HgCGIExceptionHandler()
|
||||||
{
|
{
|
||||||
this.bundle = Bundle.getBundle(BUNDLE_PATH);
|
this.bundle = Bundle.getBundle(BUNDLE_PATH, Locale.ENGLISH,
|
||||||
|
HgCGIExceptionHandler.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<artifactId>scm-svn-plugin</artifactId>
|
<artifactId>scm-svn-plugin</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<name>scm-svn-plugin</name>
|
<name>scm-svn-plugin</name>
|
||||||
|
<packaging>smp</packaging>
|
||||||
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
<url>https://bitbucket.org/sdorra/scm-manager</url>
|
||||||
<description>Plugin for the version control system Subversion</description>
|
<description>Plugin for the version control system Subversion</description>
|
||||||
|
|
||||||
|
|||||||
@@ -56,24 +56,6 @@
|
|||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm.plugins</groupId>
|
|
||||||
<artifactId>scm-hg-plugin</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm.plugins</groupId>
|
|
||||||
<artifactId>scm-svn-plugin</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.scm.plugins</groupId>
|
|
||||||
<artifactId>scm-git-plugin</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- security -->
|
<!-- security -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -221,44 +203,6 @@
|
|||||||
<version>${mustache.version}</version>
|
<version>${mustache.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- aether -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.sonatype.aether</groupId>
|
|
||||||
<artifactId>aether-api</artifactId>
|
|
||||||
<version>${aether.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.sonatype.aether</groupId>
|
|
||||||
<artifactId>aether-impl</artifactId>
|
|
||||||
<version>${aether.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.maven</groupId>
|
|
||||||
<artifactId>maven-aether-provider</artifactId>
|
|
||||||
<version>${maven.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>plexus-component-annotations</artifactId>
|
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.sonatype.aether</groupId>
|
|
||||||
<artifactId>aether-connector-asynchttpclient</artifactId>
|
|
||||||
<version>${aether.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.sonatype.aether</groupId>
|
|
||||||
<artifactId>aether-connector-file</artifactId>
|
|
||||||
<version>${aether.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- rest documentation -->
|
<!-- rest documentation -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -364,7 +308,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -389,7 +332,6 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
@@ -408,6 +350,42 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>sonia.scm.maven</groupId>
|
||||||
|
<artifactId>smp-maven-plugin</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-hg-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<type>smp</type>
|
||||||
|
</artifactItem>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-svn-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<type>smp</type>
|
||||||
|
</artifactItem>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-git-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<type>smp</type>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-core-plugins</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-antrun-plugin</artifactId>
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -42,6 +43,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.util.AssertUtil;
|
import sonia.scm.util.AssertUtil;
|
||||||
|
import sonia.scm.util.ClassLoaders;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -50,7 +52,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -87,26 +88,35 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static ClassOverrides findOverrides()
|
public static ClassOverrides findOverrides(ClassLoader classLoader)
|
||||||
{
|
{
|
||||||
ClassOverrides overrides = new ClassOverrides();
|
final ClassOverrides overrides = new ClassOverrides();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Enumeration<URL> overridesEnm =
|
final Enumeration<URL> overridesEnm =
|
||||||
getClassLoader().getResources(OVERRIDE_PATH);
|
classLoader.getResources(OVERRIDE_PATH);
|
||||||
JAXBContext context = JAXBContext.newInstance(ClassOverrides.class);
|
final JAXBContext context = JAXBContext.newInstance(ClassOverrides.class);
|
||||||
|
|
||||||
|
ClassLoaders.executeInContext(classLoader, new Runnable()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
while (overridesEnm.hasMoreElements())
|
while (overridesEnm.hasMoreElements())
|
||||||
{
|
{
|
||||||
URL overrideUrl = overridesEnm.nextElement();
|
URL overrideUrl = overridesEnm.nextElement();
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
{
|
{
|
||||||
logger.info("load override from {}", overrideUrl.toExternalForm());
|
logger.info("load override from {}",
|
||||||
|
overrideUrl.toExternalForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -117,13 +127,16 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
|
|
||||||
overrides.append(co);
|
overrides.append(co);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (JAXBException ex)
|
||||||
{
|
{
|
||||||
logger.error("could not load ".concat(overrideUrl.toExternalForm()),
|
logger.error(
|
||||||
ex);
|
"could not load ".concat(overrideUrl.toExternalForm()), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
logger.error("could not load overrides", ex);
|
logger.error("could not load overrides", ex);
|
||||||
@@ -136,28 +149,6 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
return overrides;
|
return overrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static ClassLoader getClassLoader()
|
|
||||||
{
|
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
if (classLoader == null)
|
|
||||||
{
|
|
||||||
classLoader = ClassOverrides.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
return classLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -207,7 +198,7 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
{
|
{
|
||||||
if (moduleClasses == null)
|
if (moduleClasses == null)
|
||||||
{
|
{
|
||||||
moduleClasses = new ArrayList<Class<? extends Module>>();
|
moduleClasses = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return moduleClasses;
|
return moduleClasses;
|
||||||
@@ -238,7 +229,7 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
{
|
{
|
||||||
module = moduleClass.newInstance();
|
module = moduleClass.newInstance();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (IllegalAccessException | InstantiationException ex)
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
"could not create module instance of ".concat(
|
"could not create module instance of ".concat(
|
||||||
@@ -292,7 +283,7 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
|||||||
{
|
{
|
||||||
if (overrides == null)
|
if (overrides == null)
|
||||||
{
|
{
|
||||||
overrides = new ArrayList<ClassOverride>();
|
overrides = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return overrides;
|
return overrides;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import org.apache.shiro.guice.web.ShiroWebModule;
|
|||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
import sonia.scm.group.GroupManager;
|
import sonia.scm.group.GroupManager;
|
||||||
import sonia.scm.plugin.DefaultPluginLoader;
|
import sonia.scm.plugin.DefaultPluginLoader;
|
||||||
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
import sonia.scm.repository.HealthCheckContextListener;
|
import sonia.scm.repository.HealthCheckContextListener;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.store.StoreFactory;
|
import sonia.scm.store.StoreFactory;
|
||||||
@@ -57,6 +58,7 @@ import sonia.scm.web.security.AuthenticationManager;
|
|||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
@@ -68,6 +70,21 @@ import javax.servlet.ServletContextEvent;
|
|||||||
public class ScmContextListener extends GuiceServletContextListener
|
public class ScmContextListener extends GuiceServletContextListener
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param parent
|
||||||
|
* @param plugins
|
||||||
|
*/
|
||||||
|
public ScmContextListener(ClassLoader parent, Set<PluginWrapper> plugins)
|
||||||
|
{
|
||||||
|
this.parent = parent;
|
||||||
|
this.plugins = plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -150,6 +167,17 @@ public class ScmContextListener extends GuiceServletContextListener
|
|||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<PluginWrapper> getPlugins()
|
||||||
|
{
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -181,9 +209,10 @@ public class ScmContextListener extends GuiceServletContextListener
|
|||||||
*/
|
*/
|
||||||
private Injector getDefaultInjector(ServletContext servletContext)
|
private Injector getDefaultInjector(ServletContext servletContext)
|
||||||
{
|
{
|
||||||
DefaultPluginLoader pluginLoader = new DefaultPluginLoader();
|
DefaultPluginLoader pluginLoader = new DefaultPluginLoader(parent, plugins);
|
||||||
|
|
||||||
ClassOverrides overrides = ClassOverrides.findOverrides();
|
ClassOverrides overrides =
|
||||||
|
ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
|
||||||
ScmServletModule main = new ScmServletModule(pluginLoader, overrides);
|
ScmServletModule main = new ScmServletModule(pluginLoader, overrides);
|
||||||
List<Module> moduleList = Lists.newArrayList();
|
List<Module> moduleList = Lists.newArrayList();
|
||||||
|
|
||||||
@@ -214,6 +243,12 @@ public class ScmContextListener extends GuiceServletContextListener
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final ClassLoader parent;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final Set<PluginWrapper> plugins;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Injector globalInjector;
|
private Injector globalInjector;
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ package sonia.scm;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.multibindings.Multibinder;
|
import com.google.inject.multibindings.Multibinder;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
@@ -71,7 +72,6 @@ import sonia.scm.plugin.PluginManager;
|
|||||||
import sonia.scm.repository.DefaultRepositoryManager;
|
import sonia.scm.repository.DefaultRepositoryManager;
|
||||||
import sonia.scm.repository.DefaultRepositoryProvider;
|
import sonia.scm.repository.DefaultRepositoryProvider;
|
||||||
import sonia.scm.repository.HealthCheckContextListener;
|
import sonia.scm.repository.HealthCheckContextListener;
|
||||||
import sonia.scm.repository.LastModifiedUpdateListener;
|
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryDAO;
|
import sonia.scm.repository.RepositoryDAO;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
@@ -140,9 +140,7 @@ import com.sun.jersey.guice.JerseyServletModule;
|
|||||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -360,10 +358,11 @@ public class ScmServletModule extends JerseyServletModule
|
|||||||
bind(TemplateEngineFactory.class);
|
bind(TemplateEngineFactory.class);
|
||||||
|
|
||||||
// bind events
|
// bind events
|
||||||
bind(LastModifiedUpdateListener.class);
|
// bind(LastModifiedUpdateListener.class);
|
||||||
|
|
||||||
// jersey
|
// jersey
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
|
* params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
|
||||||
* "com.sun.jersey.api.container.filter.LoggingFilter");
|
* "com.sun.jersey.api.container.filter.LoggingFilter");
|
||||||
|
|||||||
@@ -0,0 +1,263 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.io.Resources;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.SCMContext;
|
||||||
|
import sonia.scm.ScmContextListener;
|
||||||
|
import sonia.scm.plugin.PluginException;
|
||||||
|
import sonia.scm.plugin.PluginLoadException;
|
||||||
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
|
import sonia.scm.plugin.Plugins;
|
||||||
|
import sonia.scm.util.ClassLoaders;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class BootstrapContextListener implements ServletContextListener
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_PLUGINS = "plugins";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String PLUGIN_DIRECTORY = "/WEB-INF/plugins/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the logger for BootstrapContextListener
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(BootstrapContextListener.class);
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String PLUGIN_COREINDEX =
|
||||||
|
PLUGIN_DIRECTORY.concat("plugin.idx");
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param sce
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
contextListener.contextDestroyed(sce);
|
||||||
|
|
||||||
|
for (PluginWrapper plugin : contextListener.getPlugins())
|
||||||
|
{
|
||||||
|
ClassLoader pcl = plugin.getClassLoader();
|
||||||
|
|
||||||
|
if (pcl instanceof Closeable)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
((Closeable) pcl).close();
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
logger.warn("could not close plugin classloader", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contextListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param sce
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
ServletContext context = sce.getServletContext();
|
||||||
|
List<String> lines = readCorePluginIndex(context);
|
||||||
|
|
||||||
|
File pluginDirectory = getPluginDirectory();
|
||||||
|
|
||||||
|
copyCorePlugins(context, pluginDirectory, lines);
|
||||||
|
|
||||||
|
ClassLoader cl =
|
||||||
|
ClassLoaders.getContextClassLoader(BootstrapContextListener.class);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Set<PluginWrapper> plugins = Plugins.collectPlugins(cl,
|
||||||
|
pluginDirectory.toPath());
|
||||||
|
|
||||||
|
contextListener = new ScmContextListener(cl, plugins);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new PluginLoadException("could not load plugins", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
contextListener.contextInitialized(sce);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param pluginDirectory
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void copyCorePlugin(ServletContext context, File pluginDirectory,
|
||||||
|
String name)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
URL url = context.getResource(PLUGIN_DIRECTORY.concat(name));
|
||||||
|
File file = new File(pluginDirectory, name);
|
||||||
|
|
||||||
|
try (OutputStream output = new FileOutputStream(file))
|
||||||
|
{
|
||||||
|
Resources.copy(url, output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param pluginDirectory
|
||||||
|
* @param lines
|
||||||
|
*/
|
||||||
|
private void copyCorePlugins(ServletContext context, File pluginDirectory,
|
||||||
|
List<String> lines)
|
||||||
|
{
|
||||||
|
IOUtil.mkdirs(pluginDirectory);
|
||||||
|
|
||||||
|
for (String line : lines)
|
||||||
|
{
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
if (!Strings.isNullOrEmpty(line))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
copyCorePlugin(context, pluginDirectory, line);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
logger.error("could not copy core plugin", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<String> readCorePluginIndex(ServletContext context)
|
||||||
|
{
|
||||||
|
List<String> lines;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URL index = context.getResource(PLUGIN_COREINDEX);
|
||||||
|
|
||||||
|
if (index == null)
|
||||||
|
{
|
||||||
|
throw new PluginException("no core plugin index found");
|
||||||
|
}
|
||||||
|
|
||||||
|
lines = Resources.readLines(index, Charsets.UTF_8);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new PluginException("could not load core plugin index", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private File getPluginDirectory()
|
||||||
|
{
|
||||||
|
File baseDirectory = SCMContext.getContext().getBaseDirectory();
|
||||||
|
|
||||||
|
return new File(baseDirectory, DIRECTORY_PLUGINS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private ScmContextListener contextListener;
|
||||||
|
}
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.FilterConfig;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.ServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class BootstrapFilter implements Filter
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FILTER = "com.google.inject.servlet.GuiceFilter";
|
|
||||||
|
|
||||||
/** the logger for BootstrapFilter */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(BootstrapFilter.class);
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void destroy()
|
|
||||||
{
|
|
||||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("destroy guice filter");
|
|
||||||
|
|
||||||
guiceFilter.destroy();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(oldClassLoader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @param response
|
|
||||||
* @param chain
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws ServletException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response,
|
|
||||||
FilterChain chain)
|
|
||||||
throws IOException, ServletException
|
|
||||||
{
|
|
||||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
guiceFilter.doFilter(request, response, chain);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(oldClassLoader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param filterConfig
|
|
||||||
*
|
|
||||||
* @throws ServletException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException
|
|
||||||
{
|
|
||||||
classLoader =
|
|
||||||
BootstrapUtil.getClassLoader(filterConfig.getServletContext());
|
|
||||||
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
logger.info("loading GuiceFilter with ScmBootstrapClassLoader");
|
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
|
||||||
guiceFilter = BootstrapUtil.loadClass(classLoader, Filter.class, FILTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guiceFilter == null)
|
|
||||||
{
|
|
||||||
logger.info("fallback to default classloader for GuiceFilter");
|
|
||||||
guiceFilter = BootstrapUtil.loadClass(Filter.class, FILTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
guiceFilter.init(filterConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ClassLoader classLoader;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Filter guiceFilter;
|
|
||||||
}
|
|
||||||
@@ -1,302 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.SCMContext;
|
|
||||||
import sonia.scm.SCMContextProvider;
|
|
||||||
import sonia.scm.util.ClassLoaders;
|
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
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";
|
|
||||||
|
|
||||||
/** the logger for BootstrapListener */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(BootstrapListener.class);
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param sce
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent sce)
|
|
||||||
{
|
|
||||||
if (scmContextListener != null)
|
|
||||||
{
|
|
||||||
logger.info("destroy scm context listener");
|
|
||||||
scmContextListener.contextDestroyed(sce);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServletContext servletContext = sce.getServletContext();
|
|
||||||
ClassLoader classLoader = BootstrapUtil.getClassLoader(servletContext);
|
|
||||||
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
if (classLoader instanceof Closeable)
|
|
||||||
{
|
|
||||||
logger.info("close plugin class loader");
|
|
||||||
IOUtil.close((Closeable) classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("remove plugin class loader from servlet context");
|
|
||||||
BootstrapUtil.removeClassLoader(servletContext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.debug("plugin class loader is not available");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param sce
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent sce)
|
|
||||||
{
|
|
||||||
SCMContextProvider context = SCMContext.getContext();
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("start scm-manager {} in stage: {}", context.getVersion(),
|
|
||||||
context.getStage());
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassLoader classLoader = createClassLoader(context);
|
|
||||||
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("try to use ScmBootstrapClassLoader");
|
|
||||||
}
|
|
||||||
|
|
||||||
scmContextListener = BootstrapUtil.loadClass(classLoader,
|
|
||||||
ServletContextListener.class, LISTENER);
|
|
||||||
BootstrapUtil.setClassLoader(sce.getServletContext(), classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scmContextListener == null)
|
|
||||||
{
|
|
||||||
if (logger.isWarnEnabled())
|
|
||||||
{
|
|
||||||
logger.warn("fallback to default classloader");
|
|
||||||
}
|
|
||||||
|
|
||||||
scmContextListener =
|
|
||||||
BootstrapUtil.loadClass(ServletContextListener.class, LISTENER);
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeContext(classLoader, scmContextListener, sce);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ClassLoader createClassLoader(SCMContextProvider context)
|
|
||||||
{
|
|
||||||
ClassLoader classLoader = null;
|
|
||||||
File pluginDirectory = new File(context.getBaseDirectory(),
|
|
||||||
PLUGIN_DIRECTORY);
|
|
||||||
|
|
||||||
if (pluginDirectory.exists())
|
|
||||||
{
|
|
||||||
File classpathFile = new File(pluginDirectory, PLUGIN_CLASSPATHFILE);
|
|
||||||
|
|
||||||
if (classpathFile.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Classpath classpath = JAXB.unmarshal(classpathFile, Classpath.class);
|
|
||||||
|
|
||||||
if (classpath != null)
|
|
||||||
{
|
|
||||||
classLoader = createClassLoader(pluginDirectory, classpath);
|
|
||||||
}
|
|
||||||
else if (logger.isErrorEnabled())
|
|
||||||
{
|
|
||||||
logger.error("classloader is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("could not load classpath from plugin folder", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("no plugin directory found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return classLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param pluginDirectory
|
|
||||||
* @param classpath
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ClassLoader createClassLoader(File pluginDirectory,
|
|
||||||
Classpath classpath)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("create classloader from plugin classpath");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<URL> classpathURLs = Lists.newLinkedList();
|
|
||||||
|
|
||||||
for (String path : classpath)
|
|
||||||
{
|
|
||||||
if (path.startsWith("/"))
|
|
||||||
{
|
|
||||||
path = path.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(pluginDirectory, path);
|
|
||||||
|
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
URL url = file.toURI().toURL();
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("append {} to classpath", url.toExternalForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
classpathURLs.add(url);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException ex)
|
|
||||||
{
|
|
||||||
logger.error("could not append url to classpath", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (logger.isErrorEnabled())
|
|
||||||
{
|
|
||||||
logger.error("plugin file {} does not exists", file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return BootstrapUtil.createClassLoader(classpathURLs,
|
|
||||||
ClassLoaders.getContextClassLoader(BootstrapListener.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param classLoader
|
|
||||||
* @param listener
|
|
||||||
* @param sce
|
|
||||||
*/
|
|
||||||
private void initializeContext(ClassLoader classLoader,
|
|
||||||
ServletContextListener listener, ServletContextEvent sce)
|
|
||||||
{
|
|
||||||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (classLoader != null)
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("initialize scm context listener");
|
|
||||||
listener.contextInitialized(sce);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Thread.currentThread().setContextClassLoader(oldClassLoader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ServletContextListener scmContextListener;
|
|
||||||
}
|
|
||||||
@@ -1,254 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.plugin.ChildFirstPluginClassLoader;
|
|
||||||
import sonia.scm.plugin.DefaultPluginClassLoader;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public final class BootstrapUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String CLASSLOADER = "sonia.scm.BoostrapClassLoader";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String STRATEGY =
|
|
||||||
"sonia.scm.plugin.classloader.strategy";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String STRATEGY_CHILDFIRST = "child-first";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String STRATEGY_PARENTFIRST = "parent-first";
|
|
||||||
|
|
||||||
/** the logger for BootstrapUtil */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(BootstrapUtil.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private BootstrapUtil() {}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param classpathURLs
|
|
||||||
* @param parent
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static ClassLoader createClassLoader(List<URL> classpathURLs,
|
|
||||||
ClassLoader parent)
|
|
||||||
{
|
|
||||||
ClassLoader classLoader = null;
|
|
||||||
URL[] urls = classpathURLs.toArray(new URL[classpathURLs.size()]);
|
|
||||||
String strategy = System.getProperty(STRATEGY);
|
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(strategy))
|
|
||||||
{
|
|
||||||
if (STRATEGY_CHILDFIRST.equals(strategy))
|
|
||||||
{
|
|
||||||
logger.info("using {} as plugin classloading strategy",
|
|
||||||
STRATEGY_CHILDFIRST);
|
|
||||||
classLoader = new ChildFirstPluginClassLoader(urls, parent);
|
|
||||||
}
|
|
||||||
else if (!STRATEGY_PARENTFIRST.equals(strategy))
|
|
||||||
{
|
|
||||||
logger.warn("unknown plugin classloading strategy {}", strategy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classLoader == null)
|
|
||||||
{
|
|
||||||
logger.info("using {} as plugin classloading strategy",
|
|
||||||
STRATEGY_PARENTFIRST);
|
|
||||||
classLoader = new DefaultPluginClassLoader(urls, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return classLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param classLoader
|
|
||||||
* @param clazz
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T loadClass(ClassLoader classLoader, Class<T> clazz)
|
|
||||||
{
|
|
||||||
T instance = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
instance = (T) classLoader.loadClass(clazz.getName()).newInstance();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("could not load class ".concat(clazz.getName()), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param classLoader
|
|
||||||
* @param clazz
|
|
||||||
* @param className
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T loadClass(ClassLoader classLoader, Class<T> clazz,
|
|
||||||
String className)
|
|
||||||
{
|
|
||||||
T instance = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
instance = (T) classLoader.loadClass(className).newInstance();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("could not load class ".concat(className), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* @param className
|
|
||||||
* @param <T>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T loadClass(Class<T> clazz, String className)
|
|
||||||
{
|
|
||||||
T instance = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
instance = (T) Class.forName(className).newInstance();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.error("could not load class ".concat(className), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static ClassLoader getClassLoader(ServletContext context)
|
|
||||||
{
|
|
||||||
return (ClassLoader) context.getAttribute(CLASSLOADER);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @param classLoader
|
|
||||||
*/
|
|
||||||
public static void setClassLoader(ServletContext context,
|
|
||||||
ClassLoader classLoader)
|
|
||||||
{
|
|
||||||
context.setAttribute(CLASSLOADER, classLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
public static void removeClassLoader(ServletContext context)
|
|
||||||
{
|
|
||||||
context.removeAttribute(CLASSLOADER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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>();
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.common.base.Throwables;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.artifact.Artifact;
|
|
||||||
import org.sonatype.aether.graph.DependencyFilter;
|
|
||||||
import org.sonatype.aether.graph.DependencyNode;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public abstract class AbstractDependencyFilter implements DependencyFilter
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for AbstractDependencyFilter
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(AbstractDependencyFilter.class);
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected abstract Set<String> loadExcludeSet() throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param node
|
|
||||||
* @param parents
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean accept(DependencyNode node, List<DependencyNode> parents)
|
|
||||||
{
|
|
||||||
boolean result = true;
|
|
||||||
|
|
||||||
if ((node != null) && (node.getDependency() != null))
|
|
||||||
{
|
|
||||||
Artifact artifact = node.getDependency().getArtifact();
|
|
||||||
|
|
||||||
if (artifact != null)
|
|
||||||
{
|
|
||||||
String id = getId(artifact);
|
|
||||||
|
|
||||||
result = !getExludeSet().contains(id);
|
|
||||||
|
|
||||||
if (!result && logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("exlcude dependency {} because it is blacklisted", id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Set<String> getExludeSet()
|
|
||||||
{
|
|
||||||
if (exludeSet == null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
exludeSet = loadExcludeSet();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
throw Throwables.propagate(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exludeSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param artifact
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getId(Artifact artifact)
|
|
||||||
{
|
|
||||||
return artifact.getGroupId().concat(":").concat(artifact.getArtifactId());
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Set<String> exludeSet;
|
|
||||||
}
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 org.apache.maven.repository.internal.MavenRepositorySystemSession;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.RepositorySystem;
|
|
||||||
import org.sonatype.aether.RepositorySystemSession;
|
|
||||||
import org.sonatype.aether.collection.CollectRequest;
|
|
||||||
import org.sonatype.aether.collection.DependencyCollectionException;
|
|
||||||
import org.sonatype.aether.collection.DependencyGraphTransformer;
|
|
||||||
import org.sonatype.aether.graph.Dependency;
|
|
||||||
import org.sonatype.aether.graph.DependencyFilter;
|
|
||||||
import org.sonatype.aether.graph.DependencyNode;
|
|
||||||
import org.sonatype.aether.repository.LocalRepository;
|
|
||||||
import org.sonatype.aether.repository.LocalRepositoryManager;
|
|
||||||
import org.sonatype.aether.repository.Proxy;
|
|
||||||
import org.sonatype.aether.repository.RemoteRepository;
|
|
||||||
import org.sonatype.aether.repository.RepositoryPolicy;
|
|
||||||
import org.sonatype.aether.resolution.DependencyRequest;
|
|
||||||
import org.sonatype.aether.resolution.DependencyResolutionException;
|
|
||||||
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
|
||||||
import org.sonatype.aether.util.artifact.JavaScopes;
|
|
||||||
import org.sonatype.aether.util.filter.AndDependencyFilter;
|
|
||||||
import org.sonatype.aether.util.filter.DependencyFilterUtils;
|
|
||||||
import org.sonatype.aether.util.graph.transformer
|
|
||||||
.ChainedDependencyGraphTransformer;
|
|
||||||
import org.sonatype.aether.util.graph.transformer.ConflictMarker;
|
|
||||||
import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
|
|
||||||
import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
|
|
||||||
import org.sonatype.aether.util.graph.transformer
|
|
||||||
.NearestVersionConflictResolver;
|
|
||||||
|
|
||||||
import sonia.scm.config.ScmConfiguration;
|
|
||||||
import sonia.scm.net.Proxies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public final class Aether
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final DependencyFilter FILTER =
|
|
||||||
new AndDependencyFilter(
|
|
||||||
new CoreDependencyFilter(),
|
|
||||||
new BlacklistDependencyFilter()
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for Aether
|
|
||||||
*/
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Aether.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private Aether() {}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param gav
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Dependency createDependency(String gav)
|
|
||||||
{
|
|
||||||
return new Dependency(new DefaultArtifact(gav), JavaScopes.RUNTIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static DependencyFilter createDependencyFilter()
|
|
||||||
{
|
|
||||||
return DependencyFilterUtils.andFilter(
|
|
||||||
DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), FILTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
* @param pluginRepository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static RemoteRepository createRemoteRepository(
|
|
||||||
ScmConfiguration configuration, PluginRepository pluginRepository)
|
|
||||||
{
|
|
||||||
RemoteRepository remoteRepository =
|
|
||||||
new RemoteRepository(pluginRepository.getId(), "default",
|
|
||||||
pluginRepository.getUrl());
|
|
||||||
|
|
||||||
if (Proxies.isEnabled(configuration, remoteRepository.getHost()))
|
|
||||||
{
|
|
||||||
Proxy proxy = DefaultProxySelector.createProxy(configuration);
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("enable proxy {} for {}", proxy.getHost(),
|
|
||||||
pluginRepository.getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteRepository.setProxy(proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
return remoteRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static RepositorySystem createRepositorySystem()
|
|
||||||
{
|
|
||||||
return new AetherServiceLocator().getService(RepositorySystem.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param system
|
|
||||||
* @param localRepository
|
|
||||||
* @param configuration
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static RepositorySystemSession createRepositorySystemSession(
|
|
||||||
RepositorySystem system, LocalRepository localRepository,
|
|
||||||
ScmConfiguration configuration)
|
|
||||||
{
|
|
||||||
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
|
|
||||||
|
|
||||||
session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
|
|
||||||
|
|
||||||
if (configuration.isEnableProxy())
|
|
||||||
{
|
|
||||||
logger.debug("enable proxy selector to collect dependencies");
|
|
||||||
session.setProxySelector(new DefaultProxySelector(configuration));
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalRepositoryManager localRepositoryManager =
|
|
||||||
system.newLocalRepositoryManager(localRepository);
|
|
||||||
|
|
||||||
session.setLocalRepositoryManager(localRepositoryManager);
|
|
||||||
|
|
||||||
// create graph transformer to resolve dependency conflicts
|
|
||||||
//J-
|
|
||||||
DependencyGraphTransformer dgt = new ChainedDependencyGraphTransformer(
|
|
||||||
new ConflictMarker(),
|
|
||||||
new JavaEffectiveScopeCalculator(),
|
|
||||||
new NearestVersionConflictResolver(),
|
|
||||||
new JavaDependencyContextRefiner()
|
|
||||||
);
|
|
||||||
//J+
|
|
||||||
|
|
||||||
session.setDependencyGraphTransformer(dgt);
|
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param system
|
|
||||||
* @param session
|
|
||||||
* @param request
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @throws DependencyCollectionException
|
|
||||||
* @throws DependencyResolutionException
|
|
||||||
*/
|
|
||||||
public static DependencyNode resolveDependencies(RepositorySystem system,
|
|
||||||
RepositorySystemSession session, CollectRequest request)
|
|
||||||
throws DependencyCollectionException, DependencyResolutionException
|
|
||||||
{
|
|
||||||
DependencyNode node = system.collectDependencies(session,
|
|
||||||
request).getRoot();
|
|
||||||
DependencyRequest dr = new DependencyRequest(node,
|
|
||||||
Aether.createDependencyFilter());
|
|
||||||
|
|
||||||
system.resolveDependencies(session, dr);
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.common.collect.Lists;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.RepositorySystem;
|
|
||||||
import org.sonatype.aether.RepositorySystemSession;
|
|
||||||
import org.sonatype.aether.collection.CollectRequest;
|
|
||||||
import org.sonatype.aether.collection.DependencyCollectionException;
|
|
||||||
import org.sonatype.aether.graph.Dependency;
|
|
||||||
import org.sonatype.aether.graph.DependencyNode;
|
|
||||||
import org.sonatype.aether.repository.LocalRepository;
|
|
||||||
import org.sonatype.aether.repository.RemoteRepository;
|
|
||||||
import org.sonatype.aether.resolution.DependencyResolutionException;
|
|
||||||
import org.sonatype.aether.util.graph.PreorderNodeListGenerator;
|
|
||||||
|
|
||||||
import sonia.scm.config.ScmConfiguration;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class AetherDependencyResolver
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for AetherDependencyResolver
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(AetherDependencyResolver.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
* @param system
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepositories
|
|
||||||
*/
|
|
||||||
public AetherDependencyResolver(ScmConfiguration configuration,
|
|
||||||
RepositorySystem system, LocalRepository localRepository,
|
|
||||||
List<RemoteRepository> remoteRepositories)
|
|
||||||
{
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.system = system;
|
|
||||||
this.localRepository = localRepository;
|
|
||||||
this.remoteRepositories = remoteRepositories;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String createClassPath()
|
|
||||||
{
|
|
||||||
PreorderNodeListGenerator nodeListGenerator =
|
|
||||||
new PreorderNodeListGenerator();
|
|
||||||
|
|
||||||
for (DependencyNode node : resolvedNodes)
|
|
||||||
{
|
|
||||||
node.accept(nodeListGenerator);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodeListGenerator.getClassPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param dependency
|
|
||||||
* @param dependencies
|
|
||||||
*
|
|
||||||
* @throws DependencyCollectionException
|
|
||||||
* @throws DependencyResolutionException
|
|
||||||
*/
|
|
||||||
public void resolveDependencies(Dependency dependency,
|
|
||||||
List<Dependency> dependencies)
|
|
||||||
throws DependencyCollectionException, DependencyResolutionException
|
|
||||||
{
|
|
||||||
resolveDependency(new CollectRequest(dependency, dependencies,
|
|
||||||
remoteRepositories));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
*
|
|
||||||
* @throws DependencyCollectionException
|
|
||||||
* @throws DependencyResolutionException
|
|
||||||
*/
|
|
||||||
private void resolveDependency(CollectRequest request)
|
|
||||||
throws DependencyCollectionException, DependencyResolutionException
|
|
||||||
{
|
|
||||||
DependencyNode node = Aether.resolveDependencies(system, getSession(),
|
|
||||||
request);
|
|
||||||
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
StringDependencyGraphDumper dumper = new StringDependencyGraphDumper();
|
|
||||||
|
|
||||||
node.accept(dumper);
|
|
||||||
logger.trace(dumper.getGraphAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
resolvedNodes.add(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private RepositorySystemSession getSession()
|
|
||||||
{
|
|
||||||
if (session == null)
|
|
||||||
{
|
|
||||||
session = Aether.createRepositorySystemSession(system, localRepository,
|
|
||||||
configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ScmConfiguration configuration;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private LocalRepository localRepository;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private List<RemoteRepository> remoteRepositories;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private List<DependencyNode> resolvedNodes = Lists.newArrayList();
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private RepositorySystemSession session;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private RepositorySystem system;
|
|
||||||
}
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.common.collect.Lists;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.RepositorySystem;
|
|
||||||
import org.sonatype.aether.graph.Dependency;
|
|
||||||
import org.sonatype.aether.repository.LocalRepository;
|
|
||||||
import org.sonatype.aether.repository.RemoteRepository;
|
|
||||||
|
|
||||||
import sonia.scm.ConfigurationException;
|
|
||||||
import sonia.scm.SCMContextProvider;
|
|
||||||
import sonia.scm.boot.BootstrapListener;
|
|
||||||
import sonia.scm.boot.Classpath;
|
|
||||||
import sonia.scm.config.ScmConfiguration;
|
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Marshaller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class AetherPluginHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
/** the logger for AetherPluginHandler */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(AetherPluginHandler.class);
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final Object LOCK = new Object();
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param pluginManager
|
|
||||||
* @param context
|
|
||||||
* @param configuration
|
|
||||||
*/
|
|
||||||
public AetherPluginHandler(PluginManager pluginManager,
|
|
||||||
SCMContextProvider context, ScmConfiguration configuration)
|
|
||||||
{
|
|
||||||
this.pluginManager = pluginManager;
|
|
||||||
this.configuration = configuration;
|
|
||||||
localRepositoryDirectory = new File(context.getBaseDirectory(),
|
|
||||||
BootstrapListener.PLUGIN_DIRECTORY);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
jaxbContext = JAXBContext.newInstance(Classpath.class);
|
|
||||||
}
|
|
||||||
catch (JAXBException ex)
|
|
||||||
{
|
|
||||||
throw new ConfigurationException(
|
|
||||||
"could not create jaxb context for classpath file", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
classpathFile = new File(localRepositoryDirectory,
|
|
||||||
BootstrapListener.PLUGIN_CLASSPATHFILE);
|
|
||||||
|
|
||||||
if (classpathFile.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
classpath =
|
|
||||||
(Classpath) jaxbContext.createUnmarshaller().unmarshal(classpathFile);
|
|
||||||
}
|
|
||||||
catch (JAXBException ex)
|
|
||||||
{
|
|
||||||
logger.error("could not read classpath file", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IOUtil.mkdirs(localRepositoryDirectory);
|
|
||||||
repositorySystem = Aether.createRepositorySystem();
|
|
||||||
localRepository = new LocalRepository(localRepositoryDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param gav
|
|
||||||
*/
|
|
||||||
public void install(String gav)
|
|
||||||
{
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
doInstall(gav);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: remove dependencies and remove files
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
public void uninstall(String id)
|
|
||||||
{
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
doUninstall(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositories
|
|
||||||
*/
|
|
||||||
public void setPluginRepositories(Collection<PluginRepository> repositories)
|
|
||||||
{
|
|
||||||
remoteRepositories = Lists.newArrayList();
|
|
||||||
|
|
||||||
for (PluginRepository repository : repositories)
|
|
||||||
{
|
|
||||||
remoteRepositories.add(Aether.createRemoteRepository(configuration,
|
|
||||||
repository));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param dependency
|
|
||||||
* @param dependencies
|
|
||||||
* @param localDependencies
|
|
||||||
*/
|
|
||||||
private void collectDependencies(Dependency dependency,
|
|
||||||
List<Dependency> localDependencies)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
AetherDependencyResolver resolver =
|
|
||||||
new AetherDependencyResolver(configuration, repositorySystem,
|
|
||||||
localRepository, remoteRepositories);
|
|
||||||
|
|
||||||
resolver.resolveDependencies(dependency, localDependencies);
|
|
||||||
|
|
||||||
if (classpath == null)
|
|
||||||
{
|
|
||||||
classpath = new Classpath();
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> classpathSet = createClasspathSet(resolver.createClassPath());
|
|
||||||
|
|
||||||
classpath.setPathSet(classpathSet);
|
|
||||||
storeClasspath();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new PluginException(
|
|
||||||
"could not collect dependencies or store classpath file", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param classpathString
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Set<String> createClasspathSet(String classpathString)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("set new plugin classpath: {}", classpathString);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> classpathSet = new LinkedHashSet<String>();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(classpathString))
|
|
||||||
{
|
|
||||||
String[] classpathParts = classpathString.split(File.pathSeparator);
|
|
||||||
int prefixLength = localRepositoryDirectory.getAbsolutePath().length();
|
|
||||||
|
|
||||||
for (String classpathPart : classpathParts)
|
|
||||||
{
|
|
||||||
classpathSet.add(classpathPart.substring(prefixLength));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return classpathSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param gav
|
|
||||||
*/
|
|
||||||
private void doInstall(String gav)
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("try to install plugin with gav: {}", gav);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dependency dependency = Aether.createDependency(gav);
|
|
||||||
List<Dependency> dependencies = getInstalledDependencies(null);
|
|
||||||
|
|
||||||
collectDependencies(dependency, dependencies);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
private void doUninstall(String id)
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("try to uninstall plugin: {}", id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classpath != null)
|
|
||||||
{
|
|
||||||
List<Dependency> dependencies = getInstalledDependencies(id);
|
|
||||||
|
|
||||||
collectDependencies(null, dependencies);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws JAXBException
|
|
||||||
*/
|
|
||||||
private void storeClasspath() throws JAXBException
|
|
||||||
{
|
|
||||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
|
||||||
|
|
||||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
||||||
marshaller.marshal(classpath, classpathFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param skipId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<Dependency> getInstalledDependencies(String skipId)
|
|
||||||
{
|
|
||||||
List<Dependency> dependencies = Lists.newArrayList();
|
|
||||||
Collection<PluginInformation> installed =
|
|
||||||
pluginManager.get(new StatePluginPredicate(PluginState.INSTALLED));
|
|
||||||
|
|
||||||
if (installed != null)
|
|
||||||
{
|
|
||||||
for (PluginInformation plugin : installed)
|
|
||||||
{
|
|
||||||
String id = plugin.getId();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(id) && ((skipId == null) ||!id.equals(skipId)))
|
|
||||||
{
|
|
||||||
dependencies.add(Aether.createDependency(id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Classpath classpath;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private File classpathFile;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ScmConfiguration configuration;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private JAXBContext jaxbContext;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private LocalRepository localRepository;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private File localRepositoryDirectory;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private PluginManager pluginManager;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private List<RemoteRepository> remoteRepositories;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private RepositorySystem repositorySystem;
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
|
|
||||||
import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
|
|
||||||
import org.apache.maven.repository.internal.DefaultVersionResolver;
|
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.connector.async.AsyncRepositoryConnectorFactory;
|
|
||||||
import org.sonatype.aether.connector.file.FileRepositoryConnectorFactory;
|
|
||||||
import org.sonatype.aether.impl.ArtifactDescriptorReader;
|
|
||||||
import org.sonatype.aether.impl.VersionRangeResolver;
|
|
||||||
import org.sonatype.aether.impl.VersionResolver;
|
|
||||||
import org.sonatype.aether.impl.internal.DefaultServiceLocator;
|
|
||||||
import org.sonatype.aether.impl.internal.Slf4jLogger;
|
|
||||||
import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
|
|
||||||
import org.sonatype.aether.spi.log.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class AetherServiceLocator extends DefaultServiceLocator
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String LOGGER_NAME = "org.sonatype.aether";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final Slf4jLogger logger =
|
|
||||||
new Slf4jLogger(LoggerFactory.getLogger(LOGGER_NAME));
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public AetherServiceLocator()
|
|
||||||
{
|
|
||||||
setServices(Logger.class, logger);
|
|
||||||
addService(VersionResolver.class, DefaultVersionResolver.class);
|
|
||||||
addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
|
|
||||||
addService(ArtifactDescriptorReader.class,
|
|
||||||
DefaultArtifactDescriptorReader.class);
|
|
||||||
addService(RepositoryConnectorFactory.class,
|
|
||||||
AsyncRepositoryConnectorFactory.class);
|
|
||||||
addService(RepositoryConnectorFactory.class,
|
|
||||||
FileRepositoryConnectorFactory.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.IOException;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class CoreDependencyFilter extends AbstractDependencyFilter
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String CORE_DEPENDENCIES = "/config/dependencies.list";
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Set<String> loadExcludeSet() throws IOException
|
|
||||||
{
|
|
||||||
return DependencyFilters.loadDependencySet(CORE_DEPENDENCIES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,8 +46,6 @@ import com.google.inject.Module;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.util.ClassLoaders;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -83,24 +81,33 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
|
* @param parent
|
||||||
|
* @param wrappedPlugins
|
||||||
*/
|
*/
|
||||||
public DefaultPluginLoader()
|
public DefaultPluginLoader(ClassLoader parent,
|
||||||
|
Set<PluginWrapper> wrappedPlugins)
|
||||||
{
|
{
|
||||||
ClassLoader classLoader =
|
this.uberClassLoader = new UberClassLoader(parent, wrappedPlugins);
|
||||||
ClassLoaders.getContextClassLoader(DefaultPluginLoader.class);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JAXBContext context = JAXBContext.newInstance(ScmModule.class,
|
JAXBContext context = JAXBContext.newInstance(ScmModule.class,
|
||||||
Plugin.class);
|
Plugin.class);
|
||||||
|
|
||||||
modules = getInstalled(classLoader, context, PATH_MODULECONFIG);
|
modules = getInstalled(parent, context, PATH_MODULECONFIG);
|
||||||
plugins = getInstalled(classLoader, context, PATH_PLUGINCONFIG);
|
|
||||||
|
// hidden plugins ???
|
||||||
|
Set<Plugin> ips = getInstalled(parent, context, PATH_PLUGINCONFIG);
|
||||||
|
Builder<Plugin> builder = ImmutableSet.builder();
|
||||||
|
|
||||||
|
builder.addAll(ips);
|
||||||
|
builder.addAll(Plugins.unwrap(wrappedPlugins));
|
||||||
|
plugins = builder.build();
|
||||||
|
|
||||||
appendExtensions(multiple, single, extensions, modules);
|
appendExtensions(multiple, single, extensions, modules);
|
||||||
appendExtensions(multiple, single, extensions, plugins);
|
appendExtensions(multiple, single, extensions, plugins);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (IOException | JAXBException ex)
|
||||||
{
|
{
|
||||||
throw Throwables.propagate(ex);
|
throw Throwables.propagate(ex);
|
||||||
}
|
}
|
||||||
@@ -171,6 +178,18 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ClassLoader getUberClassLoader()
|
||||||
|
{
|
||||||
|
return uberClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,6 +278,9 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final ClassLoader uberClassLoader;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<ScmModule> modules;
|
private Set<ScmModule> modules;
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ import javax.xml.bind.JAXBException;
|
|||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO replace aether stuff
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@@ -199,7 +200,7 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
|
|
||||||
PluginCenter center = getPluginCenter();
|
PluginCenter center = getPluginCenter();
|
||||||
|
|
||||||
pluginHandler.install(id);
|
// pluginHandler.install(id);
|
||||||
|
|
||||||
for (PluginInformation plugin : center.getPlugins())
|
for (PluginInformation plugin : center.getPlugins())
|
||||||
{
|
{
|
||||||
@@ -248,7 +249,7 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
throw new PluginConditionFailedException(condition);
|
throw new PluginConditionFailedException(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
/*AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
||||||
configuration);
|
configuration);
|
||||||
Collection<PluginRepository> repositories =
|
Collection<PluginRepository> repositories =
|
||||||
Sets.newHashSet(new PluginRepository("package-repository",
|
Sets.newHashSet(new PluginRepository("package-repository",
|
||||||
@@ -256,7 +257,7 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
|
|
||||||
aph.setPluginRepositories(repositories);
|
aph.setPluginRepositories(repositories);
|
||||||
|
|
||||||
aph.install(plugin.getInformation().getId());
|
aph.install(plugin.getInformation().getId());*/
|
||||||
plugin.getInformation().setState(PluginState.INSTALLED);
|
plugin.getInformation().setState(PluginState.INSTALLED);
|
||||||
installedPlugins.put(plugin.getInformation().getId(), plugin);
|
installedPlugins.put(plugin.getInformation().getId(), plugin);
|
||||||
|
|
||||||
@@ -301,12 +302,12 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
throw new PluginNotInstalledException(id.concat(" is not install"));
|
throw new PluginNotInstalledException(id.concat(" is not install"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginHandler == null)
|
/*if (pluginHandler == null)
|
||||||
{
|
{
|
||||||
getPluginCenter();
|
getPluginCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginHandler.uninstall(id);
|
pluginHandler.uninstall(id);*/
|
||||||
installedPlugins.remove(id);
|
installedPlugins.remove(id);
|
||||||
preparePlugins(getPluginCenter());
|
preparePlugins(getPluginCenter());
|
||||||
}
|
}
|
||||||
@@ -643,13 +644,13 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
preparePlugins(center);
|
preparePlugins(center);
|
||||||
cache.put(PluginCenter.class.getName(), center);
|
cache.put(PluginCenter.class.getName(), center);
|
||||||
|
|
||||||
if (pluginHandler == null)
|
/*if (pluginHandler == null)
|
||||||
{
|
{
|
||||||
pluginHandler = new AetherPluginHandler(this,
|
pluginHandler = new AetherPluginHandler(this,
|
||||||
SCMContext.getContext(), configuration);
|
SCMContext.getContext(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginHandler.setPluginRepositories(center.getRepositories());
|
pluginHandler.setPluginRepositories(center.getRepositories());*/
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -767,9 +768,6 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private final Map<String, Plugin> installedPlugins;
|
private final Map<String, Plugin> installedPlugins;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private AetherPluginHandler pluginHandler;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Unmarshaller unmarshaller;
|
private Unmarshaller unmarshaller;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.sonatype.aether.repository.Authentication;
|
|
||||||
import org.sonatype.aether.repository.Proxy;
|
|
||||||
import org.sonatype.aether.repository.ProxySelector;
|
|
||||||
import org.sonatype.aether.repository.RemoteRepository;
|
|
||||||
|
|
||||||
import sonia.scm.config.ScmConfiguration;
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class DefaultProxySelector implements ProxySelector
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the logger for DefaultProxySelector
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(DefaultProxySelector.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
*/
|
|
||||||
public DefaultProxySelector(ScmConfiguration configuration)
|
|
||||||
{
|
|
||||||
this.configuration = configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param configuration
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Proxy createProxy(ScmConfiguration configuration)
|
|
||||||
{
|
|
||||||
Authentication authentication = null;
|
|
||||||
String username = configuration.getProxyUser();
|
|
||||||
String password = configuration.getProxyPassword();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
|
|
||||||
{
|
|
||||||
authentication = new Authentication(Util.nonNull(username),
|
|
||||||
Util.nonNull(password));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Proxy(Proxy.TYPE_HTTP, configuration.getProxyServer(),
|
|
||||||
configuration.getProxyPort(), authentication);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Proxy getProxy(RemoteRepository repository)
|
|
||||||
{
|
|
||||||
Proxy proxy = createProxy(configuration);
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("enable proxy {} for {}", proxy.getHost(),
|
|
||||||
repository.getUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ScmConfiguration configuration;
|
|
||||||
}
|
|
||||||
467
scm-webapp/src/main/java/sonia/scm/plugin/PluginProcessor.java
Normal file
467
scm-webapp/src/main/java/sonia/scm/plugin/PluginProcessor.java
Normal file
@@ -0,0 +1,467 @@
|
|||||||
|
/**
|
||||||
|
* 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.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.io.ZipUnArchiver;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.DirectoryStream.Filter;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class PluginProcessor
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DESCRIPTOR = "META-INF/scm/plugin.xml";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_CLASSES = "classes";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_DEPENDENCIES = "lib";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_LINK = ".link";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_METAINF = "META-INF";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String DIRECTORY_WEBINF = "WEB-INF";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String EXTENSION_PLUGIN = ".smp";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String GLOB_JAR = "*.jar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the logger for PluginProcessor
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(PluginProcessor.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param pluginDirectory
|
||||||
|
*/
|
||||||
|
public PluginProcessor(Path pluginDirectory)
|
||||||
|
{
|
||||||
|
this.pluginDirectory = pluginDirectory;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.context = JAXBContext.newInstance(Plugin.class);
|
||||||
|
}
|
||||||
|
catch (JAXBException ex)
|
||||||
|
{
|
||||||
|
throw new PluginLoadException("could not create jaxb context", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param parentClassLoader
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private static DefaultPluginClassLoader createClassLoader(
|
||||||
|
ClassLoader parentClassLoader, Path directory)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
List<URL> urls = new ArrayList<>();
|
||||||
|
|
||||||
|
Path metaDir = directory.resolve(DIRECTORY_METAINF);
|
||||||
|
|
||||||
|
if (!Files.exists(metaDir))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("could not find META-INF directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
Path linkDir = directory.resolve(DIRECTORY_LINK);
|
||||||
|
|
||||||
|
if (!Files.exists(linkDir))
|
||||||
|
{
|
||||||
|
Files.createDirectory(linkDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path linkMetaDir = linkDir.resolve(DIRECTORY_METAINF);
|
||||||
|
|
||||||
|
if (!Files.exists(linkMetaDir))
|
||||||
|
{
|
||||||
|
Files.deleteIfExists(linkMetaDir);
|
||||||
|
Files.createSymbolicLink(linkMetaDir, linkMetaDir.relativize(metaDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
urls.add(linkDir.toUri().toURL());
|
||||||
|
|
||||||
|
Path webinfDir = directory.resolve(DIRECTORY_WEBINF);
|
||||||
|
|
||||||
|
if (Files.exists(webinfDir))
|
||||||
|
{
|
||||||
|
Path classesDir = webinfDir.resolve(DIRECTORY_CLASSES);
|
||||||
|
|
||||||
|
if (Files.exists(classesDir))
|
||||||
|
{
|
||||||
|
urls.add(classesDir.toUri().toURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
Path libDir = webinfDir.resolve(DIRECTORY_DEPENDENCIES);
|
||||||
|
|
||||||
|
if (Files.exists(libDir))
|
||||||
|
{
|
||||||
|
for (Path f : Files.newDirectoryStream(libDir, GLOB_JAR))
|
||||||
|
{
|
||||||
|
urls.add(f.toUri().toURL());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(urls);
|
||||||
|
|
||||||
|
//J-
|
||||||
|
return new DefaultPluginClassLoader(
|
||||||
|
urls.toArray(new URL[urls.size()]),
|
||||||
|
parentClassLoader
|
||||||
|
);
|
||||||
|
//J+
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
* @param filter
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private static DirectoryStream<Path> stream(Path directory,
|
||||||
|
Filter<Path> filter)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
return Files.newDirectoryStream(directory, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public Set<PluginWrapper> collectPlugins(ClassLoader classLoader)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
logger.info("collect plugins");
|
||||||
|
|
||||||
|
Set<Path> archives = collect(pluginDirectory, new PluginArchiveFilter());
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("extract {} archives", archives.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
extract(archives);
|
||||||
|
|
||||||
|
Set<Path> directories = collect(pluginDirectory, new DirectoryFilter());
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("process {} directories", directories.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<PluginWrapper> pluginWrappers = createPluginWrappers(classLoader,
|
||||||
|
directories);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("collected {} plugins", pluginWrappers.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImmutableSet.copyOf(pluginWrappers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
* @param filter
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Set<Path> collect(Path directory, Filter<Path> filter)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
Set<Path> paths;
|
||||||
|
|
||||||
|
try (DirectoryStream<Path> stream = stream(directory, filter))
|
||||||
|
{
|
||||||
|
paths = ImmutableSet.copyOf(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param descriptor
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Plugin createPlugin(ClassLoader classLoader, Path descriptor)
|
||||||
|
{
|
||||||
|
ClassLoader ctxcl = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
|
Thread.currentThread().setContextClassLoader(classLoader);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Plugin) context.createUnmarshaller().unmarshal(
|
||||||
|
descriptor.toFile());
|
||||||
|
}
|
||||||
|
catch (JAXBException ex)
|
||||||
|
{
|
||||||
|
throw new PluginLoadException(
|
||||||
|
"could not load plugin desriptor ".concat(descriptor.toString()), ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Thread.currentThread().setContextClassLoader(ctxcl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private PluginWrapper createPluginWrapper(ClassLoader classLoader,
|
||||||
|
Path directory)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
PluginWrapper wrapper = null;
|
||||||
|
Path descriptor = directory.resolve(DESCRIPTOR);
|
||||||
|
|
||||||
|
if (Files.exists(descriptor))
|
||||||
|
{
|
||||||
|
ClassLoader cl = createClassLoader(classLoader, directory);
|
||||||
|
|
||||||
|
Plugin plugin = createPlugin(cl, descriptor);
|
||||||
|
|
||||||
|
wrapper = new PluginWrapper(plugin, cl, directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param directories
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Set<PluginWrapper> createPluginWrappers(ClassLoader classLoader,
|
||||||
|
Iterable<Path> directories)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
Set<PluginWrapper> plugins = Sets.newHashSet();
|
||||||
|
|
||||||
|
for (Path directory : directories)
|
||||||
|
{
|
||||||
|
PluginWrapper plugin = createPluginWrapper(classLoader, directory);
|
||||||
|
|
||||||
|
if (plugin != null)
|
||||||
|
{
|
||||||
|
plugins.add(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param archives
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void extract(Iterable<Path> archives) throws IOException
|
||||||
|
{
|
||||||
|
logger.debug("extract archives");
|
||||||
|
|
||||||
|
for (Path archive : archives)
|
||||||
|
{
|
||||||
|
logger.trace("extract archive {}", archive);
|
||||||
|
|
||||||
|
String filename = archive.getFileName().toString();
|
||||||
|
Path directory = pluginDirectory.resolve(filename.substring(0,
|
||||||
|
filename.lastIndexOf('.')));
|
||||||
|
|
||||||
|
IOUtil.extract(archive.toFile(), directory.toFile(),
|
||||||
|
ZipUnArchiver.EXTENSION);
|
||||||
|
Files.delete(archive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/06/04
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
private static class DirectoryFilter implements DirectoryStream.Filter<Path>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param entry
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean accept(Path entry) throws IOException
|
||||||
|
{
|
||||||
|
return Files.isDirectory(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/06/04
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
private static class PluginArchiveFilter
|
||||||
|
implements DirectoryStream.Filter<Path>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param entry
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean accept(Path entry) throws IOException
|
||||||
|
{
|
||||||
|
return Files.isRegularFile(entry)
|
||||||
|
&& entry.getFileName().toString().endsWith(EXTENSION_PLUGIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final JAXBContext context;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final Path pluginDirectory;
|
||||||
|
}
|
||||||
106
scm-webapp/src/main/java/sonia/scm/plugin/Plugins.java
Normal file
106
scm-webapp/src/main/java/sonia/scm/plugin/Plugins.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class Plugins
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final String CONTEXT_VAR = "sonia.scm.plugins";
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Plugins() {}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Set<PluginWrapper> collectPlugins(ClassLoader classLoader,
|
||||||
|
Path directory)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
PluginProcessor processor = new PluginProcessor(directory);
|
||||||
|
|
||||||
|
return processor.collectPlugins(classLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param wrapped
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Iterable<Plugin> unwrap(Iterable<PluginWrapper> wrapped)
|
||||||
|
{
|
||||||
|
return Iterables.transform(wrapped, new Unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/06/05
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
private static class Unwrap implements Function<PluginWrapper, Plugin>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param wrapper
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Plugin apply(PluginWrapper wrapper)
|
||||||
|
{
|
||||||
|
return wrapper.getPlugin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 org.sonatype.aether.graph.DependencyNode;
|
|
||||||
import org.sonatype.aether.graph.DependencyVisitor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class StringDependencyGraphDumper implements DependencyVisitor
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void reset()
|
|
||||||
{
|
|
||||||
buffer = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param node
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean visitEnter(DependencyNode node)
|
|
||||||
{
|
|
||||||
buffer.append(currentIndent).append(node).append(LINE_SEPARATOR);
|
|
||||||
|
|
||||||
if (currentIndent.length() <= 0)
|
|
||||||
{
|
|
||||||
currentIndent = "+- ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
currentIndent = "| " + currentIndent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param node
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean visitLeave(DependencyNode node)
|
|
||||||
{
|
|
||||||
currentIndent = currentIndent.substring(3, currentIndent.length());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getGraphAsString()
|
|
||||||
{
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private StringBuilder buffer = new StringBuilder();
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String currentIndent = "";
|
|
||||||
}
|
|
||||||
202
scm-webapp/src/main/java/sonia/scm/plugin/UberClassLoader.java
Normal file
202
scm-webapp/src/main/java/sonia/scm/plugin/UberClassLoader.java
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
/**
|
||||||
|
* 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.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ClassLoader} which is able to load classes and resources from all
|
||||||
|
* plugins.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class UberClassLoader extends ClassLoader
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param parent
|
||||||
|
* @param plugins
|
||||||
|
*/
|
||||||
|
public UberClassLoader(ClassLoader parent, Iterable<PluginWrapper> plugins)
|
||||||
|
{
|
||||||
|
super(parent);
|
||||||
|
this.plugins = plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Class<?> findClass(String name) throws ClassNotFoundException
|
||||||
|
{
|
||||||
|
Class<?> clazz = getFromCache(name);
|
||||||
|
|
||||||
|
if (clazz == null)
|
||||||
|
{
|
||||||
|
for (PluginWrapper plugin : plugins)
|
||||||
|
{
|
||||||
|
ClassLoader cl = plugin.getClassLoader();
|
||||||
|
|
||||||
|
// load class could be slow, perhaps we should call
|
||||||
|
// find class via reflection ???
|
||||||
|
clazz = cl.loadClass(name);
|
||||||
|
|
||||||
|
if (clazz != null)
|
||||||
|
{
|
||||||
|
cache.put(name, new WeakReference<Class<?>>(clazz));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected URL findResource(String name)
|
||||||
|
{
|
||||||
|
URL url = null;
|
||||||
|
|
||||||
|
for (PluginWrapper plugin : plugins)
|
||||||
|
{
|
||||||
|
ClassLoader cl = plugin.getClassLoader();
|
||||||
|
|
||||||
|
url = cl.getResource(name);
|
||||||
|
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Enumeration<URL> findResources(String name) throws IOException
|
||||||
|
{
|
||||||
|
List<URL> urls = Lists.newArrayList();
|
||||||
|
|
||||||
|
for (PluginWrapper plugin : plugins)
|
||||||
|
{
|
||||||
|
ClassLoader cl = plugin.getClassLoader();
|
||||||
|
|
||||||
|
urls.addAll(Collections.list(cl.getResources(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.enumeration(urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Class<?> getFromCache(String name)
|
||||||
|
{
|
||||||
|
Class<?> clazz = null;
|
||||||
|
WeakReference<Class<?>> ref = cache.get(name);
|
||||||
|
|
||||||
|
if (ref != null)
|
||||||
|
{
|
||||||
|
clazz = ref.get();
|
||||||
|
|
||||||
|
if (clazz == null)
|
||||||
|
{
|
||||||
|
cache.remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final ConcurrentMap<String, WeakReference<Class<?>>> cache =
|
||||||
|
Maps.newConcurrentMap();
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final Iterable<PluginWrapper> plugins;
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.resources;
|
package sonia.scm.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -37,7 +38,7 @@ package sonia.scm.resources;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.boot.BootstrapUtil;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
@@ -72,14 +73,16 @@ public abstract class AbstractResource implements Resource
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param servletContext
|
* @param servletContext
|
||||||
|
* @param pluginLoader
|
||||||
* @param resources
|
* @param resources
|
||||||
* @param resourceHandlers
|
* @param resourceHandlers
|
||||||
*/
|
*/
|
||||||
public AbstractResource(ServletContext servletContext,
|
public AbstractResource(ServletContext servletContext,
|
||||||
List<String> resources,
|
PluginLoader pluginLoader, List<String> resources,
|
||||||
List<ResourceHandler> resourceHandlers)
|
List<ResourceHandler> resourceHandlers)
|
||||||
{
|
{
|
||||||
this.servletContext = servletContext;
|
this.servletContext = servletContext;
|
||||||
|
this.pluginLoader = pluginLoader;
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
this.resourceHandlers = resourceHandlers;
|
this.resourceHandlers = resourceHandlers;
|
||||||
}
|
}
|
||||||
@@ -180,7 +183,7 @@ public abstract class AbstractResource implements Resource
|
|||||||
private InputStream getResourceAsStream(String resource)
|
private InputStream getResourceAsStream(String resource)
|
||||||
{
|
{
|
||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
ClassLoader classLoader = BootstrapUtil.getClassLoader(servletContext);
|
ClassLoader classLoader = pluginLoader.getUberClassLoader();
|
||||||
|
|
||||||
if (classLoader != null)
|
if (classLoader != null)
|
||||||
{
|
{
|
||||||
@@ -204,6 +207,9 @@ public abstract class AbstractResource implements Resource
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final PluginLoader pluginLoader;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected List<ResourceHandler> resourceHandlers;
|
protected List<ResourceHandler> resourceHandlers;
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -65,12 +66,12 @@ public class DefaultResource extends AbstractResource
|
|||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public DefaultResource(ServletContext servletContext, List<String> resources,
|
public DefaultResource(ServletContext servletContext, PluginLoader pluginLoader, List<String> resources,
|
||||||
List<ResourceHandler> resourceHandlers,
|
List<ResourceHandler> resourceHandlers,
|
||||||
ResourceType type)
|
ResourceType type)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
super(servletContext, resources, resourceHandlers);
|
super(servletContext, pluginLoader, resources, resourceHandlers);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -30,10 +30,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.resources;
|
package sonia.scm.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@@ -46,7 +48,6 @@ import sonia.scm.plugin.PluginLoader;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -79,8 +80,7 @@ public class DefaultResourceManager extends AbstractResourceManager
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public DefaultResourceManager(ServletContext servletContext,
|
public DefaultResourceManager(ServletContext servletContext,
|
||||||
PluginLoader pluginLoader,
|
PluginLoader pluginLoader, Set<ResourceHandler> resourceHandlers)
|
||||||
Set<ResourceHandler> resourceHandlers)
|
|
||||||
{
|
{
|
||||||
super(servletContext, pluginLoader, resourceHandlers);
|
super(servletContext, pluginLoader, resourceHandlers);
|
||||||
}
|
}
|
||||||
@@ -100,8 +100,8 @@ public class DefaultResourceManager extends AbstractResourceManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Resource resource = new DefaultResource(servletContext, resources,
|
Resource resource = new DefaultResource(servletContext, pluginLoader,
|
||||||
new ArrayList<ResourceHandler>(resourceHandlers),
|
resources, Lists.newArrayList(resourceHandlers),
|
||||||
ResourceType.SCRIPT);
|
ResourceType.SCRIPT);
|
||||||
|
|
||||||
resourceMap.put(new ResourceKey(resource.getName(), ResourceType.SCRIPT),
|
resourceMap.put(new ResourceKey(resource.getName(), ResourceType.SCRIPT),
|
||||||
|
|||||||
@@ -30,10 +30,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.resources;
|
package sonia.scm.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.util.HttpUtil;
|
import sonia.scm.util.HttpUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -58,17 +60,17 @@ public class DevelopmentResource extends AbstractResource
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param servletContext
|
* @param servletContext
|
||||||
|
* @param pluginLoader
|
||||||
* @param resources
|
* @param resources
|
||||||
* @param resourceHandlers
|
* @param resourceHandlers
|
||||||
* @param name
|
* @param name
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public DevelopmentResource(ServletContext servletContext,
|
public DevelopmentResource(ServletContext servletContext,
|
||||||
List<String> resources,
|
PluginLoader pluginLoader, List<String> resources,
|
||||||
List<ResourceHandler> resourceHandlers,
|
List<ResourceHandler> resourceHandlers, String name, ResourceType type)
|
||||||
String name, ResourceType type)
|
|
||||||
{
|
{
|
||||||
super(servletContext, resources, resourceHandlers);
|
super(servletContext, pluginLoader, resources, resourceHandlers);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
if (name.startsWith(HttpUtil.SEPARATOR_PATH))
|
if (name.startsWith(HttpUtil.SEPARATOR_PATH))
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.resources;
|
package sonia.scm.resources;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -72,8 +73,7 @@ public class DevelopmentResourceManager extends AbstractResourceManager
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public DevelopmentResourceManager(ServletContext servletContext,
|
public DevelopmentResourceManager(ServletContext servletContext,
|
||||||
PluginLoader pluginLoader,
|
PluginLoader pluginLoader, Set<ResourceHandler> resourceHandlers)
|
||||||
Set<ResourceHandler> resourceHandlers)
|
|
||||||
{
|
{
|
||||||
super(servletContext, pluginLoader, resourceHandlers);
|
super(servletContext, pluginLoader, resourceHandlers);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ public class DevelopmentResourceManager extends AbstractResourceManager
|
|||||||
|
|
||||||
for (String script : scripts)
|
for (String script : scripts)
|
||||||
{
|
{
|
||||||
Resource resource = new DevelopmentResource(servletContext,
|
Resource resource = new DevelopmentResource(servletContext, pluginLoader,
|
||||||
Arrays.asList(script), Collections.EMPTY_LIST,
|
Arrays.asList(script), Collections.EMPTY_LIST,
|
||||||
script, ResourceType.SCRIPT);
|
script, ResourceType.SCRIPT);
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ public class DevelopmentResourceManager extends AbstractResourceManager
|
|||||||
|
|
||||||
name = PREFIX_HANDLER.concat(name);
|
name = PREFIX_HANDLER.concat(name);
|
||||||
resourceMap.put(new ResourceKey(name, ResourceType.SCRIPT),
|
resourceMap.put(new ResourceKey(name, ResourceType.SCRIPT),
|
||||||
new DevelopmentResource(servletContext,
|
new DevelopmentResource(servletContext, pluginLoader,
|
||||||
Collections.EMPTY_LIST, Arrays.asList(handler), name,
|
Collections.EMPTY_LIST, Arrays.asList(handler), name,
|
||||||
ResourceType.SCRIPT));
|
ResourceType.SCRIPT));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,12 @@
|
|||||||
metadata-complete="true">
|
metadata-complete="true">
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>sonia.scm.boot.BootstrapListener</listener-class>
|
<listener-class>sonia.scm.boot.BootstrapContextListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>guiceFilter</filter-name>
|
<filter-name>guiceFilter</filter-name>
|
||||||
<filter-class>sonia.scm.boot.BootstrapFilter</filter-class>
|
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
|
||||||
</filter>
|
</filter>
|
||||||
|
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
|
|||||||
Reference in New Issue
Block a user