module buildclient.tasks.Executor where import buildclient.config.BuildConfig import buildclient.util.IoUtils import frege.java.Net import frege.java.IO import frege.java.lang.Processes bcDownloadSync :: File -> BuildSource -> IO () bcDownloadSync targetDirectory (HttpSource url format archiveRoot skipDirs) = do File.mkdirs targetDirectory let etagFile = File.new targetDirectory "etag.txt" oldEtagExists <- File.exists etagFile oldEtag <- if oldEtagExists then readFileStr etagFile else pure "" parsedUrl <- URL.new url conn <- URL.openConnection parsedUrl >>= (HttpURLConnection.fromUrlConnection) HttpURLConnection.setRequestProperty conn "If-None-Match" oldEtag -- Get InputStream early to trigger communication with server -> load response headers inputStream <- URLConnection.getInputStream conn newEtag <- HttpURLConnection.getHeaderField conn "etag" maybe (return ()) (writeFileStr etagFile) newEtag resp <- HttpURLConnection.getResponseCode conn case resp of 304 = return () -- 304 indicated etag hit 200 = do let archiveFile = File.new targetDirectory "archive.zip" saveInputStreamTo inputStream $ archiveFile extractZip skipDirs archiveFile $ File.new targetDirectory "archive-extracted" otherwise = fail ("Server replied with unexpected http code " ++ show resp) return () data AFile = native java.io.File where native setExecutable :: File -> Bool -> Bool -> IO Bool bcExecuteBuild :: BuildSystem -> File -> File -> IO () bcExecuteBuild (BuildSystem.GradleBuild task project properties) buildDir targetFile = do AFile.setExecutable (File.new buildDir "gradlew") true true let commandLine = (["./gradlew", ":buildClientGenerateFile", "-Pbuildclienttarget=" ++ (File.getPath targetFile)] ++ fmap (\(a,b)-> "-P"++a++"="++b) properties) println commandLine pb <- ProcessBuilder.new (commandLine) ProcessBuilder.directory pb buildDir ProcessBuilder.inheritIO pb proc <- ProcessBuilder.start pb void $ Process.waitFor proc return ()