Skip to content

Commit 0fdfdbb

Browse files
authored
Fix java compile warning, again (#3762)
Follow up to #3711 I swear this annotation didn't work last time, and the `match` on the `discoveredModuleType` did. But now they don't. Must have been getting confused by incremental compilation Turns out the discover macro was incorrectly traversing type members and picking up their types, which is why it was appeared in the generated code, so I added a filter to filter them out Added a test to assert on the full stdout/stderr of a simple mill command run to ensure we don't have stray logs or warnings turning up
1 parent 59e1bda commit 0fdfdbb

File tree

5 files changed

+99
-10
lines changed

5 files changed

+99
-10
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979

8080
# Most of these integration tests should not depend on which mode they
8181
# are run in, so just run them in `local`
82-
- java-version: '11'
82+
- java-version: '17'
8383
millargs: "'integration.{failure,feature,ide}.__.local.testCached'"
8484

8585
# These invalidation tests need to be exercised in both execution modes
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package build
2+
import mill._, javalib._
3+
4+
object `package` extends RootModule with JavaModule {
5+
def ivyDeps = Agg(
6+
ivy"net.sourceforge.argparse4j:argparse4j:0.9.0",
7+
ivy"org.apache.commons:commons-text:1.12.0"
8+
)
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package foo;
2+
3+
import org.apache.commons.text.StringEscapeUtils;
4+
import net.sourceforge.argparse4j.ArgumentParsers;
5+
import net.sourceforge.argparse4j.inf.ArgumentParser;
6+
import net.sourceforge.argparse4j.inf.ArgumentParserException;
7+
import net.sourceforge.argparse4j.inf.Namespace;
8+
9+
10+
public class Foo{
11+
public static String generateHtml(String text){
12+
return "<h1>" + StringEscapeUtils.escapeHtml4(text) + "</h1>";
13+
}
14+
public static void main(String[] args) {
15+
ArgumentParser parser = ArgumentParsers.newFor("template").build()
16+
.defaultHelp(true)
17+
.description("Inserts text into a HTML template");
18+
19+
parser.addArgument("-t", "--text")
20+
.required(true)
21+
.help("text to insert");
22+
23+
Namespace ns = null;
24+
try {
25+
ns = parser.parseArgs(args);
26+
}catch(Exception e){
27+
System.out.println(e.getMessage());
28+
System.exit(1);
29+
}
30+
31+
System.out.println(generateHtml(ns.getString("text")));
32+
}
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package mill.integration
2+
3+
import mill.testkit.UtestIntegrationTestSuite
4+
import utest._
5+
6+
// Run simple commands on a simple build and check their entire output,
7+
// ensuring we don't get spurious warnings or logging messages slipping in
8+
object FullRunLogsTests extends UtestIntegrationTestSuite {
9+
10+
def tests: Tests = Tests {
11+
test("noticker") - integrationTest { tester =>
12+
import tester._
13+
14+
val res = eval(("--ticker", "false", "run", "--text", "hello"))
15+
res.isSuccess ==> true
16+
assert(res.out == "<h1>hello</h1>")
17+
assert(
18+
res.err.replace('\\', '/').replaceAll("(\r\n)|\r", "\n") ==
19+
s"""[build.mill] [info] compiling 1 Scala source to ${tester.workspacePath}/out/mill-build/compile.dest/classes ...
20+
|[build.mill] [info] done compiling
21+
|[info] compiling 1 Java source to ${tester.workspacePath}/out/compile.dest/classes ...
22+
|[info] done compiling""".stripMargin.replace('\\', '/').replaceAll("(\r\n)|\r", "\n")
23+
)
24+
}
25+
test("ticker") - integrationTest { tester =>
26+
import tester._
27+
28+
val res = eval(("--ticker", "true", "run", "--text", "hello"))
29+
res.isSuccess ==> true
30+
assert(res.out == "[46] <h1>hello</h1>")
31+
32+
val expectedErrorRegex =
33+
s"""==================================================== run --text hello ================================================
34+
|======================================================================================================================
35+
|[build.mill-56/60] compile
36+
|[build.mill-56] [info] compiling 1 Scala source to ${tester.workspacePath}/out/mill-build/compile.dest/classes ...
37+
|[build.mill-56] [info] done compiling
38+
|[40/46] compile
39+
|[40] [info] compiling 1 Java source to ${tester.workspacePath}/out/compile.dest/classes ...
40+
|[40] [info] done compiling
41+
|[46/46] run
42+
|[46/46] ============================================ run --text hello ============================================<seconds-digits>s
43+
|======================================================================================================================"""
44+
.stripMargin
45+
.replaceAll("(\r\n)|\r", "\n")
46+
.replace('\\', '/')
47+
.split("<seconds-digits>")
48+
.map(java.util.regex.Pattern.quote)
49+
.mkString("=? [\\d]+")
50+
51+
assert(expectedErrorRegex.r.matches(res.err.replace('\\', '/').replaceAll("(\r\n)|\r", "\n")))
52+
}
53+
}
54+
}

main/define/src/mill/define/Discover.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ object Discover {
6161
seen.add(tpe)
6262
for {
6363
m <- tpe.members.toList.sortBy(_.name.toString)
64+
if !m.isType
6465
memberTpe = m.typeSignature
6566
if memberTpe.resultType <:< typeOf[mill.define.Module] && memberTpe.paramLists.isEmpty
6667
} rec(memberTpe.resultType)
@@ -141,15 +142,7 @@ object Discover {
141142
}
142143
if overridesRoutes._1.nonEmpty || overridesRoutes._2.nonEmpty || overridesRoutes._3.nonEmpty
143144
} yield {
144-
val lhs0 = discoveredModuleType match {
145-
// Explicitly do not de-alias type refs, so type aliases to deprecated
146-
// types do not result in spurious deprecation warnings appearing
147-
case tr: TypeRef => tr
148-
// Other types are fine
149-
case _ => discoveredModuleType.typeSymbol.asClass.toType
150-
}
151-
152-
val lhs = q"classOf[$lhs0]"
145+
val lhs = q"classOf[${discoveredModuleType.typeSymbol.asClass.toType}]"
153146

154147
// by wrapping the `overridesRoutes` in a lambda function we kind of work around
155148
// the problem of generating a *huge* macro method body that finally exceeds the

0 commit comments

Comments
 (0)