Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FDN-82] Maven dependencies that override the build directory #1343

Merged
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
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# FOSSA CLI Changelog
## v3.8.27
- Maven: Fix a bug that broke maven analysis if the build directory was in a non-standard location ([#1343](https://github.com/fossas/fossa-cli/pull/1343))

## v3.8.26
- Maven: add support for maven submodule filtering [#1339](https://github.com/fossas/fossa-cli/pull/1339)
Expand Down
52 changes: 52 additions & 0 deletions integration-test/Analysis/MavenSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ guava =
[reldir|maven/guava/|]
[reldir|guava-31.1|]

simplePomFile :: AnalysisTestFixture Maven.MavenProject
simplePomFile =
AnalysisTestFixture
"simple-pom-file"
Maven.discover
mavenEnv
Nothing
$ FixtureArtifact
"https://github.com/fossas/example-pom-file/archive/refs/heads/main.tar.gz"
[reldir|maven/simple_pom_file/|]
[reldir|example-pom-file-main|]

pomFileWithBuildDirOverride :: AnalysisTestFixture Maven.MavenProject
pomFileWithBuildDirOverride =
AnalysisTestFixture
"build-dir-override"
Maven.discover
mavenEnv
Nothing
$ FixtureArtifact
"https://github.com/fossas/example-pom-file/archive/refs/heads/override-build-directory.tar.gz"
[reldir|maven/build_dir_override/|]
[reldir|example-pom-file-override-build-directory|]

testKeycloak :: Spec
testKeycloak = do
aroundAll (withAnalysisOf keycloak) $ do
Expand All @@ -76,7 +100,35 @@ testGuava =
, graphType = Complete
}

testSimplePomFile :: Spec
testSimplePomFile = do
testSuiteDepResultSummary
simplePomFile
Types.MavenProjectType
DependencyResultsSummary
{ numDeps = 25
, numDirectDeps = 2
, numEdges = 23
, numManifestFiles = 1
, graphType = Complete
}

testBuildDirOverride :: Spec
testBuildDirOverride = do
testSuiteDepResultSummary
pomFileWithBuildDirOverride
Types.MavenProjectType
DependencyResultsSummary
{ numDeps = 25
, numDirectDeps = 2
, numEdges = 23
, numManifestFiles = 1
, graphType = Complete
}

spec :: Spec
spec = do
testKeycloak
testGuava
testBuildDirOverride
testSimplePomFile
18 changes: 10 additions & 8 deletions src/Strategy/Maven/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import Path (
Path,
Rel,
fromAbsDir,
mkRelDir,
mkRelFile,
(</>),
)
Expand Down Expand Up @@ -130,10 +129,10 @@ execPluginAggregate dir plugin = do
cmd <- mavenPluginDependenciesCmd dir plugin
execPlugin (const cmd) dir plugin

execPluginReactor :: (CandidateCommandEffs sig m, Has ReadFS sig m) => Path Abs Dir -> DepGraphPlugin -> m ()
execPluginReactor dir plugin = do
cmd <- mavenPluginReactorCmd dir plugin
execPlugin (const cmd) dir plugin
execPluginReactor :: (CandidateCommandEffs sig m, Has ReadFS sig m) => Path Abs Dir -> Path Abs Dir -> DepGraphPlugin -> m ()
execPluginReactor projectdir outputdir plugin = do
cmd <- mavenPluginReactorCmd projectdir outputdir plugin
execPlugin (const cmd) projectdir plugin

outputFile :: Path Rel File
outputFile = $(mkRelFile "target/dependency-graph.txt")
Expand All @@ -146,7 +145,7 @@ reactorOutputFilename :: Path Rel File
reactorOutputFilename = $(mkRelFile "fossa-reactor-graph.json")

parseReactorOutput :: (Has ReadFS sig m, Has Diagnostics sig m) => (Path Abs Dir) -> m ReactorOutput
parseReactorOutput dir = readContentsJson $ dir </> $(mkRelDir "target/") </> reactorOutputFilename
parseReactorOutput dir = readContentsJson $ dir </> reactorOutputFilename

textArtifactToPluginOutput :: Has Diagnostics sig m => Tree TextArtifact -> m PluginOutput
textArtifactToPluginOutput
Expand Down Expand Up @@ -266,15 +265,18 @@ mavenPluginDependenciesCmd workdir plugin = do

-- | The reactor command is documented
-- [here.](https://ferstl.github.io/depgraph-maven-plugin/reactor-mojo.html)
mavenPluginReactorCmd :: (CandidateCommandEffs sig m, Has ReadFS sig m) => Path Abs Dir -> DepGraphPlugin -> m Command
mavenPluginReactorCmd workdir plugin = do
-- We set outputDirectory explicitly so that the file is written to a known spot even if the pom file
-- overrides the build directory (See FDN-82 for more details)
mavenPluginReactorCmd :: (CandidateCommandEffs sig m, Has ReadFS sig m) => Path Abs Dir -> Path Abs Dir -> DepGraphPlugin -> m Command
mavenPluginReactorCmd workdir outputdir plugin = do
candidates <- mavenCmdCandidates workdir
mkAnalysisCommand candidates workdir args Never
where
args =
[ group plugin <> ":" <> artifact plugin <> ":" <> version plugin <> ":reactor"
, "-DgraphFormat=json"
, "-DoutputFileName=" <> toText reactorOutputFilename
, "-DoutputDirectory=" <> toText outputdir
]

newtype ReactorArtifact = ReactorArtifact
Expand Down
7 changes: 5 additions & 2 deletions src/Strategy/Maven/PluginStrategy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Control.Effect.Diagnostics (
(<||>),
)
import Control.Effect.Lift (Lift)
import Control.Effect.Path (withSystemTempDir)
import Control.Monad (when)
import Data.Foldable (traverse_)
import Data.Map.Strict (Map)
Expand Down Expand Up @@ -74,14 +75,16 @@ analyzeLegacy' dir = analyze dir depGraphPluginLegacy
runReactor ::
( CandidateCommandEffs sig m
, Has ReadFS sig m
, Has (Lift IO) sig m
) =>
Path Abs Dir ->
DepGraphPlugin ->
m ReactorOutput
runReactor dir plugin =
context "Running plugin to get submodule names" $
warnOnErr MayIncludeSubmodule (execPluginReactor dir plugin >> parseReactorOutput dir)
<||> pure (ReactorOutput [])
withSystemTempDir "fossa-temp" $ \tempdir -> do
warnOnErr MayIncludeSubmodule (execPluginReactor dir tempdir plugin >> parseReactorOutput tempdir)
<||> pure (ReactorOutput [])

analyze ::
( CandidateCommandEffs sig m
Expand Down
Loading