forked from ben-manes/caffeine
/
eclipse.gradle
63 lines (59 loc) · 1.98 KB
/
eclipse.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
/**
* Configures the project in Eclipse.
*
* @see https://gradle.org/docs/current/userguide/eclipse_plugin.html
*/
apply plugin: 'eclipse'
// For the Gradle Eclipse plugin
eclipse.project.file.withXml { provider ->
ignoreDerivedResources(provider.asNode())
}
// For the Eclipse STS plugin
task afterEclipseImport(description: 'Post processing after project generation', group: 'IDE') {
ext.srcFile = file('.project')
inputs.file srcFile
outputs.dir srcFile
onlyIf { srcFile.exists() }
doLast {
def projectDescription = new XmlParser().parse(srcFile)
ignoreDerivedResources(projectDescription)
def writer = new FileWriter(srcFile)
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(projectDescription)
}
}
def ignoreDerivedResources(projectDescription, directories = [
'test-output', 'build/classes', 'build/reports', 'build/jacoco', 'build/tmp']) {
def count = directories.count { file(it).exists() }
if (count > 0) {
def filter = projectDescription
.appendNode('filteredResources')
.appendNode('filter')
filter.appendNode('id', System.currentTimeMillis().toString().trim())
filter.appendNode('type', '26')
filter.appendNode('name')
def matcher = filter.appendNode('matcher')
matcher.appendNode('id', 'org.eclipse.ui.ide.orFilterMatcher')
def arguments = matcher.appendNode('arguments')
directories.each {
if (file(it).exists()) {
def dirMatcher = arguments.appendNode('matcher')
dirMatcher.appendNode('id', 'org.eclipse.ui.ide.multiFilter')
dirMatcher.appendNode('arguments', "1.0-projectRelativePath-matches-false-false-${it}")
}
}
}
}
ext.buildAddReads = { subjectModule, addModules ->
def addReads = new StringBuilder()
addModules.each {
if (addReads.length() != 0) {
addReads.append(':')
}
addReads.append(subjectModule)
addReads.append('=')
addReads.append(it)
}
return addReads.toString()
}