Merge pull request #2126 from sbt/fix/2109-transitive-excludes

Fix/2109 transitive excludes
This commit is contained in:
eugene yokota 2015-07-24 13:23:17 -04:00
commit d08234a904
14 changed files with 140 additions and 9 deletions

View File

@ -34,8 +34,8 @@ env:
- SCRIPTED_TEST="scripted tests/*"
- SCRIPTED_TEST="scripted project-load/*"
- SCRIPTED_TEST="checkBuildScala211"
# - SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins"
# - SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*2of2"
- SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins"
- SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*2of2"
notifications:
email:

View File

@ -0,0 +1,10 @@
[@jsuereth]: http://github.com/jsuereth
[2109]: https://github.com/sbt/sbt/issues/2109
### Fixes with compatibility implications
### Improvements
### Bug fixes
- Expand transitive dependency exclusions when using sbt-maven-resolver-plugin [#2109][2109] by [@jsuereth][@jsuereth]

View File

@ -6,11 +6,11 @@ import java.util.Date
import org.apache.ivy.core.IvyContext
import org.apache.ivy.core.cache.{ ArtifactOrigin, ModuleDescriptorWriter }
import org.apache.ivy.core.module.descriptor._
import org.apache.ivy.core.module.id.{ ModuleId, ModuleRevisionId }
import org.apache.ivy.core.module.id.{ ArtifactId, ModuleId, ModuleRevisionId }
import org.apache.ivy.core.report.{ ArtifactDownloadReport, DownloadReport, DownloadStatus, MetadataArtifactDownloadReport }
import org.apache.ivy.core.resolve.{ DownloadOptions, ResolveData, ResolvedModuleRevision }
import org.apache.ivy.core.settings.IvySettings
import org.apache.ivy.plugins.matcher.ExactPatternMatcher
import org.apache.ivy.plugins.matcher.{ PatternMatcher, ExactPatternMatcher }
import org.apache.ivy.plugins.parser.m2.{ PomModuleDescriptorBuilder, ReplaceMavenConfigurationMappings }
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter
import org.apache.ivy.plugins.resolver.AbstractResolver
@ -172,7 +172,6 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
addDependenciesFromAether(result, md)
// Here we use pom.xml Dependency management section to create Ivy dependency mediators.
addManagedDependenciesFromAether(result, md)
// TODO - Add excludes?
// Here we rip out license info.
addLicenseInfo(md, result.getProperties)
@ -319,8 +318,9 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
}
/** Adds the dependency mediators required based on the managed dependency instances from this pom. */
def addManagedDependenciesFromAether(result: AetherDescriptorResult, md: DefaultModuleDescriptor) {
def addManagedDependenciesFromAether(result: AetherDescriptorResult, md: DefaultModuleDescriptor): Unit = {
for (d <- result.getManagedDependencies.asScala) {
// TODO - Figure out what to do about exclusions on managed dependencies.
md.addDependencyDescriptorMediator(
ModuleId.newInstance(d.getArtifact.getGroupId, d.getArtifact.getArtifactId),
ExactPatternMatcher.INSTANCE,
@ -334,7 +334,7 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
}
/** Adds the list of dependencies this artifact has on other artifacts. */
def addDependenciesFromAether(result: AetherDescriptorResult, md: DefaultModuleDescriptor) {
def addDependenciesFromAether(result: AetherDescriptorResult, md: DefaultModuleDescriptor): Unit = {
// First we construct a map of any extra attributes we must append to dependencies.
// This is necessary for transitive maven-based sbt plugin dependencies, where we need to
// attach the sbtVersion/scalaVersion to the dependency id otherwise we'll fail to resolve the
@ -366,7 +366,6 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
// TODO - Configuration mappings (are we grabbing scope correctly, or should the default not always be compile?)
val scope = Option(d.getScope).filterNot(_.isEmpty).getOrElse("compile")
val mapping = ReplaceMavenConfigurationMappings.addMappings(dd, scope, d.isOptional)
// TODO - include rules and exclude rules.
Message.debug(s"Adding maven transitive dependency ${md.getModuleRevisionId} -> ${dd}")
// TODO - Unify this borrowed Java code into something a bit friendlier.
// Now we add the artifact....
@ -390,6 +389,18 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
// TOOD - We may need to fix the configuration mappings here.
dd.addDependencyArtifact(optionalizedScope, depArtifact)
}
// Include rules and exclude rules.
for (e <- d.getExclusions.asScala) {
val excludedModule = new ModuleId(e.getGroupId, e.getArtifactId)
for (conf <- dd.getModuleConfigurations) {
// TODO - Do we need extra attributes for this?
dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
excludedModule, PatternMatcher.ANY_EXPRESSION,
PatternMatcher.ANY_EXPRESSION,
PatternMatcher.ANY_EXPRESSION),
ExactPatternMatcher.INSTANCE, null))
}
}
md.addDependency(dd)
}
}

