Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 10 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.spurint.maven.plugins</groupId>
<artifactId>mima-maven-plugin</artifactId>
<version>0.9.2.1-SNAPSHOT</version>
<version>0.9.3.0</version>
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
<packaging>maven-plugin</packaging>

<name>MiMa Maven Plugin</name>
Expand Down Expand Up @@ -48,12 +48,12 @@
<maven-artifact-transfer.version>0.13.1</maven-artifact-transfer.version>
<maven-plugin-annotations.version>3.6.1</maven-plugin-annotations.version>
<maven-plugin-api.version>3.8.1</maven-plugin-api.version>
<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>
<maven-plugin-plugin.version>3.9.0</maven-plugin-plugin.version>
<maven-project.version>3.0-alpha-2</maven-project.version>
<maven-shared.version>3.2.1</maven-shared.version>
<maven-common-artifact-filters.version>3.1.0</maven-common-artifact-filters.version>
<mima.version>0.9.2</mima.version>
<plexus-utils.version>3.3.0</plexus-utils.version>
<plexus-utils.version>3.5.1</plexus-utils.version>
<scala.binary.version>2.13</scala.binary.version>
<scala.version>2.13.6</scala.version>
<scala-xml.version>2.0.1</scala-xml.version>
Expand Down Expand Up @@ -98,6 +98,11 @@
<artifactId>maven-artifact-transfer</artifactId>
<version>${maven-artifact-transfer.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand All @@ -123,7 +128,7 @@
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.5.3</version>
<version>4.8.1</version>
<configuration>
<recompileMode>incremental</recompileMode>
<args>
Expand Down Expand Up @@ -154,7 +159,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down
50 changes: 40 additions & 10 deletions src/main/scala/org/spurint/maven/plugins/mima/MiMaMojo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.spurint.maven.plugins.mima
import com.typesafe.tools.mima.core.util.log.Logging
import com.typesafe.tools.mima.core.{Problem, ProblemFilter, ProblemFilters}
import com.typesafe.tools.mima.lib.MiMaLib

Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
import java.io.{File, FileNotFoundException, InputStream}
import java.net.{HttpURLConnection, URL}
import java.util
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager
import org.apache.maven.artifact.repository.ArtifactRepository
import org.apache.maven.artifact.repository.{ArtifactRepository, Authentication}
import org.apache.maven.artifact.versioning.VersionRange
import org.apache.maven.artifact.{Artifact, DefaultArtifact}
import org.apache.maven.execution.MavenSession
Expand All @@ -16,6 +17,10 @@ import org.apache.maven.plugins.annotations._
import org.apache.maven.project.{DefaultProjectBuildingRequest, MavenProject}
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate
import org.apache.maven.shared.transfer.artifact.resolve.{ArtifactResolver, ArtifactResolverException}
import org.apache.maven.plugins.annotations.Parameter
import org.apache.maven.settings.Settings

import java.util.Base64
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}
Expand Down Expand Up @@ -79,12 +84,15 @@ class MiMaMojo extends AbstractMojo {
@Parameter(property = "mima.skip", defaultValue = "false")
private var skip: Boolean = false

@Parameter(property = "readTimeout", defaultValue = "4000")
private var readTimeout: Int = 4000
@Parameter(property = "readTimeout", defaultValue = "60000")
private var readTimeout: Int = 60000
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated

@Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
private var buildOutputDirectory: File = _

@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private var settings: Settings = _

@Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
private var remoteRepositories: util.List[ArtifactRepository] = _

Expand Down Expand Up @@ -201,6 +209,19 @@ class MiMaMojo extends AbstractMojo {

private def resolveArtifact(artifact: Artifact): Option[File] = {
val buildingRequest = new DefaultProjectBuildingRequest(this.session.getProjectBuildingRequest)

remoteRepositories.forEach { repo =>
val serverOpt = Option(settings.getServer(repo.getId))
System.err.println(s"Repo: ${repo.getUrl} server: ${serverOpt.map(_.getId)}")
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
serverOpt.foreach { server =>
val user = server.getUsername
val passwd = server.getPassword
val auth = new Authentication(user, passwd)
System.err.println(s"Setting authentication for repo: ${repo.getUrl} server: ${server.getUsername} auth: ${auth.getUsername}")
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
repo.setAuthentication(auth)
}
}

buildingRequest.setRemoteRepositories(remoteRepositories)

val coordinate = new DefaultArtifactCoordinate
Expand All @@ -219,29 +240,38 @@ class MiMaMojo extends AbstractMojo {
getLog.warn(s"Unable to fetch previous artifact: $e")
Option.empty
}) match {
case Success(file) => file
case Failure(ex) => throw ex
}
case Success(file) => file
case Failure(ex) => throw ex
}
Comment thread
JaySucharitakul marked this conversation as resolved.
}

private def fetchLatestReleaseVersion(): Option[String] = {
this.remoteRepositories.asScala.foldLeft(Option.empty[String])({
case (None, repo) =>
val serverOpt = Option(settings.getServer(repo.getId))
getLog.info(s"Repo: ${repo.getUrl} server: ${serverOpt.map(_.getId)}")
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
val credsOpt = serverOpt.map( {server => (server.getUsername, server.getPassword)})
val url = new URL(s"${repo.getUrl}/${this.project.getGroupId.replace(".", "/")}/${this.project.getArtifactId}/maven-metadata.xml")
makeHttpRequest(url).flatMap({ input =>
makeHttpRequest(url, credsOpt).flatMap({ input =>
val xml = XML.load(input)
(xml \ "versioning" \ "release").headOption.map(_.text.trim)
})
case (v @ Some(_), _) => v
})
}

private def makeHttpRequest(url: URL, retriesLeft: Int = 3): Option[InputStream] = {
private def makeHttpRequest(url: URL, credsOpt: Option[(String, String)], retriesLeft: Int = 3): Option[InputStream] = {
try {
val conn = url.openConnection() match {
case huc: HttpURLConnection => huc
case x => throw new AssertionError(s"${x.getClass.getName} should be a HttpURLConnection")
}
credsOpt.foreach { case (username, password) =>
val userPass = s"$username:$password"
val basicAuth = s"Basic ${new String(Base64.getEncoder.encode(userPass.getBytes))}"
Comment thread
JaySucharitakul marked this conversation as resolved.
Outdated
getLog.info(s"$url using basic authentication.")
conn.setRequestProperty("Authorization", basicAuth)
}
conn.setConnectTimeout(2000)
conn.setReadTimeout(readTimeout)
conn.getResponseCode match {
Expand All @@ -251,14 +281,14 @@ class MiMaMojo extends AbstractMojo {
Option(conn.getHeaderField("Location")).fold(
throw new MojoExecutionException(s"Repository server at $url returned status $x but with no Location header")
)(
location => makeHttpRequest(new URL(location), retriesLeft - 1)
location => makeHttpRequest(new URL(location), credsOpt, retriesLeft - 1)
)
case 404 | 410 =>
None
case x if x >= 400 && x < 500 && x != 408 =>
throw new MojoExecutionException(s"Repository server at $url returned status $x")
case _ if retriesLeft > 0 =>
makeHttpRequest(url, retriesLeft - 1)
makeHttpRequest(url, credsOpt, retriesLeft - 1)
case x =>
throw new MojoExecutionException(s"Repository server at $url returned status $x")
}
Expand Down