Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more in RichUpdateReport #84

Merged
merged 2 commits into from
Apr 13, 2017
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package librarymanagement

import java.io.File

/** Provides extra methods for filtering the contents of an `UpdateReport` and for obtaining references to a selected subset of the underlying files. */
/**
* Provides extra methods for filtering the contents of an `UpdateReport`
* and for obtaining references to a selected subset of the underlying files.
*/
final class RichUpdateReport(report: UpdateReport) {
private[sbt] def recomputeStamps(): UpdateReport =
{
Expand All @@ -15,10 +18,10 @@ final class RichUpdateReport(report: UpdateReport) {
import DependencyFilter._

/** Obtains all successfully retrieved files in all configurations and modules. */
private[sbt] def allFiles: Seq[File] = matching(DependencyFilter.allPass)
def allFiles: Seq[File] = matching(DependencyFilter.allPass)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Vectors.


/** Obtains all successfully retrieved files in configurations, modules, and artifacts matching the specified filter. */
private[sbt] def matching(f: DependencyFilter): Seq[File] = select0(f).distinct
def matching(f: DependencyFilter): Seq[File] = select0(f).distinct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same return Vector.


/** Obtains all successfully retrieved files matching all provided filters. */
def select(configuration: ConfigurationFilter, module: ModuleFilter, artifact: ArtifactFilter): Seq[File] =
Expand All @@ -29,17 +32,27 @@ final class RichUpdateReport(report: UpdateReport) {
def select(artifact: ArtifactFilter): Seq[File] = select(configurationFilter(), moduleFilter(), artifact)

private[this] def select0(f: DependencyFilter): Seq[File] =
for (cReport <- report.configurations; mReport <- cReport.modules; (artifact, file) <- mReport.artifacts if f(cReport.configuration, mReport.module, artifact)) yield {
if (file == null) sys.error("Null file: conf=" + cReport.configuration + ", module=" + mReport.module + ", art: " + artifact)
for {
cReport <- report.configurations
mReport <- cReport.modules
(artifact, file) <- mReport.artifacts
if f(cReport.configuration, mReport.module, artifact)
} yield {
if (file == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either use Option(file).orElse { ... } or put { .. } around sys.error.

sys.error(s"Null file: conf=${cReport.configuration}, module=${mReport.module}, art: $artifact")
file
}

/** Constructs a new report that only contains files matching the specified filter.*/
private[sbt] def filter(f: DependencyFilter): UpdateReport =
def filter(f: DependencyFilter): UpdateReport =
moduleReportMap { (configuration, modReport) =>
modReport
.withArtifacts(modReport.artifacts filter { case (art, file) => f(configuration, modReport.module, art) })
.withMissingArtifacts(modReport.missingArtifacts filter { art => f(configuration, modReport.module, art) })
.withArtifacts(
modReport.artifacts filter { case (art, file) => f(configuration, modReport.module, art) }
)
.withMissingArtifacts(
modReport.missingArtifacts filter { art => f(configuration, modReport.module, art) }
)
}

private[sbt] def substitute(f: (String, ModuleID, Vector[(Artifact, File)]) => Vector[(Artifact, File)]): UpdateReport =
Expand All @@ -50,11 +63,19 @@ final class RichUpdateReport(report: UpdateReport) {
.withMissingArtifacts(modReport.missingArtifacts)
}

private[sbt] def toSeq: Seq[(String, ModuleID, Artifact, File)] =
for (confReport <- report.configurations; modReport <- confReport.modules; (artifact, file) <- modReport.artifacts) yield (confReport.configuration, modReport.module, artifact, file)
def toSeq: Seq[(String, ModuleID, Artifact, File)] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toVector and then add toSeq that calls toVector.

for {
confReport <- report.configurations
modReport <- confReport.modules
(artifact, file) <- modReport.artifacts
} yield (confReport.configuration, modReport.module, artifact, file)

private[sbt] def allMissing: Seq[(String, ModuleID, Artifact)] =
for (confReport <- report.configurations; modReport <- confReport.modules; artifact <- modReport.missingArtifacts) yield (confReport.configuration, modReport.module, artifact)
def allMissing: Seq[(String, ModuleID, Artifact)] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

for {
confReport <- report.configurations
modReport <- confReport.modules
artifact <- modReport.missingArtifacts
} yield (confReport.configuration, modReport.module, artifact)

private[sbt] def addMissing(f: ModuleID => Seq[Artifact]): UpdateReport =
moduleReportMap { (configuration, modReport) =>
Expand Down