View File

@ -25,6 +25,8 @@ cleanExampleCache := {
val checkIvyXml = taskKey[Unit]("Checks the ivy.xml transform was correct")
checkIvyXml := {
ivySbt.value.withIvy(streams.value.log) { ivy =>
val cacheDir = ivy.getSettings.getDefaultRepositoryCacheBasedir
@ -34,6 +36,9 @@ checkIvyXml := {
//cacheDir / "com.example" / "example-child" / "ivy-1.0-SNAPSHOT.xml"
val lines = IO.read(xmlFile)
if(lines.isEmpty) sys.error(s"Unable to read $xmlFile, could not resolve geronimo...")
assert(lines contains "xmlns:e", s"Failed to appropriately modify ivy.xml file for sbt extra attributes!\n$lines")
// Note: We do not do this if the maven plguin is enabled, because there is no rewrite of ivy.xml, extra attribtues
// are handled in a different mechanism. This is a hacky mechanism to detect that.
val isMavenResolver = updateOptions.value.resolverConverter != PartialFunction.empty
if(!isMavenResolver) assert(lines contains "xmlns:e", s"Failed to appropriately modify ivy.xml file for sbt extra attributes!\n$lines")
}
}

View File

@ -0,0 +1,35 @@
resolvers += {
val f = baseDirectory.value / "repository"
"local-test-repo" at f.getCanonicalFile.toURI.toASCIIString
}
libraryDependencies += "exclude.test" % "app" % "1.0.0"
val checkDependencies = taskKey[Unit]("Checks that dependcies are correct.")
checkDependencies := {
val hasBadJar = (fullClasspath in Compile).value.exists { jar => jar.data.getName contains "bottom-1.0.0.jar"}
val errorJarString = (fullClasspath in Compile).value.map(_.data.getName).mkString(" * ", "\n * ", "")
val hasBadMiddleJar = (fullClasspath in Compile).value.exists { jar => jar.data.getName contains "middle-1.0.0.jar"}
assert(!hasBadMiddleJar, s"Failed to exclude excluded dependency on classpath!\nFound:\n$errorJarString")
assert(!hasBadJar, s"Failed to exclude transitive excluded dependency on classpath!\nFound:\n$errorJarString")
val modules =
(for {
c <- update.value.configurations
m <- c.modules
if !m.evicted
} yield m.module).distinct
val hasBadDep =
modules exists { m =>
(m.organization == "exclude.test") && (m.name == "bottom")
}
val hasBadMiddleDep =
modules exists { m =>
(m.organization == "exclude.test") && (m.name == "middle")
}
val errModuleString = modules.mkString("\n * ", "\n * ", "")
assert(!hasBadMiddleDep, s"Failed to exclude transitive excluded dependency!\nFound:\n$errModuleString")
assert(!hasBadDep, s"Failed to exclude transitive excluded dependency!\nFound:\n$errModuleString")
}

View File

@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exclude.test</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>exclude.test</groupId>
<artifactId>top</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>exclude.test</groupId>
<artifactId>middle</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exclude.test</groupId>
<artifactId>bottom</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>bottom</name>
<url>http://maven.apache.org</url>
<dependencies>
</dependencies>
</project>

View File

@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exclude.test</groupId>
<artifactId>middle</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>middle</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>exclude.test</groupId>
<artifactId>bottom</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>exclude.test</groupId>
<artifactId>top</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>top</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>exclude.test</groupId>
<artifactId>middle</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1 @@
> checkDependencies