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 (ReadPrec [ArtifactSource]
ReadPrec ArtifactSource
Int -> ReadS ArtifactSource
ReadS [ArtifactSource]
(Int -> ReadS ArtifactSource)
-> ReadS [ArtifactSource]
-> ReadPrec ArtifactSource
-> ReadPrec [ArtifactSource]
-> Read ArtifactSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ArtifactSource]
$creadListPrec :: ReadPrec [ArtifactSource]
readPrec :: ReadPrec ArtifactSource
$creadPrec :: ReadPrec ArtifactSource
readList :: ReadS [ArtifactSource]
$creadList :: ReadS [ArtifactSource]
readsPrec :: Int -> ReadS ArtifactSource
$creadsPrec :: Int -> ReadS ArtifactSource
Read, Int -> ArtifactSource -> ShowS
[ArtifactSource] -> ShowS
ArtifactSource -> String
(Int -> ArtifactSource -> ShowS)
-> (ArtifactSource -> String)
-> ([ArtifactSource] -> ShowS)
-> Show ArtifactSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArtifactSource] -> ShowS
$cshowList :: [ArtifactSource] -> ShowS
show :: ArtifactSource -> String
$cshow :: ArtifactSource -> String
showsPrec :: Int -> ArtifactSource -> ShowS
$cshowsPrec :: Int -> ArtifactSource -> ShowS
Show, ArtifactSource -> ArtifactSource -> Bool
(ArtifactSource -> ArtifactSource -> Bool)
-> (ArtifactSource -> ArtifactSource -> Bool) -> Eq ArtifactSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArtifactSource -> ArtifactSource -> Bool
$c/= :: ArtifactSource -> ArtifactSource -> Bool
== :: ArtifactSource -> ArtifactSource -> Bool
$c== :: ArtifactSource -> ArtifactSource -> Bool
Eq, Typeable ArtifactSource
DataType
Constr
Typeable ArtifactSource
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArtifactSource -> c ArtifactSource)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArtifactSource)
-> (ArtifactSource -> Constr)
-> (ArtifactSource -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArtifactSource))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ArtifactSource))
-> ((forall b. Data b => b -> b)
-> ArtifactSource -> ArtifactSource)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r)
-> (forall u.
(forall d. Data d => d -> u) -> ArtifactSource -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> ArtifactSource -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource)
-> Data ArtifactSource
ArtifactSource -> DataType
ArtifactSource -> Constr
(forall b. Data b => b -> b) -> ArtifactSource -> ArtifactSource
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArtifactSource -> c ArtifactSource
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArtifactSource
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ArtifactSource -> u
forall u. (forall d. Data d => d -> u) -> ArtifactSource -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArtifactSource
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArtifactSource -> c ArtifactSource
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArtifactSource)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ArtifactSource)
$cIntoDirectory :: Constr
$cFromDirectory :: Constr
$cSetPermissions :: Constr
$cFromContent :: Constr
$cFromFile :: Constr
$tArtifactSource :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
gmapMp :: (forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
gmapM :: (forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ArtifactSource -> m ArtifactSource
gmapQi :: Int -> (forall d. Data d => d -> u) -> ArtifactSource -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ArtifactSource -> u
gmapQ :: (forall d. Data d => d -> u) -> ArtifactSource -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArtifactSource -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArtifactSource -> r
gmapT :: (forall b. Data b => b -> b) -> ArtifactSource -> ArtifactSource
$cgmapT :: (forall b. Data b => b -> b) -> ArtifactSource -> ArtifactSource
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ArtifactSource)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ArtifactSource)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ArtifactSource)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArtifactSource)
dataTypeOf :: ArtifactSource -> DataType
$cdataTypeOf :: ArtifactSource -> DataType
toConstr :: ArtifactSource -> Constr
$ctoConstr :: ArtifactSource -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArtifactSource
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArtifactSource
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArtifactSource -> c ArtifactSource
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArtifactSource -> c ArtifactSource
$cp1Data :: Typeable ArtifactSource
Data, Typeable, (forall x. ArtifactSource -> Rep ArtifactSource x)
-> (forall x. Rep ArtifactSource x -> ArtifactSource)
-> Generic ArtifactSource
forall x. Rep ArtifactSource x -> ArtifactSource
forall x. ArtifactSource -> Rep ArtifactSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ArtifactSource x -> ArtifactSource
$cfrom :: forall x. ArtifactSource -> Rep ArtifactSource x
Generic)
instance NFData ArtifactSource
getArtifactSourceFiles :: ArtifactSource -> [FilePath]
getArtifactSourceFiles :: ArtifactSource -> [String]
getArtifactSourceFiles (FromContent String
f Content
_) = [String
f]
getArtifactSourceFiles (FromFile String
f SourceFile
_) = [String
f]
getArtifactSourceFiles (IntoDirectory String
pd [ArtifactSource]
as) =
(String
pd String -> ShowS
</>) ShowS -> [String] -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([ArtifactSource]
as [ArtifactSource] -> (ArtifactSource -> [String]) -> [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ArtifactSource -> [String]
getArtifactSourceFiles)
getArtifactSourceFiles (FromDirectory String
_ [ArtifactSource]
as) = [ArtifactSource]
as [ArtifactSource] -> (ArtifactSource -> [String]) -> [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ArtifactSource -> [String]
getArtifactSourceFiles
getArtifactSourceFiles (SetPermissions Int
_ Int
_ Int
_ [ArtifactSource]
as) =
[ArtifactSource]
as [ArtifactSource] -> (ArtifactSource -> [String]) -> [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ArtifactSource -> [String]
getArtifactSourceFiles
instance Arbitrary ArtifactSource where
arbitrary :: Gen ArtifactSource
arbitrary =
[Gen ArtifactSource] -> Gen ArtifactSource
forall a. [Gen a] -> Gen a
oneof
[ String -> SourceFile -> ArtifactSource
FromFile (String -> SourceFile -> ArtifactSource)
-> Gen String -> Gen (SourceFile -> ArtifactSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String -> Gen String
forall a. Gen a -> Gen a
smaller Gen String
arbitraryFilePath Gen (SourceFile -> ArtifactSource)
-> Gen SourceFile -> Gen ArtifactSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen SourceFile -> Gen SourceFile
forall a. Gen a -> Gen a
smaller Gen SourceFile
forall a. Arbitrary a => Gen a
arbitrary,
String -> Content -> ArtifactSource
FromContent (String -> Content -> ArtifactSource)
-> Gen String -> Gen (Content -> ArtifactSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String -> Gen String
forall a. Gen a -> Gen a
smaller Gen String
arbitraryFilePath Gen (Content -> ArtifactSource)
-> Gen Content -> Gen ArtifactSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Content -> Gen Content
forall a. Gen a -> Gen a
smaller Gen Content
forall a. Arbitrary a => Gen a
arbitrary,
Int -> Int -> Int -> [ArtifactSource] -> ArtifactSource
SetPermissions
(Int -> Int -> Int -> [ArtifactSource] -> ArtifactSource)
-> Gen Int
-> Gen (Int -> Int -> [ArtifactSource] -> ArtifactSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
7)
Gen (Int -> Int -> [ArtifactSource] -> ArtifactSource)
-> Gen Int -> Gen (Int -> [ArtifactSource] -> ArtifactSource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
7)
Gen (Int -> [ArtifactSource] -> ArtifactSource)
-> Gen Int -> Gen ([ArtifactSource] -> ArtifactSource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
7)
Gen ([ArtifactSource] -> ArtifactSource)
-> Gen [ArtifactSource] -> Gen ArtifactSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [ArtifactSource] -> Gen [ArtifactSource]
forall a. Gen a -> Gen a
smaller Gen [ArtifactSource]
forall a. Arbitrary a => Gen a
arbitrary,
String -> [ArtifactSource] -> ArtifactSource
FromDirectory (String -> [ArtifactSource] -> ArtifactSource)
-> Gen String -> Gen ([ArtifactSource] -> ArtifactSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String -> Gen String
forall a. Gen a -> Gen a
smaller Gen String
arbitraryFilePath Gen ([ArtifactSource] -> ArtifactSource)
-> Gen [ArtifactSource] -> Gen ArtifactSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [ArtifactSource] -> Gen [ArtifactSource]
forall a. Gen a -> Gen a
smaller Gen [ArtifactSource]
forall a. Arbitrary a => Gen a
arbitrary,
String -> [ArtifactSource] -> ArtifactSource
IntoDirectory (String -> [ArtifactSource] -> ArtifactSource)
-> Gen String -> Gen ([ArtifactSource] -> ArtifactSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String -> Gen String
forall a. Gen a -> Gen a
smaller Gen String
arbitraryFilePath Gen ([ArtifactSource] -> ArtifactSource)
-> Gen [ArtifactSource] -> Gen ArtifactSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [ArtifactSource] -> Gen [ArtifactSource]
forall a. Gen a -> Gen a
smaller Gen [ArtifactSource]
forall a. Arbitrary a => Gen a
arbitrary
]