Skip to content

Commit

Permalink
sbt.Plugin -> sbt.AutoPlugin which lets us make the S3RawRepository i…
Browse files Browse the repository at this point in the history
…mplicit automatically available
  • Loading branch information
tpunder committed Oct 8, 2014
1 parent ae11ec1 commit cc9f1b5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/main/scala/fm/sbt/S3Implicits.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2014 Frugal Mechanic (http://frugalmechanic.com)
*
* Licensed 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.
*/
package fm.sbt

object S3Implicits extends S3Implicits

trait S3Implicits {
implicit def toS3RawRepository(name: String): S3RawRepository = new S3RawRepository(name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
package fm.sbt

import java.util.{Collections, List}
import org.apache.ivy.core.module.descriptor.DependencyDescriptor
import sbt.{RawRepository, Resolver}

object S3 {
implicit class S3Repo(val name: String) extends AnyVal {
def atS3(location: String): Resolver = {
require(null != location && location != "", "Empty Location!")
val pattern: List[String] = Collections.singletonList(resolvePattern(location, Resolver.mavenStyleBasePattern))
new RawRepository(new S3URLResolver(name, location, pattern))
}
final class S3RawRepository(val name: String) extends AnyVal {
def atS3(location: String): Resolver = {
require(null != location && location != "", "Empty Location!")
val pattern: List[String] = Collections.singletonList(resolvePattern(location, Resolver.mavenStyleBasePattern))
new RawRepository(new S3URLResolver(name, location, pattern))
}

private def resolvePattern(base: String, pattern: String): String = {
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/fm/sbt/S3ResolverPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import org.apache.ivy.util.url.{URLHandlerDispatcher, URLHandlerRegistry}
/**
* All this does is register the s3:// url handler with the JVM and IVY
*/
object S3ResolverPlugin extends Plugin {
object S3ResolverPlugin extends AutoPlugin {
object autoImport extends S3Implicits

//
// This *should* work but it looks like SBT is doing some multi class loader stuff
// because the class loader used to load java.net.URL doesn't see fm.sbt.s3.Handler.
Expand Down

0 comments on commit cc9f1b5

Please sign in to comment.