-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.gradle
193 lines (161 loc) · 5.14 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
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
// version 6.2.0 of OptaPlanner requires JavaBeans libraries repacked into jar file
/*
import java.nio.channels.Channels
import java.nio.channels.ReadableByteChannel
String OPENBEANS_URL = "https://openbeans.googlecode.com/files/openbeans-1.0.jar";
String JARJAR_URL = "https://jarjar.googlecode.com/files/jarjar-1.4.jar";
String JAVABEANS = "javabeans.jar"
String OPENBEANS = "openbeans.jar";
String JARJAR = "jarjar.jar";
String RULES = "rule.txt";
String LIBS_DIR = "app/libs/";
String RULE = "rule com.googlecode.openbeans.** java.beans.@1";
String COMMAND = "java -jar " + JARJAR + " process " + RULES + " " + OPENBEANS + " " + JAVABEANS;
void downloadJar(String url, String path) {
File file = new File(path);
if (!file.exists()) {
URL fileUrl = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(fileUrl.openStream());
FileOutputStream fos = new FileOutputStream(path);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
}
void deleteFile(String path) {
File file = new File(path);
if (file.exists()) {
file.delete()
}
}
task checkLibsDir {
description = "Checks if " + LIBS_DIR + " directory exists.";
group = "Preparation";
}
checkLibsDir << {
logger.info("Checking directory: '{}'", LIBS_DIR);
File libs = new File(LIBS_DIR);
if (!libs.exists()) {
libs.mkdir();
}
}
task deleteJarJar {
description = "Deletes " + JARJAR + " file.";
group = "Preparation";
}
deleteJarJar << {
logger.info("Deleting file: '{}'", JARJAR);
deleteFile(LIBS_DIR + JARJAR);
}
task deleteOpenBeans {
description = "Deletes " + OPENBEANS + " file.";
group = "Preparation";
}
deleteOpenBeans << {
logger.info("Deleting file: '{}'", OPENBEANS);
deleteFile(LIBS_DIR + OPENBEANS);
}
task deleteJavaBeans {
description = "Deletes " + JAVABEANS + " file.";
group = "Preparation";
}
deleteJavaBeans << {
logger.info("Deleting file: '{}'", JAVABEANS);
deleteFile(LIBS_DIR + JAVABEANS);
}
task deleteRule {
description = "Deletes " + RULES + " file.";
group = "Preparation";
}
deleteRule << {
logger.info("Deleting file: '{}'", RULES);
deleteFile(LIBS_DIR + RULES);
}
task downloadJarJar {
description = "Downloads " + JARJAR + " file.";
group = "Preparation";
}
downloadJarJar << {
logger.info("Downloading file: '{}' to '{}'", JARJAR, LIBS_DIR);
downloadJar(JARJAR_URL, LIBS_DIR + JARJAR);
}
task dowloadOpenBeans {
description = "Downloads " + OPENBEANS + " file.";
group = "Preparation";
}
dowloadOpenBeans << {
logger.info("Downloading file: '{}' to '{}'", OPENBEANS, LIBS_DIR);
downloadJar(OPENBEANS_URL, LIBS_DIR + OPENBEANS);
}
task createRuleFile {
description = "Creates " + RULES + " file.";
group = "Preparation";
}
createRuleFile << {
File rule = new File(LIBS_DIR + RULES);
if (!rule.exists()) {
logger.info("Creating file: '{}' in '{}'", RULES, LIBS_DIR);
PrintWriter writer = new PrintWriter(rule, "UTF-8");
logger.info("Writing rule: '{}' to '{}'", RULE, RULES);
writer.println(RULE);
writer.close();
}
}
task repackOpenBeans {
description = "Repacks " + OPENBEANS + " file to " + JAVABEANS + " file.";
group = "Preparation";
}
repackOpenBeans << {
logger.info("Running command: '{}' in '{}'", COMMAND, LIBS_DIR);
Runtime.getRuntime().exec(COMMAND, null, new File(LIBS_DIR)).waitFor();
}
task editDx {
description = "Add --core-library flag to dx file";
group = "Preparation"
}
editDx << {
logger.info("Reading properties: getting sdk.dir");
Properties properties = new Properties();
properties.load(project.rootProject.file('local.properties').newDataInputStream());
String dxLocation = properties.getProperty('sdk.dir') + "/build-tools/";
dxLocation += properties.getProperty('build-tools.version') + "/dx";
logger.info("Reading file: dx");
String line;
StringBuilder dx = new StringBuilder();
BufferedReader file = new BufferedReader(new FileReader(dxLocation));
while ((line = file.readLine()) != null) {
dx.append(line).append(String.format("%n"))
}
logger.info("Adding parameter: --core-library");
String oldDx = dx.toString();
if (!oldDx.contains("--core-library \"\$@\"")) {
String newDx = oldDx.replace("\"\$@\"", "--core-library \"\$@\"");
logger.info("Writing changes to file: dx");
FileOutputStream fos = new FileOutputStream(dxLocation);
fos.write(newDx.getBytes());
fos.close();
}
}
createRuleFile.dependsOn checkLibsDir
downloadJarJar.dependsOn checkLibsDir
dowloadOpenBeans.dependsOn checkLibsDir
repackOpenBeans.dependsOn deleteJavaBeans, createRuleFile, downloadJarJar, dowloadOpenBeans
repackOpenBeans.finalizedBy deleteJarJar, deleteOpenBeans, deleteRule
*/
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url "https://repository.jboss.org/nexus/content/groups/public/"
}
}
}