Skip to content
Open
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ jobs:
- uses: sbt/setup-sbt@v1
- name: Test
shell: bash
run: sbt -v clean +test +scripted
run: sbt -v clean test scripted
- name: Test sbt 2
shell: bash
if: ${{ matrix.java != '8' }}
run: sbt -v "++ 3.x" test # TODO enable scripted test
- name: Ensure formatting
shell: bash
run: sbt -v clean scalafmtSbtCheck scalafmtCheckAll
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-java@v5
with:
distribution: "zulu"
java-version: "8"
java-version: "17"
cache: sbt
- uses: sbt/setup-sbt@v1
- name: Release
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.0"
version = "3.11.0"
maxColumn = 120
project.git = true
runner.dialect = scala212source3
Expand Down
12 changes: 11 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ lazy val root = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(nocomma {
name := "sbt-pom-reader"
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" =>
Seq("-release:8")
case _ =>
Nil
}
}
scalacOptions ++= Seq(
"-Wconf:any:wv",
"-Xlint:unused",
Expand Down Expand Up @@ -46,10 +54,12 @@ lazy val root = (project in file("."))
scriptedLaunchOpts := scriptedLaunchOpts.value ++ Seq("-Dproject.version=" + version.value)
scriptedLaunchOpts ++= Seq("-Dplugin.version=" + version.value)
scriptedBufferLog := true
crossScalaVersions += "3.8.4"
addSbtPlugin("com.github.sbt" % "sbt2-compat" % "0.1.0")
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.9.9"
case _ => "2.0.0-RC6"
case _ => "2.0.0"
}
}
scriptedSbt := {
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/sbtpomreader/MavenHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.apache.maven.model.{
Repository as PomRepository
}
import org.apache.maven.settings.Settings as MavenSettings
import sbtcompat.PluginCompat.*

/** Helper object to extract maven settings. */
object MavenHelper {
Expand Down Expand Up @@ -99,7 +100,7 @@ object MavenHelper {
pr ++ sr
},
// TODO - split into Compile/Test/Runtime/Console
scalacOptions ++= {
scalacOptions ++= Def.uncached {
getScalacOptions(effectivePom.value)
},
credentials ++= createSbtCredentialsFromUserSettings(effectivePom.value, effectiveSettings.value)
Expand Down Expand Up @@ -132,10 +133,10 @@ object MavenHelper {
}

def getAdditionalSourcesPlugin(pom: PomModel): Seq[PomPlugin] = {
pom.getBuild.getPlugins.asScala filter { plugin =>
pom.getBuild.getPlugins.asScala.filter { plugin =>
(plugin.getGroupId == "org.codehaus.mojo") &&
(plugin.getArtifactId == "build-helper-maven-plugin")
}
}.toSeq
}

def getAdditionalSourcesFromPlugin(pom: PomModel): Seq[String] = {
Expand Down Expand Up @@ -226,7 +227,7 @@ object MavenHelper {
case (Some(mScope), Some(mType)) if ("test-jar".equalsIgnoreCase(mType)) =>
mod
.withConfigurations(Some(s"${mScope}->test"))
.intransitive
.intransitive()
// <classifier>tests</classifier>
// <scope>SCOPE</scope>
case (Some(mScope), _) if (mvnClassifier.getOrElse("").equalsIgnoreCase("tests")) =>
Expand All @@ -247,7 +248,7 @@ object MavenHelper {

def getDependencies(pom: PomModel): Seq[ModuleID] = {
for {
dep <- pom.getDependencies.asScala
dep <- pom.getDependencies.asScala.toSeq
} yield convertDep(dep)
}

Expand All @@ -263,7 +264,7 @@ object MavenHelper {

def getPomResolvers(pom: PomModel): Seq[Resolver] = {
for {
repo <- pom.getRepositories.asScala
repo <- pom.getRepositories.asScala.toSeq
// TODO - Support other layouts
if repo.getLayout == "default"
} yield repo.getId at repo.getUrl
Expand All @@ -276,7 +277,7 @@ object MavenHelper {
def getServerRealm(method: String, uri: String): Option[String] = {
// This is consigned to a Try until proper handling of offline mode.
Try {
val con = url(uri).openConnection.asInstanceOf[java.net.HttpURLConnection]
val con = new java.net.URI(uri).toURL.openConnection.asInstanceOf[java.net.HttpURLConnection]
con setRequestMethod method
if (con.getResponseCode == 401) {
val authRealmConfigs = con.getHeaderField("WWW-Authenticate")
Expand Down
18 changes: 9 additions & 9 deletions src/main/scala/sbtpomreader/MavenProjectHelper.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbtpomreader

import sbt.*
import sbt.{ given, * }

import scala.collection.JavaConverters.*

Expand Down Expand Up @@ -103,16 +103,16 @@ object MavenProjectHelper {
// TODO - Configure debugging output....
val currentProject: Project = (
Project(makeProjectName(current.model, overrideRootProjectName), current.dir)
// First pull in settings from pom
settings (useMavenPom*)
// First pull in settings from pom
.settings(useMavenPom*)
// Now update depends on relationships with actual configurations
dependsOn (projectsWithModules.map { case (p, m) => new ClasspathDependency(p, m.configurations) }*)
.dependsOn(projectsWithModules.map { case (p, m) => new ClasspathDependency(p, m.configurations) }*)
// Now fix aggregate relationships
aggregate (aggregates.map(x => x: ProjectReference)*)
.aggregate(aggregates.map(x => x: ProjectReference)*)
// Now remove any inter-project dependencies we pulled in from the maven pom.
// TODO - Maybe we can fix the useMavenPom settings so we don't need to
// post-filter artifacts?
settings (
.settings(
Keys.libraryDependencies := {
val depIds = getDepsFor(current).map(_.id).toSet
Keys.libraryDependencies.value.filterNot { dep =>
Expand Down Expand Up @@ -146,7 +146,7 @@ object MavenProjectHelper {
// An unsorted walk of the tree
def allProjectsInTree(tree: ProjectTree): Seq[ProjectTree] =
tree match {
case x: SimpleProject => Seq(x)
case x: SimpleProject => Seq(x)
case agg: AggregateProject =>
Seq(agg) ++ agg.children.flatMap(allProjectsInTree)
}
Expand All @@ -156,7 +156,7 @@ object MavenProjectHelper {
for (project <- projects) yield {
val deps =
for {
dep <- Option(project.model.getDependencies).map(_.asScala).getOrElse(Nil)
dep <- Option(project.model.getDependencies).map(_.asScala.toSeq).getOrElse(Nil)
depId = makeId(dep.getGroupId, dep.getArtifactId, dep.getVersion)
pdep <- projects
if pdep.id == depId
Expand All @@ -168,7 +168,7 @@ object MavenProjectHelper {

def getChildProjectPoms(pom: PomModel, pomFile: File): Seq[File] =
for {
childDirName <- Option(pom.getModules) map (_.asScala) getOrElse Nil
childDirName <- Option(pom.getModules) map (_.asScala.toSeq) getOrElse Nil
childPom = pomFile.getParentFile / childDirName / "pom.xml"
if childPom.exists
} yield childPom
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/sbtpomreader/MavenUserSettingsHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object MavenUserSettingsHelper {
def getUserResolvers(settings: MavenSettings): Seq[Resolver] = {
val profiles = settings.getProfilesAsMap
for {
profileName <- settings.getActiveProfiles.asScala
profileName <- settings.getActiveProfiles.asScala.toSeq
profile <- Option(profiles.get(profileName)).toSeq
repo <- profile.getRepositories.asScala
} yield repo.getId at repo.getUrl
Expand All @@ -43,7 +43,7 @@ object MavenUserSettingsHelper {
def getUserRemoteRepositories(settings: MavenSettings): Seq[RemoteRepository] = {
val profiles = settings.getProfilesAsMap
for {
profileName <- settings.getActiveProfiles.asScala
profileName <- settings.getActiveProfiles.asScala.toSeq
profile <- Option(profiles.get(profileName)).toSeq
repo <- profile.getRepositories.asScala
} yield new RemoteRepository.Builder(repo.getId, repo.getLayout, repo.getUrl).build()
Expand All @@ -52,7 +52,7 @@ object MavenUserSettingsHelper {
/** Extract the server credentials from the given settings file. */
def serverCredentials(settings: MavenSettings): Seq[ServerCredentials] =
for {
s <- settings.getServers.asScala
s <- settings.getServers.asScala.toSeq
} yield ServerCredentials(s.getId, s.getUsername, s.getPassword)

/** Associates server credentials defined in the settings with repositories referenced in the POM. */
Expand All @@ -63,7 +63,7 @@ object MavenUserSettingsHelper {
): Seq[(PomRepository, ServerCredentials)] = {
// TODO: handle repos in settings.xml
for {
repo <- pom.getRepositories.asScala
repo <- pom.getRepositories.asScala.toSeq
cred <- creds
if cred.id == repo.getId
} yield (repo -> cred)
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/sbtpomreader/SbtPomKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait SbtPomKeys {
lazy val effectivePom = SettingKey[Model]("mvn-effective-pom", "Reads the maven effective pom.")
lazy val effectiveSettings =
SettingKey[Option[MavenSettings]]("mvn-effective-settings", "The effective maven settings model.")
@transient
lazy val showEffectivePom = TaskKey[Unit]("show-effective-pom", "Displays the effective pom from maven.")
lazy val mavenUserProperties =
SettingKey[Map[String, String]]("maven-user-properties", "A map of user properties to be applied")
Expand Down