<commit_before>DESCRIPTION = "The extensible open source Java/OSGi IoT Edge Framework"
HOMEPAGE = "https://www.eclipse.org/kura/"
LICENSE = "EPL-1.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=52a21f73ac77fd790dc40dc5acda0fc2"

inherit systemd update-rc.d

DEPENDS = "\
    maven-native \
    openjdk-8-native \
    unzip-native \
"

RDEPENDS_${PN} += "java2-runtime"

SRC_URI = "\
    git://github.com/eclipse/kura.git;branch=develop;tag=KURA_${PV}_RELEASE \
"

# Patches
SRC_URI += "\
    file://Remove-default-build-profiles.patch \
    file://Add-Yocto-build-profile.patch \
    file://Fix-equinox-build.patch \
    file://Disable-checksum-generation.patch \
"

# Config
SRC_URI += "\
    file://kura.properties.default \
    file://jdk.dio.properties.default \
    file://snapshot_0.xml.default \
    file://log4j.xml.default \
"

PR = "r0"

S = "${WORKDIR}/git"
B = "${WORKDIR}/${BPN}_${PV}_yocto"

KURA_MEMSIZE ?= "1024"
KURA_PROPERTIES ?= "${WORKDIR}/kura.properties.default"
KURA_DIO_PROPERTIES ?= "${WORKDIR}/jdk.dio.properties.default"
KURA_SNAPSHOT ?= "${WORKDIR}/snapshot_0.xml.default"
KURA_LOG4J_CONFIG ?= "${WORKDIR}/log4j.xml.default"


do_configure() {
    # Config
    sed -i 's|%ARCH%|${TARGET_ARCH}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%DISTRO%|${DISTRO}-${DISTRO_VERSION}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%MACHINE%|${MACHINE}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%MEMSIZE%|${KURA_MEMSIZE}|g' ${S}/kura/distrib/pom.xml
    
    if ${<EMAIL>('DISTRO_FEATURES','systemd','true','false',d)}; then
        sed -i 's|%SERVICE_MANAGER%|systemd|g' ${S}/kura/distrib/pom.xml
    elif ${<EMAIL>('DISTRO_FEATURES','sysvinit','true','false',d)}; then
        sed -i 's|%SERVICE_MANAGER%|sysv|g' ${S}/kura/distrib/pom.xml
    else
        sed -i 's|%SERVICE_MANAGER%|none|g' ${S}/kura/distrib/pom.xml
    fi
    
    # Snapshot
    sed -i 's|%MACHINE%|${MACHINE}|g' ${KURA_SNAPSHOT}
    
    # Properties
    sed -i 's|%DISTRO%|${DISTRO}|g' ${KURA_PROPERTIES}
    sed -i 's|%DISTRO_VERSION%|${DISTRO_VERSION}|g' ${KURA_PROPERTIES}
    sed -i 's|%MACHINE%|${MACHINE}|g' ${KURA_PROPERTIES}
    sed -i 's|%TARGET_SYS%|${TARGET_SYS}|g' ${KURA_PROPERTIES}
    
    # Create Yocto resources
    mkdir -p ${S}/kura/distrib/src/main/resources/yocto
    cp ${KURA_SNAPSHOT} ${S}/kura/distrib/src/main/resources/yocto/snapshot_0.xml
    cp ${KURA_DIO_PROPERTIES} ${S}/kura/distrib/src/main/resources/yocto/jdk.dio.properties
    cp ${KURA_PROPERTIES} ${S}/kura/distrib/src/main/resources/yocto/kura.properties
    cp ${KURA_LOG4J_CONFIG} ${S}/kura/distrib/src/main/resources/yocto/log4j.xml
}

do_compile() {
    export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
    export M3_HOME="${STAGING_DIR_NATIVE}/usr/bin/maven-native"

    cd ${S}
    mvn -Dmaven.test.skip=true -f target-platform/pom.xml clean install
    mvn -Dmaven.test.skip=true -f kura/pom.xml clean install
    mvn -Dmaven.test.skip=true -f kura/distrib/pom.xml clean install

    # Populate build directory
    unzip -o ${S}/kura/distrib/target/${BPN}_${PV}_yocto.zip -d ${WORKDIR}
}

