Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

fix(maven): Locators should include group ID #332

Merged
merged 2 commits into from
Aug 16, 2021
Merged
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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Spectrometer Changelog

## v2.15.2

- Maven: Fixes an issue where dependencies parsed from `dependency:tree` would fail to resolve when uploaded. ([#332](https://github.com/fossas/spectrometer/pull/332))

## v2.15.1

- Maven: Fixes an issue where dependencies with a platform specifier were not correctly parsed. ([#329](https://github.com/fossas/spectrometer/pull/329))
Expand Down
5 changes: 3 additions & 2 deletions src/Strategy/Maven/DepTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Strategy.Maven.DepTree (
-- * Exported for testing
DotGraph (..),
PackageId (..),
toDependency,
) where

import Control.Algebra (Has, run)
Expand Down Expand Up @@ -144,10 +145,10 @@ buildGraph :: [DotGraph] -> Graphing Dependency
buildGraph = gmap toDependency . foldMap toGraph

toDependency :: PackageId -> Dependency
toDependency PackageId{artifactName, artifactVersion, buildTag} =
toDependency PackageId{groupName, artifactName, artifactVersion, buildTag} =
Dependency
{ dependencyType = MavenType
, dependencyName = artifactName
, dependencyName = groupName <> ":" <> artifactName
, dependencyVersion = Just $ CEq artifactVersion
, dependencyLocations = []
, dependencyEnvironments = maybe [EnvProduction] ((: []) . toBuildTag) buildTag
Expand Down
36 changes: 34 additions & 2 deletions test/Maven/DepTreeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ module Maven.DepTreeSpec (spec) where

import Data.Text (Text)
import Data.Text.IO qualified as TextIO
import Strategy.Maven.DepTree (DotGraph (..), PackageId (..), parseDotGraphs)
import Test.Hspec (Spec, describe, it, runIO)
import DepTypes (
DepEnvironment (..),
DepType (MavenType),
Dependency (..),
VerConstraint (..),
)
import Strategy.Maven.DepTree (
DotGraph (..),
PackageId (..),
parseDotGraphs,
toDependency,
)
import Test.Hspec (Spec, describe, it, runIO, shouldBe)
import Test.Hspec.Megaparsec (shouldParse, shouldSucceedOn)
import Text.Megaparsec (parse)

Expand All @@ -30,6 +41,27 @@ spec =
parse parseDotGraphs "" fixturePackageIDWithPlatformContents
`shouldParse` fixturePackageIDWithPlatformGraph

it "renders parsed dependencies" $ do
let p =
PackageId
{ groupName = "org.apache.commons"
, artifactName = "commons-rng-parent"
, artifactType = "pom"
, artifactVersion = "1.4-SNAPSHOT"
, artifactPlatform = Nothing
, buildTag = Nothing
}
let d =
Dependency
{ dependencyType = MavenType
, dependencyName = "org.apache.commons:commons-rng-parent"
, dependencyVersion = Just (CEq "1.4-SNAPSHOT")
, dependencyLocations = []
, dependencyEnvironments = [EnvProduction]
, dependencyTags = mempty
}
toDependency p `shouldBe` d

fixtureSingleFile :: FilePath
fixtureSingleFile = "test/Maven/testdata/fossa-deptree.dot"

Expand Down