module B9.Artifact.Readable.Source
( ArtifactSource (..),
getArtifactSourceFiles,
)
where
import B9.Artifact.Content.Readable
import B9.Artifact.Content.StringTemplate
import B9.QCUtil
import Control.Parallel.Strategies
import Data.Data
import GHC.Generics (Generic)
import System.FilePath ((</>))
import Test.QuickCheck
data ArtifactSource
=
FromFile
FilePath
SourceFile
|
FromContent
FilePath
Content
|
SetPermissions
Int
Int
Int
[ArtifactSource]
|
FromDirectory
FilePath
[ArtifactSource]
|
IntoDirectory
FilePath
[ArtifactSource]
deriving (Read, Show, Eq, Data, Typeable, Generic)
instance NFData ArtifactSource
getArtifactSourceFiles :: ArtifactSource -> [FilePath]
getArtifactSourceFiles (FromContent f _) = [f]
getArtifactSourceFiles (FromFile f _) = [f]
getArtifactSourceFiles (IntoDirectory pd as) =
(pd </>) <$> (as >>= getArtifactSourceFiles)
getArtifactSourceFiles (FromDirectory _ as) = as >>= getArtifactSourceFiles
getArtifactSourceFiles (SetPermissions _ _ _ as) =
as >>= getArtifactSourceFiles
instance Arbitrary ArtifactSource where
arbitrary =
oneof
[ FromFile <$> smaller arbitraryFilePath <*> smaller arbitrary,
FromContent <$> smaller arbitraryFilePath <*> smaller arbitrary,
SetPermissions
<$> choose (0, 7)
<*> choose (0, 7)
<*> choose (0, 7)
<*> smaller arbitrary,
FromDirectory <$> smaller arbitraryFilePath <*> smaller arbitrary,
IntoDirectory <$> smaller arbitraryFilePath <*> smaller arbitrary
]