do_install() {
    install -d ${D}/${bindir}
    install -d ${D}/opt/eclipse/kura
    install -d ${D}/opt/eclipse/kura/bin
    install -d ${D}/opt/eclipse/kura/framework
    install -d ${D}/opt/eclipse/kura/plugins
    install -d ${D}/opt/eclipse/kura/user
    install -d ${D}/opt/eclipse/kura/user/snapshots
    install -d ${D}/opt/eclipse/kura/user/security
    
    # License
    install -m 0644 ${B}/*.html ${D}/opt/eclipse/kura/

    # Startup Scripts
    install -m 0755 ${B}/bin/*.sh ${D}/opt/eclipse/kura/bin
    ln -s /opt/eclipse/kura/bin/start_kura.sh ${D}${bindir}/kura

    # Framework
    install -m 0644 ${B}/framework/* ${D}/opt/eclipse/kura/framework/

    # Plugins
    install -m 0644 ${B}/plugins/*.jar ${D}/opt/eclipse/kura/plugins/

    # User
    install -m 0644 ${B}/user/log4j.xml ${D}/opt/eclipse/kura/user/
    install -m 0644 ${B}/user/kura_custom.properties ${D}/opt/eclipse/kura/user/
    install -m 0644 ${B}/user/security/cacerts.ks ${D}/opt/eclipse/kura/user/security/
    install -m 0644 ${B}/user/snapshots/*.xml ${D}/opt/eclipse/kura/user/snapshots/

    # Systemd Service
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${B}/install/kura.service ${D}${systemd_unitdir}/system

    # Sysvinit Service
    install -d ${D}/${INIT_D_DIR}
	install -m 0755 ${B}/install/kura.init.yocto ${D}/${INIT_D_DIR}/kura

}

SYSTEMD_SERVICE_${PN} = "kura.service"
SYSTEMD_AUTO_ENABLE ?= "enable"
INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_NAME_${PN} = "kura"

FILES_${PN} = "\
    ${bindir} \
    ${INIT_D_DIR} \
    ${systemd_unitdir}/system \
    /opt/eclipse/kura \
"
<commit_msg>kura: Fix formatting issues<commit_after>DESCRIPTION = "The extensible open source Java/OSGi IoT Edge Framework"
HOMEPAGE = "https://www.eclipse.org/kura/"
LICENSE = "EPL-1.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=52a21f73ac77fd790dc40dc5acda0fc2"

inherit systemd update-rc.d

DEPENDS = "\
    maven-native \
    openjdk-8-native \
    unzip-native \
"

RDEPENDS_${PN} += "java2-runtime"

SRC_URI = "\
    git://github.com/eclipse/kura.git;branch=develop;tag=KURA_${PV}_RELEASE \
"

# Patches
SRC_URI += "\
    file://Remove-default-build-profiles.patch \
    file://Add-Yocto-build-profile.patch \
    file://Fix-equinox-build.patch \
    file://Disable-checksum-generation.patch \
"

# Config
SRC_URI += "\
    file://kura.properties.default \
    file://jdk.dio.properties.default \
    file://snapshot_0.xml.default \
    file://log4j.xml.default \
"

PR = "r0"

S = "${WORKDIR}/git"
B = "${WORKDIR}/${BPN}_${PV}_yocto"

KURA_MEMSIZE ?= "1024"
KURA_PROPERTIES ?= "${WORKDIR}/kura.properties.default"
KURA_DIO_PROPERTIES ?= "${WORKDIR}/jdk.dio.properties.default"
KURA_SNAPSHOT ?= "${WORKDIR}/snapshot_0.xml.default"
KURA_LOG4J_CONFIG ?= "${WORKDIR}/log4j.xml.default"


do_configure() {
    # Config
    sed -i 's|%ARCH%|${TARGET_ARCH}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%DISTRO%|${DISTRO}-${DISTRO_VERSION}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%MACHINE%|${MACHINE}|g' ${S}/kura/distrib/pom.xml
    sed -i 's|%MEMSIZE%|${KURA_MEMSIZE}|g' ${S}/kura/distrib/pom.xml
    
    if <EMAIL>('DISTRO_FEATURES','systemd','true','false',d)}; then
        sed -i 's|%SERVICE_MANAGER%|systemd|g' ${S}/kura/distrib/pom.xml
    elif ${<EMAIL>('DISTRO_FEATURES','sysvinit','true','false',d)}; then
        sed -i 's|%SERVICE_MANAGER%|sysv|g' ${S}/kura/distrib/pom.xml
    else
        sed -i 's|%SERVICE_MANAGER%|none|g' ${S}/kura/distrib/pom.xml
    fi
    
    # Snapshot
    sed -i 's|%MACHINE%|${MACHINE}|g' ${KURA_SNAPSHOT}
    
    # Properties
    sed -i 's|%DISTRO%|${DISTRO}|g' ${KURA_PROPERTIES}
    sed -i 's|%DISTRO_VERSION%|${DISTRO_VERSION}|g' ${KURA_PROPERTIES}
    sed -i 's|%MACHINE%|${MACHINE}|g' ${KURA_PROPERTIES}
    sed -i 's|%TARGET_SYS%|${TARGET_SYS}|g' ${KURA_PROPERTIES}
    
    # Create Yocto resources
    mkdir -p ${S}/kura/distrib/src/main/resources/yocto
    cp ${KURA_SNAPSHOT} ${S}/kura/distrib/src/main/resources/yocto/snapshot_0.xml
    cp ${KURA_DIO_PROPERTIES} ${S}/kura/distrib/src/main/resources/yocto/jdk.dio.properties
    cp ${KURA_PROPERTIES} ${S}/kura/distrib/src/main/resources/yocto/kura.properties
    cp ${KURA_LOG4J_CONFIG} ${S}/kura/distrib/src/main/resources/yocto/log4j.xml
}

do_compile() {
    export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
    export M3_HOME="${STAGING_DIR_NATIVE}/usr/bin/maven-native"

    cd ${S}
    mvn -Dmaven.test.skip=true -f target-platform/pom.xml clean install
    mvn -Dmaven.test.skip=true -f kura/pom.xml clean install
    mvn -Dmaven.test.skip=true -f kura/distrib/pom.xml clean install

    # Populate build directory
    unzip -o ${S}/kura/distrib/target/${BPN}_${PV}_yocto.zip -d ${WORKDIR}
}

do_install() {
    install -d ${D}/${bindir}
    install -d ${D}/opt/eclipse/kura
    install -d ${D}/opt/eclipse/kura/bin
    install -d ${D}/opt/eclipse/kura/framework
    install -d ${D}/opt/eclipse/kura/plugins
    install -d ${D}/opt/eclipse/kura/user
    install -d ${D}/opt/eclipse/kura/user/snapshots
    install -d ${D}/opt/eclipse/kura/user/security
    
    # License
    install -m 0644 ${B}/*.html ${D}/opt/eclipse/kura/

    # Startup Scripts
    install -m 0755 ${B}/bin/*.sh ${D}/opt/eclipse/kura/bin
    ln -s /opt/eclipse/kura/bin/start_kura.sh ${D}${bindir}/kura

    # Framework
    install -m 0644 ${B}/framework/* ${D}/opt/eclipse/kura/framework/

    # Plugins
    install -m 0644 ${B}/plugins/*.jar ${D}/opt/eclipse/kura/plugins/

    # User
    install -m 0644 ${B}/user/log4j.xml ${D}/opt/eclipse/kura/user/
    install -m 0644 ${B}/user/kura_custom.properties ${D}/opt/eclipse/kura/user/
    install -m 0644 ${B}/user/security/cacerts.ks ${D}/opt/eclipse/kura/user/security/
    install -m 0644 ${B}/user/snapshots/*.xml ${D}/opt/eclipse/kura/user/snapshots/

    # Systemd Service
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${B}/install/kura.service ${D}${systemd_unitdir}/system

    # Sysvinit Service
    install -d ${D}/${INIT_D_DIR}
    install -m 0755 ${B}/install/kura.init.yocto ${D}/${INIT_D_DIR}/kura

}

SYSTEMD_SERVICE_${PN} = "kura.service"
SYSTEMD_AUTO_ENABLE ?= "enable"
INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_NAME_${PN} = "kura"

FILES_${PN} = "\
    ${bindir} \
    ${INIT_D_DIR} \
    ${systemd_unitdir}/system \
    /opt/eclipse/kura \
"

{'fraction_non_alphanumeric': 0.18866121668966981, 'fraction_numerical': 0.016349930990551015, 'mean_word_length': 3.424612494128699, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 36}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818285', 'n_tokens_mistral': 4050, 'n_tokens_neox': 3908, 'n_words': 549}