-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvelcro.gradle
92 lines (69 loc) · 2.56 KB
/
velcro.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
import java.nio.file.Files
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
ext {
/** Folder where the application we are generating the archetype is coming from */
APP_FOLDER = "velcro-app"
/** The resources folder inside the archetype to place the app files */
LAZYBONES_FOLDER = "velcro-lazybones/src/templates/velcro"
/** App Name needs to be filtered out of files and replaced with ${applicationName} */
FILTER_APP_NAME = "Velcro"
/** What the application name should be replaced with. This value is defined in archetype-metadata.xml */
APP_NAME_REPLACE = "{{applicationName}}"
/** Package value that needs to be filtered out and replaced with archetype variable */
FILTER_PACKAGE = "com.andrewreitz.velcro"
/** Package variable. */
PACKAGE_REPLACE = "{{packageName}}"
/** files to be kept when doing a clean. These are setup specific to the archetype */
KEEP_FILES = ["README.md", 'lazybones.groovy', 'VERSION', '.gitignore']
/** Files with these extensions have values that should be replaced with archetype variable */
FILTER_EXTENSIONS = [".xml", ".java", ".md"]
isSnapshot = !project.hasProperty('release')
}
allprojects {
version = "1.2.2${isSnapshot == true ? "-SNAPSHOT" : ""}"
}
task cleanLazybones(type: Delete) {
description = "Clean the velcro-lazybones folder."
doFirst {
def files = files { file(LAZYBONES_FOLDER).listFiles() }
files.each { File file ->
if (!KEEP_FILES.contains(file.name)) {
logger.debug("Delete $file")
delete file
}
}
}
}
task copyToLazybones(type: Copy) {
description = "Copy velcro-app to velcro-lazybones."
// copy explicitly the git ignore because gradle copy forgets it...
File gitIgnore = new File((String) APP_FOLDER, ".gitignore")
Files.copy(gitIgnore.toPath(), new File((String) LAZYBONES_FOLDER, gitIgnore.name).toPath(),
REPLACE_EXISTING)
def copySpec = project.copySpec {
from APP_FOLDER
into LAZYBONES_FOLDER
eachFile { file ->
// Skip trying to copy a file we save
KEEP_FILES.each { name ->
if (file.name == name) {
file.exclude()
return
}
}
// Only filter specific files, images and binaries will become corrupt
for (String ext in FILTER_EXTENSIONS) {
if (file.name.toLowerCase().endsWith(ext)) {
filter {
it.replace(FILTER_APP_NAME, APP_NAME_REPLACE).replace(FILTER_PACKAGE, PACKAGE_REPLACE)
}
}
}
}
}
into '.'
with copySpec
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}