-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
163 lines (144 loc) · 4.02 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
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
buildDir = file(project.projectDir.getAbsolutePath() + "/build/")
def generatedPom = file(project.projectDir.getAbsolutePath() + "/generated-pom.xml")
def odooRepoUrl = "https://github.com/odoo/odoo.git"
def testResourcesDir = file(buildDir.getAbsolutePath() + "/tests/resources/")
def initzDir = file(project.projectDir.getAbsolutePath() + "/" + project.name + "/")
def getVersion = {
def stdout = new ByteArrayOutputStream()
exec {
workingDir project.projectDir.getAbsolutePath() + "/" + project.name + "/"
commandLine 'python',
'-c',
'import sys; import ast; file = open("__manifest__.py"); manifest = ast.literal_eval(file.read()); sys.stdout.write(manifest["version"])'
standardOutput = stdout
}
return stdout.toString()
}
project.version = getVersion()
project.group = "net.mekomsolutions.odoo"
task removeOdoo(type: Exec) {
commandLine 'docker',
'rm',
'-vf',
'dockerfiles_odoo_1'
}
task copyTestResources(type: Copy) {
from initzDir.getAbsolutePath() + "/tests/resources/"
into testResourcesDir
expand(testResources: testResourcesDir.getAbsolutePath(), sources: initzDir.getAbsolutePath())
}
task removeOdooWithCompose(type: Exec) {
dependsOn copyTestResources
workingDir testResourcesDir
commandLine 'docker-compose',
'-f',
'dockerfiles/initialize-db.yml',
'down',
'-v'
}
task runTests(type: Exec) {
dependsOn copyTestResources
workingDir testResourcesDir
commandLine 'docker-compose',
'-f',
'dockerfiles/run-tests.yml',
'up',
'--abort-on-container-exit'
}
task runOdoo(type: Exec) {
dependsOn copyTestResources
workingDir testResourcesDir
commandLine 'docker-compose',
'-f',
'dockerfiles/process-csvs.yml',
'up',
'--abort-on-container-exit'
}
task copySources(type: Copy) {
from "./" + project.name + "/"
exclude "tests"
into "" + buildDir + "/" + project.name + "/"
}
task packageSources(type: Zip) {
dependsOn copySources
archiveBaseName = project.name
archiveVersion = project.version
from buildDir
include project.name + '/**/*'
destinationDirectory = buildDir
}
def getMavenSettingsCredentials = {
String userHome = System.getProperty( "user.home" );
File mavenSettings = new File(userHome, ".m2/settings.xml")
def xmlSlurper = new XmlSlurper()
def output = xmlSlurper.parse(mavenSettings)
return output."servers"."server"
}
def getCredentials = { serverName ->
def entries = getMavenSettingsCredentials()
for (entry in entries) {
if ( entry."id".text() == serverName ) {
return [username: entry.username.text(), password: entry.password.text()]
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact packageSources
}
}
repositories {
maven {
credentials {
def usernameFromSettingsXML = null
def passwordFromSettingsXML = null
if (project.findProperty("repoId")) {
def creds = getCredentials(project.findProperty("repoId"))
usernameFromSettingsXML = creds["username"]
passwordFromSettingsXML = creds["password"]
}
username project.findProperty("user") ?: usernameFromSettingsXML
password project.findProperty("password") ?: passwordFromSettingsXML
}
def releasesRepoUrl = "https://nexus.mekomsolutions.net/repository/maven-releases"
def snapshotsRepoUrl = "https://nexus.mekomsolutions.net/repository/maven-snapshots"
def nexusUrl = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl: releasesRepoUrl
url = project.findProperty("url") ?: nexusUrl
}
}
}
task createPom {
doLast {
pom {
project {
groupId project.group
artifactId project.name
version project.version
}
}.writeTo(generatedPom.getAbsolutePath())
}
}
test {
dependsOn runTests
}
task cleanDocker {
dependsOn removeOdooWithCompose
}
clean {
delete buildDir.getAbsolutePath()
delete generatedPom.getAbsolutePath()
}
task run(type: Exec) {
dependsOn runOdoo
}
install {
dependsOn createPom, publishMavenJavaPublicationToMavenLocal
}
build {
dependsOn(test, install)
}