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

feat: Using dependency walking to verify JDK9 Plugin works #1065

Merged
merged 9 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions .github/workflows/binary-compatibility-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Compile code
run: sbt +compile

- name: Verify JDK9 settings apply
run: sbt jdk9Check

- name: Report MiMa Binary Issues
run: |-
sbt +mimaReportBinaryIssues
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ jobs:
- name: Enable jvm-opts
run: cp .jvmopts-ci .jvmopts

- name: Verify JDK9 settings apply
run: sbt jdk9Check

- name: Compile and Test
# note that this is not running any multi-jvm tests because multi-in-test=false
run: |-
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ lazy val clusterSharding = pekkoModule("cluster-sharding")
.settings(AutomaticModuleName.settings("pekko.cluster.sharding"))
.settings(OSGi.clusterSharding)
.settings(Protobuf.settings)
.enablePlugins(MultiNode, ScaladocNoVerificationOfDiagrams, Jdk9, SbtOsgi)
.enablePlugins(MultiNode, ScaladocNoVerificationOfDiagrams, Jdk9, Jdk9PackageCheck, SbtOsgi)

lazy val clusterTools = pekkoModule("cluster-tools")
.dependsOn(
Expand Down Expand Up @@ -399,7 +399,7 @@ lazy val remote =
.settings(Protobuf.settings)
.settings(Test / parallelExecution := false)
.settings(serialversionRemoverPluginSettings)
.enablePlugins(Jdk9, SbtOsgi)
.enablePlugins(Jdk9, Jdk9PackageCheck, SbtOsgi)

lazy val remoteTests = pekkoModule("remote-tests")
.dependsOn(
Expand Down Expand Up @@ -428,7 +428,7 @@ lazy val stream = pekkoModule("stream")
.settings(OSGi.stream)
.settings(Protobuf.settings)
.settings(VerifyJDK9Classes.settings)
.enablePlugins(BoilerplatePlugin, Jdk9, SbtOsgi)
.enablePlugins(BoilerplatePlugin, Jdk9, Jdk9PackageCheck, SbtOsgi)

lazy val streamTestkit = pekkoModule("stream-testkit")
.dependsOn(stream, testkit % "compile->compile;test->test")
Expand Down Expand Up @@ -483,7 +483,7 @@ lazy val actorTyped = pekkoModule("actor-typed")

implicit val timeout = Timeout(5 seconds)
""")
.enablePlugins(Jdk9, SbtOsgi)
.enablePlugins(Jdk9, Jdk9PackageCheck, SbtOsgi)

lazy val persistenceTyped = pekkoModule("persistence-typed")
.dependsOn(
Expand Down
88 changes: 88 additions & 0 deletions project/Jdk9PackageCheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import Jdk9.CompileJdk9
import sbt.AutoPlugin
import sbt.Def
import sbt.Keys._
import sbt._
import sbt.internal.BuildStructure

object Jdk9PackageCheck extends AutoPlugin {
Roiocam marked this conversation as resolved.
Show resolved Hide resolved

object autoImport {
lazy val jdk9Check = taskKey[Unit]("Report which jars are in each scope.")
Roiocam marked this conversation as resolved.
Show resolved Hide resolved
}

import autoImport._

override lazy val trigger = NoTrigger
override lazy val requires = Jdk9
val validScopeKey = (Compile / packageBin).scopedKey

def scopedKeyMatch(scopedKey: ScopedKey[_], projectRef: ProjectRef): Boolean = {
if (scopedKey.key != validScopeKey.key || scopedKey.scope.config != validScopeKey.scope.config)
return false

scopedKey.scope.project match {
case Select(s) => s == projectRef
case _ => false
}
}

def hasJdk9Config(set: Set[_ <: sbt.ScopedKey[_]])(implicit cMap: Map[Def.ScopedKey[_], Def.Flattened]): Boolean = {
set.exists { key =>
key.scope.config match {
case Select(s) if s.name == CompileJdk9.name => true
He-Pin marked this conversation as resolved.
Show resolved Hide resolved
case _ =>
cMap.get(key).exists { flattened =>
val dependencies = flattened.dependencies.toSet
dependencies.nonEmpty && hasJdk9Config(dependencies)
}
}
}
}

lazy val checkSettings = Seq(
jdk9Check := {
implicit val display = Project.showContextKey(state.value)
val structure: BuildStructure = Project.extract(state.value).structure
val currentProjectRef = thisProjectRef.value

// Crawl all configurations of the current project
val comp = Def.compiled(structure.settings, true)(structure.delegates, structure.scopeLocal, display)
implicit val cMap = Def.flattenLocals(comp)

// Filter: The packaging task of the current execution module
val checkScopeKey = cMap.collect {
case (key, _) if scopedKeyMatch(key, currentProjectRef) => key
}
// Dependency walking and check
for (t <- checkScopeKey) {
val depends = cMap.get(t) match {
case Some(c) => c.dependencies.toSet;
case None => Set.empty
}
if (!hasJdk9Config(depends)) {
throw new Exception("No JDK9 configuration detected.")
Roiocam marked this conversation as resolved.
Show resolved Hide resolved
}
}
})

override def projectSettings: Seq[Def.Setting[_]] = checkSettings

}
Loading