zifter-google-java-format (empty) → 0.0.0.0
raw patch · 4 files changed
+141/−0 lines, 4 filesdep +basedep +filepathdep +pathsetup-changed
Dependencies added: base, filepath, path, path-io, process, safe, zifter
Files
- LICENSE +21/−0
- Setup.hs +3/−0
- src/Zifter/GoogleJavaFormat.hs +87/−0
- zifter-google-java-format.cabal +30/−0
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2017 Tom Sydney Kerckhove++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ src/Zifter/GoogleJavaFormat.hs view
@@ -0,0 +1,87 @@+{-# LANGUAGE TemplateHaskell #-}++module Zifter.GoogleJavaFormat where++import Control.Monad++import System.Exit+import qualified System.FilePath as FP+import System.IO+import System.Process++import Safe++import Path+import Path.IO++import Zifter.Zift++googleJavaFormatZift :: Zift ()+googleJavaFormatZift = do+ format <- getJavaFormatter+ rd <- getRootDir+ fs <- liftIO $ snd <$> listDirRecur rd+ let sources =+ filter (not . hidden) $ filter ((== ".java") . fileExtension) fs+ forZ_ sources format++getJavaFormatter :: Zift (Path Abs File -> Zift ())+getJavaFormatter = do+ downloadJavaFormatIfMissing+ jarFile <- javaFormatterJarFile+ pure $ \abspath ->+ runZiftCommand $+ unwords+ [ "java"+ , "-jar"+ , toFilePath jarFile+ , "--replace"+ , toFilePath abspath+ ]++downloadJavaFormatIfMissing :: Zift ()+downloadJavaFormatIfMissing = do+ jarFile <- javaFormatterJarFile+ exists <- doesFileExist jarFile+ unless exists $ do+ ensureDir $ parent jarFile+ runZiftCommand $+ unwords+ [ wgetCmd+ , javaFormatterUrl+ , "--output-document"+ , toFilePath jarFile+ ]++javaFormatDir :: Zift (Path Abs Dir)+javaFormatDir = (</> $(mkRelDir "google-java-format")) <$> getTempDir++javaFormatterJarFile :: Zift (Path Abs File)+javaFormatterJarFile =+ (</> $(mkRelFile "google-java-format-1.0-all-deps.jar")) <$> javaFormatDir++wgetCmd :: String+wgetCmd = "wget"++javaFormatterUrl :: FilePath+javaFormatterUrl =+ "https://github.com/google/google-java-format/releases/download/google-java-format-1.0/google-java-format-1.0-all-deps.jar"++hidden :: Path Abs t -> Bool+hidden = any ((Just '.' ==) . headMay) . FP.splitPath . toFilePath++runZiftCommand :: String -> Zift ()+runZiftCommand command = do+ let cp = shell command+ (_, mouth, merrh, ph) <- liftIO $ createProcess cp+ ec <- liftIO $ waitForProcess ph+ case mouth of+ Nothing -> pure ()+ Just outh -> liftIO (hGetContents outh) >>= printZift+ case merrh of+ Nothing -> pure ()+ Just errh -> liftIO (hGetContents errh) >>= printPreprocessingError+ case ec of+ ExitFailure c ->+ fail $ unwords [command, "failed with exit code", show c]+ ExitSuccess -> printPreprocessingDone $ unwords [command, "succeeded."]
+ zifter-google-java-format.cabal view
@@ -0,0 +1,30 @@+name: zifter-google-java-format+version: 0.0.0.0+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE+copyright: Copyright: (c) 2017 Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+homepage: http://cs-syd.eu+synopsis: zifter-google-java-format+description:+ zifter-google-java-format+category: Zift+author: Tom Sydney Kerckhove++library+ exposed-modules:+ Zifter.GoogleJavaFormat+ build-depends:+ base >=4.9 && <=5,+ zifter >=0.0.1.2 && <0.1,+ path >=0.5 && <0.6,+ path-io >=1.2 && <1.3,+ process >=1.4 && <1.5,+ safe >=0.3 && <0.4,+ filepath >=1.4 && <1.5+ default-language: Haskell2010+ hs-source-dirs: src/+ ghc-options: -Wall+