/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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.
 *
 *
 */

apply plugin: 'polygene-library'

description = "Apache Polygene™ Http Library provides embedded Jetty for Apache Polygene™ application use."

jar { manifest { name = "Apache Polygene™ Library - Http" } }

dependencies {
  api polygene.core.bootstrap
  api libraries.servlet_api

  implementation polygene.library( 'jmx' )
  implementation polygene.library( 'constraints' )
  implementation libraries.bouncy_castle
  implementation libraries.jetty_webapp
  implementation libraries.jetty_jmx

  runtimeOnly polygene.core.runtime

  testImplementation polygene.core.testsupport
  testImplementation libraries.http_client
  testImplementation libraries.junit

  testRuntimeOnly libraries.logback
}

// Do not run vhost tests on Java >= 9 because they use internal JDK apis
if( JavaVersion.current() < JavaVersion.VERSION_1_9 )
{
  sourceSets {
    vhostTest {
      java {
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
        srcDir file( 'src/vhost-test/java' )
      }
      resources {
        srcDir file( 'src/vhost-test/resources' )
      }
    }
  }
  configurations {
    vhostTestImplementation.extendsFrom testImplementation
    vhostTestRuntimeOnly.extendsFrom testRuntimeOnly
  }
  dependencies {
    vhostTestImplementation libraries.dnsjava
  }
  task vhostTest( type: Test ) {
    // TODO Test JVM won't start when offline
    try
    {
      new URL( 'https://polygene.apache.org/' ).text
      enabled = true
    }
    catch( Exception ex )
    {
      enabled = false
    }
    testClassesDirs = sourceSets.vhostTest.output.classesDirs
    classpath = sourceSets.vhostTest.runtimeClasspath
    systemProperties 'networkaddress.cache.ttl': '0'
    systemProperties 'sun.net.spi.nameservice.provider.1': 'dns,LocalManagedDns'
  }
  check.dependsOn vhostTest
  vhostTest.mustRunAfter test
}
