-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2249 from scala-steward-org/topic/load-latest-art…
…ifact-migrations Load artifact migrations from this repository
- Loading branch information
Showing
15 changed files
with
336 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 0 additions & 117 deletions
117
modules/core/src/main/scala/org/scalasteward/core/update/ArtifactMigrations.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/core/src/main/scala/org/scalasteward/core/update/artifact/ArtifactChange.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018-2021 Scala Steward contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.scalasteward.core.update.artifact | ||
|
||
import io.circe.Decoder | ||
import io.circe.generic.extras.{semiauto, Configuration} | ||
import org.scalasteward.core.data.GroupId | ||
|
||
final case class ArtifactChange( | ||
groupIdBefore: Option[GroupId], | ||
groupIdAfter: GroupId, | ||
artifactIdBefore: Option[String], | ||
artifactIdAfter: String, | ||
initialVersion: String | ||
) | ||
|
||
object ArtifactChange { | ||
implicit val configuration: Configuration = | ||
Configuration.default.withDefaults | ||
|
||
implicit val decoder: Decoder[ArtifactChange] = | ||
semiauto.deriveConfiguredDecoder | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/core/src/main/scala/org/scalasteward/core/update/artifact/ArtifactChanges.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2018-2021 Scala Steward contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.scalasteward.core.update.artifact | ||
|
||
import io.circe.Decoder | ||
import io.circe.generic.extras.{semiauto, Configuration} | ||
|
||
final case class ArtifactChanges(changes: List[ArtifactChange]) | ||
|
||
object ArtifactChanges { | ||
implicit val configuration: Configuration = | ||
Configuration.default.withDefaults | ||
|
||
implicit val artifactChangesDecoder: Decoder[ArtifactChanges] = | ||
semiauto.deriveConfiguredDecoder | ||
} |
48 changes: 48 additions & 0 deletions
48
.../core/src/main/scala/org/scalasteward/core/update/artifact/ArtifactMigrationsFinder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2018-2021 Scala Steward contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.scalasteward.core.update.artifact | ||
|
||
import cats.syntax.all._ | ||
import org.scalasteward.core.data.{CrossDependency, Dependency, Update} | ||
import org.scalasteward.core.util.Nel | ||
|
||
final class ArtifactMigrationsFinder(migrations: List[ArtifactChange]) { | ||
def findUpdateWithRenamedArtifact(dependency: Dependency): Option[Update.Single] = | ||
migrations | ||
.find { migration => | ||
(migration.groupIdBefore, migration.artifactIdBefore) match { | ||
case (Some(groupId), Some(artifactId)) => | ||
groupId === dependency.groupId && | ||
artifactId === dependency.artifactId.name | ||
case (Some(groupId), None) => | ||
groupId === dependency.groupId && | ||
migration.artifactIdAfter === dependency.artifactId.name | ||
case (None, Some(artifactId)) => | ||
migration.groupIdAfter === dependency.groupId && | ||
artifactId === dependency.artifactId.name | ||
case (None, None) => false | ||
} | ||
} | ||
.map { migration => | ||
Update.Single( | ||
CrossDependency(dependency), | ||
Nel.one(migration.initialVersion), | ||
Some(migration.groupIdAfter), | ||
Some(migration.artifactIdAfter) | ||
) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../core/src/main/scala/org/scalasteward/core/update/artifact/ArtifactMigrationsLoader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2018-2021 Scala Steward contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.scalasteward.core.update.artifact | ||
|
||
import cats.MonadThrow | ||
import cats.syntax.all._ | ||
import io.circe.config.parser.decode | ||
import org.http4s.Uri | ||
import org.http4s.implicits.http4sLiteralsSyntax | ||
import org.scalasteward.core.io.FileAlg | ||
import org.scalasteward.core.update.artifact.ArtifactMigrationsLoader.defaultArtifactMigrationsUrl | ||
import org.typelevel.log4cats.Logger | ||
|
||
final class ArtifactMigrationsLoader[F[_]](implicit | ||
fileAlg: FileAlg[F], | ||
logger: Logger[F], | ||
F: MonadThrow[F] | ||
) { | ||
def createFinder(artifactMigrations: List[Uri]): F[ArtifactMigrationsFinder] = | ||
loadAll(artifactMigrations).map(new ArtifactMigrationsFinder(_)) | ||
|
||
def loadAll(artifactMigrations: List[Uri]): F[List[ArtifactChange]] = | ||
(defaultArtifactMigrationsUrl :: artifactMigrations) | ||
.flatTraverse(loadMigrations) | ||
.flatTap(migrations => logger.info(s"Loaded ${migrations.size} artifact migrations")) | ||
|
||
private def loadMigrations(uri: Uri): F[List[ArtifactChange]] = | ||
logger.debug(s"Loading artifact migrations from $uri") >> | ||
fileAlg.readUri(uri).flatMap(decodeMigrations(_, uri)).map(_.changes) | ||
|
||
private def decodeMigrations(content: String, uri: Uri): F[ArtifactChanges] = | ||
F.fromEither(decode[ArtifactChanges](content)) | ||
.adaptErr(new Throwable(s"Failed to load artifact migrations from ${uri.renderString}", _)) | ||
} | ||
|
||
object ArtifactMigrationsLoader { | ||
val defaultArtifactMigrationsUrl: Uri = | ||
uri"https://raw.githubusercontent.com/scala-steward-org/scala-steward/master/modules/core/src/main/resources/artifact-migrations.conf" | ||
} |
Oops, something went wrong.