From 95e9b5cda73cf54827238b5682a32e8612832153 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Sat, 8 Mar 2014 00:24:15 -0500 Subject: [PATCH] Don't fail publishing on overwrite, but issue a warning. 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. --- ivy/src/main/scala/sbt/ConvertResolver.scala | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ivy/src/main/scala/sbt/ConvertResolver.scala b/ivy/src/main/scala/sbt/ConvertResolver.scala index 58ba6d4ac..a93a57011 100644 --- a/ivy/src/main/scala/sbt/ConvertResolver.scala +++ b/ivy/src/main/scala/sbt/ConvertResolver.scala @@ -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} @@ -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) @@ -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) + } + } + } }