Search in sources :

Example 16 with BlazeArtifact

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);
}
Also used : BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) Nullable(javax.annotation.Nullable)

Example 17 with BlazeArtifact

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);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) FileCacheDiffer(com.google.idea.blaze.base.filecache.FileCacheDiffer) HashMap(java.util.HashMap) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) HashSet(java.util.HashSet) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) Map(java.util.Map) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) Project(com.intellij.openapi.project.Project) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) Collection(java.util.Collection) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Set(java.util.Set) IOException(java.io.IOException) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) ExecutionException(java.util.concurrent.ExecutionException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) RemoteOutputArtifact(com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) SyncMode(com.google.idea.blaze.base.sync.SyncMode) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) HashMap(java.util.HashMap) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 18 with BlazeArtifact

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);
    }
}
Also used : Path(java.nio.file.Path) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) InputStream(java.io.InputStream) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) IOException(java.io.IOException) File(java.io.File)

Aggregations

BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)18 File (java.io.File)11 Nullable (javax.annotation.Nullable)10 IOException (java.io.IOException)9 Map (java.util.Map)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 LocalFileArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact)7 InputStream (java.io.InputStream)7 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)6 Futures (com.google.common.util.concurrent.Futures)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)6 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)6 RemoteOutputArtifact (com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact)6 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)6 RemoteArtifactPrefetcher (com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher)6 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)6 EventType (com.google.idea.blaze.base.scope.scopes.TimingScope.EventType)6 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)6 Logger (com.intellij.openapi.diagnostic.Logger)6