use of com.android.builder.internal.SymbolLoader in project bazel by bazelbuild.
the class RClassGeneratorAction method main.
public static void main(String[] args) throws Exception {
final Stopwatch timer = Stopwatch.createStarted();
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
optionsParser.enableParamsFileSupport(FileSystems.getDefault());
if (args.length == 1 && args[0].startsWith("@")) {
args = Files.readAllLines(Paths.get(args[0].substring(1)), StandardCharsets.UTF_8).toArray(new String[0]);
}
optionsParser.parseAndExitUponError(args);
Options options = optionsParser.getOptions(Options.class);
Preconditions.checkNotNull(options.classJarOutput);
final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(STD_LOGGER);
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_res_compile_tmp")) {
Path tmp = scopedTmp.getPath();
Path classOutPath = tmp.resolve("compiled_classes");
logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
List<SymbolFileProvider> libraries = new ArrayList<>();
for (DependencySymbolFileProvider library : options.libraries) {
libraries.add(library);
}
// are no libraries).
if (options.primaryRTxt != null) {
String appPackageName = options.packageForR;
if (appPackageName == null) {
appPackageName = VariantConfiguration.getManifestPackage(options.primaryManifest.toFile());
}
Multimap<String, SymbolLoader> libSymbolMap = ArrayListMultimap.create();
SymbolLoader fullSymbolValues = resourceProcessor.loadResourceSymbolTable(libraries, appPackageName, options.primaryRTxt, libSymbolMap);
logger.fine(String.format("Load symbols finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
// For now, assuming not used for libraries and setting final access for fields.
if (fullSymbolValues != null) {
resourceProcessor.writePackageRClasses(libSymbolMap, fullSymbolValues, appPackageName, classOutPath, true);
logger.fine(String.format("Finished R.class at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
} else {
Files.createDirectories(classOutPath);
}
// We write .class files to temp, then jar them up after (we create a dummy jar, even if
// there are no class files).
AndroidResourceOutputs.createClassJar(classOutPath, options.classJarOutput);
logger.fine(String.format("createClassJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
} finally {
resourceProcessor.shutdown();
}
logger.fine(String.format("Compile action done in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
use of com.android.builder.internal.SymbolLoader in project bazel by bazelbuild.
the class AndroidResourceProcessor method writePackageRClasses.
void writePackageRClasses(Multimap<String, SymbolLoader> libMap, SymbolLoader fullSymbolValues, String appPackageName, Path classesOut, boolean finalFields) throws IOException {
for (String packageName : libMap.keySet()) {
Collection<SymbolLoader> symbols = libMap.get(packageName);
RClassGenerator classWriter = RClassGenerator.fromSymbols(classesOut, packageName, fullSymbolValues, symbols, finalFields);
classWriter.write();
}
// Unlike the R.java generation, we also write the app's R.class file so that the class
// jar file can be complete (aapt doesn't generate it for us).
RClassGenerator classWriter = RClassGenerator.fromSymbols(classesOut, appPackageName, fullSymbolValues, ImmutableList.of(fullSymbolValues), finalFields);
classWriter.write();
}
use of com.android.builder.internal.SymbolLoader in project bazel by bazelbuild.
the class AndroidResourceProcessor method writePackageRJavaFiles.
private void writePackageRJavaFiles(Multimap<String, SymbolLoader> libMap, SymbolLoader fullSymbolValues, Path sourceOut) throws IOException {
// Loop on all the package name, merge all the symbols to write, and write.
for (String packageName : libMap.keySet()) {
Collection<SymbolLoader> symbols = libMap.get(packageName);
SymbolWriter writer = new SymbolWriter(sourceOut.toString(), packageName, fullSymbolValues);
for (SymbolLoader symbolLoader : symbols) {
writer.addSymbolsToWrite(symbolLoader);
}
writer.write();
}
}
use of com.android.builder.internal.SymbolLoader in project bazel by bazelbuild.
the class AndroidResourceProcessor method writeDependencyPackageRJavaFiles.
void writeDependencyPackageRJavaFiles(List<DependencyAndroidData> dependencyData, String customPackageForR, Path androidManifest, Path sourceOut) throws IOException {
List<SymbolFileProvider> libraries = new ArrayList<>();
for (DependencyAndroidData dataDep : dependencyData) {
SymbolFileProvider library = dataDep.asSymbolFileProvider();
libraries.add(library);
}
String appPackageName = customPackageForR;
if (appPackageName == null) {
appPackageName = VariantConfiguration.getManifestPackage(androidManifest.toFile());
}
Multimap<String, SymbolLoader> libSymbolMap = ArrayListMultimap.create();
Path primaryRTxt = sourceOut != null ? sourceOut.resolve("R.txt") : null;
if (primaryRTxt != null && !libraries.isEmpty()) {
SymbolLoader fullSymbolValues = loadResourceSymbolTable(libraries, appPackageName, primaryRTxt, libSymbolMap);
if (fullSymbolValues != null) {
writePackageRJavaFiles(libSymbolMap, fullSymbolValues, sourceOut);
}
}
}
use of com.android.builder.internal.SymbolLoader in project bazel by bazelbuild.
the class RClassGeneratorTest method corruptIntArraysOmittedMiddle.
@Test
public void corruptIntArraysOmittedMiddle() throws Exception {
boolean finalFields = true;
SymbolLoader symbolValues = createSymbolFile("R.txt", "int[] styleable ActionMenuView { 1, , 2 }");
SymbolLoader symbolsInLibrary = symbolValues;
Path out = temp.resolve("classes");
Files.createDirectories(out);
thrown.expect(NumberFormatException.class);
RClassGenerator writer = RClassGenerator.fromSymbols(out, "com.foo", symbolValues, ImmutableList.of(symbolsInLibrary), finalFields);
writer.write();
}
Aggregations