forked from dotCMS/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.gradle
executable file
·200 lines (155 loc) · 7.97 KB
/
deploy.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
def scriptDescription = """\
********************************************************
Script that will upload a given file as released or as a snapshot using the 'uploadArchives' task:
When the file is treated as a release will be uploaded to the libs-release-local repository (http://repo.dotcms.com/artifactory/libs-release-local)
otherwise it will be treated as a snapshot and uploaded to the libs-snapshot-local repository (http://repo.dotcms.com/artifactory/libs-snapshot-local)
'uploadArchives' task
----------------------
"""
def taskDescription = """
Parameters:
groupId: - Repository group id
-> Required
file: File to upload
-> Required
release: (true/false) - true if is a release upload, false if is a snapshot
-> Default false
includeDependencies: (true/false) - If upload given file including the complete set of dependencies in the file pom (required for the dotcms jar).
-> Default false The set of dependencies is given by the dependencies.gradle script
username: - user name of the user with upload privileges
-> Required
password: - password of the user with upload privileges
-> Required
Examples of use:
dotcms jar:
Name convention: dotcms_version_hash.jar -> dotcms_3.0_a434224.jar
As snapshot: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms -PincludeDependencies=true -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/dotcms_3.0_a434224.jar
As release: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms -PincludeDependencies=true -Prelease=true -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/dotcms_3.0_a434224.jar
Enterprise jar
Name convention: ee_hash.jar -> ee_6536e59.jar
As snapshot: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms.enterprise -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/ee_6536e59.jar
As release: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms.enterprise -Prelease=true -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/ee_6536e59.jar
Enterprise license jar
Name convention: eelic_hash.jar -> eelic_57b3ae9.jar
As snapshot: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms.enterprise -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/eelic_57b3ae9.jar
As release: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms.enterprise -Prelease=true -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/WEB-INF/lib/eelic_57b3ae9.jar
starter zip
Name convention: starter_timestamp.zip -> starter_20140805.zip
As snapshot: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/starter_20140805.zip
As release: gradle -b deploy.gradle uploadArchives -PgroupId=com.dotcms -Prelease=true -Pusername=username -Ppassword=XYZ -Pfile=/project/path/dotCMS/dotCMS/starter_20140805.zip
NOTE:
For a known gradle bug we can not use the default snapshot behaviour and right now each snapshot have to be an artifact:
http://issues.gradle.org/browse/GRADLE-2784
http://forums.gradle.org/gradle/topics/using_a_specific_snapshot_version_of_an_artifact
"""
/**
* Override both the Gradle out-of-the-box 'help' task
*/
task help(overwrite:true) << {
print """
Welcome to Gradle $gradle.gradleVersion.
To run a build, run 'gradle <task> ...'
To see a list of available tasks, run 'gradle tasks'
To see a list of command-line options, run 'gradle --help'
"""
println scriptDescription
print taskDescription
}
help.description = 'Displays a help message'
apply plugin: 'maven'
apply plugin: 'application'
import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact
repositories {
maven { url "http://repo.dotcms.com/artifactory/libs-release" }
maven { url "http://repo.dotcms.com/artifactory/libs-snapshot-local" }
}
ext {
releaseRepository = "http://repo.dotcms.com/artifactory/libs-release-local"
snapshotRepository = "http://repo.dotcms.com/artifactory/libs-snapshot-local"
repositoryUrl = snapshotRepository
artifactGroupId = ""
if (project.hasProperty('groupId')) {
artifactGroupId = "$groupId"
}
fileToUpload = ""
if (project.hasProperty('file')) {
fileToUpload = "$file"
}
releaseUpload = "false"
if (project.hasProperty('release')) {
releaseUpload = "$release"
}
//true if we want to add all the dotcms dependencies to the generated pom file
useDependencies = "false"
if (project.hasProperty('includeDependencies')) {
useDependencies = "$includeDependencies"
}
repositoryUsername = ""
if (project.hasProperty('username')) {
repositoryUsername = "$username"
}
repositoryPassword = ""
if (project.hasProperty('password')) {
repositoryPassword = "$password"
}
}
//We will only apply the dependencies for the dotcms_version.jar, adding these dependencies affects the creation of the pom file for this artifact
if (useDependencies == "true") {
//Import and apply the dependencies from the dependencies scripts
apply from: "$rootDir/dependencies.gradle"
}
File toUpload
artifacts {
if (fileToUpload.length() > 0) {
toUpload = file(new File(fileToUpload))
def extension = toUpload.name.substring(toUpload.name.lastIndexOf(".") + 1, toUpload.name.length())
def fileName = toUpload.name.replace("." + extension, "")
archives new DefaultPublishArtifact(fileName, extension, extension, null, new Date(), toUpload)
}
}
uploadArchives() {
description = taskDescription
repositories {
mavenDeployer {
if (toUpload != null) {
def isRelease = false
if (releaseUpload == "true") {
isRelease = true
}
def extension = toUpload.name.substring(toUpload.name.lastIndexOf(".") + 1, toUpload.name.length())
def fileName = toUpload.name.replace("." + extension, "")
def nameArray = fileName.split("_")
def artifactId = nameArray[0]
def version = nameArray[1]
if (nameArray.length > 2 && !isRelease) {//If is a release we don't need a second identifier
version += "_" + nameArray[2]
}
//Required for artifactory in order to upload it to the snapshots repo, without it the upload fails
if (!isRelease) {
version += "-SNAPSHOT"
}
//Verify if we are releasing or just creating a snapshot
if (isRelease) {
repositoryUrl = releaseRepository
}
addFilter(fileName) { artifact, file ->
artifact.name == fileName
}
//Setting the properties for the pom and artifactory
pom(fileName).artifactId = artifactId
pom(fileName).version = version
pom(fileName).groupId = artifactGroupId
//Some feedback
println " --> Preparing to upload: " + fileName
println "\tgroupId: " + artifactGroupId
println "\tartifactId: " + artifactId
println "\tversion: " + version
println "\trepository: " + repositoryUrl
repository(url: repositoryUrl) {
authentication(userName: repositoryUsername, password: repositoryPassword)
}
}
}
}
}
defaultTasks 'help', 'tasks'