Skip to content

Commit

Permalink
Delete unused references to PngCruncher in Android rules.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 443674555
  • Loading branch information
Googler authored and copybara-github committed Apr 22, 2022
1 parent f970db5 commit 128e4b3
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ private Set<Long> getZipEntryTimestamps(Path zip) throws IOException {
ImmutableList.<DependencyAndroidData>of(),
resourcesOut,
assetsOut,
null,
VariantType.LIBRARY,
null,
/* filteredResources= */ ImmutableList.of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@
package com.google.devtools.build.android;

import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;

import com.android.ide.common.internal.PngCruncher;
import com.android.ide.common.internal.PngException;
import com.google.common.collect.ImmutableMap;
import com.google.common.jimfs.Jimfs;
import com.google.common.truth.Subject;
import com.google.common.util.concurrent.MoreExecutors;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -83,27 +78,6 @@ public void writePngInRawAndNotInRaw() throws Exception {
target,
target.resolve("res"),
target.resolve("assets"),
new PngCruncher() {
@Override
public int start() {
return 0;
}

@Override
public void end(int key) throws InterruptedException {
}

@Override
public void crunchPng(int key, File from, File to)
throws PngException {
assertThat(from.toString()).doesNotContain(raw);
try {
Files.copy(from.toPath(), to.toPath());
} catch (IOException e) {
throw new PngException(e);
}
}
},
MoreExecutors.newDirectExecutorService());
ParsedAndroidData direct =
AndroidDataBuilder.of(source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public static void main(String[] args) throws IOException {
ImmutableList.<DependencyAndroidData>of(),
resourcesOut,
assetsOut,
null,
VariantType.LIBRARY,
null,
/* filteredResources= */ ImmutableList.<String>of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void run(Path tmp, ExecutorServiceCloser executorService) throws Exception {
options.transitiveData,
/* resourcesOut = */ ignored,
mergedAssets,
/* cruncher = */ null,
VariantType.LIBRARY,
/* symbolsOut = */ null,
/* rclassWriter = */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// limitations under the License.
package com.google.devtools.build.android;

import com.android.SdkConstants;
import com.android.annotations.NonNull;
import com.android.ide.common.internal.PngCruncher;
import com.android.ide.common.internal.PngException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
Expand All @@ -27,13 +23,8 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.devtools.build.android.AndroidResourceMerger.MergingException;
import com.google.devtools.build.android.junctions.JunctionCreator;
import com.google.devtools.build.android.junctions.NoopJunctionCreator;
import com.google.devtools.build.android.junctions.WindowsJunctionCreator;
import com.google.devtools.build.android.xml.Namespaces;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
Expand All @@ -58,32 +49,6 @@
/** Writer for UnwrittenMergedAndroidData. */
public class AndroidDataWriter implements AndroidDataWritingVisitor {

private static final class CrunchTask implements Callable<Boolean> {
private final Path destinationPath;
private final Path source;
private final PngCruncher cruncher;

private CrunchTask(PngCruncher cruncher, Path destinationPath, Path source) {
this.cruncher = cruncher;
this.destinationPath = destinationPath;
this.source = source;
}

@Override
public Boolean call() throws Exception {
try (JunctionCreator junc =
System.getProperty("os.name").toLowerCase().startsWith("windows")
? new WindowsJunctionCreator(Files.createTempDirectory("pngcrunch"))
: new NoopJunctionCreator()) {
Files.createDirectories(destinationPath.getParent());
cruncher.crunchPng(0, junc.create(source).toFile(), junc.create(destinationPath).toFile());
} catch (PngException e) {
throw MergingException.wrapException(e);
}
return Boolean.TRUE;
}
}

private static final class CopyTask implements Callable<Boolean> {

private final Path sourcePath;
Expand All @@ -108,55 +73,31 @@ public Boolean call() throws Exception {
private static final char[] START_RESOURCES_TAG = "<resources".toCharArray();
public static final char[] END_RESOURCES = "</resources>".toCharArray();
private static final char[] LINE_END = "\n".toCharArray();
static final PngCruncher NOOP_CRUNCHER =
new PngCruncher() {
@Override
public int start() {
return 0;
}

@Override
public void end(int key) throws InterruptedException {}

@Override
public void crunchPng(int key, @NonNull File source, @NonNull File destination)
throws PngException {
try {
Files.createDirectories(destination.toPath().getParent());
Files.copy(source.toPath(), destination.toPath());
} catch (IOException e) {
throw new PngException(e);
}
}
};

private final Path destination;

private final Map<String, ResourceValuesDefinitions> valueTags = new LinkedHashMap<>();
private final Path resourceDirectory;
private final Path assetDirectory;
private final PngCruncher cruncher;
private final List<ListenableFuture<Boolean>> writeTasks = new ArrayList<>();
private final ListeningExecutorService executorService;

private AndroidDataWriter(
Path destination,
Path resourceDirectory,
Path assetsDirectory,
PngCruncher cruncher,
ListeningExecutorService executorService) {
this.destination = destination;
this.resourceDirectory = resourceDirectory;
this.assetDirectory = assetsDirectory;
this.cruncher = cruncher;
this.executorService = executorService;
}

/**
* Creates a new, naive writer for testing.
*
* <p>This writer has "assets" and a "res" directory from the destination directory, as well as a
* noop png cruncher and a {@link ExecutorService} of 1 thread.
* {@link ExecutorService} of 1 thread.
*
* @param destination The base directory to derive all paths.
* @return A new {@link AndroidDataWriter}.
Expand All @@ -167,7 +108,6 @@ static AndroidDataWriter createWithDefaults(Path destination) {
destination,
destination.resolve("res"),
destination.resolve("assets"),
NOOP_CRUNCHER,
MoreExecutors.newDirectExecutorService());
}

Expand All @@ -177,22 +117,18 @@ static AndroidDataWriter createWithDefaults(Path destination) {
* @param manifestDirectory The base directory for the AndroidManifest.
* @param resourceDirectory The directory to copy resources into.
* @param assetsDirectory The directory to copy assets into.
* @param cruncher The cruncher for png files. If the cruncher is null, it will be replaced with a
* noop cruncher.
* @param executorService An execution service for multi-threaded writing.
* @return A new {@link AndroidDataWriter}.
*/
public static AndroidDataWriter createWith(
Path manifestDirectory,
Path resourceDirectory,
Path assetsDirectory,
@Nullable PngCruncher cruncher,
ListeningExecutorService executorService) {
return new AndroidDataWriter(
manifestDirectory,
resourceDirectory,
assetsDirectory,
cruncher == null ? NOOP_CRUNCHER : cruncher,
executorService);
}

Expand All @@ -219,15 +155,9 @@ public void copyAsset(Path source, String relativeDestinationPath) throws IOExce
}

@Override
public void copyResource(final Path source, final String relativeDestinationPath)
throws MergingException {
public void copyResource(final Path source, final String relativeDestinationPath) {
final Path destinationPath = resourceDirectory.resolve(relativeDestinationPath);
if (!source.getParent().getFileName().toString().startsWith(SdkConstants.FD_RES_RAW)
&& source.getFileName().toString().endsWith(SdkConstants.DOT_PNG)) {
writeTasks.add(executorService.submit(new CrunchTask(cruncher, destinationPath, source)));
} else {
copy(source, destinationPath);
}
copy(source, destinationPath);
}

private void copy(final Path sourcePath, final Path destinationPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.android.annotations.Nullable;
import com.android.builder.core.VariantType;
import com.android.ide.common.internal.PngCruncher;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListeningExecutorService;
Expand Down Expand Up @@ -92,7 +91,6 @@ public static MergedAndroidData mergeDataAndWrite(
final List<? extends SerializedAndroidData> transitive,
final Path resourcesOut,
final Path assetsOut,
@Nullable final PngCruncher cruncher,
final VariantType type,
@Nullable final Path symbolsOut,
final List<String> filteredResources,
Expand All @@ -106,7 +104,6 @@ public static MergedAndroidData mergeDataAndWrite(
transitive,
resourcesOut,
assetsOut,
cruncher,
type,
symbolsOut,
/* rclassWriter= */ null,
Expand All @@ -129,7 +126,6 @@ public static MergedAndroidData mergeDataAndWrite(
final List<? extends SerializedAndroidData> transitive,
final Path resourcesOut,
final Path assetsOut,
@Nullable final PngCruncher cruncher,
final VariantType type,
@Nullable final Path symbolsOut,
@Nullable final AndroidResourceClassWriter rclassWriter,
Expand All @@ -147,7 +143,6 @@ public static MergedAndroidData mergeDataAndWrite(
transitive,
resourcesOut,
assetsOut,
cruncher,
type,
symbolsOut,
rclassWriter,
Expand All @@ -164,7 +159,6 @@ private static MergedAndroidData mergeDataAndWrite(
final List<? extends SerializedAndroidData> transitive,
final Path resourcesOut,
final Path assetsOut,
@Nullable final PngCruncher cruncher,
final VariantType type,
@Nullable final Path symbolsOut,
@Nullable AndroidResourceClassWriter rclassWriter,
Expand Down Expand Up @@ -202,7 +196,7 @@ private static MergedAndroidData mergeDataAndWrite(
}
AndroidDataWriter writer =
AndroidDataWriter.createWith(
resourcesOut.getParent(), resourcesOut, assetsOut, cruncher, executorService);
resourcesOut.getParent(), resourcesOut, assetsOut, executorService);
return merged.write(writer);
} catch (IOException e) {
throw MergingException.wrapException(e);
Expand Down

This file was deleted.

0 comments on commit 128e4b3

Please sign in to comment.