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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.
*/
package com.android.jack.test.toolchain;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.android.jack.Options;
import com.android.jack.api.v01.AbortException;
import com.android.jack.api.v01.Api01Config;
import com.android.jack.api.v01.ConfigurationException;
import com.android.jack.api.v01.DebugInfoLevel;
import com.android.jack.api.v01.ReporterKind;
import com.android.jack.api.v01.VerbosityLevel;
import com.android.jack.shrob.spec.Flags;
import com.android.jack.test.TestConfigurationException;
import com.android.sched.vfs.Container;
import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
/**
* This {@link Toolchain} uses Jack through v01 API
*/
public class JackApiV01Toolchain extends JackApiToolchainBase {
@Nonnull
private Api01Config apiV01Config;
JackApiV01Toolchain(@Nonnull File jackPrebuilt) {
super(jackPrebuilt, Api01Config.class);
apiV01Config = (Api01Config) config;
}
@Override
public void srcToExe(@Nonnull File out, boolean zipFile, @Nonnull File... sources)
throws Exception {
srcToCommon(sources);
setOutputDex(out);
run();
}
@Override
public void srcToLib(@Nonnull File out, boolean zipFiles, @Nonnull File... sources)
throws Exception {
srcToCommon(sources);
setOutputJack(out);
run();
}
@Override
public void libToExe(@Nonnull File[] in, @Nonnull File out, boolean zipFile) throws Exception {
libToCommon(in);
setOutputDex(out);
run();
}
@Override
public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception {
libToCommon(in);
setOutputJack(out);
run();
}
@Override
@Nonnull
public JackApiV01Toolchain setIncrementalFolder(@Nonnull File incrementalFolder) {
try {
apiV01Config.setIncrementalDir(incrementalFolder);
return this;
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
}
@Override
@Nonnull
public JackApiV01Toolchain setVerbose(boolean isVerbose) {
super.setVerbose(isVerbose);
try {
if (isVerbose) {
apiV01Config.setVerbosityLevel(VerbosityLevel.DEBUG);
} else {
apiV01Config.setVerbosityLevel(VerbosityLevel.WARNING);
}
return this;
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
}
@Override
@Nonnull
public final JackApiV01Toolchain addProperty(@Nonnull String propertyName,
@Nonnull String propertyValue) {
try {
apiV01Config.setProperty(propertyName, propertyValue);
return this;
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
}
@Override
@Nonnull
public JackApiV01Toolchain setWithDebugInfos(boolean withDebugInfos) {
try {
apiV01Config.setDebugInfoLevel(DebugInfoLevel.FULL);
return this;
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
}
@Override
@Nonnull
public JackApiV01Toolchain setShrobFlags(@Nonnull Flags shrobFlags) {
// STOPSHIP(jmhenaff): another CL remove the need for this API
throw new AssertionError("Must no be used");
}
@Override
@Nonnull
public JackApiV01Toolchain setSanityChecks(boolean sanityChecks) {
try {
apiV01Config.setProperty(Options.SANITY_CHECKS.getName(), Boolean.toString(sanityChecks));
return this;
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
}
@Override
@Nonnull
public final Toolchain setErrorStream(@Nonnull OutputStream errorStream) {
super.setErrorStream(errorStream);
try {
apiV01Config.setReporter(ReporterKind.DEFAULT, errorStream);
} catch (ConfigurationException e) {
throw new TestConfigurationException(e);
}
return this;
}
private void run() throws Exception {
try {
System.setOut(outRedirectStream);
System.setErr(errRedirectStream);
apiV01Config.getTask().run();
} catch (ConfigurationException e) {
Throwable t1 = e.getCause();
if (t1 instanceof Exception) {
throw (Exception) t1;
} else {
throw new AssertionError();
}
} catch (AbortException e1) {
Throwable t1 = e1.getCause();
if (t1 instanceof Exception) {
throw (Exception) t1;
} else {
throw new AssertionError();
}
} finally {
System.setOut(stdOut);
System.setOut(stdErr);
}
}
private void srcToCommon(@Nonnull File... sources) throws Exception {
apiV01Config.setClasspath(classpath);
apiV01Config.setImportedJackLibraryFiles(staticLibs);
apiV01Config.setSourceEntries(Lists.newArrayList(sources));
apiV01Config.setResourceDirs(resImport);
apiV01Config.setProguardConfigFiles(proguardFlags);
if (jarjarRules != null) {
apiV01Config.setJarJarConfigFile(jarjarRules);
}
apiV01Config.setProcessorOptions(annotationProcessorOptions);
if (annotationProcessorClasses != null) {
apiV01Config.setProcessorNames(annotationProcessorClasses);
}
if (processorPath != null) {
List<File> fileList = new ArrayList<File>();
for (String entry : Splitter.on(File.pathSeparatorChar).split(processorPath)) {
fileList.add(new File(entry));
}
apiV01Config.setProcessorPath(fileList);
}
}
private void libToCommon(@Nonnull File... in) throws Exception {
apiV01Config.setClasspath(classpath);
List<File> importedLibs = new ArrayList<File>(staticLibs);
Collections.addAll(importedLibs, in);
apiV01Config.setImportedJackLibraryFiles(importedLibs);
apiV01Config.setResourceDirs(resImport);
apiV01Config.setProguardConfigFiles(proguardFlags);
if (jarjarRules != null) {
apiV01Config.setJarJarConfigFile(jarjarRules);
}
}
private void setOutputDex(@Nonnull File outDex) throws Exception {
if (outDex.isDirectory()) {
apiV01Config.setOutputDexDir(outDex);
} else {
apiV01Config.setProperty(Options.DEX_OUTPUT_CONTAINER_TYPE.getName(), Container.ZIP.name());
apiV01Config.setProperty(Options.GENERATE_DEX_FILE.getName(), "true");
apiV01Config.setProperty(Options.DEX_OUTPUT_ZIP.getName(), outDex.getAbsolutePath());
}
}
private void setOutputJack(@Nonnull File outjack) throws Exception {
if (!outjack.isDirectory()) {
apiV01Config.setOutputJackFile(outjack);
} else {
apiV01Config.setProperty(Options.LIBRARY_OUTPUT_CONTAINER_TYPE.getName(),
Container.DIR.name());
apiV01Config.setProperty(Options.LIBRARY_OUTPUT_DIR.getName(), outjack.getAbsolutePath());
apiV01Config.setProperty(Options.GENERATE_JACK_LIBRARY.getName(), "true");
apiV01Config.setProperty(Options.GENERATE_JAYCE_IN_LIBRARY.getName(), "true");
apiV01Config.setProperty(Options.GENERATE_DEPENDENCIES_IN_LIBRARY.getName(), "true");
}
}
}
|