/*
    Copyright (C) 2000 - 2024 Silverpeas

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    As a special exception to the terms and conditions of version 3.0 of
    the GPL, you may redistribute this Program in connection with Free/Libre
    Open Source Software ("FLOSS") applications as described in Silverpeas's
    FLOSS exception.  You should have received a copy of the text describing
    the FLOSS exception, and it is also available here:
    "https://www.silverpeas.org/legal/floss_exception.html"

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
import org.apache.tools.ant.filters.ReplaceTokens

buildscript {
  repositories {
    maven {
      url 'https://nexus3.silverpeas.org/repository/silverpeas'
    }
    mavenLocal()
  }
}

plugins {
  id 'java-gradle-plugin'
  id 'org.ajoberstar.grgit' version '5.2.0' apply true
  id 'idea'
  id 'maven-publish'
  id 'net.linguica.maven-settings' version '0.5'
  id 'groovy'
}

description = 'The Gradle plugin to set up Silverpeas. It is used both to install or to upgrade Silverpeas.'
group = 'org.silverpeas'
version = '6.4.7-SNAPSHOT'

gradlePlugin {
  plugins {
    silversetup {
      id = 'silversetup'
      implementationClass = 'org.silverpeas.setup.SilverpeasSetupPlugin'
    }
  }
}

/* cache management
configurations {
  all {
    resolutionStrategy {
      cacheDynamicVersionsFor 0, 'seconds'
      cacheChangingModulesFor 0, 'seconds'
    }
  }
}*/

project.configure(project) {
  if (project.version.endsWith('-SNAPSHOT')) {
    project.extensions.snapshot = true
  } else {
    project.extensions.snapshot = false
  }
}

repositories {
  maven {
    name 'silverpeas'
    url 'https://nexus3.silverpeas.org/repository/silverpeas'
  }
  maven {
    name 'gradle-plugins'
    url 'https://plugins.gradle.org/m2/'
  }
  mavenLocal()
}

java {
  sourceCompatibility = JavaVersion.VERSION_11
  targetCompatibility = JavaVersion.VERSION_11
  withSourcesJar()
}

publishing {
  publications {
    maven(MavenPublication) {
      from components.java
    }
  }

  repositories {
    maven {
      if (project.snapshot) {
        name 'silverpeas-snapshots'
        url 'https://nexus3.silverpeas.org/repository/snapshots/'
      } else {
        name 'silverpeas'
        url 'https://nexus3.silverpeas.org/repository/releases/'
      }
    }
  }
}


dependencies {
  api gradleApi()
  api 'org.apache.commons:commons-lang3:3.12.0'
  api 'commons-io:commons-io:2.11.0'
  api 'org.apache.commons:commons-dbcp2:2.9.0'
  api 'commons-codec:commons-codec:1.15'
  api 'com.google.guava:guava:31.0.1-jre'
  api 'javax.jcr:jcr:2.0'
  api 'org.apache.jackrabbit:oak-jcr:1.52.0'
  api 'org.apache.jackrabbit:oak-segment-tar:1.52.0'
  api 'org.apache.jackrabbit:oak-store-document:1.52.0'


  runtimeOnly 'org.eclipse.jetty:jetty-jndi:11.0.14'
  runtimeOnly 'org.eclipse.jetty:jetty-util:11.0.14'
  runtimeOnly 'com.h2database:h2:2.1.214'
  runtimeOnly 'org.postgresql:postgresql:42.5.4'
  runtimeOnly 'net.sourceforge.jtds:jtds:1.3.1'
  runtimeOnly 'io.dropwizard.metrics:metrics-core:3.2.6'
  runtimeOnly 'org.mongodb:mongo-java-driver:3.12.11'
  testImplementation gradleTestKit()
  testImplementation platform("org.spockframework:spock-bom:2.3-groovy-3.0")
  testImplementation 'org.spockframework:spock-core'
  testImplementation 'org.spockframework:spock-junit4'
  testImplementation 'junit:junit:4.13.2'
}

ext {
  revision = grgit.head().abbreviatedId
}

jar {
  manifest {
    attributes(
        "Build-Version": project.version,
        "Git-Commit": grgit.head().abbreviatedId)
  }
}

task sourceJar(type: Jar) {
    from sourceSets.main.allSource
}

processTestResources {
  filesMatching('**/*.properties') {
    filter(ReplaceTokens,
        tokens: [buildDir: buildDir.path.replace('\\', '/')], beginToken: '${', endToken: '}')
  }
  filesMatching('**/*.xml') {
    filter(ReplaceTokens,
        tokens: [buildDir: buildDir.path.replace('\\', '/')], beginToken: '${', endToken: '}')
  }
}
