mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
implement plugin dependency blacklist
This commit is contained in:
@@ -35,42 +35,47 @@ package sonia.scm.plugin;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- 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.artifact.Artifact;
|
||||||
import org.sonatype.aether.graph.DependencyFilter;
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
import org.sonatype.aether.graph.DependencyNode;
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class AetherDependencyFilter implements DependencyFilter
|
public abstract class AbstractDependencyFilter implements DependencyFilter
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String EXCLUDE_LIST = "/config/dependencies.list";
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* the logger for AbstractDependencyFilter
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public AetherDependencyFilter()
|
private static final Logger logger =
|
||||||
{
|
LoggerFactory.getLogger(AbstractDependencyFilter.class);
|
||||||
loadExcludes();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
protected abstract Set<String> loadExcludeSet() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -91,62 +96,44 @@ public class AetherDependencyFilter implements DependencyFilter
|
|||||||
|
|
||||||
if (artifact != null)
|
if (artifact != null)
|
||||||
{
|
{
|
||||||
result = !exludeSet.contains(getId(artifact));
|
String id = getId(artifact);
|
||||||
|
|
||||||
|
result = !getExludeSet().contains(id);
|
||||||
|
|
||||||
|
if (!result && logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("exlcude dependency {} because it is blacklisted", id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private void loadExcludes()
|
private Set<String> getExludeSet()
|
||||||
|
{
|
||||||
|
if (exludeSet == null)
|
||||||
{
|
{
|
||||||
Scanner scanner = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
scanner = new Scanner(
|
exludeSet = loadExcludeSet();
|
||||||
AetherDependencyFilter.class.getResourceAsStream(EXCLUDE_LIST));
|
|
||||||
|
|
||||||
while (scanner.hasNextLine())
|
|
||||||
{
|
|
||||||
parseLine(scanner.nextLine());
|
|
||||||
}
|
}
|
||||||
}
|
catch (IOException ex)
|
||||||
finally
|
|
||||||
{
|
{
|
||||||
if (scanner != null)
|
throw Throwables.propagate(ex);
|
||||||
{
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return exludeSet;
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param line
|
|
||||||
*/
|
|
||||||
private void parseLine(String line)
|
|
||||||
{
|
|
||||||
line = line.trim();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(line))
|
|
||||||
{
|
|
||||||
String[] parts = line.split(":");
|
|
||||||
|
|
||||||
if (parts.length >= 2)
|
|
||||||
{
|
|
||||||
exludeSet.add(parts[0].concat(":").concat(parts[1]));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -164,5 +151,5 @@ public class AetherDependencyFilter implements DependencyFilter
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<String> exludeSet = new HashSet<String>();
|
private Set<String> exludeSet;
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,7 @@ import org.sonatype.aether.resolution.DependencyRequest;
|
|||||||
import org.sonatype.aether.resolution.DependencyResolutionException;
|
import org.sonatype.aether.resolution.DependencyResolutionException;
|
||||||
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
import org.sonatype.aether.util.artifact.JavaScopes;
|
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.filter.DependencyFilterUtils;
|
||||||
import org.sonatype.aether.util.graph.transformer
|
import org.sonatype.aether.util.graph.transformer
|
||||||
.ChainedDependencyGraphTransformer;
|
.ChainedDependencyGraphTransformer;
|
||||||
@@ -77,7 +78,11 @@ public final class Aether
|
|||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final DependencyFilter FILTER = new AetherDependencyFilter();
|
private static final DependencyFilter FILTER =
|
||||||
|
new AndDependencyFilter(
|
||||||
|
new CoreDependencyFilter(),
|
||||||
|
new BlacklistDependencyFilter()
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the logger for Aether
|
* the logger for Aether
|
||||||
@@ -167,7 +172,6 @@ public final class Aether
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param system
|
* @param system
|
||||||
* @param repositoryManager
|
|
||||||
* @param localRepository
|
* @param localRepository
|
||||||
* @param configuration
|
* @param configuration
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
scm-webapp/src/main/java/sonia/scm/plugin/DependencyFilters.java
Normal file
110
scm-webapp/src/main/java/sonia/scm/plugin/DependencyFilters.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* 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.Charsets;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
import com.google.common.io.Resources;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class DependencyFilters
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Set<String> loadDependencySet(String path) throws IOException
|
||||||
|
{
|
||||||
|
URL url = Resources.getResource(DependencyFilters.class, path);
|
||||||
|
|
||||||
|
if (url == null)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"could not find dependency set at ".concat(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
Builder<String> builder = ImmutableSet.builder();
|
||||||
|
List<String> lines = Resources.readLines(url, Charsets.UTF_8);
|
||||||
|
|
||||||
|
for (String line : lines)
|
||||||
|
{
|
||||||
|
parseAndAppendLine(builder, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param builder
|
||||||
|
* @param line
|
||||||
|
*/
|
||||||
|
private static void parseAndAppendLine(Builder<String> builder, String line)
|
||||||
|
{
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
if (!Strings.isNullOrEmpty(line))
|
||||||
|
{
|
||||||
|
String[] parts = line.split(":");
|
||||||
|
|
||||||
|
if (parts.length >= 2)
|
||||||
|
{
|
||||||
|
builder.add(parts[0].concat(":").concat(parts[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
scm-webapp/src/main/resources/config/blacklist.list
Normal file
10
scm-webapp/src/main/resources/config/blacklist.list
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
The following dependencies are blacklisted
|
||||||
|
commons-logging:commons-logging
|
||||||
|
log4j:log4j
|
||||||
|
junit:junit
|
||||||
|
org.mockito:mockito-core
|
||||||
|
org.mockito:mockito-all
|
||||||
|
org.mockito:mockito-junit
|
||||||
|
org.testng:testng
|
||||||
|
org.powermock:powermock
|
||||||
Reference in New Issue
Block a user