Skip to content

Commit

Permalink
Merge pull request #2520 from Arthurm1/java_targets
Browse files Browse the repository at this point in the history
Handle Java-only build targets
  • Loading branch information
Arthurm1 authored Dec 23, 2021
2 parents 69c1200 + 675816a commit 11c7c27
Show file tree
Hide file tree
Showing 46 changed files with 1,474 additions and 354 deletions.
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",
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)
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

0 comments on commit 11c7c27

Please sign in to comment.