1 /*
  2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 plugins {
 25     id 'org.openjdk.skara.gradle.proxy'
 26     id 'org.openjdk.skara.gradle.version'
 27     id 'org.openjdk.skara.gradle.reproduce'
 28 }
 29 
 30 configure(subprojects.findAll() { it.name != 'bots' }) {
 31     apply plugin: 'java-library'
 32     apply plugin: 'maven-publish'
 33     apply plugin: 'org.openjdk.skara.gradle.module'
 34     apply plugin: 'org.openjdk.skara.gradle.version'
 35 
 36     group = 'org.openjdk.skara'
 37 
 38     repositories {
 39         mavenLocal()
 40         maven {
 41             url System.getProperty('maven.url', 'https://repo.maven.apache.org/maven2/')
 42         }
 43     }
 44 
 45     dependencies {
 46         testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
 47         testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.1'
 48         testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.1'
 49         // Force Gradle to load the JUnit Platform Launcher from the module-path, as
 50         // configured in buildSrc/.../ModulePlugin.java -- see SKARA-69 for details.
 51         testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.5.1'
 52     }
 53 
 54     test {
 55         useJUnitPlatform()
 56 
 57         if (findProperty('credentials')) {
 58             systemProperty "credentials", findProperty('credentials')
 59         }
 60 
 61         testLogging {
 62             events "passed", "skipped", "failed"
 63         }
 64     }
 65 
 66     publishing {
 67         repositories {
 68             maven {
 69                 url = findProperty('mavenRepositoryUrl')
 70                 credentials {
 71                     username = findProperty('mavenRepositoryUser')
 72                     password = findProperty('mavenRepositoryPassword')
 73                 }
 74             }
 75         }
 76     }
 77 
 78     gradle.taskGraph.whenReady { graph ->
 79         if (graph.hasTask(publish) && !findProperty('mavenRepositoryUrl')) {
 80             throw new GradleException("To publish artifacts, set the maven repository url -PmavenRepositoryUrl=<url>")
 81         }
 82         if (graph.hasTask(publish) && !findProperty('mavenRepositoryUser')) {
 83             throw new GradleException("To publish artifacts, set the maven repository user name -PmavenRepositoryUser=<user>")
 84         }
 85         if (graph.hasTask(publish) && !findProperty('mavenRepositoryPassword')) {
 86             throw new GradleException("To publish artifacts, set the maven repository password -PmavenRepositoryPassword=<password>")
 87         }
 88     }
 89 }
 90 
 91 task jar {
 92     subprojects.findAll() { it.name != 'bots' }.each { dependsOn "${it.path}:jar" }
 93 }
 94 
 95 task test {
 96     subprojects.findAll() { it.name != 'bots' }.each { dependsOn "${it.path}:test" }
 97 }
 98 
 99 reproduce {
100     dockerfile = 'test.dockerfile'
101 }
102 
103 task deleteBuildDir(type: Delete) {
104     delete project.buildDir
105 }
106 
107 task local(type: Copy) {
108     def os = System.getProperty('os.name').toLowerCase()
109     def osName = os.startsWith('win') ? 'Windows' :
110         os.startsWith('mac') ? 'Macos' : 'Linux'
111 
112     dependsOn ':cli:image' + osName
113     dependsOn deleteBuildDir
114     from zipTree(file(project.rootDir.toString() +
115                       '/cli/build/distributions/cli' +
116                       '-' + project.version + '-' +
117 		      osName.toLowerCase() + '.zip'))
118     into project.buildDir
119 }
120 
121 defaultTasks 'local'