Add handling for transitive exclude rules in pom.xml files.

Fixes #2109

* Add maven resolver tests back to travisCI
* Disable ivy.xml translation test from maven-repository-resolver config, due to incorrect assumptions.
This commit is contained in:
Josh Suereth 2015-07-21 21:51:13 -04:00
parent efa6041103
commit bad1e9d487
4 changed files with 35 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")
}
}