-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
182 lines (159 loc) · 4.67 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* (c) Copyright IBM Corporation 2017.
* This is licensed under the following license.
* The Eclipse Public 1.0 License (http://www.eclipse.org/legal/epl-v10.html)
* U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
/* The Groovy plugin for Gradle assumes the following layout
* src/main/java
* src/main/resources
* src/main/groovy
*
* src/test/java
* src/test/resources
* src/test/groovy
*
* src/<sourceSet>/java
* src/<sourceSet>/resources
* src/<sourceSet>/groovy
*
* You can override or create a new sourceSet with the following snippet:
*
* sourceSets {
* main {
* // We can override src/main/groovy to also add src/main/zip
* groovy {
* srcDirs = ['src/main/groovy', 'src/main/zip']
* }
* }
* mySourceSet {
* groovy {
* srcDirs = ['src/myDir/groovy']
* }
* }
* }
*/
import org.apache.tools.ant.filters.ReplaceTokens
def pluginName="Ansible-Toolkit-UCD"
String pluginVersion
if (project.hasProperty('pluginVersion')) {
pluginVersion = project.getProperty('pluginVersion')
} else {
def pluginNode = new XmlParser().parse(new File('src/main/zip/plugin.xml'))
pluginVersion = "${pluginNode.header.identifier.@version[0]}.dev"
}
apply plugin: 'groovy'
defaultTasks("dist")
def buildLocaleDir = 'build/locale'
def buildUtilDir = 'build/util'
configurations {
// Remove the groovy-all jar from runtime dependencies
runtimeClasspath.exclude module: 'groovy-all'
}
repositories {
mavenCentral()
maven {
url "https://public.dhe.ibm.com/software/products/UrbanCode/maven2/"
}
}
dependencies {
// groovy-plugin-utils pulls down groovy-all as a transitive dependency for the 'compile' configuration
implementation 'com.ibm.urbancode.plugins:groovy-plugin-utils:+'
implementation 'com.ibm.urbancode.util:i18n-scraper:+'
// This compiles the i18n-scraper script
implementation localGroovy()
testImplementation 'junit:junit:4.11'
testImplementation 'org.hamcrest:hamcrest-core:1.3'
}
sourceSets {
main {
groovy {
srcDirs = ['src/main/groovy', 'src/main/zip', "${buildDir}/util"]
}
}
zip {
groovy {
srcDirs = ['src/main/zip']
}
}
classes {
groovy {
srcDirs = ['src/main/groovy', "${buildDir}/util"]
}
}
}
compileJava {
dependsOn 'extractGPU', 'copyi18n'
}
compileGroovy {
include "i18n-scraper.groovy"
}
task copyDeps(type: Copy) {
into 'lib'
copy {
from configurations.runtimeClasspath
include { target ->
return target.file.path.contains("com.ibm.urbancode")
}
into 'lib'
rename { fileName ->
stripVersion(fileName)
}
}
copy {
from configurations.runtimeClasspath
exclude { target ->
return target.file.path.contains("com.ibm.urbancode")
}
into 'lib'
}
}
task extractGPU(type: Copy) {
def zipFile = file('lib/groovy-plugin-utils.jar')
def outputDir = file("${buildDir}/util")
from zipTree(zipFile)
into outputDir
}
task copyi18n(type: Copy) {
def i18nFile = file('lib/i18n-scraper.groovy')
def outputDir = file("${buildDir}/util")
from i18nFile
into outputDir
}
task dist(type: Zip, dependsOn: ['compileGroovy', 'gatherI18n']) {
from(sourceSets.zip.groovy.srcDirs) {
filter(ReplaceTokens, tokens: [RELEASE_VERSION: pluginVersion])
}
into('lib') {
from copyDeps
exclude 'i18n-scraper.groovy'
exclude 'groovy-plugin-utils.jar'
exclude 'groovy-all-*.jar'
exclude 'gson-*.jar'
}
into('locale') {
from buildLocaleDir
}
into('classes') {
from sourceSets.classes.groovy.srcDirs
exclude 'META-INF', 'i18n-scraper.groovy'
}
if (pluginVersion) {
archiveFileName = "${pluginName}-v${pluginVersion}.zip"
} else {
archiveFileName = "${pluginName}-dev.zip"
}
}
task gatherI18n(type: JavaExec) {
delete buildLocaleDir
mkdir buildLocaleDir
main = 'i18n-scraper'
args 'build/locale/en.properties'
classpath = sourceSets.main.runtimeClasspath
}
task cleanAll(dependsOn: ['clean', 'cleanCopyDeps', 'cleanDistPlugin', 'cleanGatherI18n'])
String stripVersion(String fileNameWithVersion) {
String ext = fileNameWithVersion.substring(fileNameWithVersion.lastIndexOf("."),fileNameWithVersion.length())
int end = fileNameWithVersion.lastIndexOf("-"); //assumes that: name-version.ext. Will not work with name-version-SNAPSHOT.ext
return fileNameWithVersion.substring(0, end) + ext
}