/*
 * Copyright Consensys Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

apply plugin: 'java-library'

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)) {
  throw new GradleException("Java 21 or later is required to build Besu.\n" +
          "  Detected version ${JavaVersion.current()}")
}

sourceCompatibility = 21
targetCompatibility = 21

tasks.withType(JavaCompile) {
  options.compilerArgs += [
    '-Xlint:unchecked',
    '-Xlint:cast',
    '-Xlint:rawtypes',
    '-Xlint:overloads',
    '-Xlint:divzero',
    '-Xlint:finally',
    '-Xlint:static',
    '-Werror',
  ]

  options.encoding = 'UTF-8'
}

def lineaSequencerProject = project(lineaSequencerProjectPath)

// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT
// with the git commit version.
ext.calculateVersion = { ->
  String version = lineaSequencerProject.releaseVersion
  if (version.endsWith("-SNAPSHOT")) {
    version = version.replace("-SNAPSHOT", "-dev-${getCheckedOutGitCommitHash()}")
  }

  return version
}

static def getCheckedOutGitCommitHash() {
  def hashLength = 8
  "git rev-parse HEAD".execute().text.take(hashLength)
}