[go: up one dir, main page]

Menu

[3f6e40]: / build.gradle  Maximize  Restore  History

Download this file

196 lines (165 with data), 5.8 kB

  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
import groovy.xml.MarkupBuilder
ant.importBuild 'build.xml'
def excludes = [
".svn",
"ofm.tools.charting",
"ofm.tools.rankingtool"
]
ext {
zipName = "${buildDir}/OFMTools-${ant.properties['app.version']}.zip"
pluginHelpers = []
updateDir = "${buildDir}/Updates"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.1'
}
task distZip () {
description = 'clean - build - dist'
inputs.dir "${projectDir}/plugins"
outputs.file project.ext.zipName
}
distZip << {
println '[ANT] clean'
clean.execute()
println '[ANT] build'
build.execute()
println '[ANT] dist'
dist.execute()
}
task generateUpdates(dependsOn: [ build, distZip ]) {
description = 'generates Update.xml'
inputs.dir "${projectDir}/plugins"
outputs.file "${buildDir}/updates.xml"
}
generateUpdates << {
File srcDir = new File("${projectDir}/plugins")
File destFile = new File("${buildDir}/updates.xml")
description = 'Generates xml for plugin-update-repository.'
println 'generating updates.xml'
File[] fileList = srcDir.listFiles()
List<File> filteredList = fileList.collect { File file ->
if(!excludes.contains(file.name)) {
return new File(file.absoluteFile.toString() + "/plugin.xml")
}
} as List
filteredList.removeAll {
it == null ? true:false;
}
StringWriter writer = new StringWriter()
MarkupBuilder xml = new groovy.xml.MarkupBuilder(writer)
xml.updates() { allPlugins2XML(xml, filteredList) }
destFile.write(writer.toString())
println 'File was created: ' + destFile.absoluteFile
}
task unzip(type: Copy, dependsOn:[generateUpdates, distZip]){
description = 'unzips .zip to get all plugin.zips'
def zipFile = file(project.ext.zipName)
def outputDir = file("${buildDir}/tmp")
inputs.file project.ext.zipName
outputs.dir outputDir
from zipTree(zipFile)
into outputDir
}
unzip << {
println '[GRADLE] starting unzipping'
}
task prepUpload(type: Copy, dependsOn:[unzip,generateUpdates,distZip]) {
description = 'prepares Upload Folder'
def updatesXml = "${buildDir}/updates.xml"
def outputDir = project.ext.updateDir
inputs.dir "${buildDir}/tmp/plugins"
inputs.file updatesXml
outputs.dir outputDir
from updatesXml
into outputDir
}
prepUpload << {
println '[GRADLE] Preparing Upload Folder'
File pluginDir = file("${buildDir}/tmp/plugins")
for(File f in pluginDir.listFiles()) {
File newFolder = createMissingPluginFolder(f)
copy{
from f
into newFolder
}
}
}
def createMissingPluginFolder(def file) {
def outputDirPlugins = new File("${project.ext.updateDir}/Plugins")
def matcher = file.name =~ /\w*\.\w*\.(\w*)-/
def shortName = matcher[0][1].replaceAll(/[^a-zA-Z]/,"")
println "[INFO] moving ${file.name} - short: ${shortName}"
def newFolder = new File("${outputDirPlugins}\\${shortName}")
if(!newFolder.mkdirs()) {
println "[WARNUNG] Folder ${newFolder.absoluteFile} couldn't be created"
}
return newFolder
}
task readPluginTest(type: Test) { description = 'test Plugin reading' }
readPluginTest << {
def plugin = readPluginInfo(file("${projectDir}/plugins/ofm.tools.awprechner/plugin.xml"))
assert plugin.name == 'ofm.tools.awprechner'
println "${it.name} successfull"
}
task parsePlugin2XmlTest(type: Test) { description = 'Test parsing of Plugin to xml' }
parsePlugin2XmlTest << {
StringWriter writer = new StringWriter()
MarkupBuilder xml = new groovy.xml.MarkupBuilder(writer)
xml.updates() {
pluginInfo2XML(xml, file("${projectDir}/plugins/ofm.tools.awprechner/plugin.xml"))
}
def updates = new XmlParser().parseText(writer.toString())
assert updates.plugin[0].@name == 'ofm.tools.awprechner'
println "${it.name} successfull"
}
def readPluginInfo ( File file ) {
def pluginXML = new XmlParser().parse(file)
def plugin = new PluginHelper(name: pluginXML.@id, version: pluginXML.@version )
pluginXML.requires.import.each { dependency ->
plugin.requires << addRequiredPlugin(dependency)
}
project.ext.pluginHelpers << plugin
return plugin
}
def readBasicPluginInfo(File file) {
def pluginXML = new XmlParser().parse(file)
return new PluginHelper(name: pluginXML.@id, version: pluginXML.@version )
}
def addRequiredPlugin(def dependency) {
def requiredPlugin = new PluginHelper()
requiredPlugin.name = dependency.attribute('plugin-id')
def version = dependency.attribute('plugin-version')
if(version == null) {
version = readBasicPluginInfo(file("${projectDir}/plugins/${requiredPlugin.name}/plugin.xml")).version
}
requiredPlugin.version = version
return requiredPlugin
}
def allPlugins2XML( MarkupBuilder builder, List<File> files) {
files.each { file ->
pluginInfo2XML(builder,file)
}
}
def pluginInfo2XML (MarkupBuilder builder, File file) {
println 'Parsing Plugin to updatesxml format: ' + file.absoluteFile.toString().replace(projectDir.absolutePath.toString(),"")
def myPlugin = readPluginInfo(file)
builder.plugin(name: myPlugin.name, version: myPlugin.version, link: myPlugin.updateUrl) {
dependencies2XML(builder, myPlugin.requires)
}
}
def dependencies2XML(builder, deps) {
deps.each { dep ->
builder.dependency(name: dep.name, version: dep.version)
}
}
class PluginHelper {
String name
String version
List requires = []
String getShortName() {
return name.split(/\./)[2]
}
String getUpdateUrl() {
"http://sourceforge.net/projects/ofmtools/files/OFMTools/Updates/Plugins/${shortName}/${name}-${version}.zip"
}
}