Skip to content

Commit

Permalink
Work with sbt-sonatype
Browse files Browse the repository at this point in the history
  • Loading branch information
hamnis committed Nov 14, 2023
1 parent 8b80633 commit bd5568a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 14 deletions.
29 changes: 24 additions & 5 deletions aether-deploy/src/main/scala/aether/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ object AetherPlugin extends AutoPlugin {
}

private def toRepository(
repo: MavenRepository,
repo: RepoRef,
overridePluginType: Boolean,
credentials: Option[DirectCredentials]
): RemoteRepository = {
val builder: Builder = new Builder(repo.name, if (overridePluginType) "sbt-plugin" else "default", repo.root)
val builder: Builder = new Builder(repo.name, if (overridePluginType) "sbt-plugin" else "default", repo.url.toString)
credentials.foreach { c =>
builder.setAuthentication(new AuthenticationBuilder().addUsername(c.userName).addPassword(c.passwd).build())
}
Expand All @@ -165,15 +165,32 @@ object AetherPlugin extends AutoPlugin {
)(implicit
stream: TaskStreams
) {
object IsPatternMavenRepo {
def unapply(resolver: Resolver): Option[(sbt.PatternsBasedRepository, String)] = {
resolver match {
case repository: FileRepository if repository.patterns.isMavenCompatible =>
repository.patterns.artifactPatterns.headOption
.flatMap { pattern =>
val idx = pattern.indexOf(Resolver.mavenStyleBasePattern)
if (idx > 0) Some(pattern.substring(0, idx - 1))
else None
}
.map(repository -> _)
case _ => None
}
}
}

val repository = repo
.collect {
case x: MavenRepository => x
case x => sys.error("The configured repo MUST be a maven repo, but was: " + x)
case x: MavenRepository => RepoRef(x.name, URI.create(x.root))
case IsPatternMavenRepo((x, root)) => RepoRef(x.name, URI.create(if (root.startsWith("/")) "file:" + root else root))
case x => sys.error("The configured repo MUST be a maven compatible repo, but was: " + x)
}
.getOrElse(sys.error("There MUST be a configured publish repo"))

val maybeCred = Try {
val href = URI.create(repository.root)
val href = repository.url
val c = Credentials.forHost(cred, href.getHost)
if (c.isEmpty && href.getHost != null) {
stream.log.warn("No credentials supplied for %s".format(href.getHost))
Expand Down Expand Up @@ -209,4 +226,6 @@ object AetherPlugin extends AutoPlugin {
throw ex
}
}

case class RepoRef(name: String, url: URI)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / version := "0.1"

name := "deploy-file-pattern"

organization := "deploy-file-pattern"

scalaVersion := "3.3.1"

publishTo := Some(Resolver.file("foo", file(".") / "target" / "repo"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
val pluginVersion = scala.util.Properties.propOrNone("plugin.version").getOrElse(
throw new RuntimeException("""
|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.
""".stripMargin))

addSbtPlugin("no.arktekk.sbt" % "aether-deploy" % pluginVersion)
7 changes: 7 additions & 0 deletions aether-deploy/src/sbt-test/deploy/deploy-file-pattern/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Deploy to file url
> aetherDeploy
$ exists target/repo/deploy-file-pattern
$ exists target/repo/deploy-file-pattern/deploy-file-pattern_3/maven-metadata.xml
$ exists target/repo/deploy-file-pattern/deploy-file-pattern_3/0.1/
$ exists target/repo/deploy-file-pattern/deploy-file-pattern_3/0.1/deploy-file-pattern_3-0.1.jar
$ exists target/repo/deploy-file-pattern/deploy-file-pattern_3/0.1/deploy-file-pattern_3-0.1.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / version := "0.1"

name := "deploy-sbt-sonatype"

organization := "deploy-sbt-sonatype"

scalaVersion := "3.3.1"

publishTo := sonatypePublishToBundle.value
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
val pluginVersion = scala.util.Properties.propOrNone("plugin.version").getOrElse(
throw new RuntimeException("""
|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.
""".stripMargin))

addSbtPlugin("no.arktekk.sbt" % "aether-deploy" % pluginVersion)
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
9 changes: 9 additions & 0 deletions aether-deploy/src/sbt-test/deploy/deploy-sbt-sonatype/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Deploy to file url
> aetherDeploy
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/maven-metadata.xml
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/0.1/deploy-sbt-sonatype_3-0.1.jar
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/0.1/deploy-sbt-sonatype_3-0.1-javadoc.jar
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/0.1/deploy-sbt-sonatype_3-0.1-sources.jar
$ exists target/sonatype-staging/0.1/deploy-sbt-sonatype/deploy-sbt-sonatype_3/0.1/deploy-sbt-sonatype_3-0.1.pom
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ lazy val aetherDeploy = (project in file("aether-deploy"))
.settings(
name := "aether-deploy",
libraryDependencies ++= {
val mavenVersion = "3.9.4"
val mavenResolverVersion = "1.9.15"
val mavenVersion = "3.9.5"
val mavenResolverVersion = "1.9.16"
Seq(
"org.apache.maven" % "maven-resolver-provider" % mavenVersion,
"org.apache.maven.resolver" % "maven-resolver-api" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-impl" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-transport-file" % mavenResolverVersion,
"org.apache.maven" % "maven-resolver-provider" % mavenVersion,
"org.apache.maven.resolver" % "maven-resolver-api" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-impl" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-transport-file" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-connector-basic" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-transport-http" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-transport-file" % mavenResolverVersion,
"commons-logging" % "commons-logging" % "1.2"
"org.apache.maven.resolver" % "maven-resolver-transport-http" % mavenResolverVersion,
"org.apache.maven.resolver" % "maven-resolver-transport-file" % mavenResolverVersion,
"commons-logging" % "commons-logging" % "1.2"
)
}
)
Expand Down

0 comments on commit bd5568a

Please sign in to comment.