/*
 * 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.
 */


// Maven publications and configuration.
//
// the 'published' list contains an explicit list of all projects
// which should be published to Maven repositories.

configure(rootProject) {
  ext {
    published = [
        ":lucene:analysis:common",
        ":lucene:analysis:icu",
        ":lucene:analysis:kuromoji",
        ":lucene:analysis:morfologik",
        ":lucene:analysis:nori",
        ":lucene:analysis:opennlp",
        ":lucene:analysis:phonetic",
        ":lucene:analysis:smartcn",
        ":lucene:analysis:stempel",
        ":lucene:backward-codecs",
        ":lucene:benchmark",
        ":lucene:classification",
        ":lucene:codecs",
        ":lucene:core",
        ":lucene:demo",
        ":lucene:expressions",
        ":lucene:facet",
        ":lucene:grouping",
        ":lucene:highlighter",
        ":lucene:join",
        ":lucene:luke",
        ":lucene:memory",
        ":lucene:misc",
        ":lucene:monitor",
        ":lucene:queries",
        ":lucene:queryparser",
        ":lucene:replicator",
        ":lucene:sandbox",
        ":lucene:spatial-extras",
        ":lucene:spatial3d",
        ":lucene:suggest",
        ":lucene:test-framework",

        ":solr:core",
        ":solr:solrj",
        ":solr:contrib:analysis-extras",
        ":solr:contrib:dataimporthandler",
        ":solr:contrib:dataimporthandler-extras",
        ":solr:contrib:analytics",
        ":solr:contrib:clustering",
        ":solr:contrib:extraction",
        ":solr:contrib:langid",
        ":solr:contrib:jaegertracer-configurator",
        ":solr:contrib:prometheus-exporter",
        ":solr:contrib:velocity",
        ":solr:test-framework",
    ]
  }

  configure(subprojects.findAll { it.path in rootProject.published }) {
    apply plugin: 'maven-publish'
    apply plugin: 'signing'

    publishing {
      // TODO: Add publishing repository details.
    }

    plugins.withType(JavaPlugin) {
      task sourcesJar(type: Jar, dependsOn: classes) {
        archiveClassifier = 'sources'
        from sourceSets.main.allJava
      }

      task javadocJar(type: Jar, dependsOn: javadoc) {
        archiveClassifier = 'javadoc'
        from javadoc.destinationDir
      }

      publishing {
        def configurePom = {
          name = "Apache Solr/Lucene (${project.name})"
          licenses {
            license {
              name = 'Apache 2'
              url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
            }
          }
        }

        publications {
          // JARS and sources, no javadocs (for local inspection only).
          jars(MavenPublication) {
            from components.java
            groupId = project.group
            artifactId = project.archivesBaseName

            artifact sourcesJar

            pom(configurePom)
          }

          // Full set of signed artifacts.
          signed(MavenPublication) {
            from components.java
            groupId = project.group
            artifactId = project.archivesBaseName

            artifact sourcesJar
            artifact javadocJar

            pom(configurePom)
          }
        }
      }

      signing {
        sign publishing.publications.signed
      }
    }
  }
}