From f64a275abeb31d99fcb2eea4f88916f0c1f5fc04 Mon Sep 17 00:00:00 2001 From: Andy Jayne Date: Thu, 30 Nov 2023 13:00:13 +0000 Subject: [PATCH 1/2] Add test for semver metadata in version string This test checks whether the plugin correctly handles dependencies where the version contains a + character. The character is commonly used in semver version strings to add build metadata to the version. Per https://semver.org/ Currently this test fails as the plugin is comparing the following version strings that do not match: 7.2.27+33-04a1ea9e-SNAPSHOT 7.2.27%2B33-04a1ea9e-SNAPSHOT Reproduces: https://github.com/cb372/sbt-explicit-dependencies/issues/110 --- src/sbt-test/basic/semver-metadata/build.sbt | 5 +++++ src/sbt-test/basic/semver-metadata/project/plugins.sbt | 1 + .../basic/semver-metadata/src/main/scala/Main.scala | 10 ++++++++++ src/sbt-test/basic/semver-metadata/test | 2 ++ 4 files changed, 18 insertions(+) create mode 100644 src/sbt-test/basic/semver-metadata/build.sbt create mode 100644 src/sbt-test/basic/semver-metadata/project/plugins.sbt create mode 100644 src/sbt-test/basic/semver-metadata/src/main/scala/Main.scala create mode 100644 src/sbt-test/basic/semver-metadata/test diff --git a/src/sbt-test/basic/semver-metadata/build.sbt b/src/sbt-test/basic/semver-metadata/build.sbt new file mode 100644 index 0000000..6724785 --- /dev/null +++ b/src/sbt-test/basic/semver-metadata/build.sbt @@ -0,0 +1,5 @@ +scalaVersion := sys.props("scala.version") +resolvers ++= Seq("Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots") +libraryDependencies ++= Seq( + "org.scalaz" %% "scalaz-core" % "7.2.27+33-04a1ea9e-SNAPSHOT" +) diff --git a/src/sbt-test/basic/semver-metadata/project/plugins.sbt b/src/sbt-test/basic/semver-metadata/project/plugins.sbt new file mode 100644 index 0000000..40f24a3 --- /dev/null +++ b/src/sbt-test/basic/semver-metadata/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % sys.props("plugin.version")) diff --git a/src/sbt-test/basic/semver-metadata/src/main/scala/Main.scala b/src/sbt-test/basic/semver-metadata/src/main/scala/Main.scala new file mode 100644 index 0000000..132b030 --- /dev/null +++ b/src/sbt-test/basic/semver-metadata/src/main/scala/Main.scala @@ -0,0 +1,10 @@ +import scalaz._ +import scalaz.std.anyVal._ +import scalaz.std.list._ +import scalaz.std.option._ +import scalaz.syntax.equal._ + +object Main { + val list1: List[Option[Int]] = List(Some(1), Some(2), Some(3), Some(4)) + assert(Traverse[List].sequence(list1) === Some(List(1,2,3,4))) +} diff --git a/src/sbt-test/basic/semver-metadata/test b/src/sbt-test/basic/semver-metadata/test new file mode 100644 index 0000000..a465c04 --- /dev/null +++ b/src/sbt-test/basic/semver-metadata/test @@ -0,0 +1,2 @@ +> unusedCompileDependenciesTest +> undeclaredCompileDependenciesTest From 9334a09aa091d762e9714f28843645c8837281a7 Mon Sep 17 00:00:00 2001 From: Andy Jayne Date: Thu, 30 Nov 2023 13:09:48 +0000 Subject: [PATCH 2/2] Handle semver metadata in version string Update how version is parsed for pom files in the jar file to dependency logic to to cater for characters that are valid in version strings but encoded in the file path. For example, "+" which is used for semver metadata, encoded as "%2B". Before this change 7.2.27+33-04a1ea9e-SNAPSHOT version string was not handled consistently and would result in different values in the declared/used compile dependencies. Fixes: https://github.com/cb372/sbt-explicit-dependencies/issues/110 --- src/main/scala/explicitdeps/BoringStuff.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/scala/explicitdeps/BoringStuff.scala b/src/main/scala/explicitdeps/BoringStuff.scala index 4436862..399a4b7 100644 --- a/src/main/scala/explicitdeps/BoringStuff.scala +++ b/src/main/scala/explicitdeps/BoringStuff.scala @@ -65,7 +65,12 @@ object BoringStuff { val rawName = (xml \ "artifactId").text // We use the parent dir to get the version because it's sometimes not present in the pom file - val version = file.getParentFile.getName + // We use URL decoder to cater for characters that are valid in version strings but encoded + // in the file path, such as "+" used for semver metadata, encoded as "%2B" + val version = java.net.URLDecoder.decode( + file.getParentFile.getName, + java.nio.charset.Charset.forName("utf8") + ) val (name, crossVersion) = parseModuleName(scalaVersion)(rawName)