/*
 * MIT License
 *
 * Copyright (c) 2018 Axis Communications AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

apply plugin: 'java'

version = '0.1'

repositories {
        jcenter()
}

jar {
        manifest {
                attributes 'Main-Class': 'Main'
        }
}

sourceSets {
        main {
                java {
                        srcDirs 'src'
                }
        }
}

dependencies {
        compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
        compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
        compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '4.10.0.201712302008-r'
        compile group: 'commons-io', name: 'commons-io', version: '2.6'
        compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
        compile group: 'info.debatty', name: 'java-string-similarity', version: '1.0.1'
        compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
}

task runJar(type: JavaExec) {
        def issues_var = ""
        if (project.hasProperty("issues")) {
                issues_var = issues
        }

        def repository_var = ""
        if (project.hasProperty("repo")) {
                repository_var = repo
        }

        args issues_var, repository_var
        jvmArgs = ['-Xms1028m', '-Xmx2056m']
        classpath = files('build/libs/read.jar')
        classpath += sourceSets.main.runtimeClasspath
        main = 'Main'
}

task fatJar(type: Jar) {
        manifest {
                attributes 'Implementation-Title': 'SZZ Algorithm: Bug Introducing Commits Finder',
                     'Implementation-Version': version,
                     'Main-Class': 'Main'
        }
        baseName = 'szz_find_bug_introducers'
        from { configurations.compile.collect {it.isDirectory() ? it : zipTree(it) } } {
                exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
        }
        with jar
}
