-
Notifications
You must be signed in to change notification settings - Fork 951
/
RefreshDependencies.groovy
80 lines (74 loc) · 2.99 KB
/
RefreshDependencies.groovy
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
/*
* Copyright 2011 SpringSource
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import groovy.xml.NamespaceBuilder
import org.codehaus.groovy.grails.resolve.IvyDependencyManager
import org.apache.commons.io.*
/**
* Refreshes application dependencies, installing any necessary plugins as necessary
*
* @author Graeme Rocher
*
* @since 1.2
*/
includeTargets << grailsScript("_PluginDependencies")
target(refreshDependencies:"Refreshes application dependencies, installing any necessary plugins as necessary") {
resolveDependencies()
if (argsMap.params) {
// write data to file
def f = new File(argsMap.params[0])
f.withWriter { writer ->
def xml = new groovy.xml.MarkupBuilder(writer)
xml.dependencies {
xml.build {
handleArtifactReport(grailsSettings.buildResolveReport.allArtifactsReports, xml)
}
xml.compile {
handleArtifactReport(grailsSettings.compileResolveReport.allArtifactsReports, xml)
}
xml.test {
handleArtifactReport(grailsSettings.testResolveReport.allArtifactsReports, xml)
}
xml.runtime {
handleArtifactReport(grailsSettings.runtimeResolveReport.allArtifactsReports, xml)
}
xml.provided {
handleArtifactReport(grailsSettings.providedResolveReport.allArtifactsReports, xml)
}
}
}
}
event "StatusFinal", ["Dependencies refreshed."]
}
private handleArtifactReport(allReports, xml) {
allReports.findAll { downloadReport ->
!downloadReport.localFile.name.endsWith("-sources.jar") && !downloadReport.localFile.name.endsWith("-javadoc.jar")
}.each { downloadReport ->
def mrid = downloadReport.artifact.moduleRevisionId
xml.dependency(group:mrid.organisation, name:mrid.name, version:mrid.revision) {
xml.jar downloadReport.localFile
def baseName = FilenameUtils.getBaseName(downloadReport.localFile.name)
def sourceJar = allReports.find { "$baseName-sources.jar" == it.localFile?.name}
if(sourceJar) {
xml.source sourceJar.localFile
}
def javadocJar = allReports.find { "$baseName-javadoc.jar" == it.localFile?.name}
if (javadocJar) {
xml.javadoc javadocJar.localFile
}
}
}
}
setDefaultTarget(refreshDependencies)