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.2'
47 testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
48 testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
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.2'
52 }
53
54 compileJava.options.encoding = 'UTF-8'
55 compileTestJava.options.encoding = 'UTF-8'
56
57 test {
58 useJUnitPlatform()
59
60 if (findProperty('credentials')) {
61 systemProperty "credentials", findProperty('credentials')
62 }
63
64 testLogging {
65 events "passed", "skipped", "failed"
66 exceptionFormat "full"
67 }
68 }
69
70 publishing {
71 repositories {
72 maven {
73 url = findProperty('mavenRepositoryUrl')
74 credentials {
75 username = findProperty('mavenRepositoryUser')
76 password = findProperty('mavenRepositoryPassword')
77 }
78 }
79 }
80 }
81
82 gradle.taskGraph.whenReady { graph ->
83 if (graph.hasTask(publish) && !findProperty('mavenRepositoryUrl')) {
84 throw new GradleException("To publish artifacts, set the maven repository url -PmavenRepositoryUrl=<url>")
85 }
86 if (graph.hasTask(publish) && !findProperty('mavenRepositoryUser')) {
87 throw new GradleException("To publish artifacts, set the maven repository user name -PmavenRepositoryUser=<user>")
88 }
89 if (graph.hasTask(publish) && !findProperty('mavenRepositoryPassword')) {
90 throw new GradleException("To publish artifacts, set the maven repository password -PmavenRepositoryPassword=<password>")
91 }
92 }
93 }
94
95 task test {
96 subprojects.findAll() { !it.getTasksByName('test', false).isEmpty() }.each { dependsOn "${it.path}:test" }
97 }
98
99 task clean {
100 subprojects.findAll() { !it.getTasksByName('clean', false).isEmpty() }.each { dependsOn "${it.path}:clean" }
101 }
102
103 reproduce {
104 dockerfile = 'test.dockerfile'
105 }
106
107 def getOS() {
108 def os = System.getProperty('os.name').toLowerCase()
109 if (os.startsWith('linux')) {
110 return 'linux'
111 }
112 if (os.startsWith('mac')) {
113 return 'macos'
114 }
115 if (os.startsWith('win')) {
116 return 'windows'
117 }
118 if (os.startsWith('sunos')) {
119 return 'solaris'
120 }
121 throw new GradleException("Unexpected operating system: " + os)
122 }
123
124 def getCPU() {
125 def cpu = System.getProperty('os.arch').toLowerCase()
126 if (cpu.startsWith('amd64')) {
127 return 'x64'
128 }
129 if (cpu.startsWith('x86') || cpu.startsWith('i386')) {
130 return 'x86'
131 }
132 if (cpu.startsWith('sparc')) {
133 return 'sparc'
134 }
135 if (cpu.startsWith('ppc')) {
136 return 'ppc'
137 }
138 if (cpu.startsWith('arm')) {
139 return 'arm'
140 }
141 throw new GradleException("Unexpected operating system: " + cpu)
142 }
143
144 task local(type: Copy) {
145 doFirst {
146 delete project.buildDir
147 }
148
149 def os = getOS()
150 def cpu = getCPU()
151
152 if (os in ['linux', 'macos', 'windows'] && cpu == 'x64') {
153 def target = os.substring(0, 1).toUpperCase() + os.substring(1) +
154 cpu.substring(0, 1).toUpperCase() + cpu.substring(1)
155 dependsOn ':cli:image' + target
156 } else {
157 dependsOn ':cli:imageLocal'
158 }
159
160 from zipTree(file(project.rootDir.toString() +
161 '/cli/build/distributions/cli' +
162 '-' + project.version + '-' +
163 os + '-' + cpu + '.zip'))
164 into project.buildDir
165 }
166
167 task offline(type: Copy) {
168 doFirst {
169 delete project.buildDir
170 }
171
172 def os = getOS()
173 def cpu = getCPU()
174
175 dependsOn ':cli:imageLocal'
176 from zipTree(file(project.rootDir.toString() +
177 '/cli/build/distributions/cli' +
178 '-' + project.version + '-' +
179 os + '-' + cpu + '.zip'))
180 into project.buildDir
181 }
182
183 defaultTasks 'local'