diff --git a/.travis.yml b/.travis.yml index 6b62e1071..486022e06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,14 +35,10 @@ env: - SBT_CMD="scripted source-dependencies/*3of3" - SBT_CMD="scripted tests/*" - SBT_CMD="scripted project-load/*" - - SBT_CMD="checkBuildScala211" - - SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins" - - SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*2of2" notifications: email: - - eugene.yokota@typesafe.com - - joshua.suereth@typesafe.com + - sbt-dev-bot@googlegroups.com script: - sbt -J-XX:ReservedCodeCacheSize=128m "$SBT_CMD" diff --git a/build.sbt b/build.sbt index c549bb69b..5d0032ed2 100644 --- a/build.sbt +++ b/build.sbt @@ -19,11 +19,10 @@ def buildLevelSettings: Seq[Setting[_]] = inThisBuild(Seq( )) def commonSettings: Seq[Setting[_]] = Seq[SettingsDefinition]( - scalaVersion := scala210, + scalaVersion := scala211, publishArtifact in packageDoc := false, publishMavenStyle := false, componentID := None, - crossPaths := false, resolvers += Resolver.typesafeIvyRepo("releases"), resolvers += Resolver.sonatypeRepo("snapshots"), resolvers += Resolver.bintrayRepo("sbt", "maven-releases"), @@ -31,7 +30,7 @@ def commonSettings: Seq[Setting[_]] = Seq[SettingsDefinition]( testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-w", "1"), javacOptions in compile ++= Seq("-target", "6", "-source", "6", "-Xlint", "-Xlint:-serial"), incOptions := incOptions.value.withNameHashing(true), - crossScalaVersions := Seq(scala210), + crossScalaVersions := Seq(scala211), bintrayPackage := (bintrayPackage in ThisBuild).value, bintrayRepository := (bintrayRepository in ThisBuild).value, mimaDefaultSettings, @@ -77,6 +76,7 @@ lazy val bundledLauncherProj = description := "sbt application launcher", publishArtifact in packageSrc := false, autoScalaLibrary := false, + crossPaths := false, publish := Release.deployLauncher.value, publishLauncher := Release.deployLauncher.value, packageBin in Compile := sbtLaunchJar.value @@ -199,16 +199,6 @@ lazy val sbtProj = (project in sbtPath). libraryDependencies ++= Seq(compilerBrdige) ) -lazy val mavenResolverPluginProj = (project in file("sbt-maven-resolver")). - dependsOn(sbtProj). - settings( - baseSettings, - sbtBinaryVersion := "1.0.0-SNAPSHOT", - name := "sbt-maven-resolver", - libraryDependencies ++= aetherLibs ++ Seq(utilTesting % Test, (libraryManagement % Test).classifier("tests"), libraryManagement % Test), - sbtPlugin := true - ) - def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask { val result = scriptedSource(dir => (s: State) => Scripted.scriptedParser(dir)).parsed publishAll.value @@ -231,7 +221,7 @@ lazy val myProvided = config("provided") intransitive def allProjects = Seq( testingProj, testAgentProj, taskProj, stdTaskProj, runProj, scriptedSbtProj, scriptedPluginProj, - actionsProj, commandProj, mainSettingsProj, mainProj, sbtProj, bundledLauncherProj, mavenResolverPluginProj) + actionsProj, commandProj, mainSettingsProj, mainProj, sbtProj, bundledLauncherProj) def projectsWithMyProvided = allProjects.map(p => p.copy(configurations = (p.configurations.filter(_ != Provided)) :+ myProvided)) lazy val nonRoots = projectsWithMyProvided.map(p => LocalProject(p.id)) @@ -247,19 +237,9 @@ def otherRootSettings = Seq( val _ = (publishLocal).all(ScopeFilter(inAnyProject)).value }, aggregate in bintrayRelease := false -) ++ inConfig(Scripted.MavenResolverPluginTest)(Seq( - scripted <<= scriptedTask, - scriptedUnpublished <<= scriptedUnpublishedTask, - scriptedPrescripted := { f => - val inj = f / "project" / "maven.sbt" - if (!inj.exists) { - IO.write(inj, "addMavenResolverPlugin") - // sLog.value.info(s"""Injected project/maven.sbt to $f""") - } - } -)) +) lazy val docProjects: ScopeFilter = ScopeFilter( - inAnyProject -- inProjects(sbtRoot, sbtProj, scriptedSbtProj, scriptedPluginProj, mavenResolverPluginProj), + inAnyProject -- inProjects(sbtRoot, sbtProj, scriptedSbtProj, scriptedPluginProj), inConfigurations(Compile) ) def fullDocSettings = Util.baseScalacOptions ++ Docs.settings ++ Sxr.settings ++ Seq( @@ -295,7 +275,7 @@ lazy val otherProjects: ScopeFilter = ScopeFilter( testingProj, testAgentProj, taskProj, scriptedSbtProj, scriptedPluginProj, commandProj, mainSettingsProj, mainProj, - sbtProj, mavenResolverPluginProj), + sbtProj), inConfigurations(Test) ) diff --git a/launch/src/main/input_resources/sbt/sbt.boot.properties b/launch/src/main/input_resources/sbt/sbt.boot.properties index 9234be5f8..7a10ad53c 100644 --- a/launch/src/main/input_resources/sbt/sbt.boot.properties +++ b/launch/src/main/input_resources/sbt/sbt.boot.properties @@ -1,5 +1,5 @@ [scala] - version: ${sbt.scala.version-auto} + version: 2.11.8 [app] org: ${sbt.organization-${{org}}} @@ -7,7 +7,7 @@ version: ${sbt.version-read(sbt.version)[${{sbt.version}}]} class: ${sbt.main.class-sbt.xMain} components: xsbti,extra - cross-versioned: ${sbt.cross.versioned-false} + cross-versioned: ${sbt.cross.versioned-binary} resources: ${sbt.extraClasspath-} [repositories] diff --git a/launch/src/main/resources/sbt.boot.properties0.13.0 b/launch/src/main/resources/sbt.boot.properties0.13.0 new file mode 100644 index 000000000..b1d906481 --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.13.0 @@ -0,0 +1,26 @@ +[scala] + version: 2.10.6 + +[app] + org: ${sbt.organization-org.scala-sbt} + name: sbt + version: ${sbt.version-read(sbt.version)[0.13.9]} + class: sbt.xMain + components: xsbti,extra + cross-versioned: ${sbt.cross.versioned-false} + resources: ${sbt.extraClasspath-} + +[repositories] + local + maven-central + typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly + sbt-ivy-snapshots: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly + +[boot] + directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/} + +[ivy] + ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/} + checksums: ${sbt.checksums-sha1,md5} + override-build-repos: ${sbt.override.build.repos-false} + repository-config: ${sbt.repository.config-${sbt.global.base-${user.home}/.sbt}/repositories} diff --git a/main/src/main/scala/sbt/BuildUtil.scala b/main/src/main/scala/sbt/BuildUtil.scala index cbe1e03aa..31989f28f 100644 --- a/main/src/main/scala/sbt/BuildUtil.scala +++ b/main/src/main/scala/sbt/BuildUtil.scala @@ -72,7 +72,7 @@ object BuildUtil { } } - def baseImports: Seq[String] = "import sbt._, Keys._, dsl._, Import._" :: Nil + def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, dsl._, Import._" :: Nil def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports ++ unit.definitions.dslDefinitions.imports diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index f5e3cae69..bbd3504b3 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1158,9 +1158,9 @@ object Classpaths { val id = app.provider.id val scalaVersion = app.provider.scalaProvider.version val binVersion = binaryScalaVersion(scalaVersion) - val cross = if (id.crossVersioned) CrossVersion.binary else CrossVersion.Disabled - val base = ModuleID(id.groupID, id.name, sbtVersion.value, crossVersion = cross) - CrossVersion(scalaVersion, binVersion)(base).copy(crossVersion = CrossVersion.Disabled) + val cross = CrossVersion.binary + ModuleID(id.groupID, id.name, sbtVersion.value, crossVersion = cross) + // CrossVersion(scalaVersion, binVersion)(base) // .copy(crossVersion = CrossVersion.Disabled) } )) @@ -1368,7 +1368,7 @@ object Classpaths { val depDir = dependencyCacheDirectory.value withExcludes(out, mod.classifiers, lock(app)) { excludes => val noExplicitCheck = ivyScala.value.map(_.copy(checkExplicit = false)) - IvyActions.transitiveScratch(is, "sbt", GetClassifiersConfiguration(mod, excludes, c.copy(artifactFilter = c.artifactFilter.invert), noExplicitCheck, srcTypes, docTypes), uwConfig, LogicalClock(state.value.hashCode), Some(depDir), s.log) + IvyActions.transitiveScratch(is, "sbt_2.11", GetClassifiersConfiguration(mod, excludes, c.copy(artifactFilter = c.artifactFilter.invert), noExplicitCheck, srcTypes, docTypes), uwConfig, LogicalClock(state.value.hashCode), Some(depDir), s.log) } } tag (Tags.Update, Tags.Network) )) ++ Seq(bootIvyConfiguration := (ivyConfiguration in updateSbtClassifiers).value) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c077f4afd..93a935fce 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,7 +6,7 @@ object Dependencies { lazy val scala292 = "2.9.2" lazy val scala293 = "2.9.3" lazy val scala210 = "2.10.6" - lazy val scala211 = "2.11.7" + lazy val scala211 = "2.11.8" // sbt modules val utilVersion = "0.1.0-M10" @@ -57,41 +57,4 @@ object Dependencies { } lazy val scalaXml = scala211Module("scala-xml", "1.0.1") lazy val scalaParsers = scala211Module("scala-parser-combinators", "1.0.1") - - // Maven related dependnecy craziness - //val mvnEmbedder = "org.apache.maven" % "maven-embedder" % mvnVersion - val mvnWagonVersion = "2.4" - val mvnVersion = "3.2.3" - val aetherVersion = "1.0.1.v20141111" - - val mvnAether = "org.apache.maven" % "maven-aether-provider" % mvnVersion - val aether = "org.eclipse.aether" % "aether" % aetherVersion - val aetherImpl = "org.eclipse.aether" % "aether-impl" % aetherVersion - val aetherUtil = "org.eclipse.aether" % "aether-util" % aetherVersion - val aetherTransportFile = "org.eclipse.aether" % "aether-transport-file" % aetherVersion - val aetherTransportWagon = "org.eclipse.aether" % "aether-transport-wagon" % aetherVersion - val aetherTransportHttp = "org.eclipse.aether" % "aether-transport-http" % aetherVersion - val aetherConnectorBasic = "org.eclipse.aether" % "aether-connector-basic" % aetherVersion - val sisuPlexus = ("org.eclipse.sisu" % "org.eclipse.sisu.plexus" % "0.3.0.M1").exclude("javax.enterprise", "cdi-api").exclude("com.google.code.findbugs", "jsr305") - val guice = "com.google.inject" % "guice" % "3.0" - val guava = "com.google.guava" % "guava" % "18.0" - val javaxInject = "javax.inject" % "javax.inject" % "1" - - //val sisuGuice = ("org.eclipse.sisu" % "sisu-guice" % "3.1.0").classifier("no_aop").exclude("javax.enterprise", "cdi-api", ) - - /* - val mvnWagon = "org.apache.maven.wagon" % "wagon-http" % mvnWagonVersion - val mvnWagonProviderApi = "org.apache.maven.wagon" % "wagon-provider-api" % mvnWagonVersion - val mvnWagonLwHttp = "org.apache.maven.wagon" % "wagon-http-lightweight" % mvnWagonVersion - val mvnWagonFile = "org.apache.maven.wagon" % "wagon-file" % mvnWagonVersion - */ - def aetherLibs = - Seq( - guava, - javaxInject, - sisuPlexus, - aetherImpl, - aetherConnectorBasic, - mvnAether) - } diff --git a/sbt-maven-resolver/src/main/java/org/apache/maven/repository/internal/SbtArtifactDescriptorReader.java b/sbt-maven-resolver/src/main/java/org/apache/maven/repository/internal/SbtArtifactDescriptorReader.java deleted file mode 100644 index b215ea720..000000000 --- a/sbt-maven-resolver/src/main/java/org/apache/maven/repository/internal/SbtArtifactDescriptorReader.java +++ /dev/null @@ -1,560 +0,0 @@ -package org.apache.maven.repository.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.License; -import org.apache.maven.model.Model; -import org.apache.maven.model.Prerequisites; -import org.apache.maven.model.Relocation; -import org.apache.maven.model.Repository; -import org.apache.maven.model.building.DefaultModelBuilderFactory; -import org.apache.maven.model.building.DefaultModelBuildingRequest; -import org.apache.maven.model.building.FileModelSource; -import org.apache.maven.model.building.ModelBuilder; -import org.apache.maven.model.building.ModelBuildingException; -import org.apache.maven.model.building.ModelBuildingRequest; -import org.apache.maven.model.building.ModelProblem; -import org.apache.maven.model.resolution.UnresolvableModelException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.eclipse.aether.RepositoryException; -import org.eclipse.aether.RepositoryEvent.EventType; -import org.eclipse.aether.RepositoryEvent; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.RequestTrace; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.ArtifactProperties; -import org.eclipse.aether.artifact.ArtifactType; -import org.eclipse.aether.artifact.ArtifactTypeRegistry; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.artifact.DefaultArtifactType; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.Exclusion; -import org.eclipse.aether.impl.*; -import org.eclipse.aether.repository.WorkspaceRepository; -import org.eclipse.aether.resolution.ArtifactDescriptorException; -import org.eclipse.aether.resolution.ArtifactDescriptorPolicy; -import org.eclipse.aether.resolution.ArtifactDescriptorPolicyRequest; -import org.eclipse.aether.resolution.ArtifactDescriptorRequest; -import org.eclipse.aether.resolution.ArtifactDescriptorResult; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.resolution.VersionRequest; -import org.eclipse.aether.resolution.VersionResolutionException; -import org.eclipse.aether.resolution.VersionResult; -import org.eclipse.aether.spi.locator.Service; -import org.eclipse.aether.spi.locator.ServiceLocator; -import org.eclipse.aether.spi.log.Logger; -import org.eclipse.aether.spi.log.LoggerFactory; -import org.eclipse.aether.spi.log.NullLoggerFactory; -import org.eclipse.aether.transfer.ArtifactNotFoundException; -import sbt.internal.librarymanagement.mavenint.PomExtraDependencyAttributes; -import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties; - -/** - * A hacked version of maven's default artifact descriptor reader which we use in place of the standard aether adapter. - * - * This adds the following to the parsing of maven files: - * - * Additonal properties: - * - * - `sbt.pom.packaging` - The pom.packaging value. - * - * - * @author Benjamin Bentmann - * @author Josh Suereth - Adapted for sbt - */ -@Named -@Component( role = ArtifactDescriptorReader.class ) -public class SbtArtifactDescriptorReader - implements ArtifactDescriptorReader, Service -{ - - @SuppressWarnings( "unused" ) - @Requirement( role = LoggerFactory.class ) - private Logger logger = NullLoggerFactory.LOGGER; - - @Requirement - private RemoteRepositoryManager remoteRepositoryManager; - - @Requirement - private VersionResolver versionResolver; - - @Requirement - private VersionRangeResolver versionRangeResolver; - - @Requirement - private ArtifactResolver artifactResolver; - - @Requirement - private RepositoryEventDispatcher repositoryEventDispatcher; - - @Requirement - private ModelBuilder modelBuilder; - - public SbtArtifactDescriptorReader() - { - // enable no-arg constructor - } - - @Inject - SbtArtifactDescriptorReader( RemoteRepositoryManager remoteRepositoryManager, VersionResolver versionResolver, - ArtifactResolver artifactResolver, ModelBuilder modelBuilder, - RepositoryEventDispatcher repositoryEventDispatcher, LoggerFactory loggerFactory ) - { - setRemoteRepositoryManager( remoteRepositoryManager ); - setVersionResolver( versionResolver ); - setArtifactResolver( artifactResolver ); - setModelBuilder( modelBuilder ); - setLoggerFactory( loggerFactory ); - setRepositoryEventDispatcher( repositoryEventDispatcher ); - } - - public void initService( ServiceLocator locator ) - { - setLoggerFactory(locator.getService(LoggerFactory.class)); - setRemoteRepositoryManager(locator.getService(RemoteRepositoryManager.class)); - setVersionResolver(locator.getService(VersionResolver.class)); - setArtifactResolver(locator.getService(ArtifactResolver.class)); - setRepositoryEventDispatcher(locator.getService(RepositoryEventDispatcher.class)); - setVersionRangeResolver(locator.getService(VersionRangeResolver.class)); - modelBuilder = locator.getService( ModelBuilder.class ); - if ( modelBuilder == null ) - { - setModelBuilder( new DefaultModelBuilderFactory().newInstance() ); - } - } - - public SbtArtifactDescriptorReader setLoggerFactory( LoggerFactory loggerFactory ) - { - this.logger = NullLoggerFactory.getSafeLogger( loggerFactory, getClass() ); - return this; - } - - void setLogger( LoggerFactory loggerFactory ) - { - // plexus support - setLoggerFactory( loggerFactory ); - } - - public SbtArtifactDescriptorReader setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager ) - { - if ( remoteRepositoryManager == null ) - { - throw new IllegalArgumentException( "remote repository manager has not been specified" ); - } - this.remoteRepositoryManager = remoteRepositoryManager; - return this; - } - - public SbtArtifactDescriptorReader setVersionResolver( VersionResolver versionResolver ) - { - if ( versionResolver == null ) - { - throw new IllegalArgumentException( "version resolver has not been specified" ); - } - this.versionResolver = versionResolver; - return this; - } - - public SbtArtifactDescriptorReader setArtifactResolver( ArtifactResolver artifactResolver ) - { - if ( artifactResolver == null ) - { - throw new IllegalArgumentException( "artifact resolver has not been specified" ); - } - this.artifactResolver = artifactResolver; - return this; - } - - public SbtArtifactDescriptorReader setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher ) - { - if ( repositoryEventDispatcher == null ) - { - throw new IllegalArgumentException( "repository event dispatcher has not been specified" ); - } - this.repositoryEventDispatcher = repositoryEventDispatcher; - return this; - } - - public SbtArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilder ) - { - if ( modelBuilder == null ) - { - throw new IllegalArgumentException( "model builder has not been specified" ); - } - this.modelBuilder = modelBuilder; - return this; - } - - public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session, - ArtifactDescriptorRequest request ) - throws ArtifactDescriptorException - { - ArtifactDescriptorResult result = new ArtifactDescriptorResult( request ); - - Model model = loadPom( session, request, result ); - - if ( model != null ) - { - - ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); - - for ( Repository r : model.getRepositories() ) - { - result.addRepository( ArtifactDescriptorUtils.toRemoteRepository( r ) ); - } - - for ( org.apache.maven.model.Dependency dependency : model.getDependencies() ) - { - result.addDependency( convert( dependency, stereotypes ) ); - } - - DependencyManagement mngt = model.getDependencyManagement(); - if ( mngt != null ) - { - for ( org.apache.maven.model.Dependency dependency : mngt.getDependencies() ) - { - result.addManagedDependency( convert( dependency, stereotypes ) ); - } - } - - Map properties = new LinkedHashMap(); - - Prerequisites prerequisites = model.getPrerequisites(); - if ( prerequisites != null ) - { - properties.put( "prerequisites.maven", prerequisites.getMaven() ); - } - - List licenses = model.getLicenses(); - properties.put( SbtPomExtraProperties.LICENSE_COUNT_KEY, licenses.size() ); - for ( int i = 0; i < licenses.size(); i++ ) - { - License license = licenses.get( i ); - properties.put( SbtPomExtraProperties.makeLicenseName(i), license.getName() ); - properties.put( SbtPomExtraProperties.makeLicenseUrl(i), license.getUrl() ); - properties.put( "license." + i + ".comments", license.getComments() ); - properties.put( "license." + i + ".distribution", license.getDistribution() ); - } - - // SBT ADDED - Here we push in the pom packaging type for Ivy expectations. - final String packaging = - (model.getPackaging() == null) ? "jar" : model.getPackaging(); - properties.put(SbtPomExtraProperties.MAVEN_PACKAGING_KEY, packaging); - // SBT ADDED - Here we inject the sbt/scala version we parse out of the pom. - final Properties mprops = model.getProperties(); - if(mprops.containsKey(SbtPomExtraProperties.POM_SBT_VERSION)) { - final String sbtVersion = mprops.getProperty(SbtPomExtraProperties.POM_SBT_VERSION); - properties.put(SbtPomExtraProperties.SBT_VERSION_KEY, sbtVersion); - } - if(mprops.containsKey(SbtPomExtraProperties.POM_SCALA_VERSION)) { - properties.put(SbtPomExtraProperties.SCALA_VERSION_KEY, mprops.getProperty(SbtPomExtraProperties.POM_SCALA_VERSION)); - } - - // SBT-Added - Here we inject the additional dependency attributes (for transitive plugin resolution). - PomExtraDependencyAttributes.transferDependencyExtraAttributes(model.getProperties(), properties); - - result.setProperties( properties); - - setArtifactProperties( result, model ); - } - - return result; - } - - // SBT FIX - We make sure that artifact properties are copied over here, so we can find sbt-plugin POM files. - public static Artifact toPomArtifact(Artifact artifact) { - Artifact pomArtifact = artifact; - if(artifact.getClassifier().length() > 0 || !"pom".equals(artifact.getExtension())) { - // TODO - only copy over sbt-important properties. - pomArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion()).setProperties(artifact.getProperties()); - } - return pomArtifact; - } - - private Model loadPom( RepositorySystemSession session, ArtifactDescriptorRequest request, - ArtifactDescriptorResult result ) - throws ArtifactDescriptorException - { - RequestTrace trace = RequestTrace.newChild( request.getTrace(), request ); - - Set visited = new LinkedHashSet(); - for ( Artifact artifact = request.getArtifact();; ) - { - // SBT FIX - we need to use our own variant here to preserve extra attributes. - // Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifact( artifact ); - Artifact pomArtifact = toPomArtifact(artifact); - try - { - VersionRequest versionRequest = - new VersionRequest( artifact, request.getRepositories(), request.getRequestContext() ); - versionRequest.setTrace( trace ); - VersionResult versionResult = versionResolver.resolveVersion( session, versionRequest ); - - artifact = artifact.setVersion( versionResult.getVersion() ); - - versionRequest = - new VersionRequest( pomArtifact, request.getRepositories(), request.getRequestContext() ); - versionRequest.setTrace( trace ); - versionResult = versionResolver.resolveVersion( session, versionRequest ); - - pomArtifact = pomArtifact.setVersion( versionResult.getVersion() ); - } - catch ( VersionResolutionException e ) - { - result.addException( e ); - throw new ArtifactDescriptorException( result ); - } - - if ( !visited.add( artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion() ) ) - { - RepositoryException exception = - new RepositoryException( "Artifact relocations form a cycle: " + visited ); - invalidDescriptor( session, trace, artifact, exception ); - if ( ( getPolicy( session, artifact, request ) & ArtifactDescriptorPolicy.IGNORE_INVALID ) != 0 ) - { - return null; - } - result.addException( exception ); - throw new ArtifactDescriptorException( result ); - } - - ArtifactResult resolveResult; - try - { - ArtifactRequest resolveRequest = - new ArtifactRequest( pomArtifact, request.getRepositories(), request.getRequestContext() ); - resolveRequest.setTrace( trace ); - resolveResult = artifactResolver.resolveArtifact( session, resolveRequest ); - pomArtifact = resolveResult.getArtifact(); - result.setRepository( resolveResult.getRepository() ); - } - catch ( ArtifactResolutionException e ) - { - if ( e.getCause() instanceof ArtifactNotFoundException ) - { - missingDescriptor( session, trace, artifact, (Exception) e.getCause() ); - if ( ( getPolicy( session, artifact, request ) & ArtifactDescriptorPolicy.IGNORE_MISSING ) != 0 ) - { - return null; - } - } - result.addException( e ); - throw new ArtifactDescriptorException( result ); - } - - Model model; - try - { - ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); - modelRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); - modelRequest.setProcessPlugins(false); - modelRequest.setTwoPhaseBuilding(false); - modelRequest.setSystemProperties(toProperties(session.getUserProperties(), - session.getSystemProperties())); - modelRequest.setModelCache(DefaultModelCache.newInstance(session)); - modelRequest.setModelResolver( - new DefaultModelResolver( - session, - trace.newChild(modelRequest), - request.getRequestContext(), - artifactResolver, - versionRangeResolver, - remoteRepositoryManager, - request.getRepositories()) - ); - if ( resolveResult.getRepository() instanceof WorkspaceRepository ) - { - modelRequest.setPomFile( pomArtifact.getFile() ); - } - else - { - modelRequest.setModelSource( new FileModelSource( pomArtifact.getFile() ) ); - } - - model = modelBuilder.build( modelRequest ).getEffectiveModel(); - } - catch ( ModelBuildingException e ) - { - for ( ModelProblem problem : e.getProblems() ) - { - if ( problem.getException() instanceof UnresolvableModelException ) - { - result.addException( problem.getException() ); - throw new ArtifactDescriptorException( result ); - } - } - invalidDescriptor( session, trace, artifact, e ); - if ( ( getPolicy( session, artifact, request ) & ArtifactDescriptorPolicy.IGNORE_INVALID ) != 0 ) - { - return null; - } - result.addException( e ); - throw new ArtifactDescriptorException( result ); - } - - Relocation relocation = getRelocation( model ); - - if ( relocation != null ) - { - result.addRelocation( artifact ); - artifact = - new RelocatedArtifact( artifact, relocation.getGroupId(), relocation.getArtifactId(), - relocation.getVersion() ); - result.setArtifact( artifact ); - } - else - { - return model; - } - } - } - - private Properties toProperties( Map dominant, Map recessive ) - { - Properties props = new Properties(); - if ( recessive != null ) - { - props.putAll( recessive ); - } - if ( dominant != null ) - { - props.putAll( dominant ); - } - return props; - } - - private Relocation getRelocation( Model model ) - { - Relocation relocation = null; - DistributionManagement distMngt = model.getDistributionManagement(); - if ( distMngt != null ) - { - relocation = distMngt.getRelocation(); - } - return relocation; - } - - private void setArtifactProperties( ArtifactDescriptorResult result, Model model ) - { - String downloadUrl = null; - DistributionManagement distMngt = model.getDistributionManagement(); - if ( distMngt != null ) - { - downloadUrl = distMngt.getDownloadUrl(); - } - if ( downloadUrl != null && downloadUrl.length() > 0 ) - { - Artifact artifact = result.getArtifact(); - Map props = new HashMap( artifact.getProperties() ); - props.put( ArtifactProperties.DOWNLOAD_URL, downloadUrl ); - result.setArtifact( artifact.setProperties( props ) ); - } - } - - private Dependency convert( org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes ) - { - ArtifactType stereotype = stereotypes.get( dependency.getType() ); - if ( stereotype == null ) - { - stereotype = new DefaultArtifactType( dependency.getType() ); - } - - boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0; - - Map props = null; - if ( system ) - { - props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, dependency.getSystemPath() ); - } - - Artifact artifact = - new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, - dependency.getVersion(), props, stereotype ); - - List exclusions = new ArrayList( dependency.getExclusions().size() ); - for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() ) - { - exclusions.add( convert( exclusion ) ); - } - - Dependency result = new Dependency( artifact, dependency.getScope(), dependency.isOptional(), exclusions ); - - return result; - } - - private Exclusion convert( org.apache.maven.model.Exclusion exclusion ) - { - return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" ); - } - - private void missingDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact, - Exception exception ) - { - RepositoryEvent.Builder event = new RepositoryEvent.Builder( session, EventType.ARTIFACT_DESCRIPTOR_MISSING ); - event.setTrace( trace ); - event.setArtifact( artifact ); - event.setException( exception ); - - repositoryEventDispatcher.dispatch( event.build() ); - } - - private void invalidDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact, - Exception exception ) - { - RepositoryEvent.Builder event = new RepositoryEvent.Builder( session, EventType.ARTIFACT_DESCRIPTOR_INVALID ); - event.setTrace( trace ); - event.setArtifact( artifact ); - event.setException( exception ); - - repositoryEventDispatcher.dispatch( event.build() ); - } - - private int getPolicy( RepositorySystemSession session, Artifact artifact, ArtifactDescriptorRequest request ) - { - ArtifactDescriptorPolicy policy = session.getArtifactDescriptorPolicy(); - if ( policy == null ) - { - return ArtifactDescriptorPolicy.STRICT; - } - return policy.getPolicy( session, new ArtifactDescriptorPolicyRequest( artifact, request.getRequestContext() ) ); - } - - public void setVersionRangeResolver(final VersionRangeResolver versionRangeResolver) { - this.versionRangeResolver = versionRangeResolver; - } -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/MavenResolverConverter.scala b/sbt-maven-resolver/src/main/scala/sbt/MavenResolverConverter.scala deleted file mode 100644 index cb52c0980..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/MavenResolverConverter.scala +++ /dev/null @@ -1,15 +0,0 @@ -package sbt - -import sbt.librarymanagement.{ MavenCache, MavenRepository, UpdateOptions } - -import UpdateOptions.ResolverConverter -import sbt.mavenint.{ MavenCacheRepositoryResolver, MavenRemoteRepositoryResolver } - -object MavenResolverConverter { - val converter: ResolverConverter = { - case (cache: MavenCache, settings, log) => - new MavenCacheRepositoryResolver(cache, settings) - case (repo: MavenRepository, settings, log) => - new MavenRemoteRepositoryResolver(repo, settings) - } -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/FileTransport.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/FileTransport.scala deleted file mode 100644 index 2966395e6..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/FileTransport.scala +++ /dev/null @@ -1,50 +0,0 @@ -package sbt.mavenint - -import org.apache.ivy.plugins.repository.Resource -import org.apache.ivy.plugins.repository.url.URLResource -import org.eclipse.aether.repository.RemoteRepository -import org.eclipse.aether.spi.connector.transport._ - -import sbt.io.IO - -/** - * A bridge file transportation protocol which uses some Ivy/sbt mechanisms. - */ -class FileTransport(repository: RemoteRepository) extends AbstractTransporter { - class NotFoundException(msg: String) extends Exception(msg) - private def toURL(task: TransportTask): java.net.URL = - try new java.net.URL(s"${repository.getUrl}/${task.getLocation.toASCIIString}") - catch { - case e: IllegalArgumentException => throw new IllegalArgumentException(s" URL (${task.getLocation}) is not absolute.") - } - private def toResource(task: TransportTask): Resource = new URLResource(toURL(task)) - private def toFile(task: TransportTask): java.io.File = - new java.io.File(toURL(task).toURI) - override def implPeek(peek: PeekTask): Unit = { - if (!toFile(peek).exists()) throw new NotFoundException(s"Could not find ${peek.getLocation}") - } - override def implClose(): Unit = () - override def implGet(out: GetTask): Unit = { - val from = toFile(out) - if (!from.exists()) throw new NotFoundException(s"Could not find ${out.getLocation}") - IO.copyFile(from, out.getDataFile, true) - } - override def implPut(put: PutTask): Unit = { - val to = toFile(put) - Option(put.getDataFile) match { - case Some(from) => - IO.copyFile(from, to, true) - case None => - // Here it's most likely a SHA or somethign where we read from memory. - val in = put.newInputStream - try IO.transfer(in, to) - finally in.close() - } - } - override def classify(err: Throwable): Int = - err match { - // TODO - Have we caught enough exceptions here? - case _: NotFoundException => Transporter.ERROR_NOT_FOUND - case _ => Transporter.ERROR_OTHER - } -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/HttpTransport.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/HttpTransport.scala deleted file mode 100644 index 21c0be482..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/HttpTransport.scala +++ /dev/null @@ -1,47 +0,0 @@ -package sbt.mavenint - -import org.apache.ivy.plugins.repository.Resource -import org.apache.ivy.plugins.repository.url.URLResource -import org.apache.ivy.util.url.URLHandlerRegistry -import org.eclipse.aether.repository.RemoteRepository -import org.eclipse.aether.spi.connector.transport._ - -/** Aether Http <-> Ivy Http adapter. Aether's is better, but Ivy's has configuration hooks in sbt. */ -class HttpTransport(repository: RemoteRepository) extends AbstractTransporter { - class NotFoundException(msg: String) extends Exception(msg) - private def toURL(task: TransportTask): java.net.URL = - try new java.net.URL(s"${repository.getUrl}/${task.getLocation.toASCIIString}") - catch { - case e: IllegalArgumentException => throw new IllegalArgumentException(s" URL (${task.getLocation}) is not absolute.") - } - private def toResource(task: TransportTask): Resource = new URLResource(toURL(task)) - override def implPeek(peek: PeekTask): Unit = { - if (!toResource(peek).exists()) throw new NotFoundException(s"Could not find ${peek.getLocation}") - } - override def implClose(): Unit = () - override def implGet(out: GetTask): Unit = { - if (!toResource(out).exists()) throw new NotFoundException(s"Could not find ${out.getLocation}") - URLHandlerRegistry.getDefault.download(toURL(out), out.getDataFile, null) - } - override def implPut(put: PutTask): Unit = { - val to = toURL(put) - Option(put.getDataFile) match { - case Some(file) => URLHandlerRegistry.getDefault.upload(file, to, null) - case None => - // TODO - Ivy does not support uploading not from a file. This isn't very efficient in ANY way, - // so if we rewrite the URL handler for Ivy we should fix this as well. - sbt.io.IO.withTemporaryFile("tmp", "upload") { file => - val in = put.newInputStream() - try sbt.io.IO.transfer(in, file) - finally in.close() - URLHandlerRegistry.getDefault.upload(file, to, null) - } - } - } - override def classify(err: Throwable): Int = - err match { - // TODO - Have we caught all the important exceptions here. - case _: NotFoundException => Transporter.ERROR_NOT_FOUND - case _ => Transporter.ERROR_OTHER - } -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenCacheRepositoryResolver.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenCacheRepositoryResolver.scala deleted file mode 100644 index feda8eb7e..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenCacheRepositoryResolver.scala +++ /dev/null @@ -1,88 +0,0 @@ -package sbt -package mavenint - -import org.apache.ivy.core.module.id.ModuleRevisionId -import org.apache.ivy.core.settings.IvySettings -import org.eclipse.aether.artifact.{ DefaultArtifact => AetherArtifact } -import org.eclipse.aether.installation.{ InstallRequest => AetherInstallRequest } -import org.eclipse.aether.metadata.{ DefaultMetadata, Metadata } -import org.eclipse.aether.resolution.{ - ArtifactDescriptorRequest => AetherDescriptorRequest, - ArtifactRequest => AetherArtifactRequest, - MetadataRequest => AetherMetadataRequest, - VersionRequest => AetherVersionRequest, - VersionRangeRequest => AetherVersionRangeRequest -} - -import sbt.internal.librarymanagement.ivyint.CustomMavenResolver -import sbt.librarymanagement.MavenCache - -import scala.collection.JavaConverters._ - -import sbt.io.IO - -/** - * A resolver instance which can resolve from a maven CACHE. - * - * Note: This should never hit somethign remote, as it just looks in the maven cache for things already resolved. - */ -class MavenCacheRepositoryResolver(val repo: MavenCache, settings: IvySettings) - extends MavenRepositoryResolver(settings) with CustomMavenResolver { - setName(repo.name) - protected val system = MavenRepositorySystemFactory.newRepositorySystemImpl - IO.createDirectory(repo.rootFile) - protected val session = MavenRepositorySystemFactory.newSessionImpl(system, repo.rootFile) - protected def setRepository(request: AetherMetadataRequest): AetherMetadataRequest = request - protected def addRepositories(request: AetherDescriptorRequest): AetherDescriptorRequest = request - protected def addRepositories(request: AetherArtifactRequest): AetherArtifactRequest = request - protected def addRepositories(request: AetherVersionRequest): AetherVersionRequest = request - protected def addRepositories(request: AetherVersionRangeRequest): AetherVersionRangeRequest = request - protected def publishArtifacts(artifacts: Seq[AetherArtifact]): Unit = { - val request = new AetherInstallRequest() - artifacts foreach request.addArtifact - system.install(session, request) - } - // TODO - Share this with non-local repository code, since it's MOSTLY the same. - protected def getPublicationTime(mrid: ModuleRevisionId): Option[Long] = { - val metadataRequest = new AetherMetadataRequest() - metadataRequest.setMetadata( - new DefaultMetadata( - mrid.getOrganisation, - mrid.getName, - mrid.getRevision, - MavenRepositoryResolver.MAVEN_METADATA_XML, - Metadata.Nature.RELEASE_OR_SNAPSHOT)) - val metadataResultOpt = - try system.resolveMetadata(session, java.util.Arrays.asList(metadataRequest)).asScala.headOption - catch { - case e: org.eclipse.aether.resolution.ArtifactResolutionException => None - } - try metadataResultOpt match { - case Some(md) if md.isResolved => - import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader - import org.codehaus.plexus.util.ReaderFactory - val readMetadata = { - val reader = ReaderFactory.newXmlReader(md.getMetadata.getFile) - try new MetadataXpp3Reader().read(reader, false) - finally reader.close() - } - val timestampOpt = - for { - v <- Option(readMetadata.getVersioning) - sp <- Option(v.getSnapshot) - ts <- Option(sp.getTimestamp) - t <- MavenRepositoryResolver.parseTimeString(ts) - } yield t - val lastUpdatedOpt = - for { - v <- Option(readMetadata.getVersioning) - lu <- Option(v.getLastUpdated) - d <- MavenRepositoryResolver.parseTimeString(lu) - } yield d - // TODO - Only look at timestamp *IF* the version is for a snapshot. - timestampOpt orElse lastUpdatedOpt - case _ => None - } - } - override def toString = s"${repo.name}: ${repo.root}" -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRemoteRepositoryResolver.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRemoteRepositoryResolver.scala deleted file mode 100644 index e50b1e905..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRemoteRepositoryResolver.scala +++ /dev/null @@ -1,105 +0,0 @@ -package sbt -package mavenint - -import org.apache.ivy.core.IvyContext -import org.apache.ivy.core.module.id.ModuleRevisionId -import org.apache.ivy.core.settings.IvySettings -import org.eclipse.aether.artifact.{ DefaultArtifact => AetherArtifact } -import org.eclipse.aether.deployment.{ DeployRequest => AetherDeployRequest } -import org.eclipse.aether.metadata.{ DefaultMetadata, Metadata } -import org.eclipse.aether.resolution.{ - ArtifactDescriptorRequest => AetherDescriptorRequest, - ArtifactDescriptorResult => AetherDescriptorResult, - ArtifactRequest => AetherArtifactRequest, - MetadataRequest => AetherMetadataRequest, - VersionRequest => AetherVersionRequest, - VersionRangeRequest => AetherVersionRangeRequest -} - -import sbt.internal.librarymanagement.ivyint.CustomRemoteMavenResolver -import sbt.librarymanagement.MavenRepository - -import scala.collection.JavaConverters._ - -/** - * A resolver instance which can resolve from a REMOTE maven repository. - * - * Note: This creates its *own* local cache directory for cache metadata. using its name. - * - */ -class MavenRemoteRepositoryResolver(val repo: MavenRepository, settings: IvySettings) - extends MavenRepositoryResolver(settings) with CustomRemoteMavenResolver { - setName(repo.name) - override def toString = s"${repo.name}: ${repo.root}" - protected val system = MavenRepositorySystemFactory.newRepositorySystemImpl - // Note: All maven repository resolvers will use the SAME maven cache. - // We're not sure if we care whether or not this means that the wrong resolver may report finding an artifact. - // The key is not to duplicate files repeatedly across many caches. - private val localRepo = new java.io.File(settings.getDefaultIvyUserDir, s"maven-cache") - sbt.io.IO.createDirectory(localRepo) - protected val session = MavenRepositorySystemFactory.newSessionImpl(system, localRepo) - private val aetherRepository = { - new org.eclipse.aether.repository.RemoteRepository.Builder(repo.name, SbtRepositoryLayout.LAYOUT_NAME, repo.root).build() - } - // TODO - Check if isUseCacheOnly is used correctly. - private def isUseCacheOnly: Boolean = - Option(IvyContext.getContext).flatMap(x => Option(x.getResolveData)).flatMap(x => Option(x.getOptions)).map(_.isUseCacheOnly).getOrElse(false) - protected def addRepositories(request: AetherDescriptorRequest): AetherDescriptorRequest = - if (isUseCacheOnly) request else request.addRepository(aetherRepository) - protected def addRepositories(request: AetherArtifactRequest): AetherArtifactRequest = - if (isUseCacheOnly) request else request.addRepository(aetherRepository) - protected def addRepositories(request: AetherVersionRequest): AetherVersionRequest = - if (isUseCacheOnly) request else request.addRepository(aetherRepository) - protected def addRepositories(request: AetherVersionRangeRequest): AetherVersionRangeRequest = - if (isUseCacheOnly) request else request.addRepository(aetherRepository) - - /** Actually publishes aether artifacts. */ - protected def publishArtifacts(artifacts: Seq[AetherArtifact]): Unit = { - val request = new AetherDeployRequest() - request.setRepository(aetherRepository) - artifacts foreach request.addArtifact - system.deploy(session, request) - } - protected def getPublicationTime(mrid: ModuleRevisionId): Option[Long] = { - val metadataRequest = new AetherMetadataRequest() - metadataRequest.setMetadata( - new DefaultMetadata( - mrid.getOrganisation, - mrid.getName, - mrid.getRevision, - MavenRepositoryResolver.MAVEN_METADATA_XML, - Metadata.Nature.RELEASE_OR_SNAPSHOT)) - if (!isUseCacheOnly) metadataRequest.setRepository(aetherRepository) - val metadataResultOpt = - try system.resolveMetadata(session, java.util.Arrays.asList(metadataRequest)).asScala.headOption - catch { - case e: org.eclipse.aether.resolution.ArtifactResolutionException => None - } - try metadataResultOpt match { - case Some(md) if md.isResolved => - import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader - import org.codehaus.plexus.util.ReaderFactory - val readMetadata = { - val reader = ReaderFactory.newXmlReader(md.getMetadata.getFile) - try new MetadataXpp3Reader().read(reader, false) - finally reader.close() - } - val timestampOpt = - for { - v <- Option(readMetadata.getVersioning) - sp <- Option(v.getSnapshot) - ts <- Option(sp.getTimestamp) - t <- MavenRepositoryResolver.parseTimeString(ts) - } yield t - val lastUpdatedOpt = - for { - v <- Option(readMetadata.getVersioning) - lu <- Option(v.getLastUpdated) - d <- MavenRepositoryResolver.parseTimeString(lu) - } yield d - // TODO - Only look at timestamp *IF* the version is for a snapshot. - timestampOpt orElse lastUpdatedOpt - case _ => None - } - } -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala deleted file mode 100644 index 1c81936fa..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala +++ /dev/null @@ -1,564 +0,0 @@ -package sbt.mavenint - -import java.io.File -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.{ 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.{ 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 -import org.apache.ivy.plugins.resolver.util.ResolvedResource -import org.apache.ivy.util.Message -import org.eclipse.aether.artifact.{ DefaultArtifact => AetherArtifact } -import org.eclipse.aether.deployment.{ DeployRequest => AetherDeployRequest } -import org.eclipse.aether.installation.{ InstallRequest => AetherInstallRequest } -import org.eclipse.aether.metadata.{ DefaultMetadata, Metadata } -import org.eclipse.aether.resolution.{ - ArtifactDescriptorRequest => AetherDescriptorRequest, - ArtifactDescriptorResult => AetherDescriptorResult, - ArtifactRequest => AetherArtifactRequest, - ArtifactResolutionException, - MetadataRequest => AetherMetadataRequest, - VersionRequest => AetherVersionRequest, - VersionRangeRequest => AetherVersionRangeRequest -} -import org.eclipse.aether.{ RepositorySystem, RepositorySystemSession } - -import sbt.internal.librarymanagement.ivyint.{ CustomMavenResolver, CustomRemoteMavenResolver } -import sbt.internal.librarymanagement.mavenint.{ PomExtraDependencyAttributes, SbtPomExtraProperties } -import sbt.internal.librarymanagement.MakePom - -import sbt.mavenint.MavenRepositoryResolver.JarPackaging - -import scala.collection.JavaConverters._ - -object MavenRepositoryResolver { - val MAVEN_METADATA_XML = "maven-metadata.xml" - val CLASSIFIER_ATTRIBUTE = "e:classifier" - // TODO - This may be duplciated in more than one location. We need to consolidate. - val JarPackagings = Set("eclipse-plugin", "hk2-jar", "orbit", "scala-jar", "jar", "bundle") - object JarPackaging { - def unapply(in: String): Boolean = JarPackagings.contains(in) - } - // Example: 2014 12 18 09 33 56 - val LAST_UPDATE_FORMAT = new java.text.SimpleDateFormat("yyyyMMddhhmmss") - def parseTimeString(in: String): Option[Long] = - try Some(LAST_UPDATE_FORMAT.parse(in).getTime) - catch { - case _: java.text.ParseException => None - } - val DEFAULT_ARTIFACT_CONFIGURATION = "master" -} - -/** - * An abstract repository resolver which has the basic hooks for mapping from Maven (Aether) notions into Ivy notions. - * - * THis is used to implement local-cache resolution from ~/.m2 caches or resolving from remote repositories. - */ -abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractResolver { - - /** Our instance of the aether repository system. */ - protected val system: RepositorySystem - /** - * Our instance of the aether repository system session. - * - * TODO - We may want to tie this into an IvyContext. - */ - protected val session: RepositorySystemSession - - /** Determine the publication time of a module. The mechanism may differ if the repository is remote vs. local. */ - protected def getPublicationTime(mrid: ModuleRevisionId): Option[Long] - /** Inject necessary repositories into a descriptor request. */ - protected def addRepositories(request: AetherDescriptorRequest): AetherDescriptorRequest - protected def addRepositories(request: AetherArtifactRequest): AetherArtifactRequest - protected def addRepositories(request: AetherVersionRequest): AetherVersionRequest - protected def addRepositories(request: AetherVersionRangeRequest): AetherVersionRangeRequest - - /** Actually publishes aether artifacts. */ - protected def publishArtifacts(artifacts: Seq[AetherArtifact]): Unit - - // TOOD - deal with packaging here. - private def aetherArtifactIdFromMrid(mrid: ModuleRevisionId): String = - getSbtVersion(mrid) match { - case Some(sbt) => s"${mrid.getName}_sbt_$sbt" - case None => mrid.getName - } - private def aetherCoordsFromMrid(mrid: ModuleRevisionId): String = - s"${mrid.getOrganisation}:${aetherArtifactIdFromMrid(mrid)}:${mrid.getRevision}" - - private def aetherCoordsFromMrid(mrid: ModuleRevisionId, packaging: String): String = - s"${mrid.getOrganisation}:${aetherArtifactIdFromMrid(mrid)}:$packaging:${mrid.getRevision}" - - private def aetherCoordsFromMrid(mrid: ModuleRevisionId, packaging: String, extension: String): String = - s"${mrid.getOrganisation}:${aetherArtifactIdFromMrid(mrid)}:$extension:$packaging:${mrid.getRevision}" - - // Handles appending licenses to the module descriptor fromthe pom. - private def addLicenseInfo(md: DefaultModuleDescriptor, map: java.util.Map[String, AnyRef]) = { - val count = map.get(SbtPomExtraProperties.LICENSE_COUNT_KEY) match { - case null => 0 - case x: java.lang.Integer => x.intValue - case x: String => x.toInt - case _ => 0 - } - for { - i <- 0 until count - name <- Option(map.get(SbtPomExtraProperties.makeLicenseName(i))).map(_.toString) - url <- Option(map.get(SbtPomExtraProperties.makeLicenseUrl(i))).map(_.toString) - } md.addLicense(new License(name, url)) - } - - // This grabs the dependency for Ivy. - override def getDependency(dd: DependencyDescriptor, rd: ResolveData): ResolvedModuleRevision = { - val context = IvyContext.pushNewCopyContext - try { - val drid: ModuleRevisionId = - if (MakePom.isDependencyVersionRange(dd.getDependencyRevisionId.getRevision)) { - Message.debug(s"Got a dynamic revision, attempting to convert to real revision: ${dd.getDependencyRevisionId}") - val revision = MakePom.makeDependencyVersion(dd.getDependencyRevisionId.getRevision) - // TODO - Alter revision id to be maven-friendly first. - val coords = - s"${dd.getDependencyRevisionId.getOrganisation}:${aetherArtifactIdFromMrid(dd.getDependencyRevisionId)}:${revision}" - //val coords = aetherCoordsFromMrid(dd.getDependencyRevisionId) - Message.debug(s"Aether about to resolve version for [$coords]...") - val versionRequest = addRepositories(new AetherVersionRangeRequest().setArtifact(new AetherArtifact(coords, getArtifactProperties(dd.getDependencyRevisionId)))) - val result = system.resolveVersionRange(session, versionRequest) - Message.debug(s"Version result = $result, from $getName") - if (result.getVersions.isEmpty) throw new MavenResolutionException(s"Did not find any versions for $dd") - ModuleRevisionId.newInstance( - dd.getDependencyRevisionId.getOrganisation, - dd.getDependencyRevisionId.getName, - result.getHighestVersion.toString, - dd.getExtraAttributes) - } else dd.getDependencyRevisionId - - // TODO - Check to see if we're asking for latest.* version, and if so, we should run a latest version query - // first and use that result to return the metadata/final module. - Message.debug(s"Requesting conf [${dd.getModuleConfigurations.mkString(",")}] from Aether module ${drid} in resolver ${getName}") - val request = new AetherDescriptorRequest() - val coords = aetherCoordsFromMrid(drid) - Message.debug(s"Aether about to resolve [$coords]...") - request.setArtifact(new AetherArtifact(coords, getArtifactProperties(drid))) - addRepositories(request) - val result = system.readArtifactDescriptor(session, request) - val packaging = getPackagingFromPomProperties(result.getProperties) - Message.debug(s"Aether resolved ${dd.getDependencyId} w/ packaging ${packaging}") - - // TODO - better pub date if we have no metadata. - val lastModifiedTime = getPublicationTime(drid) getOrElse 0L - - // Construct a new Ivy module descriptor - val desc: ModuleDescriptor = { - // TODO - Better detection of snapshot and handling latest.integration/latest.snapshot - val status = - if (drid.getRevision.endsWith("-SNAPSHOT")) "integration" - else "release" - val md = - new DefaultModuleDescriptor(drid, status, null /* pubDate */ , false) - //DefaultModuleDescriptor.newDefaultInstance(dd.getDependencyRevisionId) - // Here we add the standard configurations - for (config <- PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS) { - md.addConfiguration(config) - } - - // Here we look into the artifacts specified from the dependency descriptor *and* those that are defaulted, - // and append them to the appropriate configurations. - // TODO - Feed correct revision down here - addArtifactsFromPom(drid, dd, packaging, md, lastModifiedTime) - // Here we add dependencies. - addDependenciesFromAether(result, md) - // Here we use pom.xml Dependency management section to create Ivy dependency mediators. - addManagedDependenciesFromAether(result, md) - - // Here we rip out license info. - addLicenseInfo(md, result.getProperties) - md.addExtraInfo(SbtPomExtraProperties.MAVEN_PACKAGING_KEY, packaging) - Message.debug(s"Setting publication date to ${new Date(lastModifiedTime)}") - // TODO - Figure out the differences between these items. - md.setPublicationDate(new Date(lastModifiedTime)) - md.setLastModified(lastModifiedTime) - md.setResolvedPublicationDate(new Date(lastModifiedTime)) - md.check() - // TODO - do we need the toSystem? - toSystem(md) - } - - // Here we need to pretend we downloaded the pom.xml file - val pom = DefaultArtifact.newPomArtifact(drid, new java.util.Date(lastModifiedTime)) - val madr = new MetadataArtifactDownloadReport(pom) - madr.setSearched(true) - madr.setDownloadStatus(DownloadStatus.SUCCESSFUL) // TODO - Figure this things out for this report. - val rmr = new ResolvedModuleRevision(this, this, desc, madr, false /* Force */ ) - - // TODO - Here we cache the transformed pom.xml into an ivy.xml in the cache because ChainResolver will be looking at it. - // This doesn't appear to really work correctly. - // However, I think the chain resolver doesn't use this instance anyway. Ideally we don't put anything - // in the ivy cache, but this should be "ok". - getRepositoryCacheManager.originalToCachedModuleDescriptor(this, - null /* ivyRef. Just passed back to us. */ , - pom, - rmr, - new ModuleDescriptorWriter() { - def write(originalMdResource: ResolvedResource, md: ModuleDescriptor, src: File, dest: File): Unit = { - // a basic ivy file is written containing default data - XmlModuleDescriptorWriter.write(md, dest); - } - } - ) - rmr - } catch { - case e: org.eclipse.aether.resolution.ArtifactDescriptorException => - Message.info(s"Failed to read descriptor ${dd} from ${getName}, ${e.getMessage}") - rd.getCurrentResolvedModuleRevision - case e: MavenResolutionException => - Message.debug(s"Resolution Exception from ${getName}, ${e.getMessage}, returning: ${rd.getCurrentResolvedModuleRevision}") - rd.getCurrentResolvedModuleRevision - } finally IvyContext.popContext() - } - - def getSbtVersion(dd: ModuleRevisionId): Option[String] = - Option(dd.getExtraAttribute(PomExtraDependencyAttributes.SbtVersionKey)) - - def getArtifactProperties(dd: ModuleRevisionId): java.util.Map[String, String] = { - val m = new java.util.HashMap[String, String] - Option(dd.getExtraAttribute(PomExtraDependencyAttributes.ScalaVersionKey)) foreach { sv => - m.put(SbtPomExtraProperties.POM_SCALA_VERSION, sv) - } - getSbtVersion(dd) foreach { sv => - m.put(SbtPomExtraProperties.POM_SBT_VERSION, sv) - } - m - } - - final def checkJarArtifactExists(dd: ModuleRevisionId): Boolean = { - // TODO - We really want this to be as fast/efficient as possible! - val request = new AetherArtifactRequest() - val art = new AetherArtifact( - aetherCoordsFromMrid(dd, "jar"), - getArtifactProperties(dd)) - request.setArtifact(art) - addRepositories(request) - try { - val result = system.resolveArtifact(session, request) - result.isResolved && !result.isMissing - } catch { - case e: ArtifactResolutionException => - // Ignore, as we're just working around issues with pom.xml's with no jars or POM packaging - Message.debug(s"Could not find $art in ${getName}") - false - } - } - - /** Determines which artifacts are associated with this maven module and appends them to the descriptor. */ - def addArtifactsFromPom(drid: ModuleRevisionId, dd: DependencyDescriptor, packaging: String, md: DefaultModuleDescriptor, lastModifiedTime: Long): Unit = { - Message.debug(s"Calculating artifacts for ${dd.getDependencyId} w/ packaging $packaging") - // Here we add in additional artifact requests, which ALLWAYS have to be explicit since - // Maven/Aether doesn't include all known artifacts in a pom.xml - // TODO - This does not appear to be working correctly. - if (dd.getAllDependencyArtifacts.isEmpty) { - val artifactId = s"${drid.getName}-${drid.getRevision}" - // Add the artifacts we know about the module - packaging match { - case "pom" => - // THere we have to attempt to download the JAR and see if it comes, if not, we can punt. - // This is because sometimes pom-packaging attaches a JAR. - if (checkJarArtifactExists(drid)) { - val defaultArt = - new DefaultArtifact(md.getModuleRevisionId, new Date(lastModifiedTime), artifactId, packaging, "jar") - md.addArtifact(MavenRepositoryResolver.DEFAULT_ARTIFACT_CONFIGURATION, defaultArt) - } - case JarPackaging() => - // Here we fail the resolution. This is an issue when pom.xml files exist with no JAR, which happens - // on maven central for some reason on old artifacts. - if (!checkJarArtifactExists(drid)) - throw new MavenResolutionException(s"Failed to find JAR file associated with $dd") - // Assume for now everything else is a jar. - val defaultArt = - new DefaultArtifact(md.getModuleRevisionId, new Date(lastModifiedTime), artifactId, packaging, "jar") - // TODO - Unfortunately we have to try to download the JAR file HERE and then fail resolution if we cannot find it. - // This is because sometime a pom.xml exists with no JARs. - md.addArtifact(MavenRepositoryResolver.DEFAULT_ARTIFACT_CONFIGURATION, defaultArt) - case _ => // Ignore, we have no idea what this artifact is. - Message.warn(s"Not adding artifacts for resolution because we don't understand packaging: $packaging") - } - - } else { - // NOTE: this means that someone is requested specific artifacts from us. What we need to do is *only* download the - // requested artifacts rather than the default "jar". What's odd, is that pretty much this almost ALWAYS happens. - // but in some circumstances, the above logic is checked. - // Additionally, we may want to somehow merge the "defined" artifacts from maven with the requested ones here, rather - // than having completely separate logic. For now, this appears to work the same way it was before. - // Since we aren't accurately guessing what maven files are meant to be included as artifacts ANYWAY, this - // is probably the right way to go. - for (requestedArt <- dd.getAllDependencyArtifacts) { - getClassifier(requestedArt) match { - case None => - // This is the default artifact. We do need to add this, and to the default configuration. - val defaultArt = - new DefaultArtifact(md.getModuleRevisionId, new Date(lastModifiedTime), requestedArt.getName, requestedArt.getType, requestedArt.getExt) - md.addArtifact(MavenRepositoryResolver.DEFAULT_ARTIFACT_CONFIGURATION, defaultArt) - case Some(scope) => - Message.debug(s"Adding additional artifact in $scope, $requestedArt") - // TODO - more Extra attributes? - val mda = - new MDArtifact( - md, - requestedArt.getName, - requestedArt.getType, - requestedArt.getExt, - requestedArt.getUrl, - requestedArt.getExtraAttributes) - md.addArtifact(getConfiguration(scope), mda) - } - } - } - } - - /** Adds the dependency mediators required based on the managed dependency instances from this pom. */ - 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, - new OverrideDependencyDescriptorMediator(null, d.getArtifact.getVersion) { - override def mediate(dd: DependencyDescriptor): DependencyDescriptor = { - super.mediate(dd) - } - }) - - } - } - - /** Adds the list of dependencies this artifact has on other artifacts. */ - 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 - // dependency correctly. - val extraAttributes = PomExtraDependencyAttributes.readFromAether(result.getProperties) - for (d <- result.getDependencies.asScala) { - // TODO - Is this correct for changing detection. We should use the Ivy mechanism configured... - val isChanging = d.getArtifact.getVersion.endsWith("-SNAPSHOT") - val drid = { - val tmp = ModuleRevisionId.newInstance(d.getArtifact.getGroupId, d.getArtifact.getArtifactId, d.getArtifact.getVersion) - extraAttributes get tmp match { - case Some(props) => - Message.debug(s"Found $tmp w/ extra attributes ${props.mkString(",")}") - ModuleRevisionId.newInstance( - d.getArtifact.getGroupId, - d.getArtifact.getArtifactId, - d.getArtifact.getVersion, - props.asJava - ) - case _ => tmp - } - } - - // Note: The previous maven integration ALWAYS set force to true for dependnecies. If we do not do this, for some - // reason, Ivy will create dummy nodes when doing dependnecy mediation (e.g. dependencyManagement of one pom overrides version of a dependency) - // which was leading to "data not found" exceptions as Ivy would pick the correct IvyNode in the dependency tree but never load it with data.... - val dd = new DefaultDependencyDescriptor(md, drid, /* force */ true, isChanging, true) {} - - // 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) - 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.... - if ((d.getArtifact.getClassifier != null) || ((d.getArtifact.getExtension != null) && !("jar" == d.getArtifact.getExtension))) { - val tpe: String = - if (d.getArtifact.getExtension != null) d.getArtifact.getExtension - else "jar" - val ext: String = tpe match { - case "test-jar" => "jar" - case JarPackaging() => "jar" - case other => other - } - // Here we add the classifier, hopefully correctly... - val extraAtt = new java.util.HashMap[String, AnyRef]() - if (d.getArtifact.getClassifier != null) { - extraAtt.put("m:classifier", d.getArtifact.getClassifier) - } - val depArtifact: DefaultDependencyArtifactDescriptor = - new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId.getName, tpe, ext, null, extraAtt) - val optionalizedScope: String = if (d.isOptional) "optional" else scope - // 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) - } - } - - // This method appears to be deprecated/unused in all of Ivy so we do not implement it. - override def findIvyFileRef(dd: DependencyDescriptor, rd: ResolveData): ResolvedResource = { - Message.error(s"Looking for ivy file ref, method not implemented! MavenRepositoryResolver($getName) will always return null.") - null - } - - private def getPackagingFromPomProperties(props: java.util.Map[String, AnyRef]): String = - if (props.containsKey(SbtPomExtraProperties.MAVEN_PACKAGING_KEY)) - props.get(SbtPomExtraProperties.MAVEN_PACKAGING_KEY).toString - else "jar" - - override def download(artifacts: Array[Artifact], dopts: DownloadOptions): DownloadReport = { - // TODO - Status reports on download and possibly parallel downloads - val report = new DownloadReport - val requests = - for (a <- artifacts) yield { - val request = new AetherArtifactRequest - val aetherArt = - getClassifier(a) match { - case None | Some("") => - new AetherArtifact( - aetherCoordsFromMrid(a.getModuleRevisionId), - getArtifactProperties(a.getModuleRevisionId)) - case Some(other) => new AetherArtifact( - aetherCoordsFromMrid(a.getModuleRevisionId, other, a.getExt), - getArtifactProperties(a.getModuleRevisionId)) - } - Message.debug(s"Requesting download of [$aetherArt]") - request.setArtifact(aetherArt) - addRepositories(request) - request - } - val (aetherResults, failed) = - try { - (system.resolveArtifacts(session, requests.toList.asJava).asScala, false) - } catch { - case e: org.eclipse.aether.resolution.ArtifactResolutionException => - Message.error(s"Failed to resolve artifacts from ${getName}, ${e.getMessage}") - (e.getResults.asScala, true) - } - for ((result, art) <- aetherResults zip artifacts) { - Message.debug(s"Aether resolved artifact result: $result") - val adr = new ArtifactDownloadReport(art) - adr.setDownloadDetails(result.toString) - // TODO - Fill this out with a real estimate on time... - adr.setDownloadTimeMillis(0L) - // TODO - what is artifact origin actuallyused for? - adr.setArtifactOrigin(new ArtifactOrigin( - art, - true, - getName)) - if (result.isMissing) { - adr.setDownloadStatus(DownloadStatus.FAILED) - adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT) - } else if (!result.isResolved) { - adr.setDownloadStatus(DownloadStatus.FAILED) - adr.setDownloadDetails(result.toString) - // TODO - we should set download status to NO in the event we don't care about an artifact... - } else { - val file = result.getArtifact.getFile - Message.debug(s"Succesffully downloaded: $file") - adr.setLocalFile(file) - adr.setSize(file.length) - adr.setDownloadStatus(DownloadStatus.SUCCESSFUL) - } - report.addArtifactReport(adr) - } - report - } - - case class PublishTransaction(module: ModuleRevisionId, artifacts: Seq[(Artifact, File)]) - private var currentTransaction: Option[PublishTransaction] = None - - override def beginPublishTransaction(module: ModuleRevisionId, overwrite: Boolean): Unit = { - currentTransaction match { - case Some(t) => throw new IllegalStateException(s"Publish Transaction already open for [$getName]") - case None => currentTransaction = Some(PublishTransaction(module, Nil)) - } - } - override def abortPublishTransaction(): Unit = { - currentTransaction = None - } - - def getClassifier(art: Artifact): Option[String] = - // TODO - Do we need to look anywere else? - Option(art.getExtraAttribute("classifier")) - - def getClassifier(art: org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor): Option[String] = - art.getType match { - case "doc" | "javadoc" => Some("javadoc") - case "src" | "source" => Some("sources") - case "test-jar" | "test" => Some("tests") - case _ => - // Look for extra attributes - art.getExtraAttribute(MavenRepositoryResolver.CLASSIFIER_ATTRIBUTE) match { - case null => None - case c => Some(c) - } - } - - def getConfiguration(classifier: String): String = - classifier match { - // TODO - choice of configuration actually depends on whether or not the artifact is - // REQUESTED by the user, in which case it should be on master. - // Currently, we don't actually look for sources/javadoc/test artifacts at all, - // which means any artifact is in the master configuration, but we should - // fix this for better integration into the maven ecosystem from ivy. - //case "sources" => "sources" - //case "javadoc" => "javadoc" - case other => MavenRepositoryResolver.DEFAULT_ARTIFACT_CONFIGURATION - } - - override def commitPublishTransaction(): Unit = { - // TODO - actually send all artifacts to aether - currentTransaction match { - case Some(t) => - Message.debug(s"Publishing module ${t.module}, with artifact count = ${t.artifacts.size}") - val artifacts = - for ((art, file) <- t.artifacts) yield { - Message.debug(s" - Publishing $art (${art.getType})(${art.getExtraAttribute("classifier")}) in [${art.getConfigurations.mkString(",")}] from $file") - new AetherArtifact( - t.module.getOrganisation, - aetherArtifactIdFromMrid(t.module), - getClassifier(art).orNull, - art.getExt, - t.module.getRevision, - getArtifactProperties(t.module), - file - ) - } - publishArtifacts(artifacts) - // TODO - Any kind of validity checking? - currentTransaction = None - case None => throw new IllegalStateException(s"Publish Transaction already open for [$getName]") - } - } - - override def publish(art: Artifact, file: File, overwrite: Boolean): Unit = { - currentTransaction match { - case Some(t) => - val allArts = t.artifacts ++ List(art -> file) - currentTransaction = Some(t.copy(artifacts = allArts)) - case None => - throw new IllegalStateException(("MavenRepositories require transactional publish")) - } - } - - override def equals(a: Any): Boolean = - a match { - case x: MavenRepositoryResolver => x.getName == getName - case _ => false - } - override def hashCode: Int = getName.hashCode -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositorySystemFactory.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositorySystemFactory.scala deleted file mode 100644 index 61ec668de..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositorySystemFactory.scala +++ /dev/null @@ -1,62 +0,0 @@ -package sbt.mavenint - -import java.io.File - -import org.apache.ivy.plugins.repository.Resource -import org.apache.ivy.plugins.repository.url.URLResource -import org.apache.ivy.util.Message -import org.apache.ivy.util.url.URLHandlerRegistry -import org.apache.maven.repository.internal.{ MavenRepositorySystemUtils, SbtArtifactDescriptorReader, SnapshotMetadataGeneratorFactory, VersionsMetadataGeneratorFactory, DefaultVersionResolver } -import org.eclipse.aether.{ RepositorySystem, RepositorySystemSession } -import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory -import org.eclipse.aether.impl.{ ArtifactDescriptorReader, DefaultServiceLocator, MetadataGeneratorFactory, VersionResolver } -import org.eclipse.aether.repository.{ LocalRepository, RemoteRepository } -import org.eclipse.aether.spi.connector.RepositoryConnectorFactory -import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory -import org.eclipse.aether.spi.connector.transport.{ TransporterFactory, _ } - -/** Helper methods for dealing with starting up Aether. */ -object MavenRepositorySystemFactory { - def newRepositorySystemImpl: RepositorySystem = { - // For now we just log Aether instantiation issues. These should probably cause fatal errors. - val locator = MavenRepositorySystemUtils.newServiceLocator() - locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler { - override def serviceCreationFailed(tpe: Class[_], impl: Class[_], exception: Throwable): Unit = { - Message.error(s"Failed to create $tpe, of class $impl") - } - }) - // Here we register the Ivy <-> Aether transport bridge - locator.addService(classOf[TransporterFactory], classOf[MyTransportFactory]) - // This connects the download mechanism to our transports. Why is it needed? no clue. - locator.addService(classOf[RepositoryConnectorFactory], classOf[BasicRepositoryConnectorFactory]) - - // Plugins cause issues here, as their layout is super odd. Here we inject a new plugin layout - locator.addService(classOf[RepositoryLayoutFactory], classOf[SbtPluginLayoutFactory]) - - // Here we add the metadata services so aether will automatically add maven-metadata.xml files. - locator.addService(classOf[MetadataGeneratorFactory], classOf[SnapshotMetadataGeneratorFactory]) - locator.addService(classOf[MetadataGeneratorFactory], classOf[VersionsMetadataGeneratorFactory]) - - // Add our hook for parsing pom.xml files. - locator.setService(classOf[ArtifactDescriptorReader], classOf[SbtArtifactDescriptorReader]) - // Finally, use the DI to create our repository system. - locator.getService(classOf[RepositorySystem]) - } - def newSessionImpl(system: RepositorySystem, localRepoDir: File): RepositorySystemSession = { - val session = MavenRepositorySystemUtils.newSession() - val localRepo = new LocalRepository(localRepoDir) - session setLocalRepositoryManager (system.newLocalRepositoryManager(session, localRepo)) - // Here we set a descriptor policy that FORCES the pom.xml to exist, otherwise Ivy's resolution - // algorithm freaks out. What we could do is also do the ivy lame-thing of checking for a JAR - // instead of a pom.xml, but let's see if this is actually a problem in practice. - val descriptorPolicy = new org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy( - /* ignoreMissing */ false, /* ignoreInvalid. */ true) - session.setArtifactDescriptorPolicy(descriptorPolicy) - session - } - - def defaultLocalRepo: java.io.File = { - new java.io.File(s"${sys.props("user.home")}/.m2/repository") - } -} - diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenResolutionException.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenResolutionException.scala deleted file mode 100644 index 3c46d71cb..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenResolutionException.scala +++ /dev/null @@ -1,4 +0,0 @@ -package sbt.mavenint - -/** An exception we can throw if we encounter issues. */ -class MavenResolutionException(msg: String) extends RuntimeException(msg) {} diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MyTransportFactory.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MyTransportFactory.scala deleted file mode 100644 index 013a48d0a..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MyTransportFactory.scala +++ /dev/null @@ -1,16 +0,0 @@ -package sbt.mavenint - -import org.eclipse.aether.RepositorySystemSession -import org.eclipse.aether.repository.RemoteRepository -import org.eclipse.aether.spi.connector.transport.{ Transporter, TransporterFactory } - -/** Override aether's default transport with Ivy-ones. */ -class MyTransportFactory extends TransporterFactory { - override def newInstance(session: RepositorySystemSession, repository: RemoteRepository): Transporter = - repository.getProtocol match { - case "http" | "https" => new HttpTransport(repository) - case "file" => new FileTransport(repository) - case other => throw new IllegalArgumentException(s"Unsupported transport protocol: $other") - } - override def getPriority: Float = 1.0f -} \ No newline at end of file diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/SbtRepositoryLayout.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/SbtRepositoryLayout.scala deleted file mode 100644 index 77d065cf1..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/SbtRepositoryLayout.scala +++ /dev/null @@ -1,99 +0,0 @@ -package sbt.mavenint - -import java.net.URI - -import org.eclipse.aether.RepositorySystemSession -import org.eclipse.aether.artifact.Artifact -import org.eclipse.aether.metadata.Metadata -import org.eclipse.aether.repository.RemoteRepository -import org.eclipse.aether.spi.connector.layout.RepositoryLayout.Checksum -import org.eclipse.aether.spi.connector.layout.{ RepositoryLayout, RepositoryLayoutFactory } -import org.eclipse.aether.transfer.NoRepositoryLayoutException - -import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties - -import scala.util.matching.Regex - -/** A factory which knows how to create repository layouts which can find sbt plugins. */ -class SbtPluginLayoutFactory extends RepositoryLayoutFactory { - def newInstance(session: RepositorySystemSession, repository: RemoteRepository): RepositoryLayout = { - repository.getContentType match { - case SbtRepositoryLayout.LAYOUT_NAME => - SbtRepositoryLayout - case _ => throw new NoRepositoryLayoutException(repository, "Not an sbt-plugin repository") - } - } - def getPriority: Float = 100.0f -} - -object SbtRepositoryLayout extends RepositoryLayout { - - val LAYOUT_NAME = "sbt-plugin" - - // get location is ALMOST the same for Metadata + artifact... but subtle differences are important. - - def getLocation(artifact: Artifact, upload: Boolean): URI = { - val sbtVersion = Option(artifact.getProperties.get(SbtPomExtraProperties.POM_SBT_VERSION)) - val scalaVersion = Option(artifact.getProperties.get(SbtPomExtraProperties.POM_SCALA_VERSION)) - val path = new StringBuilder(128) - path.append(artifact.getGroupId.replace('.', '/')).append('/') - (sbtVersion zip scalaVersion).headOption match { - case Some((sbt, scala)) => - if (artifact.getArtifactId contains "_sbt_") { - val SbtNameVersionSplit(name, sbt2) = artifact.getArtifactId - path.append(name).append('_').append(scala).append('_').append(sbt).append('/') - } else path.append(artifact.getArtifactId).append('_').append(scala).append('_').append(sbt).append('/') - case None => - // TODO - Should we automatically append the _ here if it's not there? Probably not for now. - path.append(artifact.getArtifactId).append('/') - } - path.append(artifact.getBaseVersion).append('/') - sbtVersion match { - case Some(_) if artifact.getArtifactId contains "_sbt_" => - val SbtNameVersionSplit(name, sbt2) = artifact.getArtifactId - path.append(name).append('-').append(artifact.getVersion) - case None => path.append(artifact.getArtifactId).append('-').append(artifact.getVersion) - } - - if (artifact.getClassifier != null && !artifact.getClassifier.trim.isEmpty) { - path.append("-").append(artifact.getClassifier) - } - if (artifact.getExtension.length > 0) { - path.append('.').append(artifact.getExtension) - } - URI.create(path.toString()) - } - - // Trickery for disambiguating sbt plugins in maven repositories. - val SbtNameVersionSplit = new Regex("(.*)_sbt_(.*)") - - def getLocation(metadata: Metadata, upload: Boolean): URI = { - val sbtVersion = Option(metadata.getProperties.get(SbtPomExtraProperties.POM_SBT_VERSION)) - val scalaVersion = Option(metadata.getProperties.get(SbtPomExtraProperties.POM_SCALA_VERSION)) - val path = new StringBuilder(128) - path.append(metadata.getGroupId.replace('.', '/')).append('/') - (sbtVersion zip scalaVersion).headOption match { - case Some((sbt, scala)) => - if (metadata.getArtifactId contains "_sbt_") { - val SbtNameVersionSplit(name, sbt2) = metadata.getArtifactId - path.append(name).append('_').append(scala).append('_').append(sbt).append('/') - } else path.append(metadata.getArtifactId).append('_').append(scala).append('_').append(sbt).append('/') - case None => - // TODO - Should we automatically append the _ here? Proabbly not for now. - path.append(metadata.getArtifactId).append('/') - } - if (metadata.getVersion.length > 0) - path.append(metadata.getVersion).append('/') - path.append(metadata.getType) - URI.create(path.toString) - } - - // TODO - This should be the same as configured from Ivy... - def getChecksums(artifact: Artifact, upload: Boolean, location: URI): java.util.List[Checksum] = - getChecksums(location) - def getChecksums(metadata: Metadata, upload: Boolean, location: URI): java.util.List[Checksum] = - getChecksums(location) - - private def getChecksums(location: URI): java.util.List[Checksum] = - java.util.Arrays.asList(Checksum.forLocation(location, "SHA-1"), Checksum.forLocation(location, "MD5")) -} diff --git a/sbt-maven-resolver/src/main/scala/sbt/plugins/MavenResolverPlugin.scala b/sbt-maven-resolver/src/main/scala/sbt/plugins/MavenResolverPlugin.scala deleted file mode 100644 index df166e568..000000000 --- a/sbt-maven-resolver/src/main/scala/sbt/plugins/MavenResolverPlugin.scala +++ /dev/null @@ -1,13 +0,0 @@ -package sbt -package plugins - -import Keys._ - -object MavenResolverPlugin extends AutoPlugin { - override def requires = IvyPlugin - override def trigger = allRequirements - - override lazy val projectSettings: Seq[Setting[_]] = Seq( - updateOptions := updateOptions.value.withResolverConverter(MavenResolverConverter.converter) - ) -} diff --git a/sbt-maven-resolver/src/test/scala/MavenResolutionSpec.scala b/sbt-maven-resolver/src/test/scala/MavenResolutionSpec.scala deleted file mode 100644 index 183ded0b3..000000000 --- a/sbt-maven-resolver/src/test/scala/MavenResolutionSpec.scala +++ /dev/null @@ -1,293 +0,0 @@ -package sbt - -import java.io.FileInputStream - -import sbt.internal.librarymanagement.BaseIvySpecification -import sbt.internal.librarymanagement.mavenint.PomExtraDependencyAttributes -import sbt.librarymanagement.{ Artifact, Configurations, CrossVersion, DefaultMavenRepository, MavenRepository, ModuleID, Resolver, UpdateOptions } - -import sbt.internal.util.ShowLines - -class MavenResolutionSpec extends BaseIvySpecification { - - "the maven resolution" should "handle sbt plugins" in resolveSbtPlugins - - it should "use ivy for conflict resolution" in resolveMajorConflicts - it should "handle cross configuration deps" in resolveCrossConfigurations - it should "publish with maven-metadata" in publishMavenMetadata - it should "resolve transitive maven dependencies" in resolveTransitiveMavenDependency - it should "resolve intransitive maven dependencies" in resolveIntransitiveMavenDependency - it should "handle transitive configuration shifts" in resolveTransitiveConfigurationMavenDependency - it should "resolve source and doc" in resolveSourceAndJavadoc - it should "resolve nonstandard (jdk5) classifier" in resolveNonstandardClassifier - it should "Resolve pom artifact dependencies" in resolvePomArtifactAndDependencies - it should "Fail if JAR artifact is not found w/ POM" in failIfMainArtifactMissing - it should "Fail if POM.xml is not found" in failIfPomMissing - it should "resolve publication date for -SNAPSHOT" in resolveSnapshotPubDate - - // TODO - test latest.integration and .+ - - def akkaActor = ModuleID("com.typesafe.akka", "akka-actor_2.11", "2.3.8", Some("compile")) - def akkaActorTestkit = ModuleID("com.typesafe.akka", "akka-testkit_2.11", "2.3.8", Some("test")) - def testngJdk5 = ModuleID("org.testng", "testng", "5.7", Some("compile")).classifier("jdk15") - def jmxri = ModuleID("com.sun.jmx", "jmxri", "1.2.1", Some("compile")) - def scalaLibraryAll = ModuleID("org.scala-lang", "scala-library-all", "2.11.4", Some("compile")) - def scalaCompiler = ModuleID("org.scala-lang", "scala-compiler", "2.8.1", Some("scala-tool->default(compile)")) - def scalaContinuationPlugin = ModuleID("org.scala-lang.plugins", "continuations", "2.8.1", Some("plugin->default(compile)")) - def sbtPlugin = - ModuleID("com.github.mpeltonen", "sbt-idea", "1.6.0", Some("compile")). - extra(PomExtraDependencyAttributes.SbtVersionKey -> "0.13", PomExtraDependencyAttributes.ScalaVersionKey -> "2.10"). - copy(crossVersion = CrossVersion.Disabled) - def oldSbtPlugin = - ModuleID("com.github.mpeltonen", "sbt-idea", "1.6.0", Some("compile")). - extra(PomExtraDependencyAttributes.SbtVersionKey -> "0.12", PomExtraDependencyAttributes.ScalaVersionKey -> "2.9.2"). - copy(crossVersion = CrossVersion.Disabled) - def majorConflictLib = ModuleID("com.joestelmach", "natty", "0.3", Some("compile")) - // TODO - This snapshot and resolver should be something we own/control so it doesn't disappear on us. - def testSnapshot = ModuleID("com.typesafe", "config", "0.4.9-SNAPSHOT", Some("compile")) - val SnapshotResolver = MavenRepository("some-snapshots", "https://oss.sonatype.org/content/repositories/snapshots/") - - override def resolvers = Seq(DefaultMavenRepository, SnapshotResolver, Resolver.publishMavenLocal) - import Configurations.{ Compile, Test, Runtime, CompilerPlugin, ScalaTool } - override def configurations = Seq(Compile, Test, Runtime, CompilerPlugin, ScalaTool) - - import ShowLines._ - - def defaultUpdateOptions = UpdateOptions().withResolverConverter(MavenResolverConverter.converter) - - def resolveMajorConflicts = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), - Seq(majorConflictLib), None, defaultUpdateOptions) - val report = ivyUpdate(m) // should not(throwAn[IllegalStateException]) - val jars = - for { - conf <- report.configurations - if conf.configuration == Compile.name - m <- conf.modules - if (m.module.name contains "stringtemplate") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - jars should have size 1 - } - - def resolveCrossConfigurations = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), - Seq(scalaCompiler, scalaContinuationPlugin), None, defaultUpdateOptions) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - if conf.configuration == ScalaTool.name - m <- conf.modules - if (m.module.name contains "scala-compiler") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - jars should have size 1 - } - - def resolveSbtPlugins = { - - def sha(f: java.io.File): String = sbt.io.Hash.toHex(sbt.io.Hash(f)) - def findSbtIdeaJars(dep: ModuleID, name: String) = { - val m = module(ModuleID("com.example", name, "0.1.0", Some("compile")), Seq(dep), None, defaultUpdateOptions) - val report = ivyUpdate(m) - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if (m.module.name contains "sbt-idea") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield (f, sha(f)) - } - - val oldJars = findSbtIdeaJars(oldSbtPlugin, "old") - System.err.println(s"${oldJars.mkString("\n")}") - val newJars = findSbtIdeaJars(sbtPlugin, "new") - System.err.println(s"${newJars.mkString("\n")}") - (newJars should have size 1) - (oldJars should have size 1) - (oldJars.map(_._2) should not(contain theSameElementsAs (newJars.map(_._2)))) - } - - def resolveSnapshotPubDate = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(testSnapshot), Some("2.10.2"), defaultUpdateOptions.withLatestSnapshots(true)) - val report = ivyUpdate(m) - val pubTime = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if m.module.revision endsWith "-SNAPSHOT" - date <- m.publicationDate - } yield date - (pubTime should have size 1) - } - - def resolvePomArtifactAndDependencies = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(scalaLibraryAll), Some("2.10.2"), defaultUpdateOptions) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if (m.module.name == "scala-library") || (m.module.name contains "parser") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - jars should have size 2 - } - - def failIfPomMissing = { - // TODO - we need the jar to not exist too. - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(ModuleID("org.scala-sbt", "does-not-exist", "1.0", Some("compile"))), Some("2.10.2"), defaultUpdateOptions) - an[Exception] should be thrownBy ivyUpdate(m) - } - - def failIfMainArtifactMissing = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(jmxri), Some("2.10.2"), defaultUpdateOptions) - an[Exception] should be thrownBy ivyUpdate(m) - } - - def resolveNonstandardClassifier = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(testngJdk5), Some("2.10.2"), defaultUpdateOptions) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if m.module.name == "testng" - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - (report.configurations should have size configurations.size) - (jars should have size 1) - (jars.forall(_.exists) shouldBe true) - - } - - def resolveTransitiveMavenDependency = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(akkaActor), Some("2.10.2"), defaultUpdateOptions) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if m.module.name == "scala-library" - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - (report.configurations should have size configurations.size) - (jars should not be empty) - (jars.forall(_.exists) shouldBe true) - - } - - def resolveIntransitiveMavenDependency = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(akkaActorTestkit.intransitive()), Some("2.10.2"), defaultUpdateOptions) - val report = ivyUpdate(m) - val transitiveJars = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if (m.module.name contains "akka-actor") && !(m.module.name contains "testkit") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - val directJars = - for { - conf <- report.configurations - if conf.configuration == "compile" - m <- conf.modules - if (m.module.name contains "akka-actor") && (m.module.name contains "testkit") - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - (report.configurations should have size configurations.size) - (transitiveJars shouldBe empty) - (directJars.forall(_.exists) shouldBe true) - } - - def resolveTransitiveConfigurationMavenDependency = { - val m = module(ModuleID("com.example", "foo", "0.1.0", Some("compile")), Seq(akkaActorTestkit), Some("2.10.2"), defaultUpdateOptions) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - if conf.configuration == "test" - m <- conf.modules - if m.module.name contains "akka-actor" - (a, f) <- m.artifacts - if a.extension == "jar" - } yield f - (report.configurations should have size configurations.size) - (jars should not be empty) - (jars.forall(_.exists) shouldBe true) - - } - - def resolveSourceAndJavadoc = { - val m = module( - ModuleID("com.example", "foo", "0.1.0", Some("sources")), - Seq(akkaActor.artifacts(Artifact(akkaActor.name, "javadoc"), Artifact(akkaActor.name, "sources"))), - Some("2.10.2"), - defaultUpdateOptions - ) - val report = ivyUpdate(m) - val jars = - for { - conf <- report.configurations - // We actually injected javadoc/sources into the compile scope, due to how we did the request. - // SO, we report that here. - if conf.configuration == "compile" - m <- conf.modules - (a, f) <- m.artifacts - if (f.getName contains "sources") || (f.getName contains "javadoc") - } yield f - (report.configurations should have size configurations.size) - (jars should have size 2) - } - - def publishMavenMetadata = { - val m = module( - ModuleID("com.example", "test-it", "1.0-SNAPSHOT", Some("compile")), - Seq(), - None, - defaultUpdateOptions.withLatestSnapshots(true) - ) - sbt.io.IO.withTemporaryDirectory { dir => - val pomFile = new java.io.File(dir, "pom.xml") - sbt.io.IO.write(pomFile, - """ - | - | com.example - | test-it - | 1.0-SNAPSHOT - | - """.stripMargin) - val jarFile = new java.io.File(dir, "test-it-1.0-SNAPSHOT.jar") - sbt.io.IO.touch(jarFile) - System.err.println(s"DEBUGME - Publishing $m to ${Resolver.publishMavenLocal}") - ivyPublish(m, mkPublishConfiguration( - Resolver.publishMavenLocal, - Map( - Artifact("test-it-1.0-SNAPSHOT.jar") -> pomFile, - Artifact("test-it-1.0-SNAPSHOT.pom", "pom", "pom") -> jarFile - ))) - } - val baseLocalMavenDir: java.io.File = Resolver.publishMavenLocal.rootFile - val allFiles: Seq[java.io.File] = sbt.io.PathFinder(new java.io.File(baseLocalMavenDir, "com/example/test-it")).allPaths.get - val metadataFiles = allFiles.filter(_.getName contains "maven-metadata-local") - // TODO - maybe we check INSIDE the metadata, or make sure we can get a publication date on resolve... - // We end up with 4 files, two mavne-metadata files, and 2 maven-metadata-local files. - metadataFiles should have size 2 - } - -} - diff --git a/sbt/src/main/scala/Import.scala b/sbt/src/main/scala/Import.scala index 4bd3928bf..2916a3c53 100644 --- a/sbt/src/main/scala/Import.scala +++ b/sbt/src/main/scala/Import.scala @@ -1,7 +1,6 @@ package sbt object Import { - // sbt.io val AllPassFilter = sbt.io.AllPassFilter val DirectoryFilter = sbt.io.DirectoryFilter diff --git a/sbt/src/sbt-test/actions/compile-time-only/build.sbt b/sbt/src/sbt-test/actions/compile-time-only/build.sbt index 5baf27554..a95c64199 100644 --- a/sbt/src/sbt-test/actions/compile-time-only/build.sbt +++ b/sbt/src/sbt-test/actions/compile-time-only/build.sbt @@ -1,4 +1,4 @@ -libraryDependencies += "org.scala-sbt" % "sbt" % sbtVersion.value +libraryDependencies += "org.scala-sbt" %% "sbt" % sbtVersion.value lazy val expectErrorNotCrash = taskKey[Unit]("Ensures that sbt properly set types on Trees so that the compiler doesn't crash on a bad reference to .value, but gives a proper error instead.") diff --git a/sbt/src/sbt-test/apiinfo/basic/build.sbt b/sbt/src/sbt-test/apiinfo/basic/build.sbt new file mode 100644 index 000000000..cc6aa3d78 --- /dev/null +++ b/sbt/src/sbt-test/apiinfo/basic/build.sbt @@ -0,0 +1,4 @@ +lazy val root = (project in file(".")). + settings( + scalaVersion := "2.10.6" + ) diff --git a/sbt/src/sbt-test/dependency-management/cache-classifiers/project/maven.sbt b/sbt/src/sbt-test/dependency-management/cache-classifiers/project/maven.sbt index 1ae548913..aa9b1813f 100644 --- a/sbt/src/sbt-test/dependency-management/cache-classifiers/project/maven.sbt +++ b/sbt/src/sbt-test/dependency-management/cache-classifiers/project/maven.sbt @@ -1,2 +1,2 @@ -libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value, - sbtBinaryVersion.value, scalaBinaryVersion.value) +// libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value, +// sbtBinaryVersion.value, scalaBinaryVersion.value) diff --git a/sbt/src/sbt-test/dependency-management/cross-conflict/build.sbt b/sbt/src/sbt-test/dependency-management/cross-conflict/build.sbt index 097d7674c..2e19d296a 100644 --- a/sbt/src/sbt-test/dependency-management/cross-conflict/build.sbt +++ b/sbt/src/sbt-test/dependency-management/cross-conflict/build.sbt @@ -1,3 +1,4 @@ +scalaVersion := "2.10.6" libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "1.9.1" % "test", "org.scalamock" %% "scalamock-scalatest-support" % "3.0" % "test" diff --git a/sbt/src/sbt-test/dependency-management/dynamic-revision/build.sbt b/sbt/src/sbt-test/dependency-management/dynamic-revision/build.sbt index 53db09db6..ec0e3eefe 100644 --- a/sbt/src/sbt-test/dependency-management/dynamic-revision/build.sbt +++ b/sbt/src/sbt-test/dependency-management/dynamic-revision/build.sbt @@ -1,5 +1,6 @@ lazy val root = (project in file(".")). settings( + scalaVersion := "2.10.6", libraryDependencies += "org.webjars" %% "webjars-play" % "2.1.0-3", resolvers += Resolver.typesafeRepo("releases") ) diff --git a/sbt/src/sbt-test/dependency-management/ivy-settings-a/build.sbt b/sbt/src/sbt-test/dependency-management/ivy-settings-a/build.sbt index 43349d48c..ed427e146 100644 --- a/sbt/src/sbt-test/dependency-management/ivy-settings-a/build.sbt +++ b/sbt/src/sbt-test/dependency-management/ivy-settings-a/build.sbt @@ -3,6 +3,6 @@ import sbt.internal.librarymanagement.syntax._ seq(externalIvySettings(), externalIvyFile()) TaskKey[Unit]("check") := { - val files = update.value.matching( moduleFilter(organization = "org.scalacheck", name = "scalacheck*", revision = "1.9") ) + val files = update.value.matching( moduleFilter(organization = "org.scalacheck", name = "scalacheck*", revision = "1.11.4") ) assert(files.nonEmpty, "ScalaCheck module not found in update report") } \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/ivy-settings-a/changes/scalacheck-ivy.xml b/sbt/src/sbt-test/dependency-management/ivy-settings-a/changes/scalacheck-ivy.xml index 0eea774cf..4084d70ff 100644 --- a/sbt/src/sbt-test/dependency-management/ivy-settings-a/changes/scalacheck-ivy.xml +++ b/sbt/src/sbt-test/dependency-management/ivy-settings-a/changes/scalacheck-ivy.xml @@ -2,6 +2,6 @@ - + diff --git a/sbt/src/sbt-test/dependency-management/t468/test b/sbt/src/sbt-test/dependency-management/t468/pending similarity index 100% rename from sbt/src/sbt-test/dependency-management/t468/test rename to sbt/src/sbt-test/dependency-management/t468/pending diff --git a/sbt/src/sbt-test/dependency-management/t468/project/maven.sbt b/sbt/src/sbt-test/dependency-management/t468/project/maven.sbt index 1ae548913..aa9b1813f 100644 --- a/sbt/src/sbt-test/dependency-management/t468/project/maven.sbt +++ b/sbt/src/sbt-test/dependency-management/t468/project/maven.sbt @@ -1,2 +1,2 @@ -libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value, - sbtBinaryVersion.value, scalaBinaryVersion.value) +// libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value, +// sbtBinaryVersion.value, scalaBinaryVersion.value) diff --git a/sbt/src/sbt-test/dependency-management/update-sbt-classifiers/project/plugins.sbt b/sbt/src/sbt-test/dependency-management/update-sbt-classifiers/project/plugins.sbt index b749d93bc..edc6ecae0 100644 --- a/sbt/src/sbt-test/dependency-management/update-sbt-classifiers/project/plugins.sbt +++ b/sbt/src/sbt-test/dependency-management/update-sbt-classifiers/project/plugins.sbt @@ -1 +1 @@ -libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value \ No newline at end of file +libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value \ No newline at end of file diff --git a/sbt/src/sbt-test/project/default-settings/build.sbt b/sbt/src/sbt-test/project/default-settings/build.sbt index 48dd37168..eb3cb4c16 100644 --- a/sbt/src/sbt-test/project/default-settings/build.sbt +++ b/sbt/src/sbt-test/project/default-settings/build.sbt @@ -1,5 +1,10 @@ val root = (project in file(".")) +TaskKey[Unit]("checkScalaVersion", "test") := { + val sv = scalaVersion.value + assert(sv startsWith "2.11.", s"Found $sv!") +} + TaskKey[Unit]("checkArtifacts", "test") := { val arts = packagedArtifacts.value assert(arts.nonEmpty, "Packaged artifacts must not be empty!") diff --git a/sbt/src/sbt-test/project/default-settings/test b/sbt/src/sbt-test/project/default-settings/test index 6a559c60a..d55f0991d 100644 --- a/sbt/src/sbt-test/project/default-settings/test +++ b/sbt/src/sbt-test/project/default-settings/test @@ -1 +1,2 @@ > checkArtifacts +> checkScalaVersion diff --git a/sbt/src/sbt-test/project/generated-root-no-publish/test b/sbt/src/sbt-test/project/generated-root-no-publish/test index 3cfdd4401..9b428f03a 100644 --- a/sbt/src/sbt-test/project/generated-root-no-publish/test +++ b/sbt/src/sbt-test/project/generated-root-no-publish/test @@ -1,10 +1,10 @@ > publishLocal -$ exists target/ivy-cache/local/com.example/app_2.10/0.1.0/poms/app_2.10.pom -$ exists target/ivy-cache/local/com.example/app_2.10/0.1.0/jars/app_2.10.jar -$ absent target/ivy-cache/local/com.example/default-root_2.10/0.1.0/ivys/ivy.xml +$ exists target/ivy-cache/local/com.example/app_2.11/0.1.0/poms/app_2.11.pom +$ exists target/ivy-cache/local/com.example/app_2.11/0.1.0/jars/app_2.11.jar +$ absent target/ivy-cache/local/com.example/default-root_2.11/0.1.0/ivys/ivy.xml $ copy-file changes/bare.sbt build.sbt > reload > publishLocal -$ exists target/ivy-cache/local/com.example/generated-root-no-publish_2.10/0.1.0/poms/generated-root-no-publish_2.10.pom -$ exists target/ivy-cache/local/com.example/generated-root-no-publish_2.10/0.1.0/jars/generated-root-no-publish_2.10.jar +$ exists target/ivy-cache/local/com.example/generated-root-no-publish_2.11/0.1.0/poms/generated-root-no-publish_2.11.pom +$ exists target/ivy-cache/local/com.example/generated-root-no-publish_2.11/0.1.0/jars/generated-root-no-publish_2.11.jar diff --git a/sbt/src/sbt-test/project/scripted-plugin/project/plugins.sbt b/sbt/src/sbt-test/project/scripted-plugin/project/plugins.sbt index 8cbc845fd..db3e94022 100644 --- a/sbt/src/sbt-test/project/scripted-plugin/project/plugins.sbt +++ b/sbt/src/sbt-test/project/scripted-plugin/project/plugins.sbt @@ -1,3 +1,3 @@ libraryDependencies <+= sbtVersion { sv => - "org.scala-sbt" % "scripted-plugin" % sv + "org.scala-sbt" %% "scripted-plugin" % sv } diff --git a/sbt/src/sbt-test/project/scripted13/project/plugins.sbt b/sbt/src/sbt-test/project/scripted13/project/plugins.sbt index 748bfc6b5..56c9892bd 100644 --- a/sbt/src/sbt-test/project/scripted13/project/plugins.sbt +++ b/sbt/src/sbt-test/project/scripted13/project/plugins.sbt @@ -1,5 +1,5 @@ libraryDependencies <+= sbtVersion { sbtv => - "org.scala-sbt" % "scripted-plugin" % sbtv + "org.scala-sbt" %% "scripted-plugin" % sbtv } offline := true diff --git a/sbt/src/sbt-test/project/src-plugins/plugin/build.sbt b/sbt/src/sbt-test/project/src-plugins/plugin/build.sbt index 039c85119..6857f0a9f 100644 --- a/sbt/src/sbt-test/project/src-plugins/plugin/build.sbt +++ b/sbt/src/sbt-test/project/src-plugins/plugin/build.sbt @@ -1,2 +1,2 @@ libraryDependencies += - "org.scala-sbt" % "sbt" % appConfiguration.value.provider.id.version + "org.scala-sbt" %% "sbt" % appConfiguration.value.provider.id.version diff --git a/sbt/src/sbt-test/source-dependencies/continuations/build.sbt b/sbt/src/sbt-test/source-dependencies/continuations/build.sbt index 407a68d5e..34fff642b 100644 --- a/sbt/src/sbt-test/source-dependencies/continuations/build.sbt +++ b/sbt/src/sbt-test/source-dependencies/continuations/build.sbt @@ -1,5 +1,4 @@ +scalaVersion := "2.10.6" autoCompilerPlugins := true - libraryDependencies += compilerPlugin("org.scala-lang.plugins" % "continuations" % scalaVersion.value) - scalacOptions += "-P:continuations:enable" diff --git a/sbt/src/sbt-test/source-dependencies/inherited-macros/build.sbt b/sbt/src/sbt-test/source-dependencies/inherited-macros/build.sbt index 5ecf2dc5b..85676b5fa 100644 --- a/sbt/src/sbt-test/source-dependencies/inherited-macros/build.sbt +++ b/sbt/src/sbt-test/source-dependencies/inherited-macros/build.sbt @@ -1,4 +1,5 @@ val defaultSettings = Seq( + scalaVersion := "2.10.6", libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ )//, //incOptions := incOptions.value.withNameHashing(true) ) diff --git a/sbt/src/sbt-test/source-dependencies/macro-arg-dep-nested/build.sbt b/sbt/src/sbt-test/source-dependencies/macro-arg-dep-nested/build.sbt index 17be9b032..f569c7377 100644 --- a/sbt/src/sbt-test/source-dependencies/macro-arg-dep-nested/build.sbt +++ b/sbt/src/sbt-test/source-dependencies/macro-arg-dep-nested/build.sbt @@ -1,4 +1,5 @@ val defaultSettings = Seq( + scalaVersion := "2.10.6", libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ ) ) diff --git a/sbt/src/sbt-test/source-dependencies/macro-arg-dep/build.sbt b/sbt/src/sbt-test/source-dependencies/macro-arg-dep/build.sbt index 17be9b032..f569c7377 100644 --- a/sbt/src/sbt-test/source-dependencies/macro-arg-dep/build.sbt +++ b/sbt/src/sbt-test/source-dependencies/macro-arg-dep/build.sbt @@ -1,4 +1,5 @@ val defaultSettings = Seq( + scalaVersion := "2.10.6", libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ ) ) diff --git a/sbt/src/sbt-test/source-dependencies/macro/build.sbt b/sbt/src/sbt-test/source-dependencies/macro/build.sbt index 5ecf2dc5b..85676b5fa 100644 --- a/sbt/src/sbt-test/source-dependencies/macro/build.sbt +++ b/sbt/src/sbt-test/source-dependencies/macro/build.sbt @@ -1,4 +1,5 @@ val defaultSettings = Seq( + scalaVersion := "2.10.6", libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ )//, //incOptions := incOptions.value.withNameHashing(true) ) diff --git a/sbt/src/sbt-test/tests/arguments-new/build.sbt b/sbt/src/sbt-test/tests/arguments-new/build.sbt index a406c7638..e1037fbda 100644 --- a/sbt/src/sbt-test/tests/arguments-new/build.sbt +++ b/sbt/src/sbt-test/tests/arguments-new/build.sbt @@ -1,3 +1,4 @@ +scalaVersion := "2.10.6" libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0.M6-SNAP28" % "test" diff --git a/sbt/src/sbt-test/tests/fork2/build.sbt b/sbt/src/sbt-test/tests/fork2/build.sbt index 5cd90472e..3156665b5 100644 --- a/sbt/src/sbt-test/tests/fork2/build.sbt +++ b/sbt/src/sbt-test/tests/fork2/build.sbt @@ -1,3 +1,4 @@ +scalaVersion := "2.10.6" fork := true -libraryDependencies += "org.scalatest" %% "scalatest" % "1.9" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "1.9" % "test" diff --git a/sbt/src/sbt-test/tests/it/build.sbt b/sbt/src/sbt-test/tests/it/build.sbt index 3903021d9..421d8c032 100644 --- a/sbt/src/sbt-test/tests/it/build.sbt +++ b/sbt/src/sbt-test/tests/it/build.sbt @@ -1,6 +1,7 @@ lazy val root = (project in file(".")). configs(IntegrationTest). settings( + scalaVersion := "2.10.6", Defaults.itSettings, libraryDependencies += specs ) diff --git a/sbt/src/sbt-test/tests/resources/build.sbt b/sbt/src/sbt-test/tests/resources/build.sbt index 3e6a355f7..7905ed044 100644 --- a/sbt/src/sbt-test/tests/resources/build.sbt +++ b/sbt/src/sbt-test/tests/resources/build.sbt @@ -1 +1,2 @@ +scalaVersion := "2.10.6" libraryDependencies += "org.specs2" % "specs2_2.10" % "1.12.3" % "test" diff --git a/sbt/src/sbt-test/tests/setup-cleanup/base.sbt b/sbt/src/sbt-test/tests/setup-cleanup/base.sbt index afd509cbc..0afca122e 100644 --- a/sbt/src/sbt-test/tests/setup-cleanup/base.sbt +++ b/sbt/src/sbt-test/tests/setup-cleanup/base.sbt @@ -1 +1,2 @@ -libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" \ No newline at end of file +scalaVersion := "2.10.6" +libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" diff --git a/sbt/src/sbt-test/tests/test-exclude/build.sbt b/sbt/src/sbt-test/tests/test-exclude/build.sbt index 002dbaaa9..3d05c8130 100644 --- a/sbt/src/sbt-test/tests/test-exclude/build.sbt +++ b/sbt/src/sbt-test/tests/test-exclude/build.sbt @@ -1,5 +1,6 @@ lazy val root = (project in file(".")). settings( + scalaVersion := "2.10.6", libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % Test, parallelExecution in test := false ) diff --git a/sbt/src/sbt-test/tests/test-quick/build.sbt b/sbt/src/sbt-test/tests/test-quick/build.sbt index 002dbaaa9..3d05c8130 100755 --- a/sbt/src/sbt-test/tests/test-quick/build.sbt +++ b/sbt/src/sbt-test/tests/test-quick/build.sbt @@ -1,5 +1,6 @@ lazy val root = (project in file(".")). settings( + scalaVersion := "2.10.6", libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % Test, parallelExecution in test := false ) diff --git a/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala b/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala index b24da61cb..e74a8d365 100644 --- a/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala +++ b/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala @@ -39,7 +39,7 @@ object ScriptedPlugin extends AutoPlugin { sbtLauncher <<= getJars(scriptedLaunchConf).map(_.get.head), sbtTestDirectory := sourceDirectory.value / "sbt-test", libraryDependencies ++= Seq( - "org.scala-sbt" % "scripted-sbt" % scriptedSbt.value % scriptedConf.toString, + "org.scala-sbt" %% "scripted-sbt" % scriptedSbt.value % scriptedConf.toString, "org.scala-sbt" % "sbt-launch" % scriptedSbt.value % scriptedLaunchConf.toString ), scriptedBufferLog := true,