aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java309
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java362
2 files changed, 0 insertions, 671 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java
deleted file mode 100644
index 6567c931e5..0000000000
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java
+++ /dev/null
@@ -1,309 +0,0 @@
-// Copyright 2016 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.analysis.actions;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.actions.AbstractAction;
-import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
-import com.google.devtools.build.lib.actions.ActionExecutionContext;
-import com.google.devtools.build.lib.actions.ActionExecutionException;
-import com.google.devtools.build.lib.actions.ActionExecutionMetadata;
-import com.google.devtools.build.lib.actions.ActionInput;
-import com.google.devtools.build.lib.actions.ActionInputHelper;
-import com.google.devtools.build.lib.actions.ActionKeyContext;
-import com.google.devtools.build.lib.actions.ActionOwner;
-import com.google.devtools.build.lib.actions.ActionResult;
-import com.google.devtools.build.lib.actions.Actions;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
-import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
-import com.google.devtools.build.lib.actions.ArtifactPrefixConflictException;
-import com.google.devtools.build.lib.actions.BaseSpawn;
-import com.google.devtools.build.lib.actions.ExecException;
-import com.google.devtools.build.lib.actions.RunfilesSupplier;
-import com.google.devtools.build.lib.actions.Spawn;
-import com.google.devtools.build.lib.actions.SpawnActionContext;
-import com.google.devtools.build.lib.actions.SpawnResult;
-import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.util.Fingerprint;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * An action that populates a TreeArtifact with the contents of an archive file.
- *
- * <p>Internally, the following happens at execution time:
- * <ol>
- * <li>The archive entry paths are read from the associated archive manifest file locally.
- * <li>A spawn is executed to unzip the archive contents under the root of the TreeArtifact.
- * <li>Child TreeFileArtifacts are created using the archive entry paths and then populated into
- * the output TreeArtifact.
- * </ol>
- *
- * <p>There are also several requirements regarding the archive and archive manifest file:
- * <ul>
- * <li>The entry names (paths) of the archive and archive manifest file must be valid ISO-8859-1
- * strings.
- * <li>The archive manifest file must not contain absolute, non-normalized
- * (e.g., containing '..' fragments) or duplicated paths. And no path is allowed to be a
- * prefix of another path.
- * </ul>
- */
-public final class PopulateTreeArtifactAction extends AbstractAction {
- private static final String GUID = "a3d36f29-9f14-42cf-a014-3a51e914e482";
-
- @VisibleForTesting
- static final String MNEMONIC = "PopulateTreeArtifact";
-
- private final Artifact archive;
- private final Artifact archiveManifest;
- private final SpecialArtifact outputTreeArtifact;
- private final FilesToRunProvider zipper;
-
- /**
- * Creates a PopulateTreeArtifactAction object.
- *
- * @param owner the owner of the action.
- * @param archive the archive containing files to populate into the TreeArtifact.
- * @param archiveManifest the archive manifest file specifying the entry files to populate into
- * the TreeArtifact.
- * @param treeArtifactToPopulate the TreeArtifact to be populated with archive member files.
- * @param zipper the zipper executable used to unzip the archive.
- */
- public PopulateTreeArtifactAction(
- ActionOwner owner,
- Artifact archive,
- Artifact archiveManifest,
- SpecialArtifact treeArtifactToPopulate,
- FilesToRunProvider zipper) {
- super(
- owner,
- ImmutableList.copyOf(zipper.getFilesToRun()),
- Iterables.concat(
- ImmutableList.of(archive, archiveManifest),
- ImmutableList.copyOf(zipper.getFilesToRun())),
- ImmutableList.of(treeArtifactToPopulate));
-
- Preconditions.checkArgument(
- treeArtifactToPopulate.isTreeArtifact(),
- "%s is not TreeArtifact",
- treeArtifactToPopulate);
-
- this.archive = archive;
- this.archiveManifest = archiveManifest;
- this.outputTreeArtifact = treeArtifactToPopulate;
- this.zipper = zipper;
- }
-
- private static class PopulateTreeArtifactSpawn extends BaseSpawn {
- private final SpecialArtifact treeArtifact;
- private final Iterable<PathFragment> entriesToExtract;
-
- // The output TreeFileArtifacts are created lazily outside of the contructor because potentially
- // we can have a lot of TreeFileArtifacts under a given tree artifact.
- private Collection<TreeFileArtifact> outputTreeFileArtifacts;
-
- PopulateTreeArtifactSpawn(
- SpecialArtifact treeArtifact,
- Iterable<PathFragment> entriesToExtract,
- Iterable<String> commandLine,
- RunfilesSupplier runfilesSupplier,
- ActionExecutionMetadata action) {
- super(
- ImmutableList.copyOf(commandLine),
- ImmutableMap.<String, String>of(),
- ImmutableMap.<String, String>of(),
- runfilesSupplier,
- action,
- AbstractAction.DEFAULT_RESOURCE_SET);
- this.treeArtifact = treeArtifact;
- this.entriesToExtract = entriesToExtract;
- }
-
- @Override
- public Collection<? extends ActionInput> getOutputFiles() {
- if (outputTreeFileArtifacts == null) {
- outputTreeFileArtifacts = ImmutableList.<TreeFileArtifact>copyOf(
- ActionInputHelper.asTreeFileArtifacts(treeArtifact, entriesToExtract));
- }
- return outputTreeFileArtifacts;
- }
- }
-
- @Override
- public Artifact getPrimaryOutput() {
- return outputTreeArtifact;
- }
-
- @Override
- public ActionResult execute(ActionExecutionContext actionExecutionContext)
- throws ActionExecutionException, InterruptedException {
- Spawn spawn;
-
- // Create a spawn to unzip the archive file into the output TreeArtifact.
- try {
- spawn = createSpawn();
- } catch (IOException e) {
- throw new ActionExecutionException(e, this, false);
- } catch (IllegalManifestFileException e) {
- throw new ActionExecutionException(e, this, true);
- }
-
- // If the spawn does not have any output, it means the archive file contains nothing. In this
- // case we just return without generating anything under the output TreeArtifact.
- if (spawn.getOutputFiles().isEmpty()) {
- return ActionResult.EMPTY;
- }
-
- // Check spawn output TreeFileArtifact conflicts.
- try {
- checkOutputConflicts(spawn.getOutputFiles());
- } catch (ArtifactPrefixConflictException e) {
- throw new ActionExecutionException(e, this, true);
- }
-
- // Create parent directories for the output TreeFileArtifacts.
- try {
- for (ActionInput fileEntry : spawn.getOutputFiles()) {
- FileSystemUtils.createDirectoryAndParents(
- actionExecutionContext.getInputPath(((Artifact) fileEntry)).getParentDirectory());
- }
- } catch (IOException e) {
- throw new ActionExecutionException(e, this, false);
- }
-
- // Execute the spawn.
- List<SpawnResult> spawnResults;
- try {
- spawnResults = getContext(spawn, actionExecutionContext).exec(spawn, actionExecutionContext);
- } catch (ExecException e) {
- throw e.toActionExecutionException(
- getMnemonic() + " action failed for target: " + getOwner().getLabel(),
- actionExecutionContext.getVerboseFailures(),
- this);
- }
-
- // Populate the output TreeArtifact with the Spawn output TreeFileArtifacts.
- for (ActionInput fileEntry : spawn.getOutputFiles()) {
- actionExecutionContext.getMetadataHandler().addExpandedTreeOutput(
- (TreeFileArtifact) fileEntry);
- }
- return ActionResult.create(spawnResults);
- }
-
- @Override
- protected void computeKey(ActionKeyContext actionKeyContext, Fingerprint fp) {
- fp.addString(GUID);
- fp.addString(getMnemonic());
- fp.addStrings(spawnCommandLine());
- fp.addPaths(zipper.getRunfilesSupplier().getRunfilesDirs());
- List<Artifact> runfilesManifests = zipper.getRunfilesSupplier().getManifests();
- fp.addInt(runfilesManifests.size());
- for (Artifact manifest : runfilesManifests) {
- fp.addPath(manifest.getExecPath());
- }
- }
-
- @Override
- public String getMnemonic() {
- return "PopulateTreeArtifact";
- }
-
- @Override
- public boolean shouldReportPathPrefixConflict(ActionAnalysisMetadata action) {
- return true;
- }
-
- private SpawnActionContext getContext(
- Spawn spawn, ActionExecutionContext actionExecutionContext) {
- return actionExecutionContext.getSpawnActionContext(spawn);
- }
-
- /**
- * Creates a spawn to unzip the archive members specified in the archive manifest into the
- * TreeArtifact.
- */
- @VisibleForTesting
- Spawn createSpawn() throws IOException, IllegalManifestFileException {
- Iterable<PathFragment> entries = readAndCheckManifestEntries();
- return new PopulateTreeArtifactSpawn(
- outputTreeArtifact,
- entries,
- spawnCommandLine(),
- zipper.getRunfilesSupplier(),
- this);
- }
-
- private Iterable<String> spawnCommandLine() {
- return ImmutableList.of(
- zipper.getExecutable().getExecPathString(),
- "x",
- archive.getExecPathString(),
- "-d",
- outputTreeArtifact.getExecPathString(),
- "@" + archiveManifest.getExecPathString());
- }
-
- private Iterable<PathFragment> readAndCheckManifestEntries()
- throws IOException, IllegalManifestFileException {
- ImmutableList.Builder<PathFragment> manifestEntries = ImmutableList.builder();
-
- for (String line :
- FileSystemUtils.iterateLinesAsLatin1(archiveManifest.getPath())) {
- if (!line.isEmpty()) {
- PathFragment path = PathFragment.create(line);
-
- if (!PathFragment.isNormalized(line) || path.isAbsolute()) {
- throw new IllegalManifestFileException(
- path + " is not a proper relative path");
- }
-
- manifestEntries.add(path);
- }
- }
-
- return manifestEntries.build();
- }
-
- private void checkOutputConflicts(Collection<? extends ActionInput> outputs)
- throws ArtifactPrefixConflictException {
- ImmutableMap.Builder<Artifact, ActionAnalysisMetadata> generatingActions =
- ImmutableMap.<Artifact, ActionAnalysisMetadata>builder();
- for (ActionInput output : outputs) {
- generatingActions.put((Artifact) output, this);
- }
-
- Map<ActionAnalysisMetadata, ArtifactPrefixConflictException> artifactPrefixConflictMap =
- Actions.findArtifactPrefixConflicts(generatingActions.build());
-
- if (!artifactPrefixConflictMap.isEmpty()) {
- throw artifactPrefixConflictMap.values().iterator().next();
- }
- }
-
- private static class IllegalManifestFileException extends Exception {
-
- IllegalManifestFileException(String message) {
- super(message);
- }
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java
deleted file mode 100644
index 1ce4fd5b43..0000000000
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java
+++ /dev/null
@@ -1,362 +0,0 @@
-// Copyright 2016 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.analysis.actions;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.lib.actions.Action;
-import com.google.devtools.build.lib.actions.ActionExecutionContext;
-import com.google.devtools.build.lib.actions.ActionExecutionException;
-import com.google.devtools.build.lib.actions.ActionInput;
-import com.google.devtools.build.lib.actions.ActionInputPrefetcher;
-import com.google.devtools.build.lib.actions.ActionResult;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
-import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType;
-import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
-import com.google.devtools.build.lib.actions.ArtifactOwner;
-import com.google.devtools.build.lib.actions.ArtifactRoot;
-import com.google.devtools.build.lib.actions.BaseSpawn;
-import com.google.devtools.build.lib.actions.Executor;
-import com.google.devtools.build.lib.actions.Spawn;
-import com.google.devtools.build.lib.actions.SpawnActionContext;
-import com.google.devtools.build.lib.actions.cache.Md5Digest;
-import com.google.devtools.build.lib.actions.cache.Metadata;
-import com.google.devtools.build.lib.actions.cache.MetadataHandler;
-import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
-import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.util.ActionTester;
-import com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
-import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
-import com.google.devtools.build.lib.vfs.FileStatus;
-import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests {@link PopulateTreeArtifactAction}. */
-@RunWith(JUnit4.class)
-public class PopulateTreeArtifactActionTest extends BuildViewTestCase {
- private static class TestMetadataHandler implements MetadataHandler {
- private final List<Artifact> storingExpandedTreeFileArtifacts;
-
- TestMetadataHandler(List<Artifact> storingExpandedTreeFileArtifacts) {
- this.storingExpandedTreeFileArtifacts = storingExpandedTreeFileArtifacts;
- }
-
- @Override
- public void addExpandedTreeOutput(TreeFileArtifact output) {
- storingExpandedTreeFileArtifacts.add(output);
- }
-
- @Override
- public Iterable<TreeFileArtifact> getExpandedOutputs(Artifact artifact) {
- throw new UnsupportedOperationException(artifact.prettyPrint());
- }
-
- @Override
- public Metadata getMetadata(Artifact artifact) {
- throw new UnsupportedOperationException(artifact.prettyPrint());
- }
-
- @Override
- public void setDigestForVirtualArtifact(Artifact artifact, Md5Digest md5Digest) {
- throw new UnsupportedOperationException(artifact.prettyPrint() + ": " + md5Digest);
- }
-
- @Override
- public void injectDigest(ActionInput output, FileStatus statNoFollow, byte[] digest) {
- throw new UnsupportedOperationException(output.toString());
- }
-
- @Override
- public void markOmitted(ActionInput output) {
- throw new UnsupportedOperationException(output.toString());
- }
-
- @Override
- public boolean artifactOmitted(Artifact artifact) {
- throw new UnsupportedOperationException(artifact.prettyPrint());
- }
-
- @Override
- public void discardOutputMetadata() {
- throw new UnsupportedOperationException();
- }
- };
-
- private ArtifactRoot root;
-
- @Before
- public void setRootDir() throws Exception {
- Path execRoot = scratch.getFileSystem().getPath("/exec");
- root = ArtifactRoot.asDerivedRoot(execRoot, scratch.dir("/exec/out"));
- }
-
- @Test
- public void testActionOutputs() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- assertThat(Artifact.toExecPaths(action.getOutputs()))
- .containsExactly("out/test/archive_member");
- }
-
- @Test
- public void testActionInputs() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- assertThat(Artifact.toExecPaths(action.getInputs())).containsExactly(
- "myArchive.zip",
- "archiveManifest.txt",
- "unzipBinary");
- }
-
- @Test
- public void testSpawnOutputs() throws Exception {
- PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
- Spawn spawn = action.createSpawn();
- Iterable<Artifact> outputs = actionInputsToArtifacts(spawn.getOutputFiles());
- assertThat(Artifact.toExecPaths(outputs))
- .containsExactly(
- "out/test/archive_member/archive_members/1.class",
- "out/test/archive_member/archive_members/2.class",
- "out/test/archive_member/archive_members/txt/text.txt");
- }
-
- @Test
- public void testSpawnInputs() throws Exception {
- PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
- Spawn spawn = action.createSpawn();
- Iterable<Artifact> inputs = actionInputsToArtifacts(spawn.getInputFiles());
- assertThat(Artifact.toExecPaths(inputs)).containsExactly(
- "myArchive.zip",
- "archiveManifest.txt",
- "unzipBinary");
- }
-
- @Test
- public void testSpawnArguments() throws Exception {
- PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
- BaseSpawn spawn = (BaseSpawn) action.createSpawn();
- assertThat(spawn.getArguments())
- .containsExactly(
- "unzipBinary",
- "x",
- "myArchive.zip",
- "-d",
- "out/test/archive_member",
- "@archiveManifest.txt")
- .inOrder();
- }
-
- @Test
- public void testTreeArtifactPopulated() throws Exception {
- ArrayList<Artifact> treefileArtifacts = new ArrayList<Artifact>();
- PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
- ActionExecutionContext executionContext = actionExecutionContext(treefileArtifacts);
- ActionResult actionResult = action.execute(executionContext);
-
- assertThat(actionResult.spawnResults()).isEmpty();
-
- assertThat(Artifact.toExecPaths(treefileArtifacts))
- .containsExactly(
- "out/test/archive_member/archive_members/1.class",
- "out/test/archive_member/archive_members/2.class",
- "out/test/archive_member/archive_members/txt/text.txt");
- }
-
- @Test
- public void testInvalidManifestEntryPaths() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- scratch.overwriteFile(
- "archiveManifest.txt",
- "archive_members/1.class",
- "../invalid_relative_path/myfile.class");
- ActionExecutionContext executionContext = actionExecutionContext(new ArrayList<Artifact>());
-
- try {
- action.execute(executionContext);
- fail("Invalid manifest entry paths, expected exception");
- } catch (ActionExecutionException e) {
- // Expect ActionExecutionException
- }
- }
-
- @Test
- public void testTreeFileArtifactPathPrefixConflicts() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- scratch.overwriteFile(
- "archiveManifest.txt",
- "archive_members/conflict",
- "archive_members/conflict/1.class");
- ActionExecutionContext executionContext = actionExecutionContext(new ArrayList<Artifact>());
-
- try {
- action.execute(executionContext);
- fail("Artifact path prefix conflicts, expected exception");
- } catch (ActionExecutionException e) {
- // Expect ActionExecutionException
- }
- }
-
- @Test
- public void testEmptyTreeArtifactInputAndOutput() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- scratch.overwriteFile("archiveManifest.txt", "");
-
- ArrayList<Artifact> treeFileArtifacts = new ArrayList<Artifact>();
- ActionExecutionContext executionContext = actionExecutionContext(treeFileArtifacts);
-
- ActionResult actionResult = action.execute(executionContext);
-
- assertThat(actionResult.spawnResults()).isEmpty();
- assertThat(treeFileArtifacts).isEmpty();
- }
-
- @Test
- public void testOutputTreeFileArtifactDirsCreated() throws Exception {
- Action action = createPopulateTreeArtifactAction();
- scratch.overwriteFile(
- "archiveManifest.txt",
- "archive_members/dirA/memberA",
- "archive_members/dirB/memberB");
-
- ArrayList<Artifact> treeFileArtifacts = new ArrayList<Artifact>();
- ActionExecutionContext executionContext = actionExecutionContext(treeFileArtifacts);
- ActionResult actionResult = action.execute(executionContext);
-
- assertThat(actionResult.spawnResults()).isEmpty();
-
- // We check whether the parent directory structures of output TreeFileArtifacts exist even
- // though the spawn is not executed (the SpawnActionContext is mocked out).
- assertThat(treeFileArtifacts).hasSize(2);
- for (Artifact treeFileArtifact : treeFileArtifacts) {
- assertThat(treeFileArtifact.getPath().getParentDirectory().exists()).isTrue();
- assertThat(treeFileArtifact.getPath().exists()).isFalse();
- }
- }
-
- private enum KeyAttributes {
- ARCHIVE,
- TREE_ARTIFACT,
- ARCHIVE_MANIFEST,
- ZIPPER
- }
-
- @Test
- public void testComputeKey() throws Exception {
- final Artifact archiveA = getSourceArtifact("myArchiveA.zip");
- final Artifact archiveB = getSourceArtifact("myArchiveB.zip");
- final SpecialArtifact treeArtifactToPopulateA = createTreeArtifact("testA/archive_member");
- final SpecialArtifact treeArtifactToPopulateB = createTreeArtifact("testB/archive_member");
- final Artifact archiveManifestA = getSourceArtifact("archiveManifestA.txt");
- final Artifact archiveManifestB = getSourceArtifact("archiveManifestB.txt");
- final FilesToRunProvider zipperA = FilesToRunProvider.fromSingleExecutableArtifact(
- getSourceArtifact("unzipBinaryA"));
- final FilesToRunProvider zipperB = FilesToRunProvider.fromSingleExecutableArtifact(
- getSourceArtifact("unzipBinaryB"));
-
- ActionTester.runTest(
- KeyAttributes.class,
- new ActionCombinationFactory<KeyAttributes>() {
- @Override
- public Action generate(ImmutableSet<KeyAttributes> attributesToFlip) {
- Artifact archive =
- attributesToFlip.contains(KeyAttributes.ARCHIVE) ? archiveA : archiveB;
- SpecialArtifact treeArtifactToPopulate =
- attributesToFlip.contains(KeyAttributes.TREE_ARTIFACT)
- ? treeArtifactToPopulateA
- : treeArtifactToPopulateB;
- Artifact archiveManifest =
- attributesToFlip.contains(KeyAttributes.ARCHIVE_MANIFEST)
- ? archiveManifestA
- : archiveManifestB;
- FilesToRunProvider zipper =
- attributesToFlip.contains(KeyAttributes.ZIPPER) ? zipperA : zipperB;
-
- return new PopulateTreeArtifactAction(
- ActionsTestUtil.NULL_ACTION_OWNER,
- archive,
- archiveManifest,
- treeArtifactToPopulate,
- zipper);
- }
- },
- actionKeyContext);
- }
-
- private PopulateTreeArtifactAction createPopulateTreeArtifactAction() throws Exception {
- Artifact archive = getSourceArtifact("myArchive.zip");
- SpecialArtifact treeArtifactToPopulate = createTreeArtifact("test/archive_member");
- Artifact archiveManifest = getSourceArtifact("archiveManifest.txt");
- FilesToRunProvider unzip = FilesToRunProvider.fromSingleExecutableArtifact(
- getSourceArtifact("unzipBinary"));
-
- scratch.file(
- "archiveManifest.txt",
- "archive_members/1.class",
- "archive_members/2.class",
- "archive_members/txt/text.txt");
-
- return new PopulateTreeArtifactAction(
- ActionsTestUtil.NULL_ACTION_OWNER,
- archive,
- archiveManifest,
- treeArtifactToPopulate,
- unzip);
- }
-
- private ActionExecutionContext actionExecutionContext(
- List<Artifact> storingExpandedTreeFileArtifacts) throws Exception {
- Executor executor =
- new TestExecutorBuilder(fileSystem, directories, null)
- .setExecution(PopulateTreeArtifactAction.MNEMONIC, mock(SpawnActionContext.class))
- .build();
-
- return new ActionExecutionContext(
- executor,
- null,
- ActionInputPrefetcher.NONE,
- actionKeyContext,
- new TestMetadataHandler(storingExpandedTreeFileArtifacts),
- null,
- ImmutableMap.<String, String>of(),
- null);
- }
-
- private SpecialArtifact createTreeArtifact(String rootRelativePath) {
- PathFragment relpath = PathFragment.create(rootRelativePath);
- return new SpecialArtifact(
- root,
- root.getExecPath().getRelative(relpath),
- ArtifactOwner.NullArtifactOwner.INSTANCE,
- SpecialArtifactType.TREE);
- }
-
- private Iterable<Artifact> actionInputsToArtifacts(Iterable<? extends ActionInput> files) {
- ImmutableList.Builder<Artifact> builder = ImmutableList.<Artifact>builder();
- for (ActionInput file : files) {
- builder.add((Artifact) file);
- }
- return builder.build();
- }
-}