Skip to content

Commit

Permalink
Don't fail publishing on overwrite, but issue a warning.
Browse files Browse the repository at this point in the history
Workaround for #1156.

* Creates a new FileRepository that will stil allow local files
  to be transfered if overwrite is true (non-snapshot module),
  but will issue a warning about deprecated behavior.
* Ensure warning is long enough to annoy people into asking
  what it's about.
  • Loading branch information
jsuereth committed Mar 8, 2014
1 parent 1626226 commit 875562f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ivy/src/main/scala/sbt/ConvertResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ private object ConvertResolver
}
case repo: FileRepository =>
{
val resolver = new FileSystemResolver with DescriptorRequired
val resolver = new FileSystemResolver with DescriptorRequired {
// Workaround for #1156
// Temporarily in sbt 0.13.x we deprecate overwriting
// in local files for non-changing revisions.
// This will be fully enforced in sbt 1.0.
setRepository(new WarnOnOverwriteFileRepo())
}
resolver.setName(repo.name)
initializePatterns(resolver, repo.patterns, settings)
import repo.configuration.{isLocal, isTransactional}
Expand Down Expand Up @@ -135,7 +141,7 @@ private object ConvertResolver
/** A custom Ivy URLRepository that returns FileResources for file URLs.
* This allows using the artifacts from the Maven local repository instead of copying them to the Ivy cache. */
private[this] final class LocalIfFileRepo extends URLRepo {
private[this] val repo = new FileRepo
private[this] val repo = new WarnOnOverwriteFileRepo()
override def getResource(source: String) = {
val url = new URL(source)
if(url.getProtocol == IO.FileScheme)
Expand All @@ -144,4 +150,16 @@ private object ConvertResolver
super.getResource(source)
}
}

private[this] final class WarnOnOverwriteFileRepo extends FileRepo() {
override def put(source: java.io.File, destination: String, overwrite: Boolean): Unit = {
try super.put(source, destination, overwrite)
catch {
case e: java.io.IOException if e.getMessage.contains("destination already exists") =>
import org.apache.ivy.util.Message
Message.warn(s"Attempting to overwrite $destination\n\tThis usage is deprecated and will be removed in sbt 1.0.")
super.put(source, destination, true)
}
}
}
}

0 comments on commit 875562f

Please sign in to comment.