Skip to content

Commit 12dfbb8

Browse files
zlavclaude
andcommitted
Anchor sbt plugin detection on ": enabled in"
`sbt plugins` lists user-disabled plugins (`disablePlugins(...)`) with a ": disabled in <scope>" suffix. The pre-existing substring match on the bare FQCN counted those as present, which routed `findProjects` to a task the active plugin set does not provide — same shape as the TKT-15490 regression, different trigger. Detection now requires "<FQCN>: enabled in" verbatim. Fixtures cover the two disabled cases (mini disabled, modern disabled), both expected to classify as Nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1ac512f commit 12dfbb8

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

src/Strategy/Scala/Plugin.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,24 @@ hasDependencyPlugins projectDir = do
7070
-- used on sbt < 1.4. Provides the lowercase @dependencyBrowseTreeHtml@
7171
-- task.
7272
--
73+
-- Detection anchors on the @\<FQCN\>: enabled in@ suffix rather than the bare
74+
-- FQCN. @sbt plugins@ lists plugins the user has explicitly disabled (via
75+
-- @disablePlugins(...)@) with @: disabled in \<scope\>@ — those still
76+
-- contain the FQCN as a substring, so an unanchored match would wrongly
77+
-- route to a task that doesn't exist on the active plugin set.
78+
--
7379
-- When both modern and legacy non-mini plugins are present we prefer the
7480
-- modern one (sbt 1.4+ wins) since legacy plugin presence on a modern sbt
7581
-- typically means the user has both kinds of declarations in their build.
7682
detectDependencyPlugins :: Text -> DependencyPluginsDetected
7783
detectDependencyPlugins stdoutText =
7884
DependencyPluginsDetected
79-
{ hasMiniDependencyTreePlugin = Text.count ".MiniDependencyTreePlugin" stdoutText > 0
85+
{ hasMiniDependencyTreePlugin = "sbt.plugins.MiniDependencyTreePlugin: enabled in" `Text.isInfixOf` stdoutText
8086
, dependencyTreePlugin =
81-
if Text.count "sbt.plugins.DependencyTreePlugin" stdoutText > 0
87+
if "sbt.plugins.DependencyTreePlugin: enabled in" `Text.isInfixOf` stdoutText
8288
then Just ModernDependencyTreePlugin
8389
else
84-
if Text.count "net.virtualvoid.sbt.graph.DependencyGraphPlugin" stdoutText > 0
90+
if "net.virtualvoid.sbt.graph.DependencyGraphPlugin: enabled in" `Text.isInfixOf` stdoutText
8591
then Just LegacyDependencyGraphPlugin
8692
else Nothing
8793
}

test/Scala/PluginSpec.hs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ spec = do
5959
detectDependencyPlugins sbtNoPlugins
6060
`shouldBe` DependencyPluginsDetected{hasMiniDependencyTreePlugin = False, dependencyTreePlugin = Nothing}
6161

62+
-- `sbt plugins` lists user-disabled plugins (`disablePlugins(...)`) with a
63+
-- ": disabled in <scope>" suffix. The FQCN still appears on those lines,
64+
-- so detection must anchor on ": enabled in" to avoid routing to a task
65+
-- the active plugin set doesn't provide.
66+
it "should not treat MiniDependencyTreePlugin as present when listed as disabled" $ do
67+
detectDependencyPlugins sbtDisabledMiniPlugin
68+
`shouldBe` DependencyPluginsDetected{hasMiniDependencyTreePlugin = False, dependencyTreePlugin = Nothing}
69+
70+
it "should not treat modern DependencyTreePlugin as present when listed as disabled" $ do
71+
detectDependencyPlugins sbtDisabledModernPlugin
72+
`shouldBe` DependencyPluginsDetected{hasMiniDependencyTreePlugin = False, dependencyTreePlugin = Nothing}
73+
6274
-- sbt 1.4+ with only built-in plugin
6375
sbt14BuiltinOnly :: Text
6476
sbt14BuiltinOnly =
@@ -165,3 +177,28 @@ sbtNoPlugins =
165177
[info] sbt.plugins.IvyPlugin: enabled in root
166178
[info] sbt.plugins.JvmPlugin: enabled in root
167179
|]
180+
181+
-- User-disabled MiniDependencyTreePlugin (e.g. `disablePlugins(MiniDependencyTreePlugin)`
182+
-- in build.sbt). The FQCN appears on a ": disabled in" line — detection
183+
-- must reject it.
184+
sbtDisabledMiniPlugin :: Text
185+
sbtDisabledMiniPlugin =
186+
[r|[info] welcome to sbt 1.9.7 (Eclipse Adoptium Java 11.0.21)
187+
[info] In file:/Users/test/project/
188+
[info] sbt.plugins.CorePlugin: enabled in root
189+
[info] sbt.plugins.IvyPlugin: enabled in root
190+
[info] sbt.plugins.JvmPlugin: enabled in root
191+
[info] sbt.plugins.MiniDependencyTreePlugin: disabled in root
192+
|]
193+
194+
-- User-disabled modern DependencyTreePlugin. Routing to the uppercase task
195+
-- would fail because the plugin isn't active.
196+
sbtDisabledModernPlugin :: Text
197+
sbtDisabledModernPlugin =
198+
[r|[info] welcome to sbt 1.11.5 (Eclipse Adoptium Java 17.0.10)
199+
[info] In file:/Users/test/project/
200+
[info] sbt.plugins.CorePlugin: enabled in root
201+
[info] sbt.plugins.IvyPlugin: enabled in root
202+
[info] sbt.plugins.JvmPlugin: enabled in root
203+
[info] sbt.plugins.DependencyTreePlugin: disabled in root
204+
|]

0 commit comments

Comments
 (0)