start implementation of HgConnector

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
parent 278
89087a6af16a
child 280
12b898531d1a

start implementation of HgConnector

build.gradle.kts file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/web.xml file | annotate | diff | comparison | revisions
src/test/kotlin/de/uapcore/lightpit/vcs/HgConnectorTest.kt file | annotate | diff | comparison | revisions
     1.1 --- a/build.gradle.kts	Sat Jul 15 13:49:36 2023 +0200
     1.2 +++ b/build.gradle.kts	Mon Jul 17 14:45:42 2023 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4      war
     1.5  }
     1.6  group = "de.uapcore"
     1.7 -version = "1.0.1"
     1.8 +version = "1.1.0-snapshot"
     1.9  
    1.10  repositories {
    1.11      mavenCentral()
    1.12 @@ -50,5 +50,11 @@
    1.13                  implementation("io.github.java-diff-utils:java-diff-utils:4.12")
    1.14              }
    1.15          }
    1.16 +        val test by getting {
    1.17 +            dependencies {
    1.18 +                implementation("org.jetbrains.kotlin:kotlin-test-junit5")
    1.19 +                runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
    1.20 +            }
    1.21 +        }
    1.22      }
    1.23  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt	Mon Jul 17 14:45:42 2023 +0200
     2.3 @@ -0,0 +1,54 @@
     2.4 +/*
     2.5 + * Copyright 2023 Mike Becker. All rights reserved.
     2.6 + *
     2.7 + * Redistribution and use in source and binary forms, with or without
     2.8 + * modification, are permitted provided that the following conditions are met:
     2.9 + *
    2.10 + * 1. Redistributions of source code must retain the above copyright
    2.11 + * notice, this list of conditions and the following disclaimer.
    2.12 + *
    2.13 + * 2. Redistributions in binary form must reproduce the above copyright
    2.14 + * notice, this list of conditions and the following disclaimer in the
    2.15 + * documentation and/or other materials provided with the distribution.
    2.16 + *
    2.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    2.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    2.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    2.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    2.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    2.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    2.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    2.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2.27 + *
    2.28 + */
    2.29 +
    2.30 +package de.uapcore.lightpit.vcs
    2.31 +
    2.32 +import java.util.concurrent.TimeUnit
    2.33 +
    2.34 +/**
    2.35 + * A connector for Mercurial repositories.
    2.36 + *
    2.37 + * @param path the path to the Mercurial binary
    2.38 + */
    2.39 +class HgConnector(private val path: String) {
    2.40 +
    2.41 +    /**
    2.42 +     * Checks, if the specified binary is available and executable.
    2.43 +     */
    2.44 +    fun checkAvailability(): Boolean {
    2.45 +        return try {
    2.46 +            val process = ProcessBuilder(path, "--version").start()
    2.47 +            val versionInfo = String(process.inputStream.readAllBytes(), Charsets.UTF_8)
    2.48 +            if (process.waitFor(10, TimeUnit.SECONDS)) {
    2.49 +                versionInfo.contains("Mercurial")
    2.50 +            } else {
    2.51 +                false
    2.52 +            }
    2.53 +        } catch (_: Throwable) {
    2.54 +            false
    2.55 +        }
    2.56 +    }
    2.57 +}
    2.58 \ No newline at end of file
     3.1 --- a/src/main/webapp/WEB-INF/web.xml	Sat Jul 15 13:49:36 2023 +0200
     3.2 +++ b/src/main/webapp/WEB-INF/web.xml	Mon Jul 17 14:45:42 2023 +0200
     3.3 @@ -12,6 +12,10 @@
     3.4          <param-name>available-languages</param-name>
     3.5          <param-value>en,de</param-value>
     3.6      </context-param>
     3.7 +    <context-param>
     3.8 +        <param-name>hg-binary</param-name>
     3.9 +        <param-value>/usr/bin/hg</param-value>
    3.10 +    </context-param>
    3.11      <resource-ref>
    3.12          <description>Application Database</description>
    3.13          <res-ref-name>jdbc/lightpit/app</res-ref-name>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/test/kotlin/de/uapcore/lightpit/vcs/HgConnectorTest.kt	Mon Jul 17 14:45:42 2023 +0200
     4.3 @@ -0,0 +1,46 @@
     4.4 +/*
     4.5 + * Copyright 2023 Mike Becker. All rights reserved.
     4.6 + *
     4.7 + * Redistribution and use in source and binary forms, with or without
     4.8 + * modification, are permitted provided that the following conditions are met:
     4.9 + *
    4.10 + * 1. Redistributions of source code must retain the above copyright
    4.11 + * notice, this list of conditions and the following disclaimer.
    4.12 + *
    4.13 + * 2. Redistributions in binary form must reproduce the above copyright
    4.14 + * notice, this list of conditions and the following disclaimer in the
    4.15 + * documentation and/or other materials provided with the distribution.
    4.16 + *
    4.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    4.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    4.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    4.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    4.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    4.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    4.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    4.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    4.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    4.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    4.27 + *
    4.28 + */
    4.29 +
    4.30 +package de.uapcore.lightpit.vcs
    4.31 +
    4.32 +import kotlin.test.Test
    4.33 +import kotlin.test.assertFalse
    4.34 +import kotlin.test.assertTrue
    4.35 +
    4.36 +class HgConnectorTest {
    4.37 +
    4.38 +    private val testee = HgConnector("/usr/bin/hg")
    4.39 +
    4.40 +    @Test
    4.41 +    fun checkAvailability() {
    4.42 +        assertTrue(testee.checkAvailability())
    4.43 +    }
    4.44 +
    4.45 +    @Test
    4.46 +    fun checkAvailabilityFalse() {
    4.47 +        assertFalse(HgConnector("/bin/false").checkAvailability())
    4.48 +    }
    4.49 +}
    4.50 \ No newline at end of file

mercurial