plugins {
    id 'application'
    id 'eclipse'
    id 'maven-publish'
    id 'checkstyle'
}

group = 'com.glencoesoftware'
version = '0.9.0-SNAPSHOT'

mainClassName = 'com.glencoesoftware.pyramid.PyramidFromDirectoryWriter'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url 'https://artifacts.glencoesoftware.com/artifactory/ome.releases/'
    }
    maven {
        url 'https://artifacts.glencoesoftware.com/artifactory/unidata-releases/'
    }
    maven {
        url 'https://repo.glencoesoftware.com/repository/bioformats2raw2ometiff/'
    }
    maven {
        url 'https://maven.scijava.org/content/groups/public'
    }
}

dependencies {
    implementation 'net.java.dev.jna:jna:5.10.0'
    implementation 'dev.zarr:jzarr:0.4.2'
    implementation 'info.picocli:picocli:4.7.5'
    implementation 'me.tongfei:progressbar:0.9.0'
    implementation 'ome:formats-bsd:8.3.0'
    implementation 'com.glencoesoftware:bioformats2raw:0.11.0'
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.15'
    implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.3.15'
    testImplementation 'junit:junit:4.12'
}

test {
    useJUnit()
}

jar {
    manifest {
        attributes(
            "Created-By": "Gradle ${gradle.gradleVersion}",
            "Build-Jdk": "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
            "Built-By": System.properties['user.name'],
            "Built-On": new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
            "Implementation-Build": "git rev-parse --verify HEAD".execute().getText().trim(),
            "Implementation-Title": "raw2ometiff converter",
            "Implementation-Version": archiveVersion,
            "Implementation-Vendor": "Glencoe Software Inc.",
            "Main-Class": mainClassName
        )
    }
}

distributions {
    main {
        contents {
            from("$projectDir") {
                include 'README.md'
                include 'LICENSE.txt'
            }
        }
    }
}

startScripts {
  // placing logback.xml somewhere under src/dist/lib/ keeps it out of
  // raw2ometiff-*.jar but automatically includes it in the distribution zip
  // the directory containing logback.xml must be explicitly added to the
  // startup scripts' classpath, otherwise it will not be detected

  // a subdirectory of 'src/dist/lib/' (not just 'src/dist/') is necessary,
  // likely due to https://issues.gradle.org/browse/GRADLE-2991
  // see also discussion in https://github.com/glencoesoftware/bioformats2raw/pull/169
  classpath += files('src/dist/lib/config/')

  doLast {
    windowsScript.text = windowsScript.text.replaceAll('set CLASSPATH=.*', 'set CLASSPATH=.;%APP_HOME%\\\\lib\\\\*')
  }
}

publishing {
    publications {
        raw2ometiff(MavenPublication) {
            from components.java
            pom {
                licenses {
                    license {
                        name = 'GNU General Public License version 2'
                        url = 'http://www.gnu.org/licenses/gpl-2.0.txt'
                    }
                }
            }
        }
    }

    repositories {
        maven {
            url 'https://repo.glencoesoftware.com/repository/bioformats2raw2ometiff/'
            credentials {
               username = project.properties.ArtifactoryUserName
               password = project.properties.ArtifactoryPassword
            }
        }
    }
}

checkstyle {
    toolVersion = "8.26"
}
