This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Merged
sbt strategy #54
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa57199
Add initial sbt implementation
cnr 9f9c2a7
make vertices/edges overlay clearer
cnr 5a8d70a
Remove deprecated scala.sbt
cnr 2011adb
Add missing edges to sbt poms' GlobalClosure
cnr 2403855
Add docs to scala strategy
cnr 8cf1fd3
Re-enable non-scala strategies
cnr cca0f85
Merge remote-tracking branch 'origin/master' into scala
cnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module Strategy.Maven.Pom | ||
( discover | ||
, mkProjectClosure | ||
) where | ||
|
||
import Prologue | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
-- | The scala strategy leverages the machinery from maven-pom. | ||
-- | ||
-- Sbt has a command to export pom files, with one caveat -- in multi-project | ||
-- setups, parent/child relationships are not present in the generated poms. | ||
-- | ||
-- The only non-trivial logic that exists in this strategy is adding edges | ||
-- between poms in the maven "global closure", before building the individual | ||
-- multi-project closures. | ||
module Strategy.Scala | ||
( discover, | ||
) | ||
where | ||
|
||
import qualified Algebra.Graph.AdjacencyMap as AM | ||
import Control.Effect.Output | ||
import qualified Data.Map.Strict as M | ||
import Data.Maybe (catMaybes) | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Lazy as TL | ||
import Data.Text.Lazy.Encoding (decodeUtf8) | ||
import Discovery.Walk | ||
import Control.Effect.Diagnostics | ||
import Effect.Exec | ||
import Effect.ReadFS | ||
import Prologue | ||
import Strategy.Maven.Pom (mkProjectClosure) | ||
import Strategy.Maven.Pom.Closure (buildProjectClosures) | ||
import Strategy.Maven.Pom.PomFile (MavenCoordinate (..), Pom (..)) | ||
import Strategy.Maven.Pom.Resolver (GlobalClosure (..), buildGlobalClosure) | ||
import Types | ||
|
||
discover :: HasDiscover sig m => Path Abs Dir -> m () | ||
discover basedir = | ||
walk | ||
( \_ _ files -> | ||
case find (\f -> fileName f == "build.sbt") files of | ||
Nothing -> pure WalkContinue | ||
Just file -> do | ||
runStrategy "scala-sbt" ScalaGroup (analyze basedir file) | ||
pure WalkSkipAll | ||
) | ||
basedir | ||
|
||
makePomCmd :: Command | ||
makePomCmd = | ||
Command | ||
{ cmdName = "sbt", | ||
cmdArgs = ["makePom", "-no-colors"], | ||
cmdAllowErr = Never | ||
} | ||
|
||
analyze :: | ||
( Has Exec sig m, | ||
Has Diagnostics sig m, | ||
Has ReadFS sig m, | ||
Has (Output ProjectClosure) sig m | ||
) => | ||
Path Abs Dir -> | ||
Path Abs File -> | ||
m () | ||
analyze basedir file = do | ||
stdoutBL <- execThrow (parent file) makePomCmd | ||
|
||
-- stdout for "sbt makePom" looks something like: | ||
-- | ||
-- > ... | ||
-- > [info] Wrote /absolute/path/to/pom.xml | ||
-- > [info] Wrote /absolute/path/to/other/pom.xml | ||
-- > ... | ||
let stdoutLText = decodeUtf8 stdoutBL | ||
stdout = TL.toStrict stdoutLText | ||
-- | ||
stdoutLines :: [Text] | ||
stdoutLines = T.lines stdout | ||
-- | ||
pomLines :: [Text] | ||
pomLines = catMaybes $ map (T.stripPrefix "[info] Wrote ") stdoutLines | ||
-- | ||
pomLocations :: Maybe [Path Abs File] | ||
pomLocations = traverse (parseAbsFile . T.unpack) pomLines | ||
|
||
case pomLocations of | ||
Nothing -> fatalText ("Could not parse pom paths from:\n" <> T.unlines pomLines) | ||
Just [] -> fatalText ("No sbt projects found") | ||
Just paths -> do | ||
globalClosure <- buildGlobalClosure paths | ||
|
||
-- The pom files generated by sbt do not include the proper <parent> references. | ||
-- We need to introduce these edges ourselves. | ||
let pomEdges :: AM.AdjacencyMap MavenCoordinate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the non-trivial bit. Everything else is shared with the maven-pom code. I think focusing on an integration test later will be more worthwhile than building out a unit test now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets focus on doing sbt as one of the first integration tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify here, is what you're saying that this bit is already unit tested because maven pom code is unit tested? |
||
pomEdges = | ||
AM.edges | ||
[ (parentPom, childPom) | ||
| -- build references to any pom | ||
parentPom <- AM.vertexList (globalGraph globalClosure), | ||
-- from any other pom | ||
childPom <- AM.vertexList (globalGraph globalClosure), | ||
parentPom /= childPom, | ||
-- when the other pom has it as a dependency | ||
Just (_, pom) <- [M.lookup childPom (globalPoms globalClosure)], | ||
let deps = M.keys (pomDependencies pom), | ||
any | ||
( \(group, artifact) -> | ||
coordGroup parentPom == group && coordArtifact parentPom == artifact | ||
) | ||
deps | ||
] | ||
globalClosure' = globalClosure {globalGraph = AM.overlay pomEdges (globalGraph globalClosure)} | ||
projects = buildProjectClosures basedir globalClosure' | ||
|
||
traverse_ (output . mkProjectClosure basedir) projects |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
stdout = TL.toStrict $ decodeUtf8 stdoutBL
?