-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3447
- Loading branch information
Showing
6 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
= Mill ErrorProne Plugin | ||
|
||
== Caveats / JVM Options | ||
|
||
If you're on Java 17 or newer, you need to add the following options to your `.mill-jvm-opts` file in your project directory. | ||
|
||
.Required options in `.mill-jvm-opts` | ||
---- | ||
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED | ||
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED | ||
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED | ||
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED | ||
---- | ||
|
43 changes: 43 additions & 0 deletions
43
contrib/errorprone/src/mill/contrib/errorprone/ErrorProneModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mill.contrib.errorprone | ||
|
||
import mill.api.PathRef | ||
import mill.{Agg, T} | ||
import mill.scalalib.{Dep, DepSyntax, JavaModule} | ||
|
||
import java.io.File | ||
|
||
trait ErrorProneModule extends JavaModule { | ||
def errorProneVersion: T[String] = T.input { | ||
BuildInfo.errorProneVersion | ||
} | ||
def errorProneDeps: T[Agg[Dep]] = T { | ||
Agg( | ||
ivy"com.google.errorprone:error_prone_core:${errorProneVersion()}" | ||
) | ||
} | ||
def errorProneClasspath: T[Agg[PathRef]] = T { | ||
resolveDeps(T.task { errorProneDeps().map(bindDependency()) })() | ||
} | ||
def errorProneJavacOptions: T[Seq[String]] = T { | ||
val processorPath = errorProneClasspath().map(_.path).mkString(File.pathSeparator) | ||
Seq( | ||
"-XDcompilePolicy=simple", | ||
"-processorpath", | ||
processorPath, | ||
"-Xplugin:ErrorProne" | ||
) | ||
// val java17Options = Seq( | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", | ||
// "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", | ||
// "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", | ||
// "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" | ||
// ) | ||
} | ||
override def javacOptions: T[Seq[String]] = super.javacOptions() ++ errorProneJavacOptions() | ||
} |
16 changes: 16 additions & 0 deletions
16
contrib/errorprone/test/resources/simple/src/ShortSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package simple.src; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ShortSet { | ||
public static void main (String[] args) { | ||
Set<Short> s = new HashSet<>(); | ||
for (short i = 0; i < 100; i++) { | ||
s.add(i); | ||
s.remove(i - 1); | ||
} | ||
System.out.println(s.size()); | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
contrib/errorprone/test/src/mill/contrib/errorprone/ErrorProneTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mill.contrib.errorprone | ||
|
||
import mill.scalalib.JavaModule | ||
import mill.testkit.{TestBaseModule, UnitTester} | ||
import os.Path | ||
import utest._ | ||
|
||
object ErrorProneTests extends TestSuite { | ||
|
||
object noErrorProne extends TestBaseModule with JavaModule {} | ||
object errorProne extends TestBaseModule with JavaModule with ErrorProneModule {} | ||
|
||
val testModuleSourcesPath: Path = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "simple" | ||
|
||
def tests = Tests { | ||
test("reference") { | ||
test("compile") { | ||
val eval = UnitTester(noErrorProne, testModuleSourcesPath) | ||
val res = eval(noErrorProne.compile) | ||
assert(res.isRight) | ||
} | ||
} | ||
test("errorprone") { | ||
test("compileFail") { | ||
// we require additional JVM options, which we can't set at runtime, see contrib/errorprone/readme.adoc | ||
if (scala.util.Properties.isJavaAtLeast(16)) "skipping test on Java 16+" | ||
else { | ||
val eval = UnitTester(errorProne, testModuleSourcesPath) | ||
val res = eval(errorProne.compile) | ||
assert(res.isLeft) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters