-
Notifications
You must be signed in to change notification settings - Fork 173
/
Common.hs
73 lines (63 loc) · 2.47 KB
/
Common.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Strategy.Gradle.Common (
packagePathsWithJson,
getLinesWithPrefix,
configNameToLabel,
getDebugMessages,
ConfigName (..),
GradleLabel (..),
PackageName (..),
ProjectName (..),
-- * for testing
getLogWithPrefix,
) where
import Data.Aeson (FromJSON)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Data.Text qualified as Text
import DepTypes (DepEnvironment (..))
import Strategy.Android.Util (isDefaultAndroidDevConfig, isDefaultAndroidTestConfig)
newtype ConfigName = ConfigName {unConfigName :: Text} deriving (Eq, Ord, Show, FromJSON)
newtype GradleLabel = Env DepEnvironment deriving (Eq, Ord, Show)
newtype PackageName = PackageName {unPackageName :: Text} deriving (Eq, Ord, Show, FromJSON)
newtype ProjectName = ProjectName {unProjectName :: Text} deriving (Eq, Ord, Show, FromJSON)
packagePathsWithJson :: [Text] -> [(PackageName, Text)]
packagePathsWithJson = map (\line -> let (x, y) = Text.breakOn "_{" line in (PackageName x, Text.drop 1 y))
getLinesWithPrefix :: Text -> Text -> [Text]
getLinesWithPrefix text prefix = prefixLines
where
textLines :: [Text]
textLines = Text.lines (Text.filter (/= '\r') text)
prefixLines :: [Text]
prefixLines = mapMaybe (Text.stripPrefix prefix) textLines
configNameToLabel :: Text -> GradleLabel
configNameToLabel conf =
case conf of
"compileOnly" -> Env EnvDevelopment
x | x `elem` knownTestConfigs -> Env EnvTesting
x | isDefaultAndroidDevConfig x -> Env EnvDevelopment
x | isDefaultAndroidTestConfig x -> Env EnvTesting
x -> Env $ EnvOther x
knownTestConfigs :: [Text]
knownTestConfigs =
[ "testImplementation"
, "testCompileOnly"
, "testRuntimeOnly"
, "testCompileClasspath"
, "testRuntimeClasspath"
, "testFixturesApi"
, "testFixturesImplementation"
, "testFixturesRuntimeOnly"
, "testFixturesCompileOnly"
, "testFixturesRuntimeClasspath"
, "testFixturesCompileClasspath"
, "testFixturesApiElements"
]
getDebugMessages :: Text -> [Text]
getDebugMessages text = getLogWithPrefix text "FOSSA-DEBUG"
-- | Gets the log message for matching identifier. Applies to gradle init script log format.
-- Log format of the gradle script is: 'identifier (scope): message'
--
-- >>> getLogWithPrefix "SOME-PREFIX (some scope): some message/n DEBUG (some scope): some debug message" "SOME-PREFIX"
-- ["some message"]
getLogWithPrefix :: Text -> Text -> [Text]
getLogWithPrefix text prefix = map (Text.strip . Text.drop 2 . snd . Text.breakOn "):") $ getLinesWithPrefix text prefix