# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 119562 2014-04-30 14:35:40Z hum@macports.org $

PortSystem          1.0

name                apache-solr4
version             4.8.0
categories          java textproc
maintainers         hum openmaintainer

description         An open source enterprise search platform.

long_description    Solr is the popular, blazing fast open source enterprise \
                    search platform from the Apache Lucene project.

homepage            http://lucene.apache.org/solr/
platforms           darwin
supported_archs     noarch
license             Apache-2

dist_subdir         apache-solr
distname            solr-${version}
extract.suffix      .tgz

master_sites        apache:lucene/solr/${version}/
checksums           rmd160  f9ac9977c5d39fbd43307b7f373e981aad65b4c8 \
                    sha256  59b2948f364cf1e19bfa2b2d9bf13fa16dc360a38384175c43de98f32af21e25

# set the destination paths.
set java_basepath   ${prefix}/share/java
set solr_destpath   ${java_basepath}/${distname}
set solr_path       ${solr_destpath}/example
set solr_home       ${solr_path}/solr

post-patch {
    # expand relative pathes into abusolute ones.
    reinplace "s|\"\\.\\./\\.\\./\\.\\./|\"${solr_destpath}/|g" \
        ${worksrcpath}/example/solr/collection1/conf/solrconfig.xml
}

use_configure       no

build {}

destroot {
    # copy the distribution.
    xinstall -d         ${destroot}${java_basepath}
    copy ${worksrcpath} ${destroot}${java_basepath}
    # install the solr script.
    xinstall -m 755 ${filespath}/solr.in     ${destroot}${prefix}/bin/solr4
    reinplace "s|@solr_path@|${solr_path}|g" ${destroot}${prefix}/bin/solr4
    reinplace "s|@solr_home@|${solr_home}|g" ${destroot}${prefix}/bin/solr4
}

notes "
To try apache-solr4, run 'sudo solr4' and open http://localhost:8983/solr/collection1/browse.
To store sample documents, run 'cd ${solr_path}/exampledocs && ./post.sh *.xml'."

# solr home for Japanese configurations.
set solr_home_ja    ${solr_home}-ja

variant ja description {Add Japanese settings} {
    # create Japanese solr home 'solr-ja'.
    post-extract {
        copy ${worksrcpath}/example/solr ${worksrcpath}/example/solr-ja
    }
    patchfiles-append   patch-solr-ja.diff
    post-patch {
        # expand relative pathes into abusolute ones.
        reinplace "s|\"\\.\\./\\.\\./\\.\\./|\"${solr_destpath}/|g" \
            ${worksrcpath}/example/solr-ja/collection1/conf/solrconfig.xml
    }
    post-destroot {
        # install a property file for UTF-8 encoding.
        copy ${filespath}/velocity.properties ${destroot}${solr_home_ja}/collection1/conf
        # copy a sample Japanese doc for testing.
        copy ${filespath}/solr-ja.xml ${destroot}${solr_path}/exampledocs
        # install the solr-ja script.
        xinstall -m 755 ${filespath}/solr.in        ${destroot}${prefix}/bin/solr4-ja
        reinplace "s|@solr_path@|${solr_path}|g"    ${destroot}${prefix}/bin/solr4-ja
        reinplace "s|@solr_home@|${solr_home_ja}|g" ${destroot}${prefix}/bin/solr4-ja
    }
    notes-append "

For Japanese texts, please run 'sudo solr4-ja' instead of 'sudo solr4'.
See ${solr_home_ja}."
}

livecheck.type      regex
livecheck.url       http://www.apache.org/dist/lucene/solr/
livecheck.regex     (\[0-9.\]+)\/
