aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-01-22 07:42:44 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-22 07:44:45 -0800
commit4c8fa1bab507fa7f0a1cbeac0724751d9b574f89 (patch)
tree37840fa46395b7c159630e83a1e5810f67c9b233 /src/main/java/com/google/devtools
parentd844e65ff333b1dc460ecb575c8ee42b670c54c4 (diff)
External repositories: support plain tar archives
Currently, we insist on all archives we download being compressed. But technically, there is no reason compression is needed; handling plain tar archives is no more complicated. So add that option as well; at the very least, it makes testing more easy. Change-Id: I1fddc95d5c80d195eb900ab74bf6403484f61da7 PiperOrigin-RevId: 182777193
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/TarFunction.java36
2 files changed, 39 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java
index 02df7137ec..924a8791c4 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java
@@ -55,6 +55,8 @@ public class DecompressorValue implements SkyValue {
String baseName = archivePath.getBaseName();
if (baseName.endsWith(".zip") || baseName.endsWith(".jar") || baseName.endsWith(".war")) {
return ZipDecompressor.INSTANCE;
+ } else if (baseName.endsWith(".tar")) {
+ return TarFunction.INSTANCE;
} else if (baseName.endsWith(".tar.gz") || baseName.endsWith(".tgz")) {
return TarGzFunction.INSTANCE;
} else if (baseName.endsWith(".tar.xz")) {
@@ -64,7 +66,7 @@ public class DecompressorValue implements SkyValue {
} else {
throw new RepositoryFunctionException(
new EvalException(null, String.format(
- "Expected a file with a .zip, .jar, .war, .tar.gz, .tgz, .tar.xz, or .tar.bz2 "
+ "Expected a file with a .zip, .jar, .war, .tar, .tar.gz, .tgz, .tar.xz, or .tar.bz2 "
+ "suffix (got %s)",
archivePath)),
Transience.PERSISTENT);
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/TarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/TarFunction.java
new file mode 100644
index 0000000000..e67f1ec1e1
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/TarFunction.java
@@ -0,0 +1,36 @@
+// Copyright 2015 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.bazel.repository;
+
+import com.google.devtools.build.lib.bazel.repository.DecompressorValue.Decompressor;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/** Creates a repository by unarchiving a plain .tar file. */
+public class TarFunction extends CompressedTarFunction {
+ public static final Decompressor INSTANCE = new TarFunction();
+ private static final int BUFFER_SIZE = 32 * 1024;
+
+ private TarFunction() {}
+
+ @Override
+ protected InputStream getDecompressorStream(DecompressorDescriptor descriptor)
+ throws IOException {
+ return new BufferedInputStream(
+ new FileInputStream(descriptor.archivePath().getPathFile()), BUFFER_SIZE);
+ }
+}