Skip to content

Commit

Permalink
Merge branch 'master' into ryanlink-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlink committed Jan 11, 2024
2 parents 8c36342 + 215a74f commit 6a801c5
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 45 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# FOSSA CLI Changelog

## v3.8.30

- Fix an issue with long-option syntax for older versions of `sbt` ([#1356](https://github.com/fossas/fossa-cli/pull/1356))
- Debug: add more logging for debugging missing dependencies. ([#1360](https://github.com/fossas/fossa-cli/pull/1360))

## v3.8.29
- Prevents showing SCM warnings in fossa analyze, test, and report [#1354](https://github.com/fossas/fossa-cli/pull/1354)
- Pathfinder: Pathfinder has been deprecated and removed. ([#1350](https://github.com/fossas/fossa-cli/pull/1350))
Expand Down
6 changes: 3 additions & 3 deletions integration-test/Analysis/ScalaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
module Analysis.ScalaSpec (spec) where

import Analysis.FixtureExpectationUtils (
DependencyResultsSummary (DependencyResultsSummary),
DependencyResultsSummary (..),
testSuiteDepResultSummary,
)
import Analysis.FixtureUtils (
AnalysisTestFixture (AnalysisTestFixture),
FixtureArtifact (FixtureArtifact),
AnalysisTestFixture (..),
FixtureArtifact (..),
FixtureEnvironment (NixEnv),
)
import Path (reldir)
Expand Down
4 changes: 4 additions & 0 deletions src/App/Fossa/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import Effect.Exec (Exec)
import Effect.Logger (
Logger,
Severity (..),
logDebug,
logInfo,
logStdout,
)
Expand Down Expand Up @@ -353,8 +354,10 @@ analyze cfg = Diag.context "fossa-analyze" $ do
forkTask $ do
res <- Diag.runDiagnosticsIO . diagToDebug . stickyLogStack . withEmptyStack $ Archive.discover (runAnalyzers filters) basedir ancestryDirect
Diag.withResult SevError SevWarn res (const (pure ()))
logDebug $ "Unfiltered project scans: " <> pretty (show projectScans)

let filteredProjects = mapMaybe toProjectResult projectScans
logDebug $ "Filtered project scans: " <> pretty (show filteredProjects)

maybeEndpointAppVersion <- case destination of
UploadScan apiOpts _ -> runFossaApiClient apiOpts $ do
Expand All @@ -377,6 +380,7 @@ analyze cfg = Diag.context "fossa-analyze" $ do
$ traverse (enrichPathDependencies includeAll vendoredDepsOptions revision) filteredProjects
(True, _) -> pure $ map enrichPathDependencies' filteredProjects
(False, _) -> traverse (withPathDependencyNudge includeAll) filteredProjects
logDebug $ "Filtered projects with path dependencies: " <> pretty (show filteredProjects')

let analysisResult = AnalysisScanResult projectScans vsiResults binarySearchResults manualSrcUnits dynamicLinkedResults maybeLernieResults
renderScanSummary (severity cfg) maybeEndpointAppVersion analysisResult $ Config.filterSet cfg
Expand Down
2 changes: 2 additions & 0 deletions src/Strategy/Gradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ analyze foundTargets dir = withSystemTempDir "fossa-gradle" $ \tmpDir -> do

let text = decodeUtf8 $ BL.toStrict stdout
let resolvedProjects = ResolutionApi.parseResolutionApiJsonDeps text
logDebug $ "Resolved projects: " <> pretty (show resolvedProjects)
let graphFromResolutionApi = ResolutionApi.buildGraph resolvedProjects (onlyConfigurations)
logDebug $ "Graph: " <> pretty (show graphFromResolutionApi)

-- Log debug messages as seen in gradle script
traverse_ (logDebug . pretty) (getDebugMessages text)
Expand Down
11 changes: 2 additions & 9 deletions src/Strategy/Scala.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Discovery.Walk (
walkWithFilters',
)
import Effect.Exec (
AllowErr (Never),
Command (..),
Exec,
Has,
Expand All @@ -64,6 +63,7 @@ import Strategy.Maven.Pom qualified as Pom
import Strategy.Maven.Pom.Closure (MavenProjectClosure, buildProjectClosures, closurePath)
import Strategy.Maven.Pom.PomFile (RawPom (rawPomArtifact, rawPomGroup, rawPomVersion))
import Strategy.Maven.Pom.Resolver (buildGlobalClosure)
import Strategy.Scala.Common (mkSbtCommand)
import Strategy.Scala.Errors (FailedToListProjects (FailedToListProjects), MaybeWithoutDependencyTreeTask (MaybeWithoutDependencyTreeTask), MissingFullDependencyPlugin (MissingFullDependencyPlugin))
import Strategy.Scala.Plugin (genTreeJson, hasDependencyPlugins)
import Strategy.Scala.SbtDependencyTree (SbtArtifact (SbtArtifact), analyze, sbtDepTreeCmd)
Expand Down Expand Up @@ -230,14 +230,7 @@ analyzeWithSbtDepTree (ScalaProject maybeDepTree _ closure) = context "Analyzing
pure $ SbtArtifact groupId artifactId version

makePomCmd :: Command
makePomCmd =
Command
{ cmdName = "sbt"
, -- --no-colors to disable ANSI escape codes
-- --batch to disable interactivity. normally, if an `sbt` command fails, it'll drop into repl mode: --batch will disable the repl.
cmdArgs = ["--no-colors", "--batch", "makePom"]
, cmdAllowErr = Never
}
makePomCmd = mkSbtCommand "makePom"

genPoms :: (Has Exec sig m, Has ReadFS sig m, Has Diagnostics sig m) => Path Abs Dir -> m [MavenProjectClosure]
genPoms projectDir = do
Expand Down
20 changes: 20 additions & 0 deletions src/Strategy/Scala/Common.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
module Strategy.Scala.Common (
removeLogPrefixes,
SbtArtifact (..),
mkSbtCommand,
) where

import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text qualified as Text
import Effect.Exec (AllowErr (Never), Command (..))

-- | Generate an sbt sub-command using which turns off colored output and ensures it does not enter repl mode.
--
-- example:
-- mkSbtCommand "dependencyTree" results in "sbt -batch -no-colors dependencyTree" as a CLI command.
mkSbtCommand :: Text -> Command
mkSbtCommand cmdName =
Command
{ cmdName = "sbt"
, -- Use single hyphens rather than double-hyphens for old sbt compatibility.
-- Ex: -batch instead of --batch
cmdArgs =
[ "-batch"
, "-no-colors"
, cmdName
]
, cmdAllowErr = Never
}

data SbtArtifact = SbtArtifact
{ groupId :: Text
Expand Down
35 changes: 14 additions & 21 deletions src/Strategy/Scala/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,18 @@ import Data.String.Conversion (ConvertUtf8 (decodeUtf8), toString)
import Data.Text qualified as Text
import Data.Text.Lazy qualified as TextLazy
import Effect.Exec (
AllowErr (Never),
Command (..),
Exec,
Has,
execThrow,
)
import Path (Abs, Dir, File, Path, mkRelFile, parent, parseAbsFile, (</>))
import Strategy.Scala.Common (mkSbtCommand)

-- | Returns list of plugins used by sbt.
-- Ref: https://www.scala-sbt.org/1.x/docs/Plugins.html
getPlugins :: Command
getPlugins =
Command
{ cmdName = "sbt"
, cmdArgs =
[ "--no-colors" -- to disable ANSI escape codes
, "--batch" -- to disable interactivity
, "plugins"
]
, cmdAllowErr = Never
}
getPlugins = mkSbtCommand "plugins"

-- | Returns list of plugins used by sbt.
hasDependencyPlugins :: (Has Exec sig m, Has Diagnostics sig m) => Path Abs Dir -> m (Bool, Bool)
Expand All @@ -54,17 +45,19 @@ hasDependencyPlugins projectDir = do
-- ./tree.json
-- ./tree.html
-- ./tree.data.js
--
-- This command is documented as being invoked with capital "HTML" but older versions of sbt output an error like:
--
-- [error] Not a valid command: dependencyBrowseTreeHTML
-- [error] Not a valid project ID: dependencyBrowseTreeHTML
-- [error] Expected ':'
-- [error] Not a valid key: dependencyBrowseTreeHTML (similar: dependencyBrowseTreeHtml, dependencyBrowseTree, dependencyBrowseTreeTarget)
-- [error] dependencyBrowseTreeHTML
--
-- This command is only used when the plugin is installed explicitly, i.e. sbt < 1.4.
-- Newer versions of sbt will use the built-in dependency graph plugin.
mkDependencyBrowseTreeHTMLCmd :: Command
mkDependencyBrowseTreeHTMLCmd =
Command
{ cmdName = "sbt"
, cmdArgs =
[ "--no-colors" -- to disable ANSI escape codes
, "--batch" -- to disable interactivity
, "dependencyBrowseTreeHTML"
]
, cmdAllowErr = Never
}
mkDependencyBrowseTreeHTMLCmd = mkSbtCommand "dependencyBrowseTreeHtml"

genTreeJson :: (Has Exec sig m, Has Diagnostics sig m) => Path Abs Dir -> m [Path Abs File]
genTreeJson projectDir = do
Expand Down
14 changes: 2 additions & 12 deletions src/Strategy/Scala/SbtDependencyTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import DepTypes (
VerConstraint (CEq),
)
import Effect.Exec (
AllowErr (Never),
Command (..),
Exec,
ExecErr (CommandParseError),
)
import Graphing (Graphing, shrinkRoots, subGraphOf, unfold)
import Strategy.Scala.Common (SbtArtifact (SbtArtifact, artifactId, groupId, version), removeLogPrefixes)
import Strategy.Scala.Common (SbtArtifact (SbtArtifact, artifactId, groupId, version), mkSbtCommand, removeLogPrefixes)
import Text.Megaparsec (
MonadParsec (eof, takeWhileP, try),
Parsec,
Expand All @@ -57,16 +56,7 @@ import Text.Megaparsec.Char.Lexer qualified as Lexer
-- This only works with sbt v1.4.0 greater, or with sbt which has DependencyTreePlugin.
-- Ref: https://www.scala-sbt.org/1.x/docs/sbt-1.4-Release-Notes.html#sbt-dependency-graph+is+in-sourced
sbtDepTreeCmd :: Command
sbtDepTreeCmd =
Command
{ cmdName = "sbt"
, cmdArgs =
[ "--batch" -- ensure sbt does not enter repl mode!
, "--no-colors"
, "dependencyTree"
]
, cmdAllowErr = Never
}
sbtDepTreeCmd = mkSbtCommand "dependencyTree"

data SbtDep = SbtDep
{ artifact :: SbtArtifact
Expand Down

0 comments on commit 6a801c5

Please sign in to comment.