plugins {
    id 'java-library'
    id 'war'
}

sourceSets {
    main {
        java {
            srcDir 'java/src'
            srcDir 'java/build/messages-src'
        }
    }
}

dependencies {
    api project(':core')
    api project(':apps:systray')
    api 'gnu.getopt:java-getopt:1.0.13'
    api project(':apps:ministreaming')
    api project(':apps:jetty')
    // this is not needed except for standalone,
    // but we build the standalone classes even for non-standalone
    api project(':apps:desktopgui')
}

task i2psnarkJar(type: Jar) {
    from sourceSets.main.output
    exclude 'org/klomp/snark/standalone/**'
    exclude 'org/klomp/snark/web/**'
    manifest {
        attributes 'Main-Class': 'org.klomp.snark.Snark'
        attributes 'Class-Path': 'i2p.jar mstreaming.jar streaming.jar'
    }
}

// TODO: standalone jar.  This is rather involved!

artifacts {
    archives i2psnarkJar,war
}

// Create the java files from the po files. The jar task will compile them.
// This requires gettext 0.19 or higher.
// We don't support the "slow way"
task bundle {
    doLast {
        if (!(new File("$buildDir/classes/java/main/org/klomp/snark/web/messages_de.class")).exists())
            println "apps/i2psnark/java/bundle-messages.sh".execute().text
    }
}
war.dependsOn bundle

war {
    rootSpec.exclude('/org/klomp/snark/*.class')
    rootSpec.exclude('/org/klomp/snark/bencode/**')
    rootSpec.exclude('/org/klomp/snark/comments/**')
    rootSpec.exclude('/org/klomp/snark/dht/**')
    rootSpec.exclude('/org/klomp/snark/standalone/**')
    from ('resources', {
        into ".resources"
    })
    webInf {
        into 'classes/org/klomp/snark/web'
        from 'mime.properties'
    }
    webXml = file('web.xml')
}
