/*
 * 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: 'org.apache.beam.module'
apply plugin: 'maven-publish'
apply plugin: 'java-platform'
// plugin to support repository authentication via ~/.m2/settings.xml
// https://github.com/mark-vieira/gradle-maven-settings-plugin/
project.apply plugin: 'net.linguica.maven-settings'

javaPlatform {
    allowDependencies()
}

def isRelease(Project project) {
    return project.hasProperty('isRelease')
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = project.mavenGroupId
            artifactId = archivesBaseName
            version = project.version
            pom {
                name = project.description
                if (project.hasProperty("summary")) {
                    description = project.summary
                }
                url = "https://beam.apache.org"
                inceptionYear = "2016"
                licenses {
                    license {
                        name = "Apache License, Version 2.0"
                        url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
                        distribution = "repo"
                    }
                }
                scm {
                    connection = "scm:git:https://gitbox.apache.org/repos/asf/beam.git"
                    developerConnection = "scm:git:https://gitbox.apache.org/repos/asf/beam.git"
                    url = "https://gitbox.apache.org/repos/asf?p=beam.git;a=summary"
                }
                issueManagement {
                    system = "github"
                    url = "https://github.com/apache/beam/issues"
                }
                mailingLists {
                    mailingList {
                        name = "Beam Dev"
                        subscribe = "dev-subscribe@beam.apache.org"
                        unsubscribe = "dev-unsubscribe@beam.apache.org"
                        post = "dev@beam.apache.org"
                        archive = "https://www.mail-archive.com/dev@beam.apache.org"
                    }
                    mailingList {
                        name = "Beam User"
                        subscribe = "user-subscribe@beam.apache.org"
                        unsubscribe = "user-unsubscribe@beam.apache.org"
                        post = "user@beam.apache.org"
                        archive = "https://www.mail-archive.com/user@beam.apache.org"
                    }
                    mailingList {
                        name = "Beam Commits"
                        subscribe = "commits-subscribe@beam.apache.org"
                        unsubscribe = "commits-unsubscribe@beam.apache.org"
                        post = "commits@beam.apache.org"
                        archive = "https://www.mail-archive.com/commits@beam.apache.org"
                    }
                }
                developers {
                    developer {
                        name = "The Apache Beam Team"
                        email = "dev@beam.apache.org"
                        url = "https://beam.apache.org"
                        organization = "Apache Software Foundation"
                        organizationUrl = "https://www.apache.org"
                    }
                }
            }

            pom.withXml {
                def elem = asElement()
                def hdr = elem.getOwnerDocument().createComment(
                        '''
    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.
''')
                elem.insertBefore(hdr, elem.getFirstChild())
            }

            from components.javaPlatform
        }
    }

    repositories project.ext.repositories
}

// Only sign artifacts if we are performing a release
if (isRelease(project) && !project.hasProperty('noSigning')) {
    apply plugin: "signing"
    signing {
        useGpgCmd()
        sign publishing.publications
    }
}
