Skip to content

Commit 90de075

Browse files
authored
Fix warning about workers not implementing AutoCloseable (#6259)
In cases where we define the worker type, this PR just added `extends AutoClosable` and an no-op `def close()` implementation. Otherwise (when we return some type not dedicated as a worker), we just suppress the build warning with `@nowarn`. Pull request: #6259
1 parent b905600 commit 90de075

File tree

12 files changed

+65
-14
lines changed

12 files changed

+65
-14
lines changed

contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import mill.contrib.flyway.ConsoleLog.Level
44
import org.flywaydb.core.Flyway
55
import org.flywaydb.core.api.MigrationVersion
66
import org.flywaydb.core.api.logging.LogFactory
7-
import org.flywaydb.core.internal.configuration.{ConfigUtils => flyway}
7+
import org.flywaydb.core.internal.configuration.ConfigUtils as flyway
88
import org.flywaydb.core.internal.info.MigrationInfoDumper
9-
import scala.jdk.CollectionConverters._
109

10+
import scala.jdk.CollectionConverters.*
1111
import mill.*
1212
import mill.api.PathRef
13+
import mill.api.daemon.MillURLClassLoader
1314
import mill.javalib.{Dep, JavaModule}
1415
import org.flywaydb.core.api.output.{BaselineResult, CleanResult, MigrateOutput, MigrateResult}
1516

17+
import scala.annotation.nowarn
18+
1619
trait FlywayModule extends JavaModule {
1720
import FlywayModule._
1821

@@ -34,10 +37,12 @@ trait FlywayModule extends JavaModule {
3437
.filter(_.nonEmpty)
3538
.map(key -> _)
3639

37-
def flywayClassloader = Task.Worker {
40+
def flywayClassloader: Worker[MillURLClassLoader] = Task.Worker {
3841
mill.util.Jvm.createClassLoader(jdbcClasspath().map(_.path))
3942
}
40-
def flywayInstance = Task.Worker {
43+
44+
@nowarn("msg=.*Workers should implement AutoCloseable.*")
45+
def flywayInstance: Worker[Flyway] = Task.Worker {
4146
val jdbcClassloader = flywayClassloader()
4247

4348
val configProps = Map(flyway.URL -> flywayUrl()) ++

contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import mill.playlib.api.RouteCompilerType
66
import mill.javalib.api.CompilationResult
77
import mill.*
88

9-
private[playlib] class RouteCompilerWorker {
9+
private[playlib] class RouteCompilerWorker extends AutoCloseable {
1010

1111
def compile(
1212
toolsClasspath: Seq[PathRef],
@@ -48,6 +48,10 @@ private[playlib] class RouteCompilerWorker {
4848
case err => Result.Failure(err)
4949
}
5050
}
51+
}
5152

53+
override def close(): Unit = {
54+
// no-op
55+
// TODO: cache classloader to improve repetitive compilations
5256
}
5357
}

contrib/playlib/src/mill/playlib/RouteCompilerWorkerModule.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import mill.{Module, Task, Worker}
44
import mill.api.{Discover, ExternalModule}
55

66
trait RouteCompilerWorkerModule extends Module {
7+
78
def routeCompilerWorker: Worker[RouteCompilerWorker] = Task.Worker {
89
new RouteCompilerWorker()
910
}

contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBWorker.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mill.api.PathRef
44

55
import java.io.File
66

7-
class ScalaPBWorker {
7+
class ScalaPBWorker extends AutoCloseable {
88

99
private def scalaPB(scalaPBClasspath: Seq[PathRef])(using ctx: mill.api.TaskCtx) = {
1010
val instance = new ScalaPBWorkerApi {
@@ -98,4 +98,8 @@ class ScalaPBWorker {
9898
)
9999
mill.api.Result.Success(PathRef(dest))
100100
}
101+
102+
override def close(): Unit = {
103+
// no-op
104+
}
101105
}

contrib/scoverage/api/src/mill/contrib/scoverage/api/ScoverageReportWorkerApi2.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.nio.file.Files;
66
import java.nio.file.Path;
77

8-
public interface ScoverageReportWorkerApi2 {
8+
public interface ScoverageReportWorkerApi2 extends AutoCloseable {
99

1010
interface Logger {
1111
void error(String msg);
@@ -105,4 +105,9 @@ static void makeAllDirs(Path path) throws IOException {
105105
Files.createDirectories(path);
106106
}
107107
}
108+
109+
@Override
110+
default void close() throws Exception {
111+
// no-op
112+
}
108113
}

contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import mill.contrib.scoverage.api.ScoverageReportWorkerApi2.{
1111
}
1212
import os.Path
1313

14-
class ScoverageReportWorker {
14+
class ScoverageReportWorker extends AutoCloseable {
1515

1616
def bridge(classpath: Seq[PathRef]): ScoverageReportWorkerApiBridge = {
1717
def ctx0(using ctx: TaskCtx): ApiCtx = {
@@ -74,6 +74,10 @@ class ScoverageReportWorker {
7474
))
7575
}
7676
}
77+
78+
override def close(): Unit = {
79+
// no-op
80+
}
7781
}
7882

7983
object ScoverageReportWorker extends ExternalModule {
@@ -101,5 +105,7 @@ object ScoverageReportWorker extends ExternalModule {
101105

102106
def scoverageReportWorker: Task.Worker[ScoverageReportWorker] =
103107
Task.Worker { new ScoverageReportWorker() }
108+
109+
// TODO: make protected
104110
lazy val millDiscover = Discover[this.type]
105111
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package mill.androidlib.databinding
22

3-
trait AndroidDataBindingWorker {
3+
trait AndroidDataBindingWorker extends AutoCloseable {
4+
45
def processResources(args: ProcessResourcesArgs): Unit
6+
57
def generateBindingSources(args: GenerateBindingSourcesArgs): Unit
8+
9+
override def close(): Unit = {
10+
// no-up
11+
}
612
}

libs/javalib/api/src/mill/javalib/api/internal/InternalJvmWorkerApi.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import mill.javalib.api.JvmWorkerApi.Ctx
99
import mill.javalib.api.internal.ZincOp
1010
import os.Path
1111

12-
trait InternalJvmWorkerApi extends PublicJvmWorkerApi {
12+
trait InternalJvmWorkerApi extends PublicJvmWorkerApi, AutoCloseable {
1313

1414
/** Compile a Java-only project. */
1515
def apply(
@@ -119,7 +119,12 @@ trait InternalJvmWorkerApi extends PublicJvmWorkerApi {
119119
reportCachedProblems = false
120120
)
121121
}
122+
123+
override def close(): Unit = {
124+
// bin-compat shim
125+
}
122126
}
127+
123128
object InternalJvmWorkerApi {
124129
type Ctx = PublicJvmWorkerApi.Ctx
125130
}

libs/javalib/api/src/mill/javalib/classgraph/ClassgraphWorker.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package mill.javalib.classgraph
22

33
import mill.api.TaskCtx
44

5-
trait ClassgraphWorker {
5+
trait ClassgraphWorker extends AutoCloseable {
66
def discoverMainClasses(classpath: Seq[os.Path])(using ctx: TaskCtx): Seq[String]
7+
8+
override def close(): Unit = {
9+
// noop
10+
}
711
}

libs/javalib/src/mill/javalib/MavenWorkerSupport.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import mill.javalib.publish.{Artifact, PublishInfo}
55
import mill.util.Jvm
66
import os.Path
77

8+
import scala.annotation.nowarn
9+
810
private[mill] trait MavenWorkerSupport extends CoursierModule with OfflineSupportModule {
911
private def mavenWorkerClasspath: T[Seq[PathRef]] = Task {
1012
defaultResolver().classpath(Seq(
@@ -21,6 +23,7 @@ private[mill] trait MavenWorkerSupport extends CoursierModule with OfflineSuppor
2123
Jvm.createClassLoader(classPath = classPath, parent = getClass.getClassLoader)
2224
}
2325

26+
@nowarn("msg=.*Workers should implement AutoCloseable.*")
2427
private[mill] def mavenWorker: Task.Worker[mill.javalib.internal.MavenWorkerSupport.Api] =
2528
Task.Worker {
2629
mavenWorkerClassloader().loadClass("mill.javalib.maven.worker.impl.WorkerImpl")

0 commit comments

Comments
 (0)