module System.Build.Java.Javac(
Javac,
Debug(..),
Proc,
Implicit,
noneProc,
only,
proc',
noneImplicit,
class',
implicit',
debug,
nowarn,
verbose,
deprecation,
classpath,
sourcepath,
bootclasspath,
extdirs,
endorseddirs,
proc,
processor,
processorpath,
directory,
src,
implicit,
encoding,
source,
target,
version,
help,
akv,
flags,
etc,
javac,
javac'
) where
import Data.List
import Data.Maybe
import Control.Arrow
import Control.Monad
import System.FilePath
import System.Build.CompilePaths
import System.Build.Extensions
import System.Build.OutputDirectory
import System.Build.OutputReferenceSet
import System.Build.OutputReferenceGet
import System.Build.Command
import System.Build.Args
data Debug = Lines
| Vars
| Source
| None
| All
deriving Eq
instance Show Debug where
show Lines = "lines"
show Vars = "vars"
show Source = "source"
show None = "none"
show All = "all"
instance ArgShow Debug where
arg = show
newtype Proc = Proc Bool deriving Eq
noneProc :: Proc
noneProc = Proc False
only :: Proc
only = Proc True
proc' :: Proc -> a -> a -> a
proc' (Proc False) _ f = f
proc' (Proc True) t _ = t
instance Show Proc where
show (Proc False) = "none"
show (Proc True) = "only"
instance ArgShow Proc where
arg = show
newtype Implicit = Implicit Bool deriving Eq
noneImplicit :: Implicit
noneImplicit = Implicit False
class' :: Implicit
class' = Implicit True
implicit' :: Implicit -> a -> a -> a
implicit' (Implicit False) _ f = f
implicit' (Implicit True) t _ = t
instance Show Implicit where
show (Implicit False) = "none"
show (Implicit True) = "class"
instance ArgShow Implicit where
arg = show
data Javac = Javac {
debug :: Maybe Debug,
nowarn :: Bool,
verbose :: Bool,
deprecation :: Bool,
classpath :: [FilePath],
sourcepath :: [FilePath],
bootclasspath :: [FilePath],
extdirs :: [FilePath],
endorseddirs :: [FilePath],
proc :: Maybe Proc,
processor :: [String],
processorpath :: Maybe FilePath,
directory :: Maybe FilePath,
src :: Maybe FilePath,
implicit :: Maybe Implicit,
encoding :: Maybe String,
source :: Maybe String,
target :: Maybe String,
version :: Bool,
help :: Bool,
akv :: Maybe ([String], Maybe String),
flags :: [String],
etc :: Maybe String
}
javac :: Javac
javac = Javac Nothing False False False [] [] [] [] [] Nothing [] Nothing Nothing Nothing Nothing Nothing Nothing Nothing False False Nothing [] Nothing
javac' :: Maybe Debug
-> Bool
-> Bool
-> Bool
-> [FilePath]
-> [FilePath]
-> [FilePath]
-> [FilePath]
-> [FilePath]
-> Maybe Proc
-> [String]
-> Maybe FilePath
-> Maybe FilePath
-> Maybe FilePath
-> Maybe Implicit
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Maybe ([String], Maybe String)
-> [String]
-> Maybe String
-> Javac
javac' = Javac
instance Show Javac where
show (Javac debug'
nowarn'
verbose'
deprecation'
classpath'
sourcepath'
bootclasspath'
extdirs'
endorseddirs'
proc''
processor'
processorpath'
directory'
src'
implicit''
encoding'
source'
target'
version'
help'
akv'
flags'
etc') = [d debug',
"nowarn" ~~ nowarn',
"verbose" ~~ verbose',
"deprecation" ~~ deprecation',
"classpath" ~: classpath',
"sourcepath" ~: sourcepath',
"bootclasspath" ~: bootclasspath',
"extdirs" ~: extdirs',
"endorseddirs" ~: endorseddirs',
"proc" ~~> proc'',
case processor' of [] -> []
_ -> intercalate "," processor',
"processorpath" ~~> processorpath',
"d" ~~> directory',
"s" ~~> src',
"implicit" ~~> implicit'',
"encoding" ~~> encoding',
"source" ~~> source',
"target" ~~> target',
"version" ~~ version',
"help" ~~ help',
(\z -> "-A" ++ case first (intercalate ".") z of (k, Just v) -> k ++ '=' : v
(k, Nothing) -> k) ~? akv',
intercalate " " $ map ("-J" ++) flags',
fromMaybe [] etc'] ^^^ " "
where
d (Just All) = "g" ~~ True
d k = "g" -~> k
instance CompilePaths Javac where
j =>> ps = show j ++ ' ' : space ps
instance Extensions Javac where
exts _ = ["java"]
instance OutputDirectory Javac where
outdir = directory
instance OutputReferenceSet Javac where
setReference p j = j { classpath = p }
instance OutputReferenceGet Javac where
getReference = classpath
instance Command Javac where
command _ = let envs = [
("JAVA_HOME", (</> "bin" </> "javac")),
("JDK_HOME", (</> "bin" </> "javac")),
("JAVAC", id)
]
in fromMaybe "javac" `fmap` tryEnvs envs