use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class UnpackedAars method getAarDir.
@Nullable
public File getAarDir(ArtifactLocationDecoder decoder, AarLibrary library) {
BlazeArtifact artifact = decoder.resolveOutput(library.aarArtifact);
String aarDirName = UnpackedAarUtils.getAarDirName(artifact);
return aarCache.getCachedAarDir(aarDirName);
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class UnpackedAars method getArtifactsToCache.
/**
* Returns a map from cache key to {@link AarLibraryContents}, for all the artifacts which should
* be cached.
*/
private static ImmutableMap<String, AarLibraryContents> getArtifactsToCache(ProjectViewSet projectViewSet, BlazeProjectData projectData) {
Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, projectData);
List<AarLibrary> aarLibraries = libraries.stream().filter(library -> library instanceof AarLibrary).map(library -> (AarLibrary) library).collect(Collectors.toList());
ArtifactLocationDecoder decoder = projectData.getArtifactLocationDecoder();
Map<String, AarLibraryContents> outputs = new HashMap<>();
for (AarLibrary library : aarLibraries) {
BlazeArtifact aar = decoder.resolveOutput(library.aarArtifact);
BlazeArtifact jar = library.libraryArtifact != null ? decoder.resolveOutput(library.libraryArtifact.jarForIntellijLibrary()) : null;
outputs.put(UnpackedAarUtils.getAarDirName(aar), AarLibraryContents.create(aar, jar));
}
return ImmutableMap.copyOf(outputs);
}
use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.
the class Unpacker method unpackAarToDir.
/**
* Each .aar file will be unpacked as <key_from_artifact_location>.aar directories in cache
* directory. A timestamp file will be created to decide if updated is needed when a new .aar file
* with same name is found next time.
*/
private static void unpackAarToDir(FileOperationProvider ops, AarLibraryContents aarAndJar, AarCache aarCache) {
String cacheKey = UnpackedAarUtils.getAarDirName(aarAndJar.aar());
try {
File aarDir = aarCache.recreateAarDir(ops, cacheKey);
// TODO(brendandouglas): decompress via ZipInputStream so we don't require a local file
File toCopy = getOrCreateLocalFile(aarAndJar.aar());
ZipUtil.extract(toCopy, aarDir, // which is more lightweight. But it's not applied to lint.jar
(dir, name) -> name.equals(FN_LINT_JAR) || !name.endsWith(".jar"));
BlazeArtifact aar = aarAndJar.aar();
try {
aarCache.createTimeStampFile(cacheKey, (aar instanceof LocalFileArtifact) ? ((LocalFileArtifact) aar).getFile() : null);
} catch (IOException e) {
logger.warn("Failed to set AAR cache timestamp for " + aar, e);
}
// copy merged jar
if (aarAndJar.jar() != null) {
try (InputStream stream = aarAndJar.jar().getInputStream()) {
Path destination = Paths.get(UnpackedAarUtils.getJarFile(aarDir).getPath());
ops.mkdirs(destination.getParent().toFile());
Files.copy(stream, destination, StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (IOException e) {
logger.warn(String.format("Failed to extract AAR %s to %s", aarAndJar.aar(), aarCache.aarDirForKey(cacheKey)), e);
}
}
Aggregations