Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
48 changes: 42 additions & 6 deletions io/src/main/scala/sbt/io/Using.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion project/HouseRulesPluglin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++= {
Expand Down