Skip to content

Commit

Permalink
Trim temporary directory root from entry paths when creating resource…
Browse files Browse the repository at this point in the history
…s srcjar to match standard jar format.

--
MOS_MIGRATED_REVID=104498213
  • Loading branch information
apelle03 authored and dslomov committed Oct 2, 2015
1 parent 28099de commit 2594c9e
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class AndroidResourceProcessor {
public AndroidResourceProcessor(StdLogger stdLogger) {
this.stdLogger = stdLogger;
}

/**
* Copies the R.txt to the expected place.
*/
Expand All @@ -85,15 +85,16 @@ public void createSrcJar(Path generatedSourcesRoot, Path srcJar) {
try {
Files.createDirectories(srcJar.getParent());
try (final ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(srcJar))) {
Files.walkFileTree(generatedSourcesRoot, new SymbolFileSrcJarBuildingVisitor(zip));
Files.walkFileTree(generatedSourcesRoot,
new SymbolFileSrcJarBuildingVisitor(zip, generatedSourcesRoot));
}
} catch (IOException e) {
Throwables.propagate(e);
}
}

/**
* Processes resources for generated sources, configs and packaging resources.
* Processes resources for generated sources, configs and packaging resources.
*/
public void processResources(
AndroidBuilder builder,
Expand Down Expand Up @@ -196,7 +197,7 @@ public MergedAndroidData mergeData(
set.loadFromFiles(stdLogger);
merger.addDataSet(set);
}

AssetMerger assetMerger = new AssetMerger();
for (AssetSet set : assetSets) {
set.loadFromFiles(stdLogger);
Expand Down Expand Up @@ -252,7 +253,7 @@ private String prepareOutputPath(@Nullable Path out) throws IOException {
}
return Files.createDirectories(out).toString();
}

/**
* A FileVisitor that will add all R.java files to be stored in a zip archive.
*/
Expand All @@ -261,16 +262,18 @@ private final class SymbolFileSrcJarBuildingVisitor extends SimpleFileVisitor<Pa
// The earliest date representable in a zip file, 1-1-1980.
private static final long ZIP_EPOCH = 315561600000L;
private final ZipOutputStream zip;
private final Path root;

private SymbolFileSrcJarBuildingVisitor(ZipOutputStream zip) {
private SymbolFileSrcJarBuildingVisitor(ZipOutputStream zip, Path root) {
this.zip = zip;
this.root = root;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().endsWith("R.java")) {
byte[] content = Files.readAllBytes(file);
ZipEntry entry = new ZipEntry(file.toString());
ZipEntry entry = new ZipEntry(root.relativize(file).toString());

entry.setMethod(ZipEntry.STORED);
entry.setTime(ZIP_EPOCH);
Expand Down

0 comments on commit 2594c9e

Please sign in to comment.