diff --git a/util/io/src/main/scala/sbt/DeferredWriter.scala b/util/io/src/main/scala/sbt/DeferredWriter.scala index 3e93564a2..7e6b510a8 100644 --- a/util/io/src/main/scala/sbt/DeferredWriter.scala +++ b/util/io/src/main/scala/sbt/DeferredWriter.scala @@ -2,6 +2,7 @@ package sbt import java.io.Writer +/** A `Writer` that avoids constructing the underlying `Writer` with `make` until a method other than `close` is called on this `Writer`. */ final class DeferredWriter(make: => Writer) extends Writer { private[this] var opened = false diff --git a/util/io/src/main/scala/sbt/RichURI.scala b/util/io/src/main/scala/sbt/RichURI.scala index a93ea1b62..29cc6a173 100644 --- a/util/io/src/main/scala/sbt/RichURI.scala +++ b/util/io/src/main/scala/sbt/RichURI.scala @@ -6,23 +6,33 @@ package sbt import java.net.URI +/** Extends `URI` with additional convenience methods. */ class RichURI(uri: URI) { + /** Provides a case-class-like `copy` method for URI. + * Note that this method simply passes the individual components of this URI to the URI constructor + * that accepts each component individually. It is thus limited by the implementation restrictions of the relevant methods.*/ def copy(scheme: String = uri.getScheme, userInfo: String = uri.getUserInfo, host: String = uri.getHost, port: Int = uri.getPort, path: String = uri.getPath, query: String = uri.getQuery, fragment: String = uri.getFragment) = new URI(scheme, userInfo, host, port, path, query, fragment) + /** Returns `true` if the fragment of the URI is defined. */ def hasFragment = uri.getFragment ne null + /** Returns a copy of the URI without the fragment. */ def withoutFragment = if (hasFragment) new URI(uri.getScheme, uri.getSchemeSpecificPart, null) else uri + /** Returns `true` if the scheme specific part of the URI is also a valid URI. */ def hasMarkerScheme = new URI(uri.getRawSchemeSpecificPart).getScheme ne null + /** Strips the wrapper scheme from this URI. + * If the URI has a fragment, the fragment is transferred to the wrapped URI. + * If this URI does not have a marker scheme, it is returned unchanged.*/ def withoutMarkerScheme = { if (hasMarkerScheme) @@ -37,5 +47,6 @@ class RichURI(uri: URI) object RichURI { - implicit def fromURI(uri: URI) = new RichURI(uri) + /** Provides additional convenience methods for `uri`. */ + implicit def fromURI(uri: URI): RichURI = new RichURI(uri) }