plugins {
  id 'java-gradle-plugin'
  id 'checkstyle'
  id 'com.gradle.plugin-publish' version '0.9.7'
  id 'com.github.sherter.google-java-format' version '0.8'
  id 'net.researchgate.release' version '2.6.0'
  id 'maven'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
  // use jcenter for gradle plugin portal releases.
  jcenter()
}

dependencies {
  compile gradleApi()
  testCompile 'junit:junit:4.11'
  testCompile 'org.apache.commons:commons-lang3:3.6'
  testCompile 'org.mockito:mockito-core:2.+'
}

group = 'com.google.cloud.tools'

jar {
  manifest {
    attributes 'Implementation-Title': project.name,
        'Implementation-Version': version,
        'Built-By': System.getProperty('user.name'),
        'Built-Date': new Date(),
        'Built-JDK': System.getProperty('java.version'),
        'Built-Gradle': gradle.gradleVersion
  }
}

test {
  testLogging {
    showStandardStreams = true
    exceptionFormat = 'full'
  }
}


/* GOOGLE JAVA FORMAT */
check.dependsOn verifyGoogleJavaFormat
/* GOOGLE JAVA FORMAT */


/* CHECKSTYLE */
checkstyle {
  toolVersion = "8.18"

  // get the google_checks.xml file from the checkstyle jar and take out the java checks
  def googleChecks = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml').asString()
  def fileExtensionsBefore = '<property name="fileExtensions" value="java, properties, xml"/>'
  def fileExtensionsAfter = '<property name="fileExtensions" value="properties, xml"/>'
  def googleChecksNoJava = googleChecks.replace(fileExtensionsBefore, fileExtensionsAfter)
  assert !googleChecks.equals(googleChecksNoJava)

  config = resources.text.fromString(googleChecksNoJava)

  maxErrors = 0
  maxWarnings = 0
}
/* CHECKSTYLE */

/* RELEASE */
// gradle plugin portal releases
pluginBundle {
  website = 'https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/'
  vcsUrl = 'https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/'

  plugins {
    minikubePlugin {
      id = 'com.google.cloud.tools.minikube'
      displayName = 'Gradle Minikube plugin'
      description = 'A plugin to manage the minikube lifecycle in a gradle project'
      tags = ['google', 'minikube']
    }
  }
}

// Release plugin (git release commits and version updates)
release {
  tagTemplate = 'v$version-gradle'
  git {
    requireBranch = /^gradle_release_v[0-9A-Za-z.-]+.*$/  //regex
  }
}
/* RELEASE */
