Skip to content

Commit

Permalink
Merge pull request #8 from hoangmaihuy/fix-targets
Browse files Browse the repository at this point in the history
fix: Make missinglink configurations become `Target`
  • Loading branch information
hoangmaihuy authored Dec 19, 2023
2 parents 61561d8 + 5abd6a0 commit 3e563fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,46 @@ import mill.scalalib._
trait MissinglinkCheckModule extends JavaModule {

/** Fail the build if any conflicts are found */
def missinglinkFailOnConflicts: Boolean = true
def missinglinkFailOnConflicts: T[Boolean] = T { true }

/** Also scan all dependencies */
def missinglinkScanDependencies: Boolean = false
def missinglinkScanDependencies: T[Boolean] = T { false }

/** Optional list of packages to ignore conflicts where the source of the conflict is in one of the specified
* packages.
*/
def missinglinkIgnoreSourcePackages: Seq[IgnoredPackage] = Seq.empty
def missinglinkIgnoreSourcePackages: T[Seq[IgnoredPackage]] = T { Seq.empty[IgnoredPackage] }

/** Optional list of source packages to specifically target conflicts in. Cannot be used with
* missinglinkIgnoreSourcePackages.
*/
def missinglinkTargetSourcePackages: Seq[TargetedPackage] = Seq.empty
def missinglinkTargetSourcePackages: T[Seq[TargetedPackage]] = T { Seq.empty[TargetedPackage] }

/** Optional list of packages to ignore conflicts where the destination/called-side of the conflict is in one of the
* specified packages.
*/
def missinglinkIgnoreDestinationPackages: Seq[IgnoredPackage] = Seq.empty
def missinglinkIgnoreDestinationPackages: T[Seq[IgnoredPackage]] = T { Seq.empty[IgnoredPackage] }

/** Optional list of source packages to specifically target conflicts in. Cannot be used with
* missinglinkIgnoreDestinationPackages.
*/
def missinglinkTargetDestinationPackages: Seq[TargetedPackage] = Seq.empty
def missinglinkTargetDestinationPackages: T[Seq[TargetedPackage]] = T { Seq.empty[TargetedPackage] }

/** Dependencies that are excluded from analysis */
def missinglinkExcludedDependencies: Seq[DependencyFilter] = Seq.empty
def missinglinkExcludedDependencies: T[Seq[DependencyFilter]] = T { Seq.empty[DependencyFilter] }

def missinglinkCheckCached = T {
missinglinkCheck()
}

def missinglinkCheck(): Command[Unit] = T.command {
assert(
missinglinkIgnoreSourcePackages.isEmpty || missinglinkTargetSourcePackages.isEmpty,
missinglinkIgnoreSourcePackages().isEmpty || missinglinkTargetSourcePackages().isEmpty,
"ignoreSourcePackages and targetSourcePackages cannot be defined in the same project."
)

assert(
missinglinkIgnoreDestinationPackages.isEmpty || missinglinkTargetDestinationPackages.isEmpty,
missinglinkIgnoreDestinationPackages().isEmpty || missinglinkTargetDestinationPackages().isEmpty,
"ignoreDestinationPackages and targetDestinationPackages cannot be defined in the same project."
)

Expand All @@ -59,30 +63,31 @@ trait MissinglinkCheckModule extends JavaModule {
loadArtifactsAndCheckConflicts(
runCp,
classDirectory,
missinglinkScanDependencies,
missinglinkScanDependencies(),
missinglinkExcludedDependencies(),
T.log
)

val conflictFilters = filterConflicts(
missinglinkIgnoreSourcePackages,
missinglinkIgnoreSourcePackages(),
"missinglinkIgnoreSourcePackages",
T.log,
"source",
_.fromClass
) andThen filterConflicts(
missinglinkTargetSourcePackages,
missinglinkTargetSourcePackages(),
"missinglinkTargetSourcePackages",
T.log,
"source",
_.fromClass
) andThen filterConflicts(
missinglinkIgnoreDestinationPackages,
missinglinkIgnoreDestinationPackages(),
"missinglinkIgnoreDestinationPackages",
T.log,
"destination",
_.targetClass
) andThen filterConflicts(
missinglinkTargetDestinationPackages,
missinglinkTargetDestinationPackages(),
"missinglinkTargetDestinationPackages",
T.log,
"destination",
Expand All @@ -105,7 +110,7 @@ trait MissinglinkCheckModule extends JavaModule {

outputConflicts(filteredConflicts, T.log)

if (missinglinkFailOnConflicts) {
if (missinglinkFailOnConflicts()) {
throw new Exception(s"There were $filteredTotal conflicts")
}
} else {
Expand All @@ -117,6 +122,7 @@ trait MissinglinkCheckModule extends JavaModule {
cp: Seq[os.Path],
classDirectory: os.Path,
scanDependencies: Boolean,
excludedDependencies: Seq[DependencyFilter],
log: Logger
): Seq[Conflict] = {

Expand All @@ -125,7 +131,7 @@ trait MissinglinkCheckModule extends JavaModule {
val runtimeArtifactsAfterExclusions = runtimeArtifacts
.filterNot { artifact =>
artifact.path.fold(true) { path =>
missinglinkExcludedDependencies.exists(_.check(path))
excludedDependencies.exists(_.check(path))
}
}
.map(_.artifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ package object missinglink {

}

implicit val ignoredPackageRw: upickle.default.ReadWriter[IgnoredPackage] = upickle.default.macroRW

private[missinglink] implicit object IgnoredPackages extends PackageFilters[IgnoredPackage] {


def apply(name: String)(filters: Seq[IgnoredPackage]): Boolean = filters.forall(_.apply(name))
}

Expand All @@ -22,6 +26,8 @@ package object missinglink {

}

implicit val targetedPackageRw: upickle.default.ReadWriter[TargetedPackage] = upickle.default.macroRW

private[missinglink] implicit object TargetedPackages extends PackageFilters[TargetedPackage] {

def apply(name: String)(filters: Seq[TargetedPackage]): Boolean =
Expand All @@ -48,4 +54,6 @@ package object missinglink {

}

implicit val dependencyFilterRw: upickle.default.ReadWriter[DependencyFilter] = upickle.default.macroRW

}

0 comments on commit 3e563fc

Please sign in to comment.