Search in sources :

Example 11 with BlazeArtifact

use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.

the class BlazeXmlToTestEventsConverter method parseTestXml.

/**
 * Parse all test XML files from a single test target.
 */
private static ParsedTargetResults parseTestXml(Label label, Collection<BlazeTestResult> results) {
    List<BlazeArtifact> outputFiles = new ArrayList<>();
    results.forEach(result -> outputFiles.addAll(result.getOutputXmlFiles()));
    List<TestSuite> targetSuites = new ArrayList<>();
    for (BlazeArtifact file : outputFiles) {
        try (InputStream input = file.getInputStream()) {
            targetSuites.add(BlazeXmlSchema.parse(input));
        } catch (Exception e) {
        // ignore parsing errors -- most common cause is user cancellation, which we can't easily
        // recognize.
        }
    }
    return new ParsedTargetResults(label, results, outputFiles, targetSuites);
}
Also used : TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact)

Example 12 with BlazeArtifact

use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.

the class JarCache method repackageJars.

/**
 * Repackage jars when necessary to avoid package name conflict.
 */
private ImmutableList<ListenableFuture<?>> repackageJars(BlazeProjectData projectData, Collection<BlazeArtifact> updatedJars) {
    JarRepackager jarRepackager = JarRepackager.getInstance();
    FileOperationProvider ops = FileOperationProvider.getInstance();
    if (!jarRepackager.isEnabled()) {
        return ImmutableList.of();
    }
    return LintJarHelper.collectLintJarsArtifacts(projectData).stream().map(blazeArtifact -> FetchExecutor.EXECUTOR.submit(() -> {
        try {
            repackageJar(jarRepackager, blazeArtifact, file -> {
                // repackage a jar when it's just updated or never repackaged.
                if (updatedJars.contains(blazeArtifact)) {
                    return true;
                }
                File repackagedJar = new File(jarCacheFolderProvider.getJarCacheFolder(), jarRepackager.getRepackagePrefix() + file.getName());
                return ops.exists(file) && !ops.exists(repackagedJar);
            });
        } catch (IOException | InterruptedException e) {
            logger.warn(String.format("Failed to repackage artifact %s to %s", blazeArtifact, jarCacheFolderProvider.getJarCacheFolder().getPath()), e);
        }
    })).collect(toImmutableList());
}
Also used : Arrays(java.util.Arrays) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Map(java.util.Map) FileUtil(com.intellij.openapi.util.io.FileUtil) FileSizeScanner(com.google.idea.blaze.base.io.FileSizeScanner) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) Logger(com.intellij.openapi.diagnostic.Logger) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) 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) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) FetchExecutor(com.google.idea.blaze.base.prefetch.FetchExecutor) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) FileCacheDiffer(com.google.idea.blaze.base.filecache.FileCacheDiffer) HashMap(java.util.HashMap) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ImmutableList(com.google.common.collect.ImmutableList) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) BlazeJavaUserSettings(com.google.idea.blaze.java.settings.BlazeJavaUserSettings) Nullable(javax.annotation.Nullable) RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Files(java.nio.file.Files) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) SourceArtifact(com.google.idea.blaze.base.command.buildresult.SourceArtifact) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Paths(java.nio.file.Paths) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PathUtil(com.intellij.util.PathUtil) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) IOException(java.io.IOException) File(java.io.File)

Example 13 with BlazeArtifact

use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.

the class JarCache method getCachedSourceJar.

/**
 * Gets the cached file for a source jar. If it doesn't exist, we return the file from the
 * library, or null if that also can't be accessed locally.
 */
@Nullable
public File getCachedSourceJar(ArtifactLocationDecoder decoder, ArtifactLocation sourceJar) {
    boolean enabled = isEnabled();
    BlazeArtifact artifact = decoder.resolveOutput(sourceJar);
    if (!enabled) {
        return getFallbackFile(artifact);
    }
    String cacheKey = cacheKeyForSourceJar(artifact);
    return getCacheFile(cacheKey).orElseGet(() -> getFallbackFile(artifact));
}
Also used : BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) Nullable(javax.annotation.Nullable)

Example 14 with BlazeArtifact

use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.

the class RenderJarCache method getCachedJarForBinaryTarget.

/**
 * Returns the RenderJAR corresponding to {@code target} or null if no RenderJAR corresponding to
 * {@code target} exists in cache.
 */
@Nullable
public File getCachedJarForBinaryTarget(ArtifactLocationDecoder artifactLocationDecoder, TargetIdeInfo target) {
    if (!RenderJarClassFileFinder.isEnabled()) {
        return null;
    }
    AndroidIdeInfo androidIdeInfo = target.getAndroidIdeInfo();
    if (androidIdeInfo == null) {
        return null;
    }
    ArtifactLocation jarArtifactLocation = androidIdeInfo.getRenderResolveJar();
    if (jarArtifactLocation == null) {
        return null;
    }
    BlazeArtifact jarArtifact = artifactLocationDecoder.resolveOutput(jarArtifactLocation);
    if (!(jarArtifact instanceof OutputArtifact)) {
        Logger.getInstance(RenderJarCache.class).warn("Unexpected render jar that is not an OutputArtifact: " + jarArtifactLocation);
        return null;
    }
    Path jarPath = artifactCache.get((OutputArtifact) jarArtifact);
    return jarPath == null ? null : jarPath.toFile();
}
Also used : Path(java.nio.file.Path) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with BlazeArtifact

use of com.google.idea.blaze.base.command.buildresult.BlazeArtifact in project intellij by bazelbuild.

the class UnpackedAars method getClassJar.

/**
 * Returns the merged jar derived from an AAR, in the unpacked AAR directory.
 */
@Nullable
public File getClassJar(ArtifactLocationDecoder decoder, AarLibrary library) {
    if (library.libraryArtifact == null) {
        return null;
    }
    BlazeArtifact jar = decoder.resolveOutput(library.libraryArtifact.jarForIntellijLibrary());
    if (aarCache.isEmpty()) {
        logger.warn("Cache state is empty");
        return getFallbackFile(jar);
    }
    BlazeArtifact aar = decoder.resolveOutput(library.aarArtifact);
    File aarDir = getAarDir(decoder, library);
    // check if it was actually cached
    if (aarDir == null) {
        // cannot find any fallback file.
        if (jar instanceof RemoteOutputArtifact) {
            logger.warn(String.format("Fail to look up %s from cache state for library [aarArtifact = %s, jar = %s]", aarDir, aar, jar));
            logger.debug("Cache state contains the following keys: " + aarCache.getCachedKeys());
        }
        return getFallbackFile(jar);
    }
    return UnpackedAarUtils.getJarFile(aarDir);
}
Also used : RemoteOutputArtifact(com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) File(java.io.File) Nullable(javax.annotation.Nullable)

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