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

Handle Java-only build targets #2520

Merged
merged 9 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
run: |
bin/test.sh unit/test
env:
JAVA_VERSION: ${{ matrix.java }}
TEST_SHARD: ${{ matrix.shard }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_APPLICATION_CREDENTIALS_JSON: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
Expand Down
13 changes: 10 additions & 3 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ function bloop_version {

mkdir -p ~/.bloop
touch ~/.bloop/.jvmopts
echo "-Xss16m" >> ~/.bloop/.jvmopts
echo "-Xmx1G" >> ~/.bloop/.jvmopts

echo "-Xss16m" >> ~/.bloop/.jvmopts
echo "-Xmx1G" >> ~/.bloop/.jvmopts
if [ $JAVA_VERSION -eq 17 ]
then
echo "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" >> ~/.bloop/.jvmopts
echo "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" >> ~/.bloop/.jvmopts
echo "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED" >> ~/.bloop/.jvmopts
echo "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" >> ~/.bloop/.jvmopts
echo "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" >> ~/.bloop/.jvmopts
fi
curl -Lo coursier https://git.io/coursier-cli && chmod +x coursier
./coursier launch ch.epfl.scala:bloopgun-core_2.12:$(bloop_version) -- about

Expand Down
21 changes: 21 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ inThisBuild(
resolvers += Resolver.sonatypeRepo("public"),
resolvers += Resolver.sonatypeRepo("snapshot"),
dependencyOverrides += V.guava,
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.ant.core" % "3.5.500",
Copy link
Contributor

Choose a reason for hiding this comment

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

Uff, this is a lot, thanks for compiling the list!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had more fun afternoons

Copy link
Member

Choose a reason for hiding this comment

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

If possible can we add a note here as to why we are doing this? I can see later on someone jumping in here and looking at this and wondering what in the world we are doing here with all these overrides.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of moving it later to a separate file and commenting. This PR is pretty huge and I don't want to add anything more right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think you did another comment and I can't find it 😅 which is a good indicator that this got way to big. What do you think? Is it ok to do same follow ups later?

Copy link
Member

Choose a reason for hiding this comment

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

:) of course, a follow-up is totally fine.

For the other comment 😆 I deleted it. A couple weeks ago I started reviewing this and only got like half way through and didn't realize I had draft comments saved, so when I added this comment it also posted those. They aren't relevant anymore, so I just removed them. Sorry for the noise!

dependencyOverrides += "org.eclipse.platform" % "org.eclipse.compare.core" % "3.6.600",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.commands" % "3.9.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.contenttype" % "3.7.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.expressions" % "3.6.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.filesystem" % "1.7.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.jobs" % "3.10.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.resources" % "3.13.500",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.runtime" % "3.16.0",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.core.variables" % "3.4.600",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.equinox.app" % "1.4.300",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.equinox.common" % "3.10.600",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.equinox.preferences" % "3.7.600",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.equinox.registry" % "3.8.600",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.osgi" % "3.15.0",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.team.core" % "3.8.700",
dependencyOverrides += "org.eclipse.platform" % "org.eclipse.text" % "3.9.0",
// faster publishLocal:
packageDoc / publishArtifact := sys.env.contains("CI"),
packageSrc / publishArtifact := sys.env.contains("CI"),
Expand Down Expand Up @@ -270,6 +287,7 @@ lazy val V = new {
val bloop = "1.4.11-19-93ebe2c6"
val scala3 = "3.1.0"
val nextScala3RC = "3.1.1-RC2"
val javaSemanticdb = "0.7.2"
val bloopNightly = bloop
val sbtBloop = bloop
val gradleBloop = bloop
Expand Down Expand Up @@ -538,6 +556,8 @@ lazy val metals = project
"com.thoughtworks.qdox" % "qdox" % "2.0.1",
// for finding paths of global log/cache directories
"dev.dirs" % "directories" % "26",
// for Java formatting
"org.eclipse.jdt" % "org.eclipse.jdt.core" % "3.25.0",
// ==================
// Scala dependencies
// ==================
Expand Down Expand Up @@ -578,6 +598,7 @@ lazy val metals = project
"mavenBloopVersion" -> V.mavenBloop,
"scalametaVersion" -> V.scalameta,
"semanticdbVersion" -> V.semanticdb,
"javaSemanticdbVersion" -> V.javaSemanticdb,
"scalafmtVersion" -> V.scalafmt,
"ammoniteVersion" -> V.ammonite,
"organizeImportVersion" -> V.organizeImportRule,
Expand Down
4 changes: 2 additions & 2 deletions metals/src/main/scala/scala/meta/internal/builds/Digest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ object Digest {
val ext = PathIO.extension(path.toNIO)
val isScala = Set("sbt", "scala", "sc")(ext)
// we can have both gradle and gradle.kts and build plugins can be written in any of three languages
val isGradle =
val isGeneralJVM =
Set("gradle", "groovy", "gradle.kts", "java", "kts").exists(
path.toString().endsWith(_)
)
val isXml = ext == "xml"

if (isScala && path.isFile) {
digestScala(path, digest)
} else if (isGradle && path.isFile) {
} else if (isGeneralJVM && path.isFile) {
digestGeneralJvm(path, digest)
} else if (isXml) {
digestXml(path, digest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class GlobalClassTable(
synchronized {
for {
buildTargetId <- buildTargets.inverseSources(source)
scalaTarget <- buildTargets.scalaTarget(buildTargetId)
classpath = new Classpath(scalaTarget.jarClasspath)
jarClasspath <- buildTargets.targetJarClasspath(buildTargetId)
classpath = new Classpath(jarClasspath)
} yield {
buildTargetsIndexes.getOrElseUpdate(
buildTargetId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scala.meta.internal.metals
import java.io.IOException
import java.io.InputStream
import java.net.URI
import java.util.Collections
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
Expand Down Expand Up @@ -160,10 +159,34 @@ class BuildServerConnection private (
register(server => server.workspaceBuildTargets()).asScala
}

def buildTargetJavacOptions(
params: JavacOptionsParams
): Future[JavacOptionsResult] = {
val resultOnJavacOptionsUnsupported = new JavacOptionsResult(
List.empty[JavacOptionsItem].asJava
)
if (isSbt) Future.successful(resultOnJavacOptionsUnsupported)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Arthurm1 I added this check since it seems that sbt shuts down when unexpected request is made.

else {
val onFail = Some(
(
resultOnJavacOptionsUnsupported,
"Java targets not supported by server"
)
)
register(server => server.buildTargetJavacOptions(params), onFail).asScala
}
}

def buildTargetScalacOptions(
params: ScalacOptionsParams
): Future[ScalacOptionsResult] = {
register(server => server.buildTargetScalacOptions(params)).asScala
val resultOnScalaOptionsUnsupported = new ScalacOptionsResult(
List.empty[ScalacOptionsItem].asJava
)
val onFail = Some(
(resultOnScalaOptionsUnsupported, "Scala targets not supported by server")
)
register(server => server.buildTargetScalacOptions(params), onFail).asScala
}

def buildTargetSources(params: SourcesParams): Future[SourcesResult] = {
Expand Down Expand Up @@ -228,7 +251,8 @@ class BuildServerConnection private (

}
private def register[T: ClassTag](
action: MetalsBuildServer => CompletableFuture[T]
action: MetalsBuildServer => CompletableFuture[T],
onFail: => Option[(T, String)] = None
): CompletableFuture[T] = {
val original = connection
val actionFuture = original
Expand All @@ -248,8 +272,15 @@ class BuildServerConnection private (
}
case t
if implicitly[ClassTag[T]].runtimeClass.getSimpleName != "Object" =>
val name = implicitly[ClassTag[T]].runtimeClass.getSimpleName
Future.failed(MetalsBspException(name, t.getMessage))
onFail
.map { case (defaultResult, message) =>
scribe.info(message)
Future.successful(defaultResult)
}
.getOrElse({
val name = implicitly[ClassTag[T]].runtimeClass.getSimpleName
Future.failed(MetalsBspException(name, t.getMessage))
})
}
CancelTokens.future(_ => actionFuture)
}
Expand Down Expand Up @@ -345,6 +376,7 @@ object BuildServerConnection {
}

final case class BspExtraBuildParams(
javaSemanticdbVersion: String,
semanticdbVersion: String,
supportedScalaVersions: java.util.List[String]
)
Expand All @@ -358,6 +390,7 @@ object BuildServerConnection {
serverName: String
): InitializeBuildResult = {
val extraParams = BspExtraBuildParams(
BuildInfo.javaSemanticdbVersion,
BuildInfo.scalametaVersion,
BuildInfo.supportedScala2Versions.asJava
)
Expand All @@ -369,7 +402,7 @@ object BuildServerConnection {
BuildInfo.bspVersion,
workspace.toURI.toString,
new BuildClientCapabilities(
Collections.singletonList("scala")
List("scala", "java").asJava
)
)
val gson = new Gson
Expand Down
Loading