diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index f8acfecd..98a7b2ca 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -27,10 +27,12 @@ import sbt.nio.file.FileTreeView import scala.Function.tupled import scala.annotation.tailrec +import scala.annotation.targetName import scala.jdk.CollectionConverters._ import scala.collection.immutable import scala.collection.immutable.TreeSet import scala.collection.mutable.{ HashMap, HashSet } +import scala.reflect.ClassTag import scala.reflect.{ Manifest => SManifest } import scala.util.control.Exception._ import scala.util.control.NonFatal @@ -79,9 +81,19 @@ object IO { * If the location cannot be determined, an error is generated. * Note that for JDK 11 onwards, a module will return a jrt path. */ - def classLocationPath[A](implicit mf: SManifest[A]): NioPath = + @deprecated("use classLocationPath", "2.0.0") + @targetName("classLocationPath") + def classLocationPathDeprecated[A](implicit mf: SManifest[A]): NioPath = classLocationPath(mf.runtimeClass) + /** + * Returns a NIO Path to the directory, Java module, or the JAR file for type `A` (as determined by an ClassTag). + * If the location cannot be determined, an error is generated. + * Note that for JDK 11 onwards, a module will return a jrt path. + */ + def classLocationPath[A](implicit tag: ClassTag[A]): NioPath = + classLocationPath(tag.runtimeClass) + /** * Returns the directory, Java module, or the JAR containing the class file `cl`. * If the location cannot be determined or it is not a file, an error is generated. @@ -97,9 +109,19 @@ object IO { * If the location cannot be determined or it is not a file, an error is generated. * Note that for JDK 11 onwards, the returned module path cannot be expressed as `File`, so it will return `None`. */ - def classLocationFileOption[A](implicit mf: SManifest[A]): Option[File] = + @deprecated("use classLocationFileOption", "2.0.0") + @targetName("classLocationFileOption") + def classLocationFileOptionDeprecated[A](implicit mf: SManifest[A]): Option[File] = classLocationFileOption(mf.runtimeClass) + /** + * Returns the directory, Java module, or the JAR containing the class file for type `T` (as determined by an ClassTag). + * If the location cannot be determined or it is not a file, an error is generated. + * Note that for JDK 11 onwards, the returned module path cannot be expressed as `File`, so it will return `None`. + */ + def classLocationFileOption[A](implicit tag: ClassTag[A]): Option[File] = + classLocationFileOption(tag.runtimeClass) + /** * Returns the directory, Java module, or the JAR file containing the class file `cl`. * If the location cannot be determined or it is not a file, an error is generated. @@ -174,14 +196,34 @@ object IO { * If the location cannot be determined or it is not a file, an error is generated. * Note that for JDK 11 onwards, a module will return a jrt path. */ - def classLocation[A](implicit mf: SManifest[A]): URL = + @deprecated("use classLocation", "2.0.0") + @targetName("classLocation") + def classLocationDeprecated[A](implicit mf: SManifest[A]): URL = classLocation(mf.runtimeClass) + /** + * Returns the URL to the directory, Java module, or the JAR file containing the class file `cl`. + * If the location cannot be determined or it is not a file, an error is generated. + * Note that for JDK 11 onwards, a module will return a jrt path. + */ + def classLocation[A](implicit tag: ClassTag[A]): URL = + classLocation(tag.runtimeClass) + /** * Returns a URL for the classfile containing the given class file for type `T` (as determined by an implicit Manifest). * If the location cannot be determined, an error is generated. */ - def classfileLocation[T](implicit mf: SManifest[T]): URL = classfileLocation(mf.runtimeClass) + @deprecated("use classfileLocation", "2.0.0") + @targetName("classfileLocation") + def classfileLocationDeprecated[T](implicit mf: SManifest[T]): URL = classfileLocation( + mf.runtimeClass + ) + + /** + * Returns a URL for the classfile containing the given class file for type `T` (as determined by an ClassTag). + * If the location cannot be determined, an error is generated. + */ + def classfileLocation[T](implicit tag: ClassTag[T]): URL = classfileLocation(tag.runtimeClass) /** * Returns a URL for the classfile containing the given class diff --git a/io/src/main/scala/sbt/io/Using.scala b/io/src/main/scala/sbt/io/Using.scala index 31a53d53..e4fd759c 100644 --- a/io/src/main/scala/sbt/io/Using.scala +++ b/io/src/main/scala/sbt/io/Using.scala @@ -32,6 +32,8 @@ import java.util.jar.{ JarFile, JarInputStream, JarOutputStream } import java.util.zip.{ GZIPInputStream, _ } import sbt.internal.io.ErrorHandling.translate +import scala.annotation.targetName +import scala.reflect.ClassTag abstract class Using[Source, T] { protected def open(src: Source): T @@ -47,14 +49,22 @@ abstract class Using[Source, T] { } import scala.reflect.{ Manifest => SManifest } -private[sbt] abstract class WrapUsing[Source, T](implicit - srcMf: SManifest[Source], - targetMf: SManifest[T] +private[sbt] abstract class WrapUsing[Source, T]( + srcLabel: String, + targetLabel: String ) extends Using[Source, T] { + @deprecated + def this( + srcMf: SManifest[Source], + targetMf: SManifest[T] + ) = { + this(srcMf.runtimeClass.getSimpleName, targetMf.runtimeClass.getSimpleName) + } + @deprecated protected def label[S](m: SManifest[S]) = m.runtimeClass.getSimpleName protected def openImpl(source: Source): T protected final def open(source: Source): T = - translate("Error wrapping " + label(srcMf) + " in " + label(targetMf) + ": ")(openImpl(source)) + translate("Error wrapping " + srcLabel + " in " + targetLabel + ": ")(openImpl(source)) } private[sbt] trait OpenFile[T] extends Using[File, T] { protected def openImpl(file: File): T @@ -70,16 +80,42 @@ private[sbt] trait OpenFile[T] extends Using[File, T] { object Using { def wrap[Source, T <: AutoCloseable](openF: Source => T)(implicit + srcTag: ClassTag[Source], + targetTag: ClassTag[T] + ): Using[Source, T] = + wrap(openF, closeCloseable) + + def wrap[Source, T](openF: Source => T, closeF: T => Unit)(implicit + srcTag: ClassTag[Source], + targetTag: ClassTag[T] + ): Using[Source, T] = + new WrapUsing[Source, T]( + srcTag.runtimeClass.getSimpleName, + targetTag.runtimeClass.getSimpleName + ) { + def openImpl(source: Source) = openF(source) + + def close(t: T) = closeF(t) + } + + @deprecated("use wrap", "2.0.0") + @targetName("wrap") + def wrapDeprecated[Source, T <: AutoCloseable](openF: Source => T)(implicit srcMf: SManifest[Source], targetMf: SManifest[T] ): Using[Source, T] = wrap(openF, closeCloseable) - def wrap[Source, T](openF: Source => T, closeF: T => Unit)(implicit + @deprecated("use wrap", "2.0.0") + @targetName("wrap") + def wrapDeprecated[Source, T](openF: Source => T, closeF: T => Unit)(implicit srcMf: SManifest[Source], targetMf: SManifest[T] ): Using[Source, T] = - new WrapUsing[Source, T] { + new WrapUsing[Source, T]( + srcMf.runtimeClass.getSimpleName, + targetMf.runtimeClass.getSimpleName + ) { def openImpl(source: Source) = openF(source) def close(t: T) = closeF(t) } diff --git a/project/HouseRulesPluglin.scala b/project/HouseRulesPluglin.scala index 5a87bc0b..c3e92143 100644 --- a/project/HouseRulesPluglin.scala +++ b/project/HouseRulesPluglin.scala @@ -14,7 +14,6 @@ object HouseRulesPlugin extends AutoPlugin { scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"), scalacOptions += "-language:implicitConversions", scalacOptions ++= Seq( - "-Wconf:msg=Compiler synthesis of Manifest and OptManifest is deprecated:silent", "-Wconf:msg=type Traversable in package scala:silent", ), scalacOptions ++= {