src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt

Mon, 17 Jul 2023 14:45:42 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 17 Jul 2023 14:45:42 +0200
changeset 279
d73537b925af
child 280
12b898531d1a
permissions
-rw-r--r--

start implementation of HgConnector

universe@279 1 /*
universe@279 2 * Copyright 2023 Mike Becker. All rights reserved.
universe@279 3 *
universe@279 4 * Redistribution and use in source and binary forms, with or without
universe@279 5 * modification, are permitted provided that the following conditions are met:
universe@279 6 *
universe@279 7 * 1. Redistributions of source code must retain the above copyright
universe@279 8 * notice, this list of conditions and the following disclaimer.
universe@279 9 *
universe@279 10 * 2. Redistributions in binary form must reproduce the above copyright
universe@279 11 * notice, this list of conditions and the following disclaimer in the
universe@279 12 * documentation and/or other materials provided with the distribution.
universe@279 13 *
universe@279 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@279 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@279 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
universe@279 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
universe@279 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
universe@279 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
universe@279 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
universe@279 21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
universe@279 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
universe@279 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
universe@279 24 *
universe@279 25 */
universe@279 26
universe@279 27 package de.uapcore.lightpit.vcs
universe@279 28
universe@279 29 import java.util.concurrent.TimeUnit
universe@279 30
universe@279 31 /**
universe@279 32 * A connector for Mercurial repositories.
universe@279 33 *
universe@279 34 * @param path the path to the Mercurial binary
universe@279 35 */
universe@279 36 class HgConnector(private val path: String) {
universe@279 37
universe@279 38 /**
universe@279 39 * Checks, if the specified binary is available and executable.
universe@279 40 */
universe@279 41 fun checkAvailability(): Boolean {
universe@279 42 return try {
universe@279 43 val process = ProcessBuilder(path, "--version").start()
universe@279 44 val versionInfo = String(process.inputStream.readAllBytes(), Charsets.UTF_8)
universe@279 45 if (process.waitFor(10, TimeUnit.SECONDS)) {
universe@279 46 versionInfo.contains("Mercurial")
universe@279 47 } else {
universe@279 48 false
universe@279 49 }
universe@279 50 } catch (_: Throwable) {
universe@279 51 false
universe@279 52 }
universe@279 53 }
universe@279 54 }

mercurial