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:
@@ -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 BlacklistDependencyFilter extends AbstractDependencyFilter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String BLACKLIST = "/config/blacklist.list";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
protected Set<String> loadExcludeSet() throws IOException
|
||||
{
|
||||
return DependencyFilters.loadDependencySet(BLACKLIST);
|
||||
}
|
||||
}
|
||||
@@ -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.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.ClassLoaders;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -83,24 +81,33 @@ public class DefaultPluginLoader implements PluginLoader
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
* @param parent
|
||||
* @param wrappedPlugins
|
||||
*/
|
||||
public DefaultPluginLoader()
|
||||
public DefaultPluginLoader(ClassLoader parent,
|
||||
Set<PluginWrapper> wrappedPlugins)
|
||||
{
|
||||
ClassLoader classLoader =
|
||||
ClassLoaders.getContextClassLoader(DefaultPluginLoader.class);
|
||||
this.uberClassLoader = new UberClassLoader(parent, wrappedPlugins);
|
||||
|
||||
try
|
||||
{
|
||||
JAXBContext context = JAXBContext.newInstance(ScmModule.class,
|
||||
Plugin.class);
|
||||
|
||||
modules = getInstalled(classLoader, context, PATH_MODULECONFIG);
|
||||
plugins = getInstalled(classLoader, context, PATH_PLUGINCONFIG);
|
||||
modules = getInstalled(parent, context, PATH_MODULECONFIG);
|
||||
|
||||
// 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, plugins);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (IOException | JAXBException ex)
|
||||
{
|
||||
throw Throwables.propagate(ex);
|
||||
}
|
||||
@@ -171,6 +178,18 @@ public class DefaultPluginLoader implements PluginLoader
|
||||
return plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ClassLoader getUberClassLoader()
|
||||
{
|
||||
return uberClassLoader;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -259,6 +278,9 @@ public class DefaultPluginLoader implements PluginLoader
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final ClassLoader uberClassLoader;
|
||||
|
||||
/** Field description */
|
||||
private Set<ScmModule> modules;
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
* TODO replace aether stuff
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@@ -199,7 +200,7 @@ public class DefaultPluginManager implements PluginManager
|
||||
|
||||
PluginCenter center = getPluginCenter();
|
||||
|
||||
pluginHandler.install(id);
|
||||
// pluginHandler.install(id);
|
||||
|
||||
for (PluginInformation plugin : center.getPlugins())
|
||||
{
|
||||
@@ -248,7 +249,7 @@ public class DefaultPluginManager implements PluginManager
|
||||
throw new PluginConditionFailedException(condition);
|
||||
}
|
||||
|
||||
AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
||||
/*AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
||||
configuration);
|
||||
Collection<PluginRepository> repositories =
|
||||
Sets.newHashSet(new PluginRepository("package-repository",
|
||||
@@ -256,7 +257,7 @@ public class DefaultPluginManager implements PluginManager
|
||||
|
||||
aph.setPluginRepositories(repositories);
|
||||
|
||||
aph.install(plugin.getInformation().getId());
|
||||
aph.install(plugin.getInformation().getId());*/
|
||||
plugin.getInformation().setState(PluginState.INSTALLED);
|
||||
installedPlugins.put(plugin.getInformation().getId(), plugin);
|
||||
|
||||
@@ -301,12 +302,12 @@ public class DefaultPluginManager implements PluginManager
|
||||
throw new PluginNotInstalledException(id.concat(" is not install"));
|
||||
}
|
||||
|
||||
if (pluginHandler == null)
|
||||
/*if (pluginHandler == null)
|
||||
{
|
||||
getPluginCenter();
|
||||
}
|
||||
|
||||
pluginHandler.uninstall(id);
|
||||
pluginHandler.uninstall(id);*/
|
||||
installedPlugins.remove(id);
|
||||
preparePlugins(getPluginCenter());
|
||||
}
|
||||
@@ -643,13 +644,13 @@ public class DefaultPluginManager implements PluginManager
|
||||
preparePlugins(center);
|
||||
cache.put(PluginCenter.class.getName(), center);
|
||||
|
||||
if (pluginHandler == null)
|
||||
/*if (pluginHandler == null)
|
||||
{
|
||||
pluginHandler = new AetherPluginHandler(this,
|
||||
SCMContext.getContext(), configuration);
|
||||
}
|
||||
|
||||
pluginHandler.setPluginRepositories(center.getRepositories());
|
||||
pluginHandler.setPluginRepositories(center.getRepositories());*/
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -767,9 +768,6 @@ public class DefaultPluginManager implements PluginManager
|
||||
/** Field description */
|
||||
private final Map<String, Plugin> installedPlugins;
|
||||
|
||||
/** Field description */
|
||||
private AetherPluginHandler pluginHandler;
|
||||
|
||||
/** Field description */
